Skip to content

Instantly share code, notes, and snippets.

View puzza007's full-sized avatar
💭
💅

Paul Oliver puzza007

💭
💅
View GitHub Profile
puzza@MacBook:~/src/mochiweb-read-only/ebin$ erl
Erlang R13B02 (erts-5.7.3) [source] [64-bit] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.7.3 (abort with ^G)
1> mochihex:to_bin("FEDCBA9876543210").
<<254,220,186,152,118,84,50,16>>
2> mochihex:to_hex(mochihex:to_bin("FEDCBA9876543210")).
"fedcba9876543210"
3> mochihex:to_bin("37363534333231204E6F77206973207468652074696D6520666F722000").
<<55,54,53,52,51,50,49,32,78,111,119,32,105,115,32,116,
@puzza007
puzza007 / bf_test.erl
Created October 13, 2009 15:26
Test module for crypto blowfish functions
-module(bf_test).
%% Test vectors from http://www.schneier.com/code/vectors.txt
%% I've used this on the command-line
-export([to_bin/1]).
-include_lib("eunit/include/eunit.hrl").
-define(KEY, to_bin("0123456789ABCDEFF0E1D2C3B4A59687")).
%%
%% Simple pool for gen_servers that only use :call
%%
-module(gen_server_call_pool).
-behaviour(gen_server).
%% --------------------------------------------------------------------
%% External exports
-export([start_link/3, stats/1]).
%% If this occurs in something that's called often (and might qualify as an inner loop,
%% or might not) does either method have a speed advantage?
[A,B,C] = [get_foo(S) || S<-["a","b","c"],
% versus
A = get_foo("a"),
B = get_foo("b"),
C = get_foo("c"),
@puzza007
puzza007 / foo.core
Created October 27, 2010 18:01
Core Erlang
-module(foo).
-export([list_comprehension/0, statements/0]).
get_foo(S) ->
S.
list_comprehension() ->
[get_foo(S) || S <- ["a","b","c"]].
@puzza007
puzza007 / .emacs
Created November 12, 2010 10:36
My .emacs from work
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(case-fold-search t)
'(column-number-mode t)
'(current-language-environment "Latin-1")
'(default-input-method "latin-1-prefix")
'(global-font-lock-mode t nil (font-lock))
Params = #amqp_params{
username = iolist_to_binary(User),
password = iolist_to_binary(Password),
virtual_host = iolist_to_binary(Vhost),
host = Host,
port = Port
},
Params = #amqp_params{
username = iolist_to_binary(User),
password = iolist_to_binary(Password),
# add ssh key from your machine to bitbucket keys here https://bitbucket.org/account/
puzza@imac:~/src/test$ cat ~/.ssh/id_rsa.pub
ssh-rsa XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX== puzza@Macintosh.local
# push an already existing rep
puzza@imac:~/src/test$ git init
Initialized empty Git repository in /Users/puzza/src/test/.git/
puzza@imac:~/src/test$ touch foo
puzza@imac:~/src/test$ git add .
puzza@imac:~/src/test$ git commit -m 'import an empty file'
-module(badger).
-export([encoding/1]).
-spec encoding(binary()) -> gzip | compress | deflate | identity.
encoding(AcceptEncoding) ->
EncodingList = encoding_list(AcceptEncoding),
{Enc, _} =
lists:foldl(fun({E, Q}, {MaxEnc, MaxQval}) ->
E1 = encoding_map(E),
"""Modifies the App Engine datastore to support local caching of entities.
This is achieved by monkeypatching google.appengine.ext.db to recognise model
classes that should be cached and store them locally for the duration of a
single page request.
Note that only datastore gets (and anything that relies on them, such as
ReferenceProperty fetches) are cached; queries will neither return cached
entities nor update the cache.