Skip to content

Instantly share code, notes, and snippets.

sudo apt-get install mercurial
sudo apt-get install git-core
sudo apt-get install imagemagick
sudo apt-get -y install build-essential m4 libncurses5-dev libssh-dev unixodbc-dev libgmp3-dev libwxgtk2.8-dev libglu1-mesa-dev fop xsltproc default-jdk
mkdir -p /src/erlang
cd /src/erlang
wget http://www.erlang.org/download/otp_src_R14B04.tar.gz
tar -xvzf otp_src_R14B04.tar.gz
chmod -R 777 otp_src_R14B04
cd otp_src_R14B04
@pragmaticobjects
pragmaticobjects / test.erl
Created October 28, 2011 14:56
Routing in cowboy
start(_Type, _Args) ->
Dispatch = [
{'_', [
{[<<"users">>, id, <<"messages">>], users_handler, []},
{'_', default_handler, []}
]}
],
cowboy:start_listener(http, 100,
cowboy_tcp_transport, [{port, 8080}],
cowboy_http_protocol, [{dispatch, Dispatch}]
@pragmaticobjects
pragmaticobjects / alchemy-client.js
Created October 23, 2011 16:33
Modified alchemy-client.js
/*
Alchemy Websockets Client Library
Copyright 2011 Olivine Labs, LLC.
http://www.olivinelabs.com
*/
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
@pragmaticobjects
pragmaticobjects / web_socket.js
Created October 23, 2011 16:27
Modified web_socket.js
// Copyright: Hiroshi Ichikawa <http://gimite.net/en/>
// License: New BSD License
// Reference: http://dev.w3.org/html5/websockets/
// Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol
(function () {
if (window.WebSocket || window.MozWebSocket) return;
var console = window.console;
if (!console || !console.log || !console.error) {
@pragmaticobjects
pragmaticobjects / random_password.erl
Created October 5, 2011 04:22
Generate random passwords and/or ids
-module(random_password).
-export([make_random_password/1]).
make_random_password(N) ->
{A1,A2,A3} = now(),
random:seed(A1, A2, A3),
lists:map(fun(_) -> make_random_unfunny_char() end, lists:seq(1, N)).
make_random_unfunny_char() ->
R = random:uniform(62),
@pragmaticobjects
pragmaticobjects / random_password.erl
Created October 5, 2011 04:17
Generate random passwords and/or ids
-module(random_password).
-export([make_random_password/1]).
make_random_password(N) ->
{A1,A2,A3} = now(),
random:seed(A1, A2, A3),
lists:map(fun(_) -> make_random_unfunny_char() end, lists:seq(1, N)).
make_random_unfunny_char() ->
R = random:uniform(62),
@pragmaticobjects
pragmaticobjects / removedup.erl
Created September 28, 2011 00:26
Remove duplicates in a list
-module(removedup).
-export([removedup/1]).
compare(H, []) -> [H];
compare(H, [H|T]) -> [H|T];
compare(H1, [H|T]) ->
L = [H|T],
[H1|L].
@pragmaticobjects
pragmaticobjects / closure.js
Created September 11, 2011 05:29
Another Closure
var a = (function outer() {
var b = 0;
return function inner() {
var d = 10;
b = d + b + 1;
console.log(b);
};
})();
a();
@pragmaticobjects
pragmaticobjects / closureusage3.js
Created September 11, 2011 05:04
Closure to replace switch case 3
var total = (function f(item) {
var tax= 0.08;
var fee = 10;
var sinTax = 0.02;
var calGas = function(price) { return price + price*tax + fee; };
var calSinProd = function(price) { return price + price*tax + price*sinTax; };
var calFood = function(price) { return price + price*tax; };
var h = {
@pragmaticobjects
pragmaticobjects / closureusage2.js
Created September 11, 2011 04:47
Closure to replace switch case 2
var calculateTotal = function f(item) {
var tax= 0.08;
var fee = 10;
var sinTax = 0.02;
var calGas = function(price) { return price + price*tax + fee; };
var calSinProd = function(price) { return price + price*tax + price*sinTax; };
var calFoodAsDefault = function(price) { return price + price*tax; };
var h = {