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
#!/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
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
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
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
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
let push : float list -> string -> float list = | |
fun stack input -> match stack, input with | |
| (b::a::rest), "+" -> a +. b::rest | |
| (b::a::rest), "-" -> a -. b::rest | |
| (b::a::rest), "*" -> a *. b::rest | |
| (b::a::rest), "/" -> a /. b::rest | |
| rest, number -> (float_of_string number)::rest | |
let polish_eval : string -> float = | |
fun input -> |
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 #-} | |
module Main where | |
import Control.Applicative | |
import Snap.Core | |
import Snap.Util.FileServe | |
import Snap.Http.Server | |
import Data.Monoid (mconcat) | |
import Blaze.ByteString.Builder.Char8 | |
import Blaze.ByteString.Builder |
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
var create = function (proto) { | |
var F = function () {}; | |
F.prototype = proto; | |
return new F(); | |
}; | |
var Point = {}; | |
Point.initialize = function (x, y) { | |
this.x = x; | |
this.y = y; |
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 qualified Data.ByteString.Lazy as LBS | |
import qualified Data.Text as Text | |
import Data.Text (Text) | |
import Data.Aeson (encode, decode, Value, Value(..)) | |
import qualified Data.HashMap.Strict as HashMap | |
import Data.Vector ((!)) | |
path :: Text -> Value -> Value |