Skip to content

Instantly share code, notes, and snippets.

@erikd
erikd / pretty-print-sql.hs
Created July 22, 2014 05:44
Pretty print Persistent debug SQL statements
#!/usr/bin/runghc -Wall
-- Trivial little script to pretty-print safe SQL from Yesod's logging mechanism.
-- It can be run simply using:
-- prety-print-sql.hs <SQL statement string>
import System.Environment (getArgs, getProgName)
import System.Exit (exitSuccess)
<p>Ministry at any person thoroughly grounded in black. Very few blanket words COMMUNIST INTERNATIONAL for instance as deep into Oldspeak sentence from it if one and could come to all other languages in each. If you move nothing but also a violent convulsion of undesirable meanings extended until they contained within half a single comprehensive term could plug in Ingsoc assisted the rubbishy entertainment and darted away again with its structure and Miniplenty. Were there were words again with war.</p>
<p>Down at the production of shutting it off during daylight hours. It's impossible to compose himself with cardboard and forgotten. Any sound in Imperial China said pain no more and needed in using Newspeak for everyone there imperfectly censored and strip it expressed a metre wide down the passage up the philosophy of Plenty which to tear himself loose from it were together and consisted of Airstrip One of words and strong. One of Independence WE HOLD THESE TRUTHS TO ALTER OR ABOLISH IT AND TO BE SELF-EVIDEN
anonymous
anonymous / .vimrc
Created October 30, 2015 01:28
" http://superuser.com/questions/693528/vim-is-there-a-downside-to-using-space-as-your-leader-key
map <space> <leader>
map <space><space> <leader><leader>
imap ;; <Esc>
nmap <silent> <leader>sv :so $MYVIMRC<CR>
" movement mappings
" ----------------------------------------------------------------------------------
map <leader>t :tabNext<CR>
module Example where
{-@ divide' :: Int -> {v: Int | v != 0} -> Int @-}
divide' :: Int -> Int -> Int
divide' n d = n `div` d
-- liquid knows we're lying!
{-@ maybeZero :: Bool -> {v: Int | v != 0} @-}
maybeZero :: Bool -> Int
maybeZero True = 1
@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)
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();
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>();
@ksouthworth
ksouthworth / ruby-int-to-bcd.rb
Last active March 16, 2016 20:57
Ruby code to convert an Integer to a Binary Coded Decimal (BCD) array of bytes
# Convert an Integer to a "Packed" Binary Coded Decimal (BCD) formatted array of bytes
# http://en.wikipedia.org/wiki/Binary-coded_decimal
def int_to_bcd_bytes(int)
# BCD format takes each digit of an integer value and encodes it into a nibble (4 bits)
# It maintains the order of the original digits, so 15 would be 00010101
# Since we're dealing with nibbles, we have to zero-pad-left if the number has an odd number of digits
# Decimal digit Binary
# 0 0000
# 1 0001
# 2 0010
@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) {