Skip to content

Instantly share code, notes, and snippets.

View apg's full-sized avatar
🐢
Turtle

Andrew Gwozdziewycz apg

🐢
Turtle
View GitHub Profile
(* Polymorphic pairing heap. This should really be a functor such
that it can be made min/max/whatever *)
type 'a heap = Empty | Heap of 'a * ('a heap) list
let empty = Empty
let is_empty h = match h with
Empty -> true
| _ -> false
{-- Simple implementation of a pairing heap that supports safe
head, tail --}
module PairingHeap ( empty
, insert
, head
, tail
, meld
, safeHead
, safeTail
{* Simple implementation of a pairing heap that supports safe
head, tail *}
module PairingHeap ( empty
, insert
, head
, tail
, meld
, safeHead
, safeTail ) where
@apg
apg / *buf*
Created December 7, 2011 15:54
inline function foo(x, y) {
return x + y;
}
function bar(x, y) {
foo(1, 2);
return x * y;
}
// naively becomes =>
@apg
apg / archive_logs
Created November 18, 2011 22:27
I wrote a great upload callback for boto S3 stuff
import itertools, sys
SPINNER = itertools.cycle(['-', '/', '|', '\\'])
def upload_callback(bytes_sent, bytes_total):
cols = 67
if bytes_total > 0:
percent = bytes_sent / float(bytes_total)
else:
percent = 0
@apg
apg / m.erl
Created November 15, 2011 23:03
-module(m).
-export([pow/2, digitsum/1]).
pow(B, N) when is_integer(N), N >= 0 -> pow(B, N, 1).
pow(_, 0, A) -> A;
pow(B, N, A) -> pow(B, N-1, A*B).
digitsum(N) when is_integer(N) -> lists:sum([X - $0 || X <- integer_to_list(N)]).
@apg
apg / m.erl
Created November 15, 2011 22:38
-module(m).
-export([pow/2, digitsum/1]).
pow(B, N) when is_integer(N), N >= 0 -> pow(B, N, 1).
pow(_, 0, A) -> A;
pow(B, N, A) -> pow(B, N-1, A*B).
digitsum(N) when is_integer(N) -> lists:foldl(fun (C, Acc) -> (C - $0) + Acc end,
0, integer_to_list(N)).
@apg
apg / m.erl
Created November 15, 2011 22:00
-module(m).
-export([pow/2]).
pow(B, N) when is_integer(N), N >= 0 -> pow(B, N, 1).
pow(_, 0, A) -> A;
pow(B, N, A) -> pow(B, N-1, A*B).
from com.meetup.base.util import Web, U
import uuid
import random
def coin():
return random.randint(0, 1) == 1
def uuids():
while True:
yield str(uuid.uuid4())
(ns leiningen.hooks.classpath
(:require [clojure.string :as s]
[clojure.java.io :as f]
[robert.hooke]
[leiningen.classpath]))
(defn- get-jars [dir]
(if (.endsWith dir "*")
(for [jar (.listFiles (f/file (.substring dir 0 (- (count dir) 1))))
:when (.endsWith (.getName jar) ".jar")]