Skip to content

Instantly share code, notes, and snippets.

View ferd's full-sized avatar
☢️
This place is not a place of honor… no highly esteemed deed is commemorated here

Fred Hebert ferd

☢️
This place is not a place of honor… no highly esteemed deed is commemorated here
View GitHub Profile
@mbbx6spp
mbbx6spp / erlang-shell-notes.erl
Created March 23, 2011 14:00
Notes on using Meck API (a mocking library in Erlang) which are not well documented
% Will create a fully mocked version of existing_module until caller crashes
meck:new(ExistingModule).
% Will create a fully mocked version of existing_module even after caller crashes
meck:new(ExistingModule, [nolink]).
% Will allow you to overload existing module, keeping old functions around
meck:new(ExistingModule, [passthrough]).
% Unload mocks and revert to real module implementation
@lpgauth
lpgauth / gist:3151052
Created July 20, 2012 14:35
lcnt:conflicts()
lock id #tries #collisions collisions [%] time [us] duration [%]
----- --- ------- ------------ --------------- ---------- -------------
proc_tab 1 12869 5933 46.1030 343822 114.2133
run_queue 24 172468 9301 5.3929 73889 24.5450
port_lock 3971 61326 288 0.4696 62224 20.6700
pollset 1 23543 2568 10.9077 33272 11.0525
pix_lock 256 106471 602 0.5654 20412 6.7806
drv_ev_state 16 21854 503 2.3016 20380 6.7700
proc_link 10512 58810 843 1.4334 8518 2.8296
proc_msgq 10512 83228 524 0.6296 4972 1.6516

#vim-erlang_tools

https://github.com/fishcakez/vim-erlang_tools

Vim plugin to combine vim and tmux to add support for some erlang tools to vim. Inspired by the vimux plugin. Currently erlc, ct_run, dialyzer, eunit and rebar have some support.

The plugin works by using a ct hook or an eunit listener to produce identical format to dialyzer -o outputfile. This means all tools' output can be parsed

@dergachev
dergachev / GIF-Screencast-OSX.md
Last active June 5, 2024 22:16
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@ferd
ferd / gist:5694838
Last active December 18, 2015 00:09
f(Window).
Window = fun(AttrName, Time,NumProcs) ->
Attrs = fun(Name) ->
[{Pid, {Attr, Curr, Init}}
|| Pid <- processes() -- [self()],
[{_, Attr}, {_, Curr}, {_, Init}] <-
[process_info(Pid, [Name, current_function, initial_call])]]
end,
F = fun() -> Attrs(AttrName) end,
@ferd
ferd / gist:5708689
Created June 4, 2013 19:19
loop that displays stats for a node
f(Init), f(Loop), f(Stats), f(ShowStats),
Init = fun(Delay) ->
Ref = erlang:start_timer(Delay, self(), '#delay'),
{{input,In},{output,Out}} = erlang:statistics(io),
PrevGC = erlang:statistics(garbage_collection),
{{Delay,Ref}, {In,Out}, PrevGC}
end,
Loop = fun(Self,F,N,{{D,R},{OldIn,OldOut},{OldGCs,OldWords,_}}) ->
receive
{timeout,R,'#delay'} ->
@ferd
ferd / gist:5783802
Created June 14, 2013 17:38
Compare runtime, run queue, and scheduler business
erlang:system_flag(scheduler_wall_time, true),
f(WallTimeDiff),
WallTimeDiff = fun(T1,T2) -> [trunc(100*((Active2-Active1)/(Total2-Total1)))/100 || {{I, Active1, Total1}, {I, Active2, Total2}} <- lists:zip(lists:sort(T1),lists:sort(T2))] end,
f(F), put(stime, erlang:statistics(scheduler_wall_time)),
F = fun(F,N) -> Old=get(stime), New=erlang:statistics(scheduler_wall_time), put(stime,New), io:format("rt:~p\trq:~p\t\tsched:~w~n", [element(2,erlang:statistics(runtime)), erlang:statistics(run_queue), WallTimeDiff(Old,New)]), timer:sleep(N), F(F,N) end.
%% F(F, IntervalInMS).
@ferd
ferd / cdumpbin.erl
Created July 12, 2013 19:05
Convert a crash dump Refc binary back to a regular binary. Uses the erl_eval module to evaluate the 16#... hex conversion much faster than naive string handling would do it in this little space.
%% Convert a crashdump binary back into a regular binary
%% Crash dump binary:
%% =binary:CFE75808 % <- reference to refc binary
%% CA:2A31300D0A24350D0A484D5345540D0... % <- actual binary
CDumpBin = fun(Str) ->
[Len,Num] = string:tokens(Str, ":"),
Src= lists:flatten(["<<16#",Num,":(16#",Len,"*8)>>."]),
{ok, Tokens, _}=erl_scan:string(Src),
{ok, [Form]} = erl_parse:parse_exprs(Tokens),
{value, Val, _} = erl_eval:expr(Form, erl_eval:new_bindings()),
@ferd
ferd / refc_leak.erl
Created July 18, 2013 12:32
Find Erlang processes that may be leaking refc binaries
f(MostLeaky).
MostLeaky = fun(N) ->
lists:sublist(
lists:usort(
fun({K1,V1},{K2,V2}) -> {V1,K1} =< {V2,K2} end,
[try
{_,Pre} = erlang:process_info(Pid, binary),
erlang:garbage_collect(Pid),
{_,Post} = erlang:process_info(Pid, binary),
{Pid, length(Post)-length(Pre)}
# Parse Erlang Crash Dumps and correlate mailbox size to the currently running
# function.
#
# Once in the procs section of the dump, all processes are displayed with
# =proc:<0.M.N> followed by a list of their attributes, which include the
# message queue length and the program counter (what code is currently
# executing).
BEGIN {
threshold = 10000 # mailbox size
procs = 0 # are we in the =procs entries?