Skip to content

Instantly share code, notes, and snippets.

View sujee's full-sized avatar

Sujee Maniyam sujee

View GitHub Profile
@sujee
sujee / run-emr-testMR2.sh
Created January 30, 2011 20:02
run-emr-testMR2.sh : configuring hadoop cluster
#!/bin/bash
# config
# if changing machine type, also change mapred config file
MASTER_INSTANCE_TYPE="m1.large"
SLAVE_INSTANCE_TYPE="c1.xlarge"
INSTANCES=5
export JOBNAME="MyMR"
export TIMESTAMP=$(date +%Y%m%d-%H%M%S)
# end config
@sujee
sujee / gist:859152
Created March 7, 2011 20:32
covercake web service api client in ruby
require 'rubygems'
#install the following gems
require 'json'
require 'rest_client'
API_KEY="your_key_here"
response = RestClient.get "https://covercake.com/api/v1/feeds", {:params => {:key => API_KEY}}
j = JSON::parse(response)
#p response
@sujee
sujee / gist:859234
Created March 7, 2011 21:10
covercake webservice client PHP
<?php
$API_KEY="api_key_here";
$response = file_get_contents("https://covercake.com/api/v1/feeds?key=$API_KEY");
$j = json_decode($response);
#var_dump($j);
if (strcasecmp($j->status, "OK") != 0)
@sujee
sujee / gist:1169615
Created August 25, 2011 00:00
hadoop utilities : Shell
import org.apache.hadoop.util.Shell.ShellCommandExecutor;
String[] cmd = { "ls", "/usr" };
ShellCommandExecutor shell = new ShellCommandExecutor(cmd);
shell.execute();
System.out.println("* shell exit code : " + shell.getExitCode());
System.out.println("* shell output: \n" + shell.getOutput());
/* output:
* shell exit code : 0
@sujee
sujee / gist:1169626
Created August 25, 2011 00:10
hadoop utilities : StringUtils 1
import org.apache.hadoop.util.StringUtils;
// --- human readable byte lengths -----
System.out.println ("1024 bytes = " + StringUtils.byteDesc(1024));
System.out.println ("67108864 bytes = " + StringUtils.byteDesc(67108864));
System.out.println ("1000000 bytes = " + StringUtils.byteDesc(1000000));
/* produces:
1024 bytes = 1 KB
67108864 bytes = 64 MB
@sujee
sujee / gist:1169662
Created August 25, 2011 00:32
hadoop utilities : StringUtil 2
import org.apache.hadoop.util.StringUtils;
// ----------------- String Utils : bytes <--> hex ---------
String s = "aj89y1_xxy";
byte[] b = s.getBytes();
String hex = StringUtils.byteToHexString(b);
byte[] b2 = StringUtils.hexStringToByte(hex);
String s2 = new String(b2);
System.out.println(s + " --> " + hex + " <-- " + s2);
@sujee
sujee / gist:1169675
Created August 25, 2011 00:41
hadoop utilities : StringUtils 3 : format time
System.out.println ("1000000 ms = " + StringUtils.formatTime(1000000));
long t1 = System.currentTimeMillis();
// execute a command
long t2 = System.currentTimeMillis();
t2 += 10000000; // adjust for this demo
System.out.println ("operation took : " + StringUtils.formatTimeDiff(t2, t1));
/* output:
1000000 ms = 16mins, 40sec
operation took : 2hrs, 46mins, 40sec
@sujee
sujee / gist:1169743
Created August 25, 2011 01:23
hadoop utilities : Cluster Status
package sujee;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.mapred.ClusterStatus;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
@sujee
sujee / gist:1174701
Created August 26, 2011 23:38
HBase utilities : Bytes.toBytes
// -------- Bytes.toBytes() : converting objects to bytes ------
int i = 10000;
byte [] intBytes = Bytes.toBytes(i);
System.out.println ("int " + i + " in bytes : " + Arrays.toString(intBytes));
float f = (float) 999.993;
byte [] floatBytes = Bytes.toBytes(f);
System.out.println ("float " + f + " in bytes : " + Arrays.toString(floatBytes));
String s = "foobar";
@sujee
sujee / gist:1174761
Created August 27, 2011 00:21
HBase utilities : Bytes.add
// ---------- Bytes.add() : creating composite keys ---------
// rowkey = int + long
int i = 0;
long timestamp = System.currentTimeMillis();
byte [] rowkey2 = Bytes.add(Bytes.toBytes(i), Bytes.toBytes(timestamp));
System.out.println ("rowkey2 (" + rowkey2.length + ") : " + Arrays.toString(rowkey2));
// add also supports adding 3 byte arrays
// rowkey = int + str + long
byte[] rowkey3 = Bytes.add(Bytes.toBytes(0) , Bytes.toBytes("hello"), Bytes.toBytes(timestamp));