Skip to content

Instantly share code, notes, and snippets.

View noss's full-sized avatar

Christian noss

  • Stockholm, Sweden
View GitHub Profile
-module(lcs).
-export([recursive_lcs/2]).
-export([array_lcs/2]).
%% Recursive implementation
longest(Xs, Ys) ->
case length(Xs) > length(Ys) of
-module(files).
-export([readlines/1]).
readlines(Filename) ->
{ok, Data} = file:read_file(Filename),
RevLines = lines(Data, []),
lists:reverse(RevLines).
lines(Input, Lines) ->
-module(index).
-compile(export_all).
invert({Ks, Image}) ->
[{K, Image} || K <- Ks].
update_index(KIs, Index0) ->
lists:foldl(fun({K, I}, Acc) ->
dict:append(K, I, Acc)
-module(record).
-compile(export_all).
list_to_assoc(Name, As) ->
ANs = list_to_assoc0(1, [Name|As]),
list_to_tuple(lists:sort(ANs)).
list_to_assoc(As) ->
ANs = list_to_assoc0(2, As),
-module(mysql_proto_constants).
-compile(export_all).
client_flags() ->
[{long_password, 1, "new more secure passwords"}
,{found_rows, 2, "Found instead of affected rows"}
,{long_flag, 4, "Get all column flags"}
,{connect_with_db, 8, "One can specify db on connect"}
,{no_schema, 16, "Don't allow database.table.column"}
,{compress, 32, "Can use compression protocol"}
-module(substring).
-compile(export_all).
q() ->
16#ffffff.
q(N) ->
N rem q().
rehash(D, Out, In, Hash) ->
q((Hash - (Out*D))*2 + In).
@noss
noss / zohan.erl
Created September 12, 2008 21:08 — forked from anonymous/gist:10515
-module(zohan).
-export([generate_dir/1]).
generate_dir(Filename) ->
<<A:12, B:12, _/binary>> = erlang:md5(Filename),
filename:join([queue,
io_lib:format("~3.16.0b", [A]),
io_lib:format("~3.16.0b", [B])]).
@noss
noss / csv.erl
Created August 4, 2008 21:43
Parsing files with tab-separated values in Erlang
-module(csv).
-export([lines/1,lines/2, columns/2, parse/1]).
lines(Text) ->
lines(<<>>, Text).
lines(Line, <<>>) ->
[Line];
lines(Line, <<$\n,Rest/binary>>) ->
[Line | lines(<<>>, Rest)];