Skip to content

Instantly share code, notes, and snippets.

View ngerakines's full-sized avatar
🏠
Working from home

Nick Gerakines ngerakines

🏠
Working from home
View GitHub Profile
@ngerakines
ngerakines / git2foaf.erl
Created December 27, 2008 02:35
A module used to create foaf from git profile pages.
-module(git2foaf).
-compile(export_all).
%% git2foaf:projects("ngerakines").
projects(Username) ->
{ok, {{_Version, 200, _ReasonPhrase}, _Headers, Body}} = http:request(user_url(Username)),
Profile = profile_xml(Body),
CurrentProjects = projects_xml(Body),
Following = following_xml(Body),
[CurrentProjects, Following, Profile].
class PBLexer(RegexLexer):
"""
A simple Protocol Buffer lexer useful for parsing .proto files.
Contributed by Nick Gerakines <nick@gerakines.net>.
"""
name = 'ProtocolBuffers'
aliases = ['pb']
filenames = ['*.proto']
mimetypes = ['text/pb']
@ngerakines
ngerakines / mtdump.erl
Created December 20, 2008 10:23
A module used to dump MT blog entries to Jekyll files.
-module (mtdump).
-export([start/0]).
start() ->
mysql:start_link(mt, "localhost", "user", "password", "mt_database"),
mysql:prepare(posts, <<"SELECT entry_id, entry_basename, entry_text, entry_text_more, entry_created_on, entry_title FROM mt_entry where entry_blog_id = 3">>),
Posts = case mysql:execute(mt, posts, [], infinity) of
{data, MySQLRes} ->
Fields = [ F || {_, F, _, _} <- mysql:get_result_field_info(MySQLRes)],
Rows = mysql:get_result_rows(MySQLRes),
@ngerakines
ngerakines / bottles.erl
Created December 8, 2008 04:49
A simple erlang server demo.
-module(bottles).
-export([start/0, start/1, server_loop/1, take/0, info/0, stop/0]).
start() ->
start(99).
start(State) ->
Pid = spawn(bottles, server_loop, [State]),
pg2:create(bottles_server),
pg2:join(bottles_server, Pid),
Backpack = {
setUser:function(val){
Application.prefs.setValue("backpack_user", val);
},
setDomain:function(val){
Application.prefs.setValue("backpack_domain", val);
},
setToken:function(val){
Application.prefs.setValue("backpack_token", val);
@ngerakines
ngerakines / binlog.erl
Created October 17, 2008 19:37
Determine the next binlog file for a given binlog filename.
-module(binlog).
-compile(export_all).
current_log() -> "db-000004.bin".
%% binlog:next_log(binlog:current_log()).
%% binlog:next_log("db-000004.bin").
next_log("db-" ++ TmpA) ->
"nib." ++ TmpB = lists:reverse(TmpA),
TmpC = list_to_integer(lists:reverse(TmpB)) + 1,
@ngerakines
ngerakines / lrulist.erl
Created October 5, 2008 00:52
A small LRU list based on gb_trees.
%% @doc A small LRU list container.
%% @todo Add better documentation.
%% @todo Find edge case bugs in purging.
-module(lrulist).
-author("Nick Gerakines <nick@gerakines.net>").
-export([new/0, new/1, get/2, insert/3, remove/2, purge/1, keys/1]).
-define(EXPIRE_RULES, [expire, slidingexpire]).
@ngerakines
ngerakines / memoize.erl
Created September 27, 2008 17:55
A small module to provide memoize functions in Erlang.
%% Copyright (c) 2008 Nick Gerakines <nick@gerakines.net>
%%
%% Permission is hereby granted, free of charge, to any person
%% obtaining a copy of this software and associated documentation
%% files (the "Software"), to deal in the Software without
%% restriction, including without limitation the rights to use,
%% copy, modify, merge, publish, distribute, sublicense, and/or sell
%% copies of the Software, and to permit persons to whom the
%% Software is furnished to do so, subject to the following
%% conditions:
Eshell V5.6.2 (abort with ^G)
1> c(sleeperl).
{ok,sleeperl}
2> sleeperl:testb().
Receiver spawned at {1219,775147,552727}
Spawn start at {1219,775147,552864}
Spawn done at {1219,775147,553079}
ok
3>
receiver got '{done,<0.38.0>}' at {1219,775150,571689}
Str = "2008-10-01 10:00:01",
[YY, MM, DD, Hh, Mm, Ss] = [list_to_integer(X) || X <- string:tokens(Str, " -:")],
{{YY, MM, DD}, {Hh, Mm, Ss}}.