Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View erszcz's full-sized avatar

Radek Szymczyszyn erszcz

View GitHub Profile
@erszcz
erszcz / pack.erl
Last active August 29, 2015 13:55
pack jids
-module(pack).
-compile([export_all]).
-define(SETS, gb_sets).
-define(DICT, dict).
-record(state, {pres_t = ?SETS:new(),
pres_f = ?SETS:new(),
pres_a = ?SETS:new(),
%!TEX TS-program = xelatex
\documentclass[12pt]{scrartcl}
% The declaration of the document class:
% The second line here, i.e.
% \documentclass[12pt]{scrartcl}
% is a standard LaTeX document class declaration:
% we say what kind of document we are making in curly brackets,
% and specify any options in square brackets.
@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)
//}
@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 / 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 / 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 / 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 / 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 / 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}],
#!/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