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
# put this in your .bashrc | |
PROMPT_COMMAND=__prompt_command | |
__prompt_command() { | |
local LAST_EXIT="$?" | |
PS1="" | |
local RED='\[\e[31m\]' | |
local GREEN='\[\e[01;32m\]' | |
local BLUE='\[\e[01;34m\]' |
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 System.IO (hFlush, stdout) | |
-- Should have 366 entries with probability of being born on each day, but here's a smaller example | |
-- with just 7 days (let's say they're the probability of being born on each day of the week) | |
distribution :: [Double] | |
distribution = [0.1, 0.1, 0.2, 0.0, 0.3, 0.1, 0.2] | |
medianIndex :: [Double] -> Int | |
medianIndex xs = length . takeWhile (< half) $ scanl1 (+) xs | |
where half = sum xs / 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
{-# LANGUAGE QuasiQuotes, TemplateHaskell, TypeFamilies #-} | |
{-# LANGUAGE OverloadedStrings, GADTs #-} | |
import Data.Text (Text) | |
import Data.Time (UTCTime) | |
import Database.Persist | |
import Database.Persist.Sqlite (runSqlite, runMigration) | |
import Database.Persist.TH (mkPersist, persistLowerCase, sqlSettings) | |
mkPersist sqlSettings [persistLowerCase| |
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 BangPatterns #-} | |
import System.Random | |
shuffle :: [a] -> Int -> IO [a] | |
shuffle xs 1 = return xs | |
shuffle !xs !k = do | |
i <- getStdRandom (randomR (0 , k - 1)) | |
shuffle (sswap i k xs) (k - 1) |
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 Array where | |
import qualified Data.IntMap as M | |
import {-# SOURCE #-} Object | |
data Array = Array | |
{ _map :: M.IntMap Value | |
} | |
a ! i {- | i >= baseLength ai -} = maybe vnil id $ M.lookup i (_map 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
{-# LANGUAGE RebindableSyntax #-} | |
import Prelude | |
data Height = Tall | Short | |
class IfThenElse b where | |
ifThenElse :: b -> a -> a -> a | |
instance IfThenElse Bool where |
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 | |
import Data.Char | |
import System.Directory | |
import System.Exit | |
import System.IO | |
import System.Process | |
program = "main=print$(\\xx@2012->xx)2012\n" | |
alphabet = [chr 32 .. chr 126] |
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.Generics | |
import Language.Haskell.Parser | |
import Language.Haskell.Pretty | |
import Language.Haskell.Syntax | |
main = do | |
input <- getContents | |
case parseModule input of | |
ParseOk mod -> putStrLn $ prettyPrint $ everywhere (mkT desugarExp) mod | |
ParseFailed loc msg -> failed loc msg |
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 Rank2Types #-} | |
module Church where | |
import Prelude (error) | |
type Bool = forall a. a -> a -> a | |
true, false :: Bool | |
true x _ = x |
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 parent(i): | |
return i/2 | |
def left(i): | |
return 2*i | |
def right(i): | |
return 2*i+1 | |
def heapify_cost(n, i): |
NewerOlder