Skip to content

Instantly share code, notes, and snippets.

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();
@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)
let withDefault (defaultVal: 'a, x : 'a option) =
match x with
| Some(xVal) -> xVal
| None -> defaultVal
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 / lists.md
Last active October 12, 2015 16:23
Why making each List variant its own datatype doesn't work

The problem statement, for reference:

Consider a datatype definition that introduces numeric lists as the sum of two variants: nempty and ncons. This defines a new type (nlist), and each constructor (such as ncons) creates a value of that type. As a result, however, selectors (such as nfirst) cannot statically determine whether or not they have been given the correct variant of the datatype, and must rely on a check from the run-time system. >

@corajr
corajr / 17.py
Created September 29, 2015 18:06
Prob 17
def add_to_list(w, in_boxes):
if len(in_boxes) == 0:
return [1.0-w]
else:
boxes = in_boxes[:]
max_box = max(boxes)
if w >= max_box and w != 0.0:
boxes.append(1.0-w)
return boxes
else:
@corajr
corajr / diff.html
Last active August 29, 2015 14:28
Two ways to filter a list in Haskell
<p>What do two different ways of filtering a list compile to?</p>
<p>(Example: take a list of tuples (a,b), and return a list of a for every (a,b) where b > 1.)</p>
<table>
<tr>
<th>
`map fst . filter ((>1) . snd)`
</th>
<th>
@corajr
corajr / 1-preferences.png
Last active August 29, 2015 14:25
AAS21 Zotero Instructions
1-preferences.png
@corajr
corajr / put_on_tv.sh
Last active August 29, 2015 14:13
Serve a movie file to the Raspberry Pi
put_on_tv() {
IP=$(ipconfig getifaddr en1)
PORT=$(($RANDOM%63000+2001))
FILENAME=$(basename "$*")
FILEEXT=${FILENAME##*.}
ln -s "$1" $TMPDIR/$PORT.$FILEEXT
(
cd $TMPDIR
python -m SimpleHTTPServer $PORT &
ssh -t livingroom_pi "omxplayer -o hdmi -r http://$IP:$PORT/$PORT.$FILEEXT"