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
#beam it up to the hdfs | |
hadoop fs -mkdir wordcount-input/ | |
hadoop fs -copyFromLocal lorem.txt wordcount-input/ | |
# Maven project in https://github.com/natalinobusa/wordcount/hadoop-mapreduce-java | |
$HADOOP_HOME/bin/hadoop jar target/wordcount-mapreduce-java-1.0-SNAPSHOT.jar \ | |
com.natalinobusa.WordCount wordcount-input wordcount-mapreduce-java-output | |
$HADOOP_HOME/bin/hadoop fs -cat wordcount-mapreduce-java-output |
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
$HADOOP_HOME/bin/hadoop \ | |
jar $HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.3.0.jar \ | |
wordcount wordcount-input wordcount-output | |
$HADOOP_HOME/bin/hadoop fs -cat wordcount-output | |
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
#read in and clean | |
x = scan("lorem.txt", what="", sep=" ") | |
x.clean = gsub("\\W+","",tolower(x)) | |
#word count | |
wc = table(x.clean) | |
#output to stdout | |
print(as.data.frame(wc), row.names=rep("", nrow(wc))) |
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
#readin and filter | |
txt = [c for c in open('lorem.txt').read().lower() if c.isalpha() or c==' '] | |
#groupBy in a dictionary | |
wc = dict() | |
for w in ''.join(txt).split(): | |
wc[w] = wc.setdefault(w, 0) + 1 | |
#output | |
for k,v in wc.iteritems(): |
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
//read in | |
val text = scala.io.Source.fromFile("lorem.txt").mkString | |
val wc = text. | |
toLowerCase. | |
split("\\W+"). | |
groupBy(identity). | |
mapValues( _.length ) | |
//writeout |
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
cat lorem.txt | tr [:upper:] [:lower:] | sed -E 's/[^[:alpha:]]+/\n/g' | sort | uniq -c | | awk '{ print($2,"\t",$1) }' |
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
< HTTP/1.1 200 OK | |
< Server: spray-can/1.2-RC2 | |
< Date: Mon, 10 Feb 2014 19:36:43 GMT | |
< Content-Type: application/json; charset=UTF-8 | |
< Content-Length: 247 | |
< | |
{ | |
"main": { | |
"eggs": { | |
"num": 2 |
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
> GET /api/v1/breakfast?eggs=2&strips=4&slices=1&juices=1&coffee=2 HTTP/1.1 | |
> User-Agent: curl/7.29.0 | |
> Host: localhost:8888 | |
> Accept: */* | |
> Content-Type: application/json | |
> |
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
object Boot extends App { | |
implicit val system = ActorSystem() | |
// create and start our service actor | |
val service = system.actorOf(Props[BreakfastApiService], "breakfast-api-service") | |
// start a new HTTP server with our service actor as the handler | |
IO(Http) ! Http.Bind(service, "localhost", port = 8888) | |
} |
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
val serviceRoute = { | |
pathPrefix("api" / "v1" / "breakfast") { | |
get { | |
parameters('eggs.as[Int], 'strips.as[Int], 'slices.as[Int], 'juices.as[Int], 'coffee.as[Int]) { | |
(friedeggs, baconstrips, breadslices, orangejuices, coffeemugs) => | |
complete { | |
Breakfast( | |
MainDish( |