Skip to content

Instantly share code, notes, and snippets.

View b20n's full-sized avatar

Benjamin Anderson b20n

View GitHub Profile

Keybase proof

I hereby claim:

  • I am banjiewen on github.
  • I am banjiewen (https://keybase.io/banjiewen) on keybase.
  • I have a public key whose fingerprint is 44CC 8CC2 11DB 3E86 8A82 6AF3 551D DB08 1878 1D01

To claim this, I am signing this object:

html {
font-family: 'Bitstream Vera Sans Mono';
font-size: 14px;
background-color: #fdf6e3; /* base3 */
color: #657b83; /* base00 */
}
body {}
.url { color: #d33682; } /* magenta */
.address {}
@b20n
b20n / map.js
Created April 26, 2013 01:41
Sample _count-based map/reduce view
function(doc) {
emit([doc.year, doc.ngram], null);
}
-module(avern_leveldb).
-export([
delete/3,
read/4,
write/2
]).
-spec delete(binary(), pos_integer, list()) -> any().
delete(Metric, Until, LevelDB) ->
get_random_line(#file{bin=Bin, size=Size}=F) ->
I = random:uniform(Size),
case binary:match(Bin, <<"\n">>, [{scope, {I, Size - I}}]) of
nomatch -> get_random_line(F);
{Start, _} ->
case binary:match(Bin, <<"\n">>, [{scope, Start + 1, Size - (Start +1)}]) of
nomatch -> get_random_line(F);
{End, _} ->
binary:part(Bin, Start, End)
@b20n
b20n / foo.erl
Created February 21, 2013 01:39
Weight = Count * DeltaT,
Waiting1 = try
OldWeight = dict:fetch(Metric, Index),
{value, Value} = gb_trees:lookup(OldWeight, Waiting),
NewValue = lists:delete(OldWeight, Value),
case NewValue of
[] -> gb_trees:delete(OldWeight, Waiting);
V -> gb_trees:insert(OldWeight, V, Waiting)
end
catch
>>> import emacs
>>> a = [(1, 2), (3, 4)]
a = [(1, 2), (3, 4)]
>>> for x, y in a:
for x, y in a:
... print x
print x
...
1
choose_tag_bucket(QueryTags, RowTags) ->
choose_tag_bucket(QueryTags, RowTags, []).
choose_tag_bucket(_, [], []) ->
undefined;
choose_tag_bucket([], _, Acc) ->
lists:reverse(Acc);
choose_tag_bucket([{Key, '*'}|Query], [{Key, Value}|Row], Acc) ->
choose_tag_bucket(Query, Row, [{Key, Value}|Acc]);
choose_tag_bucket([KV|Query], [KV|Row], Acc) ->
;; Integrate terminal emacs with OSX pasteboard
(defun copy-from-osx ()
(shell-command-to-string "pbpaste"))
(defun paste-to-osx (text &optional push)
(let ((process-connection-type nil))
(let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
(process-send-string proc text)
(process-send-eof proc))))
joxa-is> (defn foo () (io/format "asdf~p~n" '(14)))
ok
joxa-is> foo
:0:0 *error* reference does not exist: foo
error
joxa-is> (foo)
Function: 'interactive-name'/0
error: {error,function_clause} : [{code,load_binary,['joxa-is',[],error],[{file,"code.erl"},{line,164}]},
{'joxa-compiler','post-compile-process',1,
[{file,"/home/emerritt/workspace/joxa/src/joxa-compiler.jxa"},