This file contains 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
safeHead :: [a] -> Maybe a | |
safeHead [] = Nothing | |
safeHead (x:xs) = Just x | |
safeDiv :: Int -> Int -> Maybe Int | |
safeDiv _ 0 = Nothing | |
safeDiv x y = Just (div x y) | |
divideHeads :: [Int] -> [Int] -> Maybe Int | |
divideHeads xs ys = do |
This file contains 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
enum Status { | |
Pending, | |
PaymentReceived, | |
Shipped | |
} | |
class EnumConverter<E> { | |
toEnum(orig : string) : E { | |
return this.enumMap()[orig]; | |
} |
This file contains 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.List (sort) | |
import System.Environment (getArgs) | |
main = do (inFile:outFile:_) <- getArgs | |
writeFile outFile . unlines . sort . lines =<< readFile inFile |
This file contains 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
source "http://rubygems.org" | |
gem "guard-shell" | |
gem "rake" |
This file contains 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 'sinatra' | |
require 'pp' | |
delete '/' do | |
"you DELETED: #{request.body.string}" | |
end | |
put '/' do | |
"you PUTTED: #{request.body.string}" | |
end |
This file contains 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 #-} | |
module Main (main) where | |
import Network.Http.Client | |
main :: IO () | |
main = get ("http://localhost:4568/") printStatus | |
-- prints the status then hangs forever | |
where printStatus resp stream = print $ getStatusCode resp |
This file contains 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
# is this the best way to do it? | |
# in this way, each method must raise if something goes wrong, | |
# but this behavior isn't necessarily exceptional. composed_method | |
# uses this exception for control flow because its contract is that | |
# it returns true on success, false on failure. | |
# I've cargo culted the phrase "don't use exceptions for control flow" but I realize I don't know why... | |
def composed_method | |
frobulate_widgets | |
refrobulate_widgets | |
confribulate_frobulations |
This file contains 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
Connecting to database specified by database.yml [1286/9658] | |
Starting the New Relic Agent. | |
NewRelic Agent Developer Mode enabled. | |
To view performance information, go to http://localhost:3000/newrelic | |
Installed New Relic Browser Monitoring middleware | |
(0.3ms) BEGIN | |
ProductType Load (35.7ms) SELECT `product_types`.* FROM `product_types` WHERE `product_types`.`name` = 'Music' LIMIT 1 | |
Category Load (0.6ms) SELECT `categories`.* FROM `categories` WHERE `categories`.`name` = 'Music' LIMIT 1 | |
Descriptor Load (0.3ms) SELECT `descriptors`.* FROM `descriptors` WHERE `descriptors`.`product_type_id` = 1 AND `descriptors`.`name` = 'Discogs ID' ORDER BY name LIMIT 1 | |
Descriptor Load (0.4ms) SELECT `descriptors`.* FROM `descriptors` WHERE `descriptors`.`product_type_id` = 1 AND `descriptors`.`name` = 'Artists' ORDER BY name LIMIT 1 |
This file contains 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 'celluloid' | |
require 'stringio' | |
class Producer | |
include Celluloid | |
include Celluloid::Notifications | |
attr_reader :io, :next_pool | |
def initialize(io, next_pool) |
This file contains 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 'celluloid' | |
require './lib/discog_downloader/product' | |
module DiscogDownloader | |
class Converter | |
include Celluloid | |
def initialize(queue) | |
@queue = queue | |
end |