Skip to content

Instantly share code, notes, and snippets.

View lambda-fairy's full-sized avatar

Chris Wong lambda-fairy

View GitHub Profile
@lambda-fairy
lambda-fairy / gist:3445830
Last active October 9, 2015 05:27
Aqua programming language

TODO

  • Exceptions
  • Delimited continuations, because continuations are cool.
  • Macros (maybe)
  • Attribute lookup – lenses?
  • Keyword parameters
    • [GHC implicit parameters][] are interesting
@lambda-fairy
lambda-fairy / Birthday.hs
Created July 22, 2012 04:57
Birthday paradox calculator
-- | Birthday paradox calculator
import Control.Monad
import Data.Ratio
import System.Environment
import Text.Printf
birthday :: Fractional a => Integer -> Integer -> a
birthday days n = realToFrac $ 1 - inverse
where
@lambda-fairy
lambda-fairy / kol.js
Created June 26, 2012 06:44
KoL auto-adventure script
javascript:
var frm = window.frames[2];
function next(f) {
setTimeout(f, 100);
}
function doClick(elem) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
elem.dispatchEvent(evt);
}
@lambda-fairy
lambda-fairy / SaveRestore.hs
Created June 6, 2012 00:28
Set options temporarily - useful with Network.HTTP.Conduit.Browser
import qualified Control.Exception.Lifted as Lifted
import Control.Monad.Trans.Control
-- | Set an option, run an action, then restore the option to its
-- previous value.
--
-- @saveRestore get set value action@ is roughly equivalent to:
--
-- > do orig <- get
-- > set value
@lambda-fairy
lambda-fairy / Fold.hs
Created May 27, 2012 07:44
Data.List.Fold - fold lists in constant space
-- | Lock-step folding.
--
-- This module presents an elegant way of executing multiple left folds
-- on one list using constant memory. For example, the mean can be
-- expressed as:
--
-- @
-- average = foldLeft $ (/) <$> sumF <*> lengthF
-- @
@lambda-fairy
lambda-fairy / Soctopus.hs
Created May 22, 2012 01:17
Soctopus Prediction
-- | <http://ncss.edu.au/challenge/ncss_challenge_2012.pdf>
class Semigroup a where
(<>) :: a -> a -> a
data Result = Team String | Draw Int
resultLength :: Result -> Int
resultLength (Team name) = length name
resultLength (Draw lgth) = lgth