Skip to content

Instantly share code, notes, and snippets.

import qualified Data.Map.Strict as M
import Data.List (foldl', sortOn)
-- functors and bind to the rescue!
main :: IO ()
main = fmap countWords getContents >>= putStrLn . show
countWords :: String -> [(String,Integer)]
countWords = sortOn snd . M.toList . foldl' (\m w -> M.insertWith (+) w 1 m) M.empty . words
@rlupton20
rlupton20 / Some tests for sillyEmbed.hs
Last active October 16, 2015 17:02
Tests for monadic reactimate
-- Opening sillyEmbed.hs in ghci (with cabal repl in a sandbox),
-- we can try the following.
-- Integration test
steps = take 10000 $ repeat 0.0001
totTime = scanl (+) 0 steps
inp = zip steps (map Just $ map sin totTime)
-- Compare
embedTest = last $ sillyEmbed integral (0, inp)
-- and the analytic value
@rlupton20
rlupton20 / YampaUtils.hs
Created October 13, 2015 20:32
reactimate simplifications for Yampa
module YampaUtils
( yampaMain, sReactimate ) where
import FRP.Yampa as Y
import Data.Time.Clock.POSIX
import Data.IORef
sReactimate :: IO a -> IO (DTime, Maybe a) -> (b -> IO Bool) -> SF a b -> IO ()
sReactimate init inp out sigFun = Y.reactimate init (sInput inp) (sOutput out) sigFun
where sInput inp _ = inp
@rlupton20
rlupton20 / python_resources.md
Last active August 29, 2015 14:27 — forked from jookyboi/python_resources.md
Python-related modules and guides.

Packages

  • lxml - Pythonic binding for the C libraries libxml2 and libxslt.
  • boto - Python interface to Amazon Web Services
  • Django - Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.
  • Fabric - Library and command-line tool for streamlining the use of SSH for application deployment or systems administration task.
  • PyMongo - Tools for working with MongoDB, and is the recommended way to work with MongoDB from Python.
  • Celery - Task queue to distribute work across threads or machines.
  • pytz - pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher.

Guides

@rlupton20
rlupton20 / 0_reuse_code.js
Last active August 29, 2015 14:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console