Skip to content

Instantly share code, notes, and snippets.

@okeuday
okeuday / quine0
Created April 5, 2019 06:25
A quine in Erlang
#!/usr/bin/env escript
%%!
%-*-Mode:erlang;coding:utf-8;tab-width:4;c-basic-offset:4;indent-tabs-mode:()-*-
% ex: set ft=erlang fenc=utf-8 sts=4 ts=4 sw=4 et:
-mode(compile).
main(["-i" | _]) ->
MagicNumber = 0,
GenerationName = filename:basename(escript:script_name()),
@okeuday
okeuday / http_req_erlang.xml
Last active July 10, 2017 16:05
CloudI Erlang http_req integration test Tsung loadtest configuration
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd">
<tsung loglevel="notice" version="1.0">
<!-- Client side setup -->
<clients>
<client host="load00" maxusers="30000" use_controller_vm="false">
<ip value="192.168.2.10"/>
</client>
<client host="load01" maxusers="30000">
@okeuday
okeuday / wlan-scan.sh
Created February 23, 2017 02:00
Linux /etc/network/interfaces script for wifi
#!/bin/sh
if [ $# -ne 1 ]; then
echo "usage: $0 wlan_interface"
exit 1
fi
DIRECTORY=`dirname $0`
IFACE=$1
ifconfig $IFACE hw ether `$DIRECTORY/mac_address_reset`
@okeuday
okeuday / mac_address_reset
Created February 23, 2017 01:55
Automatically generate a valid MAC address
#!/bin/sh
# wget http://standards.ieee.org/develop/regauth/oui/oui.txt
DIRECTORY=`dirname $0`
PREFIX=`shuf $DIRECTORY/oui.txt | grep '(base 16)' | head -n 1 | cut -c '3-8'`
SUFFIX=`openssl rand -hex 3 | sed 's/.*/\U&/'`
echo "$PREFIX$SUFFIX"
erl +C multi_time_warp -noshell -pz ebin -s run test -s init stop
TEST string_key
N == 10 (10 runs)
aadict get: 2.1 us ( 1.1), set: 7.8 us ( 1.8)
btrie (binaries) get: 5.0 us ( 2.5), set: 19.8 us ( 4.5)
dict get: 5.4 us ( 2.7), set: 15.2 us ( 3.5)
ets (ordered_set) get: 5.1 us ( 2.6), set: 8.6 us ( 2.0)
ets (set) get: 5.5 us ( 2.8), set: 11.1 us ( 2.5)
ets x10 read (ordere get: 10.1 us ( 5.1)
ets x10 read (set) get: 12.1 us ( 6.1)
@okeuday
okeuday / keybase.md
Created September 13, 2016 01:09
keybase.io github verification

Keybase proof

I hereby claim:

  • I am okeuday on github.
  • I am okeuday (https://keybase.io/okeuday) on keybase.
  • I have a public key whose fingerprint is 1280 8D2D FFAE 0B0A F4DE B11A 4BE6 AE02 12FE BBB1

To claim this, I am signing this object:

Core i7 2670QM 2.2GHz 1 cpu, 4 cores/cpu, 2 hts/core
L2:4×256KB L3:6MB RAM:8GB:DDR3-1333MHz
Sandy Bridge-HE-4 (Socket G2)
TEST integer_key
N == 10 (10 runs)
aadict get: 2.5 us ( 25.0), set: 9.6 us ( 8.0)
array (dynamic) get: 1.0 us ( 10.0), set: 3.7 us ( 3.1)
array (fixed) get: 1.2 us ( 12.0), set: 2.7 us ( 2.3)
btree7 get: 2.6 us ( 26.0), set: 5.2 us ( 4.3)
...
Path = [_ | _] = os:getenv("TEST_DIR"),
ReleaseConfig = filename:join([Path, "..", "rel", "files", "app.config"]),
{ok, _} = reltool_util:config_load(ReleaseConfig),
...
ok = reltool_util:application_start(?APPLICATION,
[{listen_ip, {127,0,0,1}},
{listen_port, ?PORT}], infinity),
...
@okeuday
okeuday / package.exs
Created October 13, 2014 20:28
hex.pm package file
defmodule ErlangSyslog.Mixfile do
use Mix.Project
def project do
[app: :syslog,
version: "1.0.3",
description: description,
package: package,
deps: deps]
end
@okeuday
okeuday / immediate_gc.erl
Created September 23, 2014 05:08
Immediate Garbage Collection in Erlang (as harsh as possible)
%-*-Mode:erlang;coding:utf-8;tab-width:4;c-basic-offset:4;indent-tabs-mode:()-*-
% ex: set ft=erlang fenc=utf-8 sts=4 ts=4 sw=4 et:
%%%
%%%------------------------------------------------------------------------
%%% @doc
%%% ==Enforce immediate garbage collection on a function==
%%% @end
%%%
%%% BSD LICENSE
%%%