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 Control.Monad (guard) | |
| double :: Int -> Int | |
| double = (2 *) | |
| add_two :: Int -> Int | |
| add_two = (2 +) | |
| halve :: Int -> Int | |
| halve n = n `div` 2 |
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
| mport Sound.Tomato.Speakers | |
| sound freq duration = withSpeakers sampleRate 128 $ \s -> playSamples s sound | |
| where | |
| sampleRate = 22050 | |
| dt = 1 / sampleRate -- time in seconds of a single sample | |
| sound = take (ceiling $ duration / dt) | |
| $ map (0.3*) $ sine freq | |
| sine freq = [sin (2*pi*freq*dt*fromIntegral t) | t <- [0..]] |
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
| data EUR | |
| data USD | |
| data Amount a = Amount Float deriving Show | |
| eur :: Float -> Amount EUR | |
| eur a = Amount a | |
| usd :: Float -> Amount USD | |
| usd a = Amount a |
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
| fizz = cycle ["", "", "fizz"] | |
| buzz = cycle ["", "", "", "", "buzz"] | |
| numbers = map show [1..] | |
| combine "" "" number = number | |
| combine "fizz" "buzz" _ = "Fizz buzz!" | |
| combine "fizz" _ _ = "Fizz!" | |
| combine _ "buzz" _ = "Buzz!" | |
| fizzbuzz = zipWith3 combine fizz buzz numbers |
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
| #!/bin/bash | |
| kbd=`setxkbmap -query | grep layout | awk '{print $2}'` | |
| if [ 'fr' = $kbd ] | |
| then | |
| notify-send 'Keyboard is now Dvorak' | |
| setxkbmap dvorak en -option compose:ralt | |
| else | |
| notify-send 'Keyboard is now French' |
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 find(d, key): | |
| if key in d: | |
| yield d[key] | |
| for c in d.get('children', []): | |
| for e in find(c, key): yield e |
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 'net/http' | |
| require 'uri' | |
| require 'json' | |
| def github(*list) | |
| URI('https://api.github.com/' + list.join('/')) | |
| end | |
| def get(uri) | |
| request = Net::HTTP::Get.new uri.request_uri |
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
| bin | |
| local | |
| include | |
| lib | |
| man | |
| .Python | |
| *.pyc | |
| *.swp |
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
| from exceptions import Exception | |
| def is_valid(model, instance): | |
| missing_fields = set(model) - set(instance) | |
| if missing_fields: | |
| raise MissingFields(missing_fields) | |
| missing_types = set(instance) - set(model) | |
| if missing_types: | |
| raise MissingTypes(missing_types) | |
| type_errors = [(k, model[k], type(v)) for (k, v) in instance.items() if type(v) is not model[k]] |
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
| foldlmap :: (a -> b) -> [a] -> [b] | |
| foldlmap f = foldl (\ a b -> a ++ [f b]) [] | |
| foldrmap :: (a -> b) -> [a] -> [b] | |
| foldrmap f = foldr (\ a b -> (f a) : b) [] | |
| main :: IO () | |
| main = do |