Skip to content

Instantly share code, notes, and snippets.

View dreid's full-sized avatar
💭
Archived

dreid dreid

💭
Archived
View GitHub Profile
#!/usr/bin/env escript
%% -*- erlang -*-
main(_) ->
code:add_path("effigy/src"),
io:format("-- Before --~n~p~n", [hello:module_info()]),
{ok, _Cover} = cover:start(),
{ok, CoverModule} = cover:compile("hello.erl"),
(defun add-to-PATH (dir)
"Add the specified path element to the Emacs PATH"
(interactive "DEnter directory to be added to PATH: ")
(if (file-directory-p dir)
(setenv "PATH"
(concat (expand-file-name dir)
path-separator
(getenv "PATH")))))
(defun activate-virtualenv (dir)
@dreid
dreid / blogger2blogofile.py
Created January 21, 2011 09:45
Import an atom feed to blogofile markdown files.
#!/usr/bin/env python
import os
import re
import sys
import urllib
import datetime
from xml.etree import ElementTree as ET
MARKDOWN_TEMPLATE="""
---
<li>
<a href="{{link}}">
{{title}} &mdash; {{author_name}}
</a>
</li>
@dreid
dreid / stub_mochiweb_request.erl
Created March 11, 2011 22:14
Manually construct a parameterized module… the advantage here is multiple new functions and other static functions which do not take a module argument.
%% @author David Reid <[email protected]>
%% @copyright 2011 Mochi Media, Inc.
%% @doc Stub MochiWeb HTTP Request module implementation for testing.
-module(stub_mochiweb_request).
-record(stub_mochiweb_request, {options, headers, response_pid}).
%% Constructors and static method exports
@dreid
dreid / multiple_expect_results.erl
Created April 11, 2011 18:05
A rather convoluted mechanism for getting subsequent calls to a mecked function to return different results.
-module(multiple_expect_results).
-include_lib("eunit/include/eunit.hrl").
multiple_results_test() ->
ok = meck:new(some_mod),
meck:expect(some_mod, get_pid, fun() -> self() end),
meck:expect(some_mod, some_fun,
fun() ->
receive
@dreid
dreid / gist:1111000
Created July 28, 2011 05:08
SpiderOak apparently uses twisted.
SpiderOak.app//Contents/Resources/lib/python2.7/lib-dynload/twisted/internet/_sigchld.so
SpiderOak.app//Contents/Resources/lib/python2.7/lib-dynload/twisted/internet
SpiderOak.app//Contents/Resources/lib/python2.7/lib-dynload/twisted/protocols/_c_urlarg.so
SpiderOak.app//Contents/Resources/lib/python2.7/lib-dynload/twisted/protocols
SpiderOak.app//Contents/Resources/lib/python2.7/lib-dynload/twisted/python/_initgroups.so
SpiderOak.app//Contents/Resources/lib/python2.7/lib-dynload/twisted/python
SpiderOak.app//Contents/Resources/lib/python2.7/lib-dynload/twisted
@dreid
dreid / dialysis
Created August 10, 2011 20:52
first pass at a shell script to make building dialysis plts easier to use.
#!/bin/sh
OTP_VERSION=$(erl -noinput \
-noshell \
-eval 'io:fwrite(erlang:system_info(otp_release)).' \
-s init stop)
PLT_DIR="$HOME/.dialyzer/${OTP_VERSION}"
CURRENT_APP=$(basename $(pwd));
@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.
@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);