Skip to content

Instantly share code, notes, and snippets.

@egobrain
egobrain / ants.erl
Created September 5, 2015 13:05
Ants fp
-module(ants).
-export([main/1]).
-mode(compile).
readline_iterator(File) ->
fun() ->
case file:read_line(File) of
{ok, Line} -> {ok, Line, readline_iterator(File)};
eof -> done;
@egobrain
egobrain / remsh
Created August 10, 2015 19:02
erlang remsh
#!/bin/bash
node=$1
data=($(echo $node | tr "@" "$IFS"))
username=yk
name=${data[0]}
domain=${data[1]}
rand=$(date +%s | sha256sum | base64 | head -c 10 ; echo)
-module(list_utils).
-export([group_by/2]).
group_by(_Key, []) -> [];
group_by(Key, List) ->
[H|T] = lists:keysort(Key, List),
K = element(Key, H),
group_by_(Key, K, [H], [], T).
@egobrain
egobrain / t.erl
Created January 26, 2015 12:59
Maps performace (update by key) test.
-module(t).
-compile(export_all).
-record(r, {a1,a2,a3,a4,a5,a6,a7,a8}).
test(F, N, Times) ->
NSeq = lists:seq(1, N),
TimeSeq = lists:seq(1, Times),
R =
-module(dups).
-export([
duplicates/1,
same_order_duplicates/1
]).
duplicates([]) -> {[], []};
duplicates(List) ->
[H|T] = lists:sort(List),
0 at [1, 1]
1 at [1, 5]
2 at [1, 9]
3 at [1, 13]
4 at [1, 17]
5 at [1, 21]
6 at [1, 25]
7 at [1, 29]
8 at [1, 33]
9 at [1, 37]
#!/usr/bin/env escript
-mode(compile).
-define(M0, {0, ["111","101","101","101","111"]}).
-define(M1, {1, ["110","010","010","010","111"]}).
-define(M2, {2, ["111","001","111","100","111"]}).
-define(M3, {3, ["111","001","111","001","111"]}).
-define(M4, {4, ["101","101","111","001","001"]}).
-define(M5, {5, ["111","100","111","001","111"]}).
@egobrain
egobrain / pub_sub.erl
Last active August 29, 2015 14:05
Thirdparty gproc sub.
-module(pub_sub).
-export([
sub/1,
sub/2,
pub/2
]).
sub(Property) ->
sub(Property, self()).
@egobrain
egobrain / remove_kernels_except.sh
Created January 31, 2014 10:36
Remove all kernel except one
#!/bin/bash
zypper rm `zypper se -si 'kernel*' | grep kernel | awk '{printf("%s-%s\n",$3,$7)}' | grep -v $1 | tr "\\n" " " `
<html>
<head>
<title>Test remember password</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$('#login-button').click(function (ev) {
alert('AJAX login...');
});