Skip to content

Instantly share code, notes, and snippets.

@mallipeddi
mallipeddi / EchoNode.java
Created November 12, 2008 16:43
Demonstrates the use of JInterface library to communicate between a Erlang node and a Java node.
/*
* EchoNode.java
*
* Demonstrates the use of JInterface library to communicate between a Erlang node and a Java node.
*
* Compile & run:
* javac -cp /opt/local/lib/erlang/lib/jinterface-1.4.1/priv/OtpErlang.jar EchoNode.java
* java -cp ".:/opt/local/lib/erlang/lib/jinterface-1.4.1/priv/OtpErlang.jar" EchoNode
*
* Call echoservice from Erlang:
@mallipeddi
mallipeddi / gist:74274
Created March 5, 2009 09:53
Demonstrates the concepts of covariance and contravariance in the Java type system
import java.util.*;
/*
* Covariance and contravariance.
*
* A type operator (an operator which takes as input a type and returns another type as output) is
* said to be
* 1) `covariant` if it preserves the ordering of types and orders types
* from more specific ones to more generic ones.
* 2) `contravariant` if it preserves the ordering of types and orders types
@mallipeddi
mallipeddi / codeobjects.py
Created March 29, 2009 11:37
An experiment with code-objects and namespaces.
"""
codeobjects.py
An experiment with code-objects and namespaces.
Inspired by Jeff Rush's PyCON'09 talk.
http://us.pycon.org/2009/conference/schedule/event/7/
Compiles a module at run-time from a string containing the code for the module
and installs a new module object in sys.modules ready to be importable!
$erl -pa "../couchdb/src/couchdb" -pa "../erlang_twitter/ebin"
Erlang (BEAM) emulator version 5.6.5 [source] [smp:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.6.5 (abort with ^G)
1> mattress:run_with(tweetbed).
lookup out: [{ok,{"vyom",
{user,"6151","Deepak Jois","vyom","Seattle",
"Geek, Bibliophile and Philosopher",
"http://s3.amazonaws.com/twitter_production/profile_images/14202382/mypictr_Flickr_normal.jpg",
"http://deepak.jois.name","false","467",
COUCHDB:="../couchdb/src/couchdb"
ERLANG_TWITTER:="../erlang_twitter/ebin"
all: clean compile
clean:
rm -f *.beam
compile:
erlc -pa ${COUCHDB} -pa ${ERLANG_TWITTER} *.erl
-module(couch_file).
-behaviour(gen_server).
-export([open/1, open/2, close/1, bytes/1, sync/1, append_binary/2,old_pread/3]).
-export([append_term/2, pread_term/2, pread_iolist/2, write_header/2]).
-export([pread_binary/2, read_header/1, truncate/2, upgrade_old_header/2]).
-export([init/1, terminate/2, handle_call/3, handle_cast/2, code_change/3, handle_info/2]).
-module(couch_btree).
-export([open/2, open/3, query_modify/4, add/2, add_remove/3, foldl/3, foldl/4]).
-export([foldr/3, foldr/4, fold/4, fold/5, full_reduce/1, final_reduce/2]).
-export([fold_reduce/6, fold_reduce/7, lookup/2, get_state/1, set_options/2]).
-record(btree,
{fd,
root,
extract_kv = fun({Key, Value}) -> {Key, Value} end,
-module(tweetbed).
-author("Harish Mallipeddi <harish.mallipeddi@gmail.com>").
-behaviour(mattress).
-export([map/0, reduce/2]).
-define(TWITTER_BASE_URL, "http://twitter.com").
-define(TWITTER_USER, "INSERT TWITTER USERID HERE").
-define(TWITTER_PASS, "INSERT PASSWORD HERE").
-module(mattress).
-author("Harish Mallipeddi <harish.mallipeddi@gmail.com>").
-export([run_with/1]).
-export([behaviour_info/1]).
-record(btree,
{fd,
root,
extract_kv,
# checkout the LZO-related code from Google Code
svn checkout http://hadoop-gpl-compression.googlecode.com/svn/trunk/ hadoop-gpl-compression
# build the Java code
cd hadoop-gpl-compression
ant
# move the jar file to $HADOOP_HOME/lib
mv build/hadoop-gpl-compression-0.1.0-dev.jar $HADOOP_HOME/lib/