Skip to content

Instantly share code, notes, and snippets.

View natemurthy's full-sized avatar

Nathan Murthy natemurthy

View GitHub Profile
class Point(object):
def __init__(self, _x, _y):
self._x = _x; self._y = _y
@property
def x(self):
return self._x
@x.setter
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:
# seq.py
import time
def countdown(n):
while n > 0:
n -= 1
COUNT = 50000000
start = time.time()
countdown(COUNT)
// 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))
}
"""
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))
# author: oskar.blom@gmail.com
#
# 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
public class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
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))
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
@natemurthy
natemurthy / bst-node.scala
Last active August 29, 2015 14:06
Print elements of binary search tree
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)))