Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE DataKinds, GADTs, TypeOperators #-}
{-# LANGUAGE FlexibleContexts, FlexibleInstances, ScopedTypeVariables #-}
{-# LANGUAGE MultiParamTypeClasses, TypeFamilies #-}
module Main where
main :: IO ()
main = do
print aList
print elt0
@mkscrg
mkscrg / README.md
Last active August 29, 2015 13:57
Reservoir Sampling

Choose a random sample of 10 values from an unbounded stream. Red marks denote values currently in the sample.

From Wikipedia:

The algorithm creates a "reservoir" array of size k and populates it with the first k items of S. It then iterates through the remaining elements of S until S is exhausted. At the ith element of S, the algorithm generates a random number j between 1 and i. If j is less than k, the jth element of the reservoir array is replaced

@mkscrg
mkscrg / newcabal.sh
Created December 26, 2013 22:56
Start a new Cabal project with minimal sane defaults.
#!/usr/bin/env bash
set -e
template='name: $$NAME$$
version: 0.0.0
build-type: Simple
cabal-version: >= 1.9.2
executable $$NAME$$
main-is: Main.hs
@mkscrg
mkscrg / serve.sh
Created December 23, 2013 03:21
Serve a directory on a port with Nginx, with access logs to STDOUT and error logs to STDERR.
#!/usr/bin/env bash
set -e
usage() {
echo "usage: serve PORT [DIR]"
exit 1
}
conf_template='
worker_processes 1;
module Main where
import Data.Char
import Data.List
main :: IO ()
main = print $ wordIndexes "Hello test World"
wordIndexes :: String -> [(Int, String)]
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Applicative
import Data.Char
import Data.Attoparsec.Text
import Data.Text (Text)
public class Main {
public static void main(String[] args) {
ensureLessThanWithCast(6, 5);
ensureLessThan(6, 5);
}
public static <N extends Number & Comparable<N>, S extends N> S ensureLessThanWithCast(N threshold, S input) {
if (((N) input).compareTo(threshold) >= 0) {
throw new IllegalArgumentException("Input " + input + " is not less than " + threshold);
}
@mkscrg
mkscrg / .gitignore
Created July 26, 2012 16:57
Test topology for Issue 276
*.iml
.idea/
target/
*.DS_STORE*
@mkscrg
mkscrg / stack.txt
Created July 24, 2012 21:14
Storm/ReflectASM stack trace
2012-07-24 13:40:56 util [ERROR] Async loop died!
java.lang.LinkageError: loader (instance of com/esotericsoftware/reflectasm/AccessClassLoader): attempted duplicate class definition for name: "reflectasm/java/util/ArrayListConstructorAccess"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
at com.esotericsoftware.reflectasm.AccessClassLoader.defineClass(AccessClassLoader.java:45)
at com.esotericsoftware.reflectasm.ConstructorAccess.get(ConstructorAccess.java:61)
at com.esotericsoftware.kryo.Kryo.newInstantiator(Kryo.java:974)
at com.esotericsoftware.kryo.Kryo.newInstance(Kryo.java:1024)