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
// One note before we start: if the inhabitants of Value are a closed set, | |
// then making Value an enum is going to be a clearer model than using a | |
// protocol like this. I'm assuming you need to be able to retroactively add | |
// new members of Value. | |
// Can't use Equatable directly because of its Self requirement. | |
protocol HeteroEquatable { | |
func isEqualTo(value: HeteroEquatable) -> Bool | |
} |
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 Data.Array (Array, array, (!)) | |
deckSize = 52 | |
eachColor = 26 | |
-- Some convenience types: | |
type History = (Int, Int) -- # of red cards seen, # of black cards seen | |
data Choice = Stop | Continue deriving (Show, Eq) | |
data Decision = Decision { choice :: Choice, expectedWin :: Double } deriving (Show, Eq) |
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
# Suppose I want to the user to enter names one at a time, until the user enters a blank line, | |
# then tell each name that they're awesome. | |
# Yeah, I don't have really a better way of doing that, and that bothers me. I'd do: | |
a = [] | |
until (str = gets.chomp?).empty? | |
a << str | |
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
# In Ruby, every expression (even ifs) has a value! | |
print 'What is your name? ' | |
name = gets.chomp | |
name_response = if name == 'Suzanne' | |
then 'Oh man, ' + name + ' you are awesome' | |
else 'You, ' + name + ', are not nearly as cool as Suzanne.' | |
end | |
print name_response |
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
qsort [] = [] | |
qsort (x:xs) = qsort less ++ [x] ++ qsort more | |
where less = filter (<x) xs | |
more = filter (>=x) xs |
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
module Main where | |
import qualified Data.Set as Set | |
import qualified Data.Heap as Heap | |
import qualified Data.IntMap as IntMap | |
import Data.List | |
import Control.Monad | |
import Maybe | |
import System.Environment (getArgs) | |
import System.Process |
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
# What's wrong with List's "insert" method if called from multiple threads? | |
# How would you fix it? | |
class Node: | |
def __init__(self, value): | |
self.value = value | |
self.next = None | |
class List: | |
def __init__(self): |
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
# | |
# uncrustify config file for objective-c and objective-c++ | |
# | |
indent_with_tabs = 0 # 1=indent to level only, 2=indent with tabs | |
output_tab_size = 4 # new tab size | |
indent_columns = output_tab_size | |
indent_label = 2 # pos: absolute col, neg: relative column | |
indent_align_assign = FALSE |
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
type Call = Call { funcName :: String, | |
funcParams :: [Integer] } | |
parser :: Parser Call | |
parser = do | |
name <- ident | |
params <- commaSep integer | |
return (Call name params) |
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
Salad of braised leek, persimmon, prosciutto, pine nuts, and parmesan, with a sherry vinaigrette | |
Spiced sous vide duck breast, roasted butternut squash, orange confit, sauteed oyster mushrooms | |
Marinated idiazábal, olives, roasted almonds | |
Gingerbread cookie + caramel ice cream sandwiches, poached pears with vanilla compote |