Skip to content

Instantly share code, notes, and snippets.

View runejuhl's full-sized avatar
💻
[runejuhl is typing]

Rune Juhl Jacobsen runejuhl

💻
[runejuhl is typing]
View GitHub Profile
@runejuhl
runejuhl / gist:3305008
Created August 9, 2012 15:08
boss_db unique constraint
4> T = tag:new(id, "erlang", false).
{tag,id,"erlang",false}
5> T:save().
{error,{error,error,<<"23505">>,
<<"duplicate key value violates unique constraint \"tags_name_key\"">>,
[{detail,<<"Key (name)=(erlang) already exists.">>}]}}
@runejuhl
runejuhl / boss_db_sql.erl
Created July 20, 2012 14:32
Match boss_db column names and values for use with ErlyDTL
-module(boss_db_sql).
-compile(export_all).
%% Much more elaborate version -- and with comments!
%% Drop in src/lib/ to be able to use it from anywhere in CB.
%% Return just the values from an executed SQL query.
sql(S) ->
{ok, ColNames, Values} = boss_db:execute(S),
Values.
@runejuhl
runejuhl / irc.erl
Created May 31, 2012 17:20
IRC bot
%% First try at making a small IRC bot.
%% Dedicated to ThordenM.
%%
%% Rune Juhl Jacobsen, 2012
-module(irc).
-compile(export_all).
-define(NICK, "lolcat").
-define(USERNAME, "lolcatzz").
%% filename clashes with erlang module btree!
-module(btree).
-export([find/2, min/1, max/1, insert/1, insert/2, print/1, print/2]).
-record(node, {val, left = nil, right = nil}).
%% find a specific value in a tree, or not_found
find(Value, Node) when Value == Node#node.val ->
{ok, Node};
@runejuhl
runejuhl / coinchange.erl
Created May 25, 2012 07:13
Greedy coin change
-module(coinchange).
-export([coinchange/2]).
coinchange(_, {sorted, []}) ->
[];
coinchange(A, {sorted, [C | CS]}) when A < C ->
coinchange(A, {sorted, CS});
coinchange(A, {sorted, [C | CS]}) ->
[C | [coinchange(A-C, {sorted, [C | CS]}) ]];
coinchange(A, C) ->