Skip to content

Instantly share code, notes, and snippets.

View krestenkrab's full-sized avatar

Kresten Krab Thorup krestenkrab

View GitHub Profile
@krestenkrab
krestenkrab / funhack.erl
Created April 12, 2011 09:52
The programmatic counter-part for "fun Mod:Fun/Arity"
-module(funhack).
-export([mkfun/3]).
%% @doc
%% The programmatic counter-part for `fun Mod:Fun/Arity'.
%%
%% Erlang syntax does not allow usage of the `fun' syntax,
%% where Mod, Fun and Arity are variables; they need to be
%% atom, atom, integer. This little hack lets you avoid
%% writing `fun(A1,A2,A3...) -> Mod:Fun(A1,A2,A3,...) end'.
@krestenkrab
krestenkrab / gist:992797
Created May 26, 2011 08:52
From Zero to Erjang in 22 seconds
krab$ curl -O http://dl.dropbox.com/u/1360473/erjang-r13b04-20110524.jar && java -jar erjang-r13b04-20110524.jar
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 9737k 100 9737k 0 0 430k 0 0:00:22 0:00:22 --:--:-- 474k
Eshell V5.7.5 (abort with ^G)
1>
@krestenkrab
krestenkrab / gen_pipe.erl
Created June 16, 2011 12:16
Ramblings on a gen_pipe DSL for riak_pipe
%%
%% Generic riak_pipe_vnode_worker worker, so you can write multiple fittings in one file.
%%
%% Each fitting is a function which must accept
%%
%% ImplFun(init, InitArg) -> {ok, State}
%% ImplFun({process, Input}, State) -> {ok, State} | forward_preflist
%% ImplFun(done, State) -> ok
%%
%% gen_pipe also has some more friendly API
@krestenkrab
krestenkrab / config_protobuf_iphonesimulator.sh
Created September 23, 2011 14:40
Configure protobuf library for iphone
export ARCH=i686-apple-darwin11
export ARCH_PREFIX=${ARCH}-
export PLATFORM=iPhoneSimulator
export SDKVER=4.3
export DEVROOT=/Developer/Platforms/${PLATFORM}.platform/Developer
export SDKROOT="$DEVROOT/SDKs/${PLATFORM}$SDKVER.sdk"
export PKG_CONFIG_PATH="$SDKROOT/usr/lib/pkgconfig:$DEVROOT/usr/lib/pkgconfig"
export AS="$DEVROOT/usr/bin/as"
export ASCPP="$DEVROOT/usr/bin/as"
@krestenkrab
krestenkrab / gist:1275132
Created October 10, 2011 11:52
Thanks WebFaction
Dear customer,
Today the load on Web218 (the server hosting your account "dartinside") was very high mostly due to a huge number of requests to the /wp-admin/admin-ajax.php URL in your website. We had to disable this URL by changing the permissions for the file to 000. We're not sure what caused this number of requests - but they seem to be coming from a lot of different IPs. Please investigate this - if you need any further information, please let us know.
Regards,
Todor K.
WebFaction Support
--
WebFaction - Smarter web hosting
@krestenkrab
krestenkrab / gist:1373280
Created November 17, 2011 14:37
Parse a HTTP token-list
%%
%% Parse a comma-separated tokenlist
%%
%% the string: a, b , "c\" ", , d
%% gives : {ok, [<<"a">>, <<"b">>, <<"c\" >>, <<>>, <<"d">>]}
%%
-spec parse_tokenlist(string()) -> malformed | {ok, [binary()]}.
parse_tokenlist(String) ->
@krestenkrab
krestenkrab / hindent.el
Created December 22, 2011 14:14
hindent.el: Highlight indentation of current line
;;;
;;; Copyright (C) Kresten Krab Thorup
;;; Available under Apache License, Version 2.
;;;
;;;
;;; This minor mode will highlight the indentation of the current line
;;; as a vertical bar (grey background color) aligned with the column of the
;;; first character of the current line.
;;;
@krestenkrab
krestenkrab / iopattern.ksh
Created April 26, 2012 20:13 — forked from gburd/iopattern.ksh
iopattern - print disk I/O pattern.
#!/usr/bin/ksh
#
# iopattern - print disk I/O pattern.
# Written using DTrace (Solaris 10 3/05).
#
# This prints details on the I/O access pattern for the disks, such as
# percentage of events that were of a random or sequential nature.
# By default totals for all disks are printed.
#
# $Id: iopattern 65 2007-10-04 11:09:40Z brendan $
@krestenkrab
krestenkrab / gist:6273690
Created August 19, 2013 20:26
Sample run of Elixir on Erjang.
krab$ ./bin/iex
ej -env ERL_LIBS :/Users/krab/Projects/elixir/bin/../lib -noshell -user Elixir-IEx-CLI -extra --no-halt --erl -user Elixir-IEx-CLI
Warning: could not run smart terminal, falling back to dumb one
Interactive Elixir (0.8.2.dev) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 1/0
** (ArithmeticError) bad argument in arithmetic expression
:erlang./(1, 0)
:erlang.apply/2
erl_eval.erl:572: :erl_eval.do_apply/6
elixir.erl:133: :elixir.eval_forms/3
@krestenkrab
krestenkrab / erjang-status-aug15.md
Last active December 22, 2017 18:46
Notes on the current status of Erjang

Elixir on Erjang

The last few weeks I've spent some night hacking time to get Erjang to be able to run Elixir. Here's a short note on the current status for those interested.

The bottom line is that we can now boot the Elixir REPL, it looks like this:

krab$ ./bin/iex 
Warning: could not run smart terminal, falling back to dumb one
Aug 26, 2013 11:11:14 AM erjang.EModuleManager$FunctionInfo$1 invoke