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
class Point(object): | |
def __init__(self, _x, _y): | |
self._x = _x; self._y = _y | |
@property | |
def x(self): | |
return self._x | |
@x.setter |
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
inputFile = open('names_emails.txt') | |
names_emails = inputFile.read(); inputFile.close() | |
nameEmailArray = names_emails.split(",") | |
nameEmailDict = {}; emailOnly = [] | |
for name_email in nameEmailArray: | |
token = name_email.split(' <') | |
if len(token) == 1: | |
emailOnly.append(token[0].replace('>','')) | |
elif len(token) == 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
# seq.py | |
import time | |
def countdown(n): | |
while n > 0: | |
n -= 1 | |
COUNT = 50000000 | |
start = time.time() | |
countdown(COUNT) |
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
// map.scala | |
object `map` { | |
def main (args: Array[String]) { | |
val start = System.nanoTime | |
println("\n(Map) multiplying 60 million elements by 2") | |
val dbls = (1L to 60000000L).toArray.map(_*2) | |
println("(Reduce) sum: %d".format(dbls.sum)) | |
val end = System.nanoTime | |
println("Total MapReduce time: %f".format((end-start)/1.0e9)) | |
} |
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
""" | |
Each 'import' statement demarcates a separate file | |
""" | |
# map.py | |
import time | |
start = time.time() | |
print("\n(Map) multiplying 60 million elements by 2") | |
dbls=map(lambda n: 2*n, range(60000000)) | |
print("(Reduce) sum: %d" % sum(dbls)) |
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
# author: [email protected] | |
# | |
# Make sure your gevent version is >= 1.0 | |
import gevent | |
from gevent.wsgi import WSGIServer | |
from gevent.queue import Queue | |
from flask import Flask, Response | |
import time |
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
public class Point { | |
private int x; | |
private int y; | |
public Point(int x, int y) { | |
this.x = x; | |
this.y = 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
object `map` { | |
def main (args: Array[String]) { | |
val start = System.nanoTime | |
println("\n(Map) multiplying 20 million elements by 2") | |
val dbls = (1L to 20000000L).map(_*2) | |
//val dbls = (1L to 20000000L).toArray.map(_*2) | |
//val dbls = (1L to 20000000L).toVector.map(_*2) | |
//val dbls = (1L to 20000000L).par.map(_*2) | |
println("(Reduce) sum: %d".format(dbls.sum)) |
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
class Animal(object): | |
def __init__(self, *args, **kwargs): | |
print "Animal args", args | |
print "Animal kwargs", kwargs | |
print "Animal name", kwargs['name'] | |
class Dog(Animal): | |
def __init(self, *args, **kwargs): | |
super(Dog, self).__init__(*args, **kwargs) | |
self.name = name |
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
case class BSTNode(payload: Int, left: Option[BSTNode] = None, right: Option[BSTNode] = None) | |
object Treeutils { | |
def inOrder(root: Option[BSTNode]): List[Int] = root match { | |
case None => List() | |
case Some(BSTNode(payload, left, right)) => inOrder(left) ::: List(payload) ::: inOrder(right) | |
} | |
} | |
scala> val tree = BSTNode(10,Some(BSTNode(8,Some(BSTNode(7,Some(BSTNode(6,None,None)),Some(BSTNode(7,None,None)))),Some(BSTNode(9,None,None)))),Some(BSTNode(11,None,None))) |
OlderNewer