Skip to content

Instantly share code, notes, and snippets.

View thumphries's full-sized avatar

Tim Humphries thumphries

View GitHub Profile
build/
node_modules/
@thumphries
thumphries / client.hs
Last active May 11, 2018 04:17
Example of a redirect vulnerability
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
import Control.Applicative
import Control.Lens
import Control.Monad
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy as BSL
import qualified Data.IORef as IORef
@thumphries
thumphries / Getting.hs
Created October 4, 2017 12:38
Simulating first-class patterns by combining prisms into `Getting First`
{-# LANGUAGE TemplateHaskell #-}
module Lens where
import Control.Lens
import Data.Monoid (First, (<>))
data FooBar =
Foo (Either Int Bool)
| Bar (Maybe Bool)
@thumphries
thumphries / xdefaults2iterm.pl
Created October 8, 2012 03:27
Convert your terminal colours / Xdefaults to iTerm2 color scheme
#!/usr/bin/perl -w
# Convert .Xdefaults or similar terminal colors to iTerm2 scheme
# Only supports simple hex colors, no funny stuff
use strict;
print <<eof;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@thumphries
thumphries / Bench.hs
Created August 24, 2017 05:56
Demonstration of SIMD performance gap
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as B8
import Criterion.Main
import Criterion.Types (Config (..))
import qualified Mystery
@thumphries
thumphries / Dockerfile-7.10.3
Last active July 6, 2016 13:12
ghc-musl bootstrapping
FROM alpine:latest
COPY build.mk /tmp/
RUN apk add --update curl xz alpine-sdk perl gmp-dev file gmp openssh openssl zlib-dev strace vim less jq ncurses-dev bash autoconf
RUN cd /tmp && \
wget http://ghc-musl-dist-apse2.s3-website-ap-southeast-2.amazonaws.com/ghc-7.8.4/ghc-7.8.4-x86_64-unknown-linux.tar.bz2 && \
tar xvf ghc*.tar.bz2 && \
cd ghc-7.8.4 && \
@thumphries
thumphries / ghc-cross-linux-darwin.md
Created June 2, 2016 00:54
GHC cross-compilation

Notes on cross-compiling GHC for a Darwin target.

TL;DR I managed to get most of a stage1 to build. I got a linker failure during ghc-prim, but most of the libraries had already built successfully, including some C FFI-heavy packages like bytestring. I suspect my toolchain was just in the wrong spot, and/or libraries misconfigured.

  • We need a normal host GCC toolchain (build-essential), autoconf, happy, alex, and a platform copy of GHC (the Stage0).
  • As per the GHC CrossCompiling page on Trac, we need a GCC crosschain. I used osxcross.
@thumphries
thumphries / quickstart.md
Last active April 26, 2016 23:55
Mafia quick start

Mafia Quick Start

Mafia is a wrapper for cabal-install that eliminates most of the pain points, without the need for a blessed set of packages.

Install, use, upgrade

Put the wrapper script somewhere on your path:

cd $HOME/bin &amp;&amp; wget https://raw.githubusercontent.com/ambiata/mafia/master/script/mafia
@thumphries
thumphries / ckill
Created January 27, 2013 15:51
cocoa kill - useful for killing Mac OS X GUI applications. (Use with care!)
#!/bin/sh
if [ -z $1 ]; then echo "$0: Please supply a label"; exit 1; fi
launchctl list | grep -i "$1" | cut -f1 | grep -ve "^-" | xargs kill
@thumphries
thumphries / loadavg.c
Created October 9, 2012 02:12
proper load average binary for OS X / BSD
// loadavg.c
// Simple load average spewer for BSDs and Mac OS X
// tim at utf8.me
// (Why is there no system binary for this?)
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
double loads[3] = {0};