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 / 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) ->
%% 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 / 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").
@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 / 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.">>}]}}
int i, j;
for (i = 0; i < array.lenght(); i++) {
if ((j = array[i] * 2) > 10)
j = j % 10 + 1;
array[i] = j;
}
[{boss, [
{path, "/home/runejuhl/projects/dependencies/erlang/ChicagoBoss"},
{vm_cookie, "lollo"},
{applications, [runejerl, cb_admin]},
{db_host, "localhost"},
{db_database, "runejerl"},
{db_port, 5432},
{db_username, "runejerl"},
{db_password, "nah"},
{db_adapter, pgsql},
@runejuhl
runejuhl / userChrome.css
Created March 19, 2013 17:07
Reduce Firefox interface size, fix minor annoyances. Some tags might not do much, but the latest userChrome specification I found was from circa 2007, and restarting Firefox to check changes becomes a bother from the 5th time onwards...
/*
* Edit this file and copy it as userChrome.css into your
* profile-directory/chrome/
*/
/*
* This file can be used to customize the look of Mozilla's user interface
* You should consider using !important on rules which you want to
* override default settings.
*/
@runejuhl
runejuhl / buenos-timetest.sh
Created April 5, 2013 09:22
Timer testing for Buenos
#!/usr/bin/env bash
for i in `seq 1 10`; do make > /dev/null && yams buenos initprog=[disk]sleep | tail -n 3 | grep -v kHz| grep --color=never -oE '[0-9]+.[0-9]+' | python -c "import sys
lines = [x.strip() for x in sys.stdin.readlines()]
print str(float(lines[0])/float(lines[1])) + ' seconds'"; done
@runejuhl
runejuhl / objdumpmap.py
Created May 16, 2013 17:47
Merges objdump with strings to create a disassembly with added symbols. Will show variables (and size) and some strings. Note that string functionality hinges on the output from strings, e.g. '\nOMG' won't be found by strings.
#!/usr/bin/env python
import sys
import subprocess
import re
import os.path
def main():
if len(sys.argv) < 2:
print('Missing argument')
sys.exit(-1)