Skip to content

Instantly share code, notes, and snippets.

View erszcz's full-sized avatar

Radek Szymczyszyn erszcz

View GitHub Profile
@erszcz
erszcz / my_tracer.erl
Last active March 25, 2016 16:08
Monitored tracer process
-module(my_tracer).
-compile([export_all]).
-define(il2b, iolist_to_binary).
%% Listen carefully, since I won't repeat.
%%
%% Default dbg:dhandler/2 is nice,
%% but when you want to use domain knowledge
@erszcz
erszcz / jid_gen.erl
Last active October 27, 2015 10:32
XMPP related generators
bare_jid() ->
?LET({Username, Domain}, {username(), domain()},
<<(?l2b(Username))/bytes, "@", (?l2b(Domain))/bytes>>).
%full_jid() ->
% ?LET({Username, Domain, Res}, {username(), domain(), resource()},
% <<(?l2b(Username))/bytes, "@", (?l2b(Domain))/bytes, "/", (?l2b(Res))/bytes>>).
username() -> ascii_string().
domain() -> ascii_string().
#!/usr/bin/env escript
%% -*- erlang -*-
%% vim: ft=erlang
%% Usage:
%%
%% echo "SELECT message FROM mam_message ORDER BY id DESC LIMIT 4" | \
%% psql -U user -t | ./decode_archived_message
%%
%% Basically any query which returns just mam_message.message column can
@erszcz
erszcz / elixirc.dbg
Created June 22, 2015 15:12
Elixir compiler trace
$ erl -pa /Users/erszcz/apps/elixir/xyz/bin/../lib/eex/ebin /Users/erszcz/apps/elixir/xyz/bin/../lib/elixir/ebin /Users/erszcz/apps/elixir/xyz/bin/../lib/ex_unit/ebin /Users/erszcz/apps/elixir/xyz/bin/../lib/iex/ebin /Users/erszcz/apps/elixir/xyz/bin/../lib/logger/ebin /Users/erszcz/apps/elixir/xyz/bin/../lib/mix/ebin -elixir ansi_enabled true -noshell -s setdbg -s elixir start_cli -extra +elixirc asd.ex
(<0.51.0>) call elixir_compiler:file_to_path(<<"asd.ex">>,<<".">>)
(<0.51.0>) call elixir_compiler:file(<<"asd.ex">>,<<".">>)
(<0.51.0>) call elixir_compiler:get_opt(internal)
(<0.51.0>) returned from elixir_compiler:get_opt/1 -> false
(<0.51.0>) call elixir_compiler:string("defmodule Math do\n def sum(a, b) do\n a + b\n end\nend\n\n",<<"/private/tmp/zxc/asd.ex">>,<<"/private/tmp/zxc/.">>)
(<0.51.0>) call elixir_compiler:quoted({defmodule,[{line,1}],
[{'__aliases__',[{counter,0},{line,1}],['Math']},
[{do,{def,[{line,2}],
[{sum,[{line,2}],
@erszcz
erszcz / console-dump.txt
Created October 7, 2014 22:27
Rust bug in Unicode handling?
00:25:30 erszcz @ x2 : /tmp
$ cat zoladz.rs
fn main() {
let z = "żołądź";
println!("{:c}", z.char_at(1));
}
00:25:33 erszcz @ x2 : /tmp
$ rustc zoladz.rs
00:25:37 erszcz @ x2 : /tmp
$ ./zoladz
@erszcz
erszcz / er.c
Created September 15, 2014 20:30
nif_init(void)
ErlNifFunc funcs[] =
{
{"native_add", 2, native_add}
};
ErlNifEntry* nif_init(void) {
static ErlNifEntry entry = {
2,
6,
"er",
@erszcz
erszcz / mnesia_helper.erl
Created September 3, 2014 12:18
Mnesia Events
-module(mnesia_helper).
-compile([export_all]).
-record(some_record, {name=default, value=undefined}).
setup() ->
application:start(sasl),
application:start(mnesia),
{atomic, ok} = mnesia:create_table(some_record, [{attributes,
@erszcz
erszcz / elvis-rock-dbg-trace
Created August 5, 2014 09:47
Elvis crashes in `erl_parse:abstract/2`
2> dbg:tracer().
{ok,<0.38.0>}
3> dbg:p(all, call).
{ok,[{matched,nonode@nohost,26}]}
4> dbg:tp(elvis_code, x).
{ok,[{matched,nonode@nohost,15},{saved,x}]}
5> dbg:tp(erl_parse, x).
{ok,[{matched,nonode@nohost,20},{saved,x}]}
6>
6> elvis:rock(#{src_dirs => ["src", "include", "test"], rules => []}).
@erszcz
erszcz / parser2.rs
Created June 24, 2014 21:08
Rust: invalid memory reference
#![feature(phase, globs)]
#[phase(syntax, link)] extern crate log;
fn tokenize(s: &str) -> ~[&str] {
let t = std::str::replace(s, "(", " ( ");
let u = std::str::replace(t, ")", " ) ");
u.words().collect()
}
#[deriving(Eq, Show, Clone)]
@erszcz
erszcz / fibonacci.rs
Created June 15, 2014 14:11
Lazy Fibonacci generator in Rust
use std::iter::Unfold;
fn main() {
let it = fibonacci();
// prints the sequence
//for i in it.take(10) {
// print!("{} ", i)
//}