Skip to content

Instantly share code, notes, and snippets.

View nox's full-sized avatar
🥖

Anthony Ramine nox

🥖
View GitHub Profile
@nox
nox / gist:6623009
Created September 19, 2013 12:53
Debugging rm-reverse-eta-conversion
nox@Bellcross:~/src/otp/erts/etc/unix[rm-reverse-eta-conversion|REBASE-i 1/3]
$ gdb-x86_64-linux ~/Downloads/beam.smp ~/Downloads/core
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin11.4.2 --target=x86_64-linux-gnu".
For bug reporting instructions, please see:
%% Copyright (c) 2013, Anthony Ramine <[email protected]>
%%
%% Permission to use, copy, modify, and/or distribute this software for any
%% purpose with or without fee is hereby granted, provided that the above
%% copyright notice and this permission notice appear in all copies.
%%
%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@nox
nox / atkin.erl
Last active December 20, 2015 04:49
Sieve of Atkin in Erlang with a mutable HiPE bitarray. Forgive me, I was bored.
-module(atkin).
-export([primes_smaller_than/1]).
primes_smaller_than(Limit) ->
primes_smaller_than(Limit, sieve(Limit), []).
primes_smaller_than(0, _, Acc) ->
Acc;
primes_smaller_than(N, Bin, Acc) ->
@nox
nox / gist:5515309
Last active December 16, 2015 23:39
Attempt at making Erlang stacktraces more readable
$ bin/erl
Erlang R16B01 (erts-5.10.2) [source-7e9ae30] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V5.10.2 (abort with ^G)
1> spawn(fun () -> (fun () -> 1 + foo end)(), get(foo) end).
<0.35.0>
=ERROR REPORT==== 4-May-2013::02:12:25 ===
Error in process <0.35.0> with exit value: badarith
at erlang:'+'(1, foo)
@nox
nox / gist:5474196
Created April 27, 2013 18:57
Epp printing lines of parsed files
1> {ok, Epp} = epp:open("t.erl", [], []).
{ok,<0.34.0>}
2> epp:opened_files(Epp).
["t.erl"]
3> epp:parse_file(Epp).
[{attribute,1,file,{"t.erl",1}},
{attribute,1,module,t},
{attribute,-2,file,{"truc.hrl",1}},
{attribute,1,file,{"t.hrl",1}},
{attribute,1,foo,bar},
@nox
nox / prealloc_bin.S
Created April 10, 2013 23:49
Preallocated binaries in Erlang... well, in BEAM.
{module, prealloc_bin}. %% version = 0
{exports, [{module_info,0},{module_info,1},{new,1}]}.
{attributes, []}.
{labels, 7}.
{function, new, 1, 2}.
@nox
nox / gist:4160201
Created November 28, 2012 09:50
Building Erlang/OTP with silent rules
MAKE generate
M4 i386-apple-darwin11.4.2/opt/plain/hipe_x86_asm.h
M4 i386-apple-darwin11.4.2/opt/plain/hipe_amd64_asm.h
M4 i386-apple-darwin11.4.2/opt/plain/hipe_sparc_asm.h
M4 i386-apple-darwin11.4.2/opt/plain/hipe_ppc_asm.h
M4 i386-apple-darwin11.4.2/opt/plain/hipe_arm_asm.h
GEN i386-apple-darwin11.4.2/opt/plain/erl_alloc_types.h
GEN i386-apple-darwin11.4.2/opt/plain/OPCODES-GENERATED
GEN i386-apple-darwin11.4.2/TABLES-GENERATED
CC obj/i386-apple-darwin11.4.2/opt/plain/hipe_mkliterals.o
@nox
nox / gist:4139688
Created November 24, 2012 13:24
erlang:list_to_atom/2
erlang:list_to_atom(string(), [global | safe]).
string | options | result
---------------+--------------------------+---------------------------
"not_existing" | global | not_existing (global)
"existing" | global | existing (global)
"not_existing" | safe | not_existing (local)
"existing" | safe | existing (global)
"not_existing" | global, safe | FAILURE
"existing" | global, safe | existing (global)
@nox
nox / gist:4055121
Created November 11, 2012 14:51
EEP37 shell example
$ $ERL_TOP/bin/erl
Erlang R15B03 (erts-5.9.3) [source] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.3 (abort with ^G)
1> F = fun Myself(N) ->
1> G = fun Fact(1) ->
1> 1;
1> Fact(N) when is_integer(N), N > 1 ->
1> N * Fact(N - 1);
1> Fact(_) ->
@nox
nox / fact.S
Created November 9, 2012 13:05
EEP37 example
{module, fact}. %% version = 0
{exports, [{fact,0},{module_info,0},{module_info,1}]}.
{attributes, []}.
{labels, 11}.
{function, fact, 0, 2}.