Skip to content

Instantly share code, notes, and snippets.

@dvv
dvv / .erlang
Created March 28, 2013 18:59
Erlang shortcuts
code:load_abs(os:getenv("HOME") ++ "/.ebin/user_default"),
io:format("You may use r() to recompile the code, t() to recompile templates under priv/templates.~n", []).
@dvv
dvv / ua.erl
Created January 13, 2013 10:39
A draft of user agent determination
-spec user_agent_platform(binary()) -> undefined | atom().
user_agent_platform(Header) ->
user_agent(cowboy_bstr:to_lower(Header), [
{<<"windows">>, windows},
{<<"linux">>, linux},
{<<"os x ">>, osx},
{<<"android">>, android},
{<<"ipod">>, ipod},
{<<"iphone">>, iphone},
@dvv
dvv / peectp.erl
Created January 12, 2013 07:54
Process registrar -- gproc wrapper
%%
%% @doc Generic process registrar and operating primitives.
%% Basically, gproc wrapper.
%%
-module(peectp).
-author('Vladimir Dronnikov <dronnikov@gmail.com>').
%%
%% -----------------------------------------------------------------------------
@dvv
dvv / handler.erl
Created December 18, 2012 12:13
An attempt at hiding cookie session details in cowboy handler
-module(handler).
-author('Vladimir Dronnikov <dronnikov@gmail.com>').
-define(INFO, error_logger:info_report).
-define(ERROR, error_logger:error_report).
%%
%% ------------------------------------------------------------------
%% cowboy HTTP handler API
%% ------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Server
// -----------------------------------------------------------------------------
var listen = function () {
var server = HTTP.createServer();
server.listen(process.env.PORT || 8000, "0.0.0.0", function () {
console.log(`Starting HTTP server on ${this._connectionKey}...`);
function attach() {
app.middleware = require("./stack");
@dvv
dvv / gist:4181331
Created December 1, 2012 09:44
naive moonslice-luv performance test
Latest moonslice-luv hello world:
[dvv@dvv take6]$ wrk -c20k -r1000k http://localhost:8080/greet
Making 1000000 requests to http://localhost:8080/greet
2 threads and 20000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 268.44ms 334.12ms 2.37s 81.42%
Req/Sec 6.51k 1.99k 8.00k 88.55%
1000160 requests in 1.02m, 132.58MB read
Socket errors: connect 0, read 8774, write 0, timeout 257854
@dvv
dvv / gist:2501729
Created April 26, 2012 18:33
package.searchpath experiment
#!/usr/bin/env luajit2
local Util = require('utils')
local p = Util.prettyPrint
local resolve
do
local ffi = require('ffi')
local C = ffi.C
ffi.cdef[[
@dvv
dvv / gist:1610685
Created January 14, 2012 08:01
MoonScript + CoffeeScript syntax
is, isnt
====
is, isnt ---> ==, ~=
else if
====
if 1
p(1)
@dvv
dvv / gist:1507626
Created December 21, 2011 20:45
Adding Luvit Worker
1.
Install https://github.com/luvit/luvm
It's basically creationix/nvm ported to luvit.
The only change is the absence of 'v' prefix for versions. I found it redundant.
Nothing surprising should happen, it should require nothing beyond build-essentials.
So after vanilla sourcing luvm with `cd ~/.luvm ; . luvm.sh` and running `luvm install 0.1.4` you should have on the PATH:
- luvit binary
- lui: headless dependency fulfiller
- luvit-config: a pkg-config surrogate
@dvv
dvv / uc.js
Created December 14, 2011 16:42
killer-string-for-sockjs
var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u2000-\u20ff\ufeff\ufff0-\uffff\x00-\x1f\ud800-\udfff\ufffe\uffff\u0300-\u0333\u033d-\u0346\u034a-\u034c\u0350-\u0352\u0357-\u0358\u035c-\u0362\u0374\u037e\u0387\u0591-\u05af\u05c4\u0610-\u0617\u0653-\u0654\u0657-\u065b\u065d-\u065e\u06df-\u06e2\u06eb-\u06ec\u0730\u0732-\u0733\u0735-\u0736\u073a\u073d\u073f-\u0741\u0743\u0745\u0747\u07eb-\u07f1\u0951\u0958-\u095f\u09dc-\u09dd\u09df\u0a33\u0a36\u0a59-\u0a5b\u0a5e\u0b5c-\u0b5d\u0e38-\u0e39\u0f43\u0f4d\u0f52\u0f57\u0f5c\u0f69\u0f72-\u0f76\u0f78\u0f80-\u0f83\u0f93\u0f9d\u0fa2\u0fa7\u0fac\u0fb9\u1939-\u193a\u1a17\u1b6b\u1cda-\u1cdb\u1dc0-\u1dcf\u1dfc\u1dfe\u1f71\u1f73\u1f75\u1f77\u1f79\u1f7b\u1f7d\u1fbb\u1fbe\u1fc9\u1fcb\u1fd3\u1fdb\u1fe3\u1feb\u1fee-\u1fef\u1ff9\u1ffb\u1ffd\u2000-\u2001\u20d0-\u20d1\u20d4-\u20d7\u20e7-\u20e9\u2126\u212a-\u212b\u2329-\u232a\u2adc\u302b-\u302c\uaab2-\uaab3\uf900-\ufa0d\ufa10\ufa12\ufa15-\ufa1e\ufa20\ufa22\ufa25-\ufa26\ufa2a-\ufa2d\ufa30-\ufa6d\ufa70-\ufad