Skip to content

Instantly share code, notes, and snippets.

module Data.List.Permute where
permute :: [a] -> [[a]]
permute [] = [[]]
permute xs = let picks = pick xs
f (x, xs') = map (x:) (permute xs')
in concatMap f picks
pick :: [a] -> [(a, [a])]
pick [] = []
module Data.Tree where
import Data.List (sortBy)
import Data.Ord (comparing)
data Tree a = Tip | Node a (Tree a) (Tree a)
deriving (Show, Eq)
-- x, y
type Coords = (Int, Int)
@queertypes
queertypes / Why.java
Last active March 30, 2016 19:43
Comparing Java class definition styles
///////////////////////////////////////////////////////////
// shortest: immutable data container with public data //
///////////////////////////////////////////////////////////
public class Contact {
public final Name name;
public final Address address;
public final PhoneNumber phoneNumber;
public final Email email;
public Contact(Name n, Address a, PhoneNumber p, Email em) {

From zero to microservice with 𝚫 now

The following guide will show you how to deploy a simple microservice written in JavaScript using 𝚫 now.

It uses Open Source tools that are widely available, tested and understood:

  • Node.JS
  • NPM
  • Express
import java.util.*;
class MapDiff {
public static void main(String[] args) {
Map<String, Integer> m1 = new HashMap<String, Integer>();
m1.put("a", 1);
m1.put("b", 2);
m1.put("c", 3);
Map<String, Integer> m2 = new HashMap<String, Integer>();
@hirobert
hirobert / flask_abort_example.py
Created January 13, 2016 20:38
flask abort as json
from flask import abort, make_response, jsonify
abort(make_response(jsonify(message="Message goes here"), 400))
eg() {
tmpfile=$(mktemp -t gist)
filename=${1:-$(basename $tmpfile)}
$EDITOR $tmpfile
if [ -s $tmpfile ]
then
gist -c -f $filename $tmpfile
fi
rm -f $tmpfile
}
class MyData { ... }
class YourData { ... }
abstract class Generic<T> {
public T tObject;
// constructor takes a T, whatever it is
public Generic(T tObject) { this.tObject = tObject; }
public abstract T giveMeTheT();
@fprieur
fprieur / dnsdock.md
Last active August 30, 2016 21:46
Setup for a local nameserver on mac os with docker and dnsdock
$ docker --version
Docker version 1.9.1, build a34a1d5
$ sudo mkdir -p /etc/resolver >/dev/null 2>&1
$ echo nameserver 172.17.0.1 | sudo tee /etc/resolver/docker > /dev/null
$ sudo route -n delete -net 172.17.0.0
$ sudo route -n add 172.17.0.0/16 $(docker-machine ip default)
$ sudo route -n add 172.17.0.1/32 $(docker-machine ip default)

$ docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy

@corajr
corajr / Nat.hs
Last active December 14, 2015 04:33
module Nat where
import Prelude hiding (succ)
import Control.Monad (forM_)
data Even = Zero | EvenSucc Odd
deriving (Show, Eq)
data Odd = OddSucc Even
deriving (Show, Eq)