Skip to content

Instantly share code, notes, and snippets.

View jkvor's full-sized avatar

Jacob Vorreuter jkvor

  • Google
  • San Francisco
View GitHub Profile
F = fun(B,Val) -> hd(io_lib:format("~." ++ integer_to_list(B) ++ "B", [Val])) end. F(2, 250). F(16, 250).
code:add_patha("/src/http_omg/ebin").
code:add_patha("/src/erlang_mysql-3/ebin").
code:add_patha("/src/teh_pokemons/ebin").
code:add_patha("/src/etap_ng/ebin").
code:add_patha("/src/mochiweb/ebin").
code:add_patha("/src/yaml_erlang/ebin").
code:add_patha("/src/dynamic_compile/ebin").
code:add_patha("/src/mochixpath/ebin").
code:add_patha("/src/custom_guards/ebin").
code:add_patha("/src/excavator/ebin").
%% Consistent hashing functions
%%
%% First, hash memcached servers to unsigned integers on a continuum. To
%% map a key to a memcached server, hash the key to an unsigned integer
%% and locate the next largest integer on the continuum. That integer
%% represents the hashed server that the key maps to.
%% reference: http://www8.org/w8-papers/2a-webserver/caching/paper2.html
hash_to_uint(Host, Port) when is_list(Host), is_integer(Port) ->
hash_to_uint(Host ++ integer_to_list(Port)).
Query = #emo_query{limit=1, q=[
{<<"orderby">>, [{<<"occurred_at">>, -1}]},
{<<"query">>, [{<<"field1">>, Field1Value}]}
]},
-module(rabbit_test).
-compile(export_all).
-include_lib("rabbitmq_erlang_client/include/amqp_client.hrl").
-define(X, <<1,2,3,4>>).
-define(RoutingKey, <<5,6,7,8>>).
-define(Q, <<9,10,11,12>>).
%% -------------------------------------
@jkvor
jkvor / t.erl
Created February 12, 2010 01:08
-module(t).
-behavior(gen_server).
-export([start_link/0, print_state/0]).
-export([init/1, handle_call/3, handle_cast/2,
handle_info/2, terminate/2, code_change/3]).
%%====================================================================
%% API
@jkvor
jkvor / p.erl
Created February 12, 2010 01:08
-module(p).
-export([start_link/0, print_state/0, init/1, loop/1,
system_continue/3, system_code_change/4, system_terminate/4]).
start_link() ->
proc_lib:start_link(?MODULE, init, [self()]).
print_state() ->
{ok, Result} = gen:call(?MODULE, '$p', print_state),
Result.
@jkvor
jkvor / t_diff
Created February 12, 2010 01:35
--- t.erl 2010-02-11 17:34:00.000000000 -0800
+++ t2.erl 2010-02-11 17:33:54.000000000 -0800
@@ -35,7 +35,7 @@
%% Description: Initiates the server
%%--------------------------------------------------------------------
init([]) ->
- {ok, 0}.
+ {ok, 0.0}.
%%--------------------------------------------------------------------
@jkvor
jkvor / p.erl
Created February 16, 2010 21:10
-module(p).
-export([start_link/0, print_state/0, init/1, loop/1]).
start_link() ->
proc_lib:start_link(?MODULE, init, [self()]).
print_state() ->
{ok, Result} = gen:call(?MODULE, '$p', print_state),
Result.
@jkvor
jkvor / p_diff
Created February 16, 2010 22:52
--- p.erl 2010-02-16 14:49:04.000000000 -0800
+++ p2.erl 2010-02-16 14:49:02.000000000 -0800
@@ -12,7 +12,7 @@
init(Parent) ->
register(?MODULE, self()),
proc_lib:init_ack(Parent, {ok, self()}),
- ?MODULE:loop(0).
+ ?MODULE:loop(0.0).
@@ -28,7 +28,7 @@