Skip to content

Instantly share code, notes, and snippets.

View dreid's full-sized avatar
💭
Archived

dreid dreid

💭
Archived
View GitHub Profile
@dreid
dreid / timedefer.py
Created March 23, 2012 19:36
wrap a deferred in a context manager. Use this to collect timings with scales.
from twisted.internet.defer import maybeDeferred
def withDeferred(contextManager, f, *args, **kwargs):
contextManager.__enter__()
def _exit(result):
contextManager.__exit__(None, None, None)
return result
def _exitEb(failure):
@dreid
dreid / produces.py
Created March 23, 2012 02:15
Klein produces decorator for setting the content type and optionally installing a content encoder.
from functools import wraps
from twisted.internet.defer import maybeDeferred
def produces(contentType, encoder=None):
def maybeEncode(result, request):
request.setHeader("content-type", contentType)
if encoder is not None:
return encoder(result)
@dreid
dreid / fqn.py
Created March 9, 2012 23:17
handle the fully qualified names method descriptors.
def fullyQualifiedName(obj):
if inspect.ismethoddescriptor(obj):
objclass = fullyQualifiedName(obj.__objclass__)
return '%s.%s' % (objclass, obj.__name__)
return txFullyQualifiedName(obj)
@dreid
dreid / umloud_songs.txt
Created November 9, 2011 18:48
Sorted song list for umloud, extracted from HTML song chooser. This may not include songs which are already selected by ultimate bands.
(Damn) This Desert Air - Ghost I Own
2nd Thought - Just Hang On
3 Doors Down - Here Without You
3 Doors Down - It's Not My Time
3 Doors Down - Kryptonite
3 Doors Down - When I'm Gone
3 Doors Down - When You're Young
3 Inches of Blood - Battles and Brotherhood
30 Seconds to Mars - Attack
30 Seconds to Mars - Closer to the Edge
@dreid
dreid / index.html
Created October 20, 2011 17:06
Percentage of startups I've asked for pie.
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'didpie');
data.addColumn('number', 'percentage');
@dreid
dreid / nacl-osx.patch
Created October 2, 2011 00:01
nacl osx patch by @pr0zac
--- nacl-20110221/curvecp/nanoseconds.c 2011-02-20 17:49:34.000000000 -0800
+++ NaCl/curvecp/nanoseconds.c 2011-10-01 16:56:43.000000000 -0700
@@ -1,4 +1,8 @@
#include <time.h>
+#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
+#include <mach/clock.h>
+#include <mach/mach.h>
+#endif
#include "nanoseconds.h"
@dreid
dreid / bcdpz98.log
Created August 30, 2011 17:38
bad_central_directory debugging.
=========={{2011,8,30},{17,35,32}}==========
{trace,<0.3.0>,call,
{erl_prim_loader,apply_archive,
[{prim_state,false,undefined,"/Users/dreid/bcd/rebar"},
#Fun<erl_prim_loader.14.99960715>,
{error,enoent},
"/Users/dreid/bcd/rebar"]}}
{trace,<0.3.0>,call,{prim_file,read_file_info,["/Users/dreid/bcd/rebar"]}}
{trace,<0.3.0>,return_from,
{prim_file,read_file_info,1},
@dreid
dreid / blah.erl
Created August 27, 2011 00:13
proper:quickcheck eunit integration using a test generator to have one line of output per property.
proper_test_() ->
Properties = lists:filter(fun({F, _}) ->
case atom_to_list(F) of
"prop_" ++ _Rest ->
true;
_ ->
false
end
end,
bstrip_props:module_info(exports)),
@dreid
dreid / bstrip.erl
Created August 26, 2011 20:34
Efficient binary strip?
-module(bstrip).
-export([bstrip/1, bstrip/2]).
bstrip(Bin) ->
bstrip(Bin, both).
bstrip(Bin, left) ->
blstrip(Bin);
@dreid
dreid / dialyzer.mk
Created August 11, 2011 06:45
A second pass at making using dialyzer a little easier. This time as a Makefile.
##
## dialyzer.mk: Useful make targets for working with erlang's
## dialyzer. Manages a per-OTP version PLT which is then copied
## to your project directory and adds your dependencies to the
## plt. By default the OTP plt is stored in ~/.dialyzer so that
## it is used by all dialyzer.mk using projects. This can be
## changed with the PLT_BASE variable.
##
## Recommended usage is to add `include dialyzer.mk` to your
## projects Makefile.