This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -------- 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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------- 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)); |