This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def profile(label=nil, unit = :M) | |
| # trying to see where our memory is going | |
| population = Hash.new{|h,k| h[k] = [0,0]} | |
| array_sizes = Hash.new{|h,k| h[k] = 0} | |
| ObjectSpace.each_object do |object| | |
| # rough estimates, see http://eigenclass.org/hiki.rb?ruby+space+overhead | |
| size = case object | |
| when Array | |
| array_sizes[object.size / 10] += 1 | |
| case object.size |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 3 buckets, series, products, prices | |
| Each price links to a series and a product using tags in_series and for_product | |
| My map reduce query gets a single series as an entry point and must find the prices which point to it and then aggregate them with respect to their products. | |
| Price ---in_series---> Series | |
| Price ---for_product--->Product | |
| M/R Phases: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function(global) { | |
| function Shoes() { | |
| this.version = '0.0.0'; | |
| this.release = 'Haste'; | |
| this.canvas = null; | |
| this.context = null; | |
| } | |
| Shoes.prototype.app = function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Data.Typeable(Typeable) | |
| import Data.Data (Data ) | |
| import qualified System.Console.CmdArgs as Arg | |
| import System.Console.CmdArgs((+=),Annotate((:=)),(&=), def, opt, help) | |
| data Mode | |
| = English { name :: String } | |
| | Spanish { name :: String } | |
| deriving (Show, Typeable, Data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE DeriveDataTypeable #-} | |
| import Text.JSON | |
| import Text.JSON.Generic | |
| import Control.Monad (liftM2) | |
| data Foo = Foo { name :: String } deriving (Eq, Show, Typeable, Data) | |
| data FooSet = FooSet { foos :: [(String, Foo)]} deriving (Eq, Show) | |
| -- Input data looks like |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE OverloadedStrings #-} | |
| import Control.Monad | |
| import Control.Applicative | |
| import Data.Aeson | |
| import Data.Maybe | |
| import Data.ByteString as BS (readFile, ByteString(..)) | |
| import Data.Attoparsec (parse, maybeResult, eitherResult) | |
| main :: IO () | |
| main = do str <- BS.readFile "sample.json" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'nokogiri' | |
| XML_FILE = 'profiles.xml' | |
| INTERVAL = 60 | |
| def randomize(hash) | |
| %w[Contrast_Green Contrast_Red Contrast_Blue].each do |k| | |
| hash[k] = rand(255) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Main (main) where | |
| {-# Language Overloaded Strings #-} | |
| import Control.Exception.Base (SomeException) | |
| import Data.Aeson (Object) | |
| import Data.Aeson.Encode (encode) | |
| import Data.Aeson.Types (Value(String)) | |
| import Data.ByteString (ByteString) | |
| import qualified Data.ByteString.Lazy as LBS (putStr) | |
| import Data.CSV.Enumerator |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Input: | |
| # choices = { | |
| # 'color' => %w(blue red green), | |
| # 'sizes' => %w(small medium large extra-large), | |
| # 'style' => %w(tshirt longsleeve) | |
| # } | |
| # | |
| # Output: | |
| # [{"sizes"=>"small", "color"=>"blue", "style"=>"tshirt"}, | |
| # {"sizes"=>"small", "color"=>"blue", "style"=>"longsleeve"}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Buffer | |
| attr_reader :size, :contents | |
| def initialize(size, &block) | |
| @size = size | |
| @contents = [] | |
| @callback = block | |
| end | |
| def <<(item) | |
| @contents << item |