In [1]: from operator import add
In [2]: reduce(add, map(add, range(1000000), range(1000000)))
Out[2]: 999999000000
In [3]: %timeit reduce(add, map(add, range(1000000), range(1000000)))
10 loops, best of 3: 153 ms per loop
In [4]: %timeit reduce(add, map(add, xrange(1000000), xrange(1000000)))
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 time) | |
(defmacro timeit [expr] | |
`(let [[start# ((. time time))]] | |
(let [[val# ~expr]] | |
(let [[end# ((. time time))]] | |
(print (+ "time elapsed: " | |
(str (* (- end# start#) 1000)) | |
" msecs")))))) |
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
#-*- coding: utf-8 -*- | |
from collections import namedtuple | |
class Immutable(namedtuple("Immutable", "x, y")): | |
"""Immutable class using collections.namedtuple.""" | |
def __str__(self): | |
return "class: {c}, x: {x}, y: {y}".format(c=Immutable.__name__, | |
x=self.x, y=self.y) |
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 main | |
import ( | |
"bytes" | |
"io" | |
"log" | |
"os" | |
"golang.org/x/oauth2" | |
"golang.org/x/oauth2/google" |
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
#-*- coding: utf-8 -*- | |
from pprint import pprint | |
import json | |
import os | |
from oauth2client.client import SignedJwtAssertionCredentials | |
import httplib2 | |
ENV_SERVICE_ACCOUNT = "GAPI_SERVICE_ACCOUNT" |
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 main | |
import ( | |
"bytes" | |
"log" | |
"github.com/linkedin/goavro" | |
) | |
const schemaPerson = ` |
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.spark._ | |
import org.apache.spark.streaming._ | |
object NetworkWordCount { | |
def main(args: Array[String]) { | |
// Create a local StreamingContext with two working thread and batch interval of 1 second. | |
// The master requires 2 cores to prevent from a starvation scenario. | |
val conf = new SparkConf().setMaster("local[8]").setAppName("NetworkWordCount") | |
val ssc = new StreamingContext(conf, Seconds(5)) |
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.spark._ | |
import org.apache.spark.streaming._ | |
object StatefulNetworkWordCount { | |
def updateFunction(newValues: Seq[Int], runningCount: Option[Int]): Option[Int] = { | |
val newCount = runningCount.getOrElse(0) + newValues.sum | |
Some(newCount) | |
} | |
def main(args: Array[String]) { |
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.spark._ | |
import org.apache.spark.streaming._ | |
object StatefulNetworkWordCount2 { | |
def updateFunction2(word: String, one: Option[Int], state: State[Int]) = { | |
val sum = one.getOrElse(0) + state.getOption.getOrElse(0) | |
val output = (word, sum) | |
state.update(sum) | |
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
// type HandlerFunc func(ResponseWriter, *Request) | |
// | |
// func (f HandlerFunc) ServeHTTP(w ResponseWriter, r *Request) { | |
// f(w, r) | |
// } | |
// | |
// func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) { | |
// DefaultServeMux.HandleFunc(pattern, handler) | |
// } |
OlderNewer