Skip to content

Instantly share code, notes, and snippets.

@leandrosilva
leandrosilva / color_reference_code.txt
Created July 30, 2010 19:29
Output colorization in Ruby
Code Effect
0 Turn off all attributes
1 Set bright mode
4 Set underline mode
5 Set blink mode
7 Exchange foreground and background colors
8 Hide text (foreground color would be the same as background)
30 Black text
31 Red text
32 Green text
@leandrosilva
leandrosilva / gist:516283
Created August 9, 2010 22:59
Removing listed files from SVN
svn st | awk '{print $2}' | sudo xargs rm -rf
@leandrosilva
leandrosilva / README
Created August 21, 2010 02:53
Comet is dead long live websockets
This code was copied-pasted from a Joe Armstrong's blog post at:
Comet is dead long live websockets
http://armstrongonsoftware.blogspot.com/2009/12/comet-is-dead-long-live-websockets.html
@leandrosilva
leandrosilva / README
Created August 21, 2010 03:37
Misultin: erlang and websockets
Source code copied-pasted from blog post titled "Misultin: erlang and websockets".
http://www.ostinelli.net/misultin-erlang-and-websockets/
This is based on misultin, an Erlang library for building fast lightweight HTTP(S) servers.
http://code.google.com/p/misultin/
@leandrosilva
leandrosilva / README
Created August 29, 2010 04:05
Erlectricity sample (Erlang <-> Ruby)
This sample is strongly based on Erlectricity, avaliable from:
http://github.com/mojombo/erlectricity
The echo.rb is the same, but the echo.erl is really a little bit better. It's because I refactored it to
extract functions to send and receive messages and also (and more important) introduce some patterns on
receive statement to matching other messages (specially to receive exit_status messages from "dead" ports).
More sugar is always good. At least for me. ;)
@leandrosilva
leandrosilva / struct.erl
Created September 4, 2010 00:19
Utilities for working with mochijson2 struct
%% @doc Utilities for working with mochijson2 struct.
%%
%% COPYRIGHT - stickyNotes sample application by beepbeep.
%% struct example :
%%
%% S = {struct, [
%% {<<"name">>, <<"Foo">>},
%% {<<"activity">>, {struct, [
%% {<<"name">>, <<"Basketball">>}
@leandrosilva
leandrosilva / http_helper.erl
Created September 9, 2010 15:49
Helper module for http operations using httpc and mochiweb_request modules
%% @author Leandro Silva <leandrodoze@gmail.com>
%% @copyright 2009 Leandro Silva.
%% @doc Helper module for http operations using httpc and mochiweb_request modules.
-module(http_helper).
-author('Leandro Silva <leandrodoze@gmail.com>').
-export([http_post/2, http_get/1, http_put/2, http_delete/1]).
-export([http_response/2, http_response/3, http_response/4]).
@leandrosilva
leandrosilva / README
Created September 9, 2010 21:40
Smerl: Simple Metaprogramming for Erlang
This code was made by Yariv Sadan <yarivsblog@gmail.com> [http://yarivsblog.com], available from:
http://code.google.com/p/erlyweb/source/browse/trunk/src/smerl/smerl.erl
@leandrosilva
leandrosilva / Client.java
Created September 17, 2010 04:04
Merlin brings nonblocking I/O to the Java platform
package nonblocking.client;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.SocketChannel;
@leandrosilva
leandrosilva / ConnectionAcceptor.java
Created September 18, 2010 23:52
Reactor Pattern and Non-blocking IO
import java.io.IOException;
import java.net.SocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
/**
* Handles new client connections.
* An Acceptor is bound on a ServerSocketChannel objects, which can produce new