Skip to content

Instantly share code, notes, and snippets.

View steshaw's full-sized avatar
👨‍💻
Loves programming languages

Steven Shaw steshaw

👨‍💻
Loves programming languages
View GitHub Profile
#!/bin/bash
set -eu
source <(HALCYON_NO_SELF_UPDATE=1 /app/halcyon/halcyon paths)
HALCYON_NO_SELF_UPDATE=1 /app/halcyon/halcyon install \
--ghc-version=7.10.1 \
--app-no-strip
@steshaw
steshaw / gist:bcea5f2471497995191f
Last active August 29, 2015 14:20
Nix output from `cabal configure`
$ cabal2nix --shell . >shell.nix
$ nix-shell -I ~ --command 'cabal configure'
these derivations will be built:
/nix/store/rbij827rx40bgs6122b2n929b79z0rgy-ghc-7.10.1.drv
building path(s) ‘/nix/store/957j0j7a51xzi3bbl8ym11ha7gkg5jz8-ghc-7.10.1’
created 481 symlinks in user environment
There are problems in package conduit-extra-1.1.7.3:
dependency "attoparsec-0.12.1.6-2dceb091855fa2d2aff2ca4101afc493" doesn't exist
dependency "text-1.2.0.4-98506efb1b9ada233bb5c2b2db516d91" doesn't exist
There are problems in package hakyll-4.6.8.1:
@steshaw
steshaw / winning.js
Created May 12, 2015 00:12
Continous Winning "process diagram"
function work(workQ) {
task, workQ_ ← pop(workQ)
do(task)
work(workQ_)
}
work(workQ)
@steshaw
steshaw / modern.zsh
Created May 12, 2015 13:11
Using [[ ]] in shell
#!/usr/bin/env zsh
set -eu
unset FOO
if [[ ${FOO:-} == 'hi' ]]; then
echo "It is 'hi'"
fi
if [[ ${FOO:-} == '' ]]; then
@steshaw
steshaw / email.md
Last active August 29, 2015 14:21
perspectives on streams performance

In order to get the full benefit from JDK 8 streams we will need to make them optimize fully. Here are a few thoughts about that.

I think of streams as a more concise and orderly replacement of classic "for" loops. Every stream can be rewritten as one or more for-loops, at the cost of verbosity and commitment to hard-coding optimizations (like FJ).

A classic "for" loop is a external iterator notation: The iteration machinery is outside of (lexically around) the data structure access. This notation is at least as old as Fortran. Streams are an internal iteration notation: The iteration machinery (crucially, the looping part of the algorithm) is inside the data structure, and only the loop body appears in the user code (as a lambda). This notation is also old, found in Lisp and Smalltalk.

External iterators are easier to optimize, because their crucial iteration logic is always

class Hash
def safe_invert
lazy
.map {|a, b| [b, a]}
.group_by {|a| a[0]}
.map {|a, b| [a, b.collect {|c| c[1]}]}
.to_h
end
end
@steshaw
steshaw / munge-wordpress.hs
Last active August 29, 2015 14:21
Munging script to process urls (one per line) into a CSV file with the mapping from old url to new one (for Disqus url mapping)
#!/usr/bin/env runhaskell
import Data.List (stripPrefix, intercalate)
main = do
contents <- getContents
mapM_ munge $ lines contents
munge :: String -> IO ()
munge url = case stripPrefix "https://steshaw.wordpress.com" url of
@steshaw
steshaw / munge-posts.hs
Created May 19, 2015 07:09
Munge post urls into a CSV format suitable for Disqus url mapping tool
#!/usr/bin/env runhaskell-sandbox parsec
import Data.List (stripPrefix, intercalate)
import Text.Parsec
import Text.Parsec.Char
import Debug.Trace
main = do
contents <- getContents
let ls = lines contents
@steshaw
steshaw / huttons-razor.hs
Last active August 29, 2015 14:21
Simple interpreter for integer constants and addition
import System.Environment (getArgs)
import Control.Monad (forM_)
import Text.ParserCombinators.Parsec (spaces, char, chainl1, runParser)
import Text.ParserCombinators.Parsec.Number (int)
infixOp = do
spaces
char '+'
spaces
return (+)
@steshaw
steshaw / lambda-pi.hs
Created May 26, 2015 03:59
Grab unicode characters
Prelude> putStrLn "\x03bb\x03a0"
λΠ