Skip to content

Instantly share code, notes, and snippets.

View sujee's full-sized avatar

Sujee Maniyam sujee

View GitHub Profile
@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: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: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: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: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: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 / 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 / ParseProperties.java
Created January 30, 2011 07:11
ParseProperties.java
package amazonemr;
import java.net.URI;
import java.util.Enumeration;
import java.util.Properties;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
@sujee
sujee / job-status-parse.rb
Created January 3, 2011 07:07
job-status-parse.rb
require 'rubygems'
require 'json'
a = JSON::parse(ARGF.read)
#p a
p a["JobFlows"][0]["ExecutionStatusDetail"]["State"]
@sujee
sujee / emr-wait-for-completion.sh
Created January 2, 2011 07:14
emr-wait-for-completion.sh
#!/bin/bash
## http://sujee.net/tech/articles/amazon-emr-beyond-basics/
echo "=== $JOBID started...."
LOGDIR="/var/logs/hadoop-logs/${JOBNAME}__${JOBID}__${TIMESTAMP}"
mkdir -p "${LOGDIR}"
## stuff below is to wait till the jobs is done