Skip to content

Instantly share code, notes, and snippets.

@ijt
ijt / gofast_issue_28.go
Created July 20, 2018 16:32
Repro case for gofast issue 28
// This program spins up php-fpm in the background and a Go web server sending
// all requests to a PHP router script.
package main
import (
"context"
"flag"
"fmt"
"io/ioutil"
"log"
@ijt
ijt / random_monad_example.hs
Created October 3, 2011 00:13
Example of how to use the Random monad in Haskell
-- cabal install MonadRandom
-- ghc random_monad_example
-- ./random_monad_example
-- The code here is stolen from a comment in the MonadRandom source code.
import Control.Monad.Random
die :: RandomGen g => Rand g Int
die = getRandomR (1,6)
@ijt
ijt / mfilt
Created November 26, 2017 01:23
#!/usr/bin/env python
import argparse
import re
import sys
parser = argparse.ArgumentParser(description=
'''Filter some text with a regex, allowing matches to span multiple lines.
This tool is based on some ideas from Rob Pike's Sam editor:
@ijt
ijt / sieve.clj
Last active February 21, 2016 06:09
Translation of the Go prime sieve to Clojure
;; A concurrent prime sieve translated from
;; https://golang.org/doc/play/sieve.go
;; by Issac Trotts with help from Chris Murphy and glts on Stack Overflow.
(require '[clojure.core.async :as async :refer [<! >! <!! chan go]])
(defn generate-naturals
"Sends the sequence 2, 3, 4, ... to channel 'ch'."
[ch]
(go
@ijt
ijt / sieve.erl
Last active February 20, 2016 05:03
Translation of the Go prime sieve to Erlang
#!/usr/bin/env escript
%% -*- mode: erlang -*-
%%! -smp enable -hidden
%%
%% A concurrent prime sieve, inspired by the Go prime sieve
%% with daisy-chained filter processes.
%% https://golang.org/doc/play/sieve.go
%%
%% Translated by Issac Trotts (2016)
%% with help from Amiramix on StackOverflow.
@ijt
ijt / quine.go
Created November 7, 2012 05:07
A quine in Go
package main
import "fmt"
func main() {
s := "package main\n\nimport \"fmt\"\n\nfunc main() {\n\ts := %#v\n\tfmt.Printf(s, s)\n}\n"
fmt.Printf(s, s)
}
@ijt
ijt / splat.go
Created October 26, 2012 20:22
Argument splatting in Go
// See https://code.google.com/p/go/issues/detail?id=640
package main
import "fmt"
func main() {
args := []int{1, 2, 3}
fmt.Println(sum(args...))
}
@ijt
ijt / focus.go
Created October 8, 2012 05:49
Web proxy that disallows distracting websites
package main
import (
"flag"
"fmt"
"github.com/elazarl/goproxy"
"log"
"net/http"
"os"
)
@ijt
ijt / check_balance.hs
Created February 18, 2012 18:23
Check for balanced parentheses in a SQL statement
#!/usr/bin/env runhaskell
{-# LANGUAGE TemplateHaskell #-}
import Test.QuickCheck ((==>), Property)
import Test.QuickCheck.All (quickCheckAll)
-- main = interact $ show . checkBalance
main = $quickCheckAll
checkBalance :: String -> Bool
@ijt
ijt / median.hs
Created February 14, 2012 08:24
Print the median of a newline-separated list of numbers
#!/usr/bin/env runhaskell
import Data.List (sort, (\\))
import Test.QuickCheck (Property, (==>))
main = interact (showLn . median . map read . lines)
showLn :: Show a => a -> String
showLn x = show x ++ "\n"