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
@ferd
ferd / erlang-shell-search-history.patch
Created December 20, 2012 13:59
Add search to Erlang shell's history Search mode can be entered by pressing ctrl-r. Enter terms and press ctrl-r again to search backwards, or ctrl-s to then search forward (if you terminal doesn't eat up that one). Press enter to execute the line, or use tab, arrow keys, or other control sequences (^D, ^K, etc.) to exit search mode while remain…
From d98e6c32d44e00f954c3912b08c6ebf48d55729c Mon Sep 17 00:00:00 2001
From: Fred Hebert <mononcqc@ferd.ca>
Date: Thu, 20 Dec 2012 08:41:33 -0500
Subject: [PATCH] Add search to Erlang shell's history
Search mode can be entered by pressing ctrl-r. Enter terms and press
ctrl-r again to search backwards, or ctrl-s to then search forward (if
you terminal doesn't eat up that one). Press enter to execute the line,
or use tab, arrow keys, or other control sequences (^D, ^K, etc.) to
exit search mode while remaining on the last found line.
@ferd
ferd / app_deps.erl
Created September 23, 2012 05:33
Quick escript to generate a visualization of app dependencies in Erlang/OTP.
%%% Run with 'escript app_deps.erl'
%%% Change the path in filelib:wildcard/1 as required to capture all
%%% your dependencies.
%%%
%%% Rectangular nodes will represent library apps (no processes involved)
%%% and the circular nodes will represent regular apps. An arrow going from
%%% 'A -> B' means 'A depends on B'.
%%%
%%% This script depends on graphviz being present on the system.
-module(app_deps).
%%% Macro definitions for lazy (or rather delayed) evaluation.
%% Force and delay are used in combination to delay evaluation to only
%% when strictly needed:
%% Promise = ?delay(expensive_computation(A,B,C)),
%% Value = ?force(Promise).
%%
%% These macros should be used with extreme precaution when sending a
%% function to another process as it relies on closures and the sharing of
%% information is lost when copying. So is memoization. Therefore, lazy
@ferd
ferd / gist:3274480
Created August 6, 2012 13:29
copy/paste in the shell, call Biggest(Milliseconds, N)
F = fun() -> [{Pid, {Reds, Curr, Init}} || Pid <- processes(),
{_, Reds} <- [process_info(Pid, reductions)],
{_, Curr} <- [process_info(Pid, current_function)],
{_, Init} <- [process_info(Pid, initial_call)]] end.
Fetch = fun(T) -> A = F(), timer:sleep(T), B= F(), {A,B} end.
Build = fun({A,B}) ->
D = dict:from_list(A),
lists:foldl(fun({Pid,{Red,Cur,Init}}, Dict) ->
#lang racket
(require racket/match)
(require racket/string)
(define (to-roman x)
(define (digit digits)
(match digits
[(list 1 x _ _) (list x)]
[(list 2 x _ _) (list x x)]
[(list 3 x _ _) (list x x x)]
-module(lazy).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
%% A lazy list is build from cells containing the value of their current
%% computation and a function that will return the next one.
%% Once a lazy list is over, the atom 'done' is returned.
-define(lcell(Term, Fun), {Term, Fun}).
-type lcell() :: {term(), fun(() -> tuple() | 'done' )}
| 'done'.
@ferd
ferd / tend_gist_load.erl
Created July 7, 2012 22:52
Test Module for The Erl Next Door
-module(tend_gist_load).
-export([run/0]).
run() -> ':)'.
58> [timer:tc(dispcount,checkout,[Info]) || _ <- lists:seq(1,100)].
[{34,{ok,{<0.62.0>,#Ref<0.0.0.470>},#Ref<0.0.0.398>}},
{22,{ok,{<0.64.0>,#Ref<0.0.0.472>},#Ref<0.0.0.399>}},
{3,{error,busy}},
{26,{ok,{<0.59.0>,#Ref<0.0.0.474>},#Ref<0.0.0.328>}},
{21,{ok,{<0.61.0>,#Ref<0.0.0.476>},#Ref<0.0.0.458>}},
{20,{ok,{<0.63.0>,#Ref<0.0.0.478>},#Ref<0.0.0.402>}},
{38,{ok,{<0.57.0>,#Ref<0.0.0.480>},#Ref<0.0.0.326>}},
{20,{ok,{<0.66.0>,#Ref<0.0.0.482>},#Ref<0.0.0.457>}},
{3,{error,busy}},
24> proper:quickcheck(dispcount_prop:prop_parallel_nocrash(), [{numtests, 5000}]).
.................................................................................................................................................................................................................!
Failed: After 210 test(s).
{[{init,{state,[],undefined}}],[[{set,{var,1},{call,dispcount,checkout,[{call,erlang,element,[2,{call,dispcount,dispatcher_info,[prop_dispatch]}]}]}}],[{set,{var,2},{call,dispcount,checkout,[{call,erlang,element,[2,{call,dispcount,dispatcher_info,[prop_dispatch]}]}]}},{set,{var,3},{call,dispcount,checkout,[{call,erlang,element,[2,{call,dispcount,dispatcher_info,[prop_dispatch]}]}]}}]]}
History: {{[{init,{state,[],undefined}}],
[[{set,{var,1},
{call,dispcount,checkout,
[{call,erlang,element,
[2,
{call,dispcount,dispatcher_info,
9> gen_udp:open(8789, [binary, {active,true}]).
{ok,#Port<0.665>}
10> inet:i(udp).
Port Module Recv Sent Owner Local Address Foreign Address State Type
665 inet_udp 0 0 <0.49.0> *:8789 *:* BOUND DGRAM
ok