Skip to content

Instantly share code, notes, and snippets.

object WordCount {
def main(args: Array[String]): Unit = {
val files = args.map(Source.fromFile)
vale results = files.
flatMap(_.mkString.split("\\n")).
groupBy(word _> word).
map(group -> (group._1, group._2.size))
}
}
public class WordCount {
public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
object Anagrams {
def main(words: List[String]): Unit = {
words.
groupBy(word => new String[word.toCharArray.sorted]).
map(_,_2).
map(anagram => join(anagrams, ' ')).
foreach(println)
}
}
class ScaldingAnagrams {
val input = TextLine("data/nytime_1899-2012")
val output = TextLine("data/anagrams")
//Mappers
def tokenizeWords(s: String): array[String] = StringUtils.split(s, "\n\t")
def makeAnagramHash(s: String): String = new String(s.toCharArray.sorted)
//Reduce

Tips and tricks for understanding this document:

  • The dollar sign refers to the terminal prompt. The text after it is what you type in. The lines without $ is the terminal's response. (This holds except for in telnet, in which inputs and responses unfortunately look the same. But fortunately, you're smart.)
$ ping google.com 
PING google.com (74.125.239.128): 56 data bytes</code>
@stevekrouse
stevekrouse / csv_dicts.py
Created December 20, 2013 03:48
csvs to and from dics
import csv
def dicts_from_csv(filename):
with open(filename, 'rU') as f:
reader = csv.DictReader(f)
return [row for row in reader]
def csv_from_dicts(filename, dicts, fieldnames=None):
<button>Click me!</button>
@stevekrouse
stevekrouse / index.html
Created October 5, 2015 13:56 — forked from anonymous/index.html
My first webpage // source http://jsbin.com/bojejahabe
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My first webpage</title>
</head>
<body>
<h1>Franny's webpage</h1>
<p>This is my website</p>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
// use a function