Skip to content

Instantly share code, notes, and snippets.

View archaelus's full-sized avatar

Geoff Cant archaelus

  • San Francisco, CA
View GitHub Profile
@archaelus
archaelus / tuple_match.erl
Created March 3, 2011 01:28
Tuple space matching
-module(tuple_match).
-export([match/2, match2/2,
match_elements/2]).
-include_lib("eunit/include/eunit.hrl").
match(any, T) when is_tuple(T) ->
true;
match(P, Q)
when is_tuple(P), is_tuple(Q) ->
@archaelus
archaelus / netmask.erl
Created February 22, 2011 22:55
CIDR in/out net calculation
-module(netmask).
-export([in_network/3]).
in_network(Net, CIDR, IP)
when is_binary(Net), is_binary(IP), is_integer(CIDR) ->
<<NetworkPrefix:CIDR/bits, _/bits>> = Net,
case IP of
<<NetworkPrefix:CIDR/bits, _Host/bits>> ->
in_net;
_ -> not_in_net
@archaelus
archaelus / gist:788856
Created January 20, 2011 22:47
apt blah
aptitude install erlang=1:14.b-0ubuntu1
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
The following packages are BROKEN:
erlang erlang-ic-java
The following NEW packages will be installed:
ca-certificates-java{a} default-jre-headless{a} erlang-jinterface{a} icedtea-6-jre-cacao{a} java-common{a} liblcms1{a} libnspr4-0d{a} libnss3-1d{a}
@archaelus
archaelus / gist:788848
Created January 20, 2011 22:44
apt-cache policy erlang
erlang:
Installed: 1:13.b.1-dfsg-2ubuntu1.1
Candidate: 1:14.b-0ubuntu1
Version table:
1:14.b-0ubuntu1 0
500 file: ./ Packages
*** 1:13.b.1-dfsg-2ubuntu1.1 0
500 http://mirror.rightscale.com karmic-updates/universe Packages
500 http://mirror.rightscale.com karmic-security/universe Packages
100 /var/lib/dpkg/status
-module(p2pphonebook).
-export([start/1, add/2, list_all/1, update/2,delete/2,find/2,join/2,join/3,splitContacts/2,updateContactsAndPeers/2]).
%% Interface
start(X) -> spawn(fun() -> loop({dict:new(),{'','',erlang:md5(X),''}}) end).
add(Pid, Contact) ->
rpc(Pid, {add, Contact}).
a_start(App, Type) ->
start_ok(App, Type, application:start(App, Type)).
start_ok(_App, _Type, ok) -> ok;
start_ok(_App, _Type, {error, {already_started, _App}}) -> ok;
start_ok(App, Type, {error, {not_started, Dep}}) ->
ok = a_start(Dep, Type),
a_start(App, Type);
start_ok(App, _Type, {error, Reason}) ->
erlang:error({app_start_failed, App, Reason}).
start(App) ->
start_ok(App, application:start(App)).
start_ok(_App, ok) -> ok;
start_ok(_App, {error, {already_started, _App}}) -> ok;
start_ok(App, {error, {not_started, Dep}}) ->
ok = start(Dep),
start(App);
start_ok(App, {error, Reason}) ->
erlang:error({app_start_failed, App, Reason}).
#!/bin/bash
rm -rf ~/erlang/otp/release
cd ~/otp
./otp_build release -a ~/erlang/otp/release && \
(brew unlink erlang; \
rm -rf ~/usr/Cellar/erlang/HEAD; \
mv ~/erlang/otp/release ~/usr/Cellar/erlang/HEAD; \
cd ~/usr/Cellar/erlang/HEAD; \
./Install -minimal ~/usr/Cellar/erlang/HEAD; \
%% @copyright Geoff Cant 2010
%% @author Geoff Cant <[email protected]>
%% @doc Erlang shell code to cause a gen* process to evaluate a fun.
%%
%% @license This code was translated from an ancient tome in the
%% Arkham university library (restricted section, 4th vault). As such,
%% use of this code is restricted to only those who see it as the
%% manifestly evil. Using this code under any circumstances other than in
%% dire need while debugging revokes your right to use, view, posess
%% said code.
%% @copyright Geoff Cant 2009, 2010
%% @author Geoff Cant <[email protected]>
%% @version {@vsn}, {@date} {@time}
%% @doc Erlang shell code to trace the messages for one process.
%% @end
dbg:stop_clear(),
f(GL).
GL=group_leader(),
dbg:tracer(process,