This file contains hidden or 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
// define a simple list | |
scala> val l = List("a", "b", "c") | |
l: List[java.lang.String] = List(a, b, c) | |
// print each element of the list | |
scala> l.foreach{ println } | |
a | |
b | |
c |
This file contains hidden or 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
#Compile HelloWorld, with jars in this directory | |
javac -cp ".:*" HelloWorld.java | |
scalac -cp ".:*" HelloWorld.scala | |
#Run | |
java -cp ".:*" HelloWorld | |
scala -cp ".:*" HelloWorld | |
# HelloWorld.java | |
class HelloWorld { |
This file contains hidden or 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
# first we'll create a new project | |
mvn archetype:generate -DarchetypeGroupId=org.scala-tools.archetypes -DarchetypeArtifactId=scala-archetype-simple -DgroupId=myGroup -DartifactId=myTestProject -Dversion=1.0 -DinteractiveMode=false | |
# then we will package it to create a jar, and populate target/ | |
cd myTestProject | |
optional: rm -rf src/test | |
mvn package |
This file contains hidden or 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
// Jongo.java | |
import com.mongodb.Mongo; | |
import com.mongodb.MongoClient; | |
import com.mongodb.MongoException; | |
import com.mongodb.WriteConcern; | |
import com.mongodb.DB; | |
import com.mongodb.DBCollection; | |
import com.mongodb.BasicDBObject; | |
import com.mongodb.DBObject; |
This file contains hidden or 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
# The reduce() function applies a function which will reduce the sequence to a single value. | |
# There are a number of special-purpose reduce functions that we’ve already seen. | |
# These reductions include sum(), any(), all(). | |
def red_max(x, y): | |
return x if x > y else y | |
def red_sum(x, y): | |
return x + y |
This file contains hidden or 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
print 'If you are running ubuntu, the site-packages is in:' | |
print '/usr/local/lib/pythonX.X/dist-packages' | |
print 'Otherwise it\'s here:' | |
from distutils.sysconfig import get_python_lib; | |
print get_python_lib() |
This file contains hidden or 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(function, iterable, ...) | |
# | |
# http://docs.python.org/2/library/functions.html#map | |
nums = range(5) | |
extended_nums = range(10) | |
double = lambda x: x*2 | |
concat = lambda x,y: "{x}{y}".format(x=x, y=y) |
This file contains hidden or 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
# Core functions | |
def triple(num): | |
return num*3 | |
def double(num): | |
return num*2 | |
# Input values | |
nums = [1,2,3,4,5,6] |
This file contains hidden or 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 csv | |
import StringIO | |
# cStringIO is faster, but cannot handle unicode characters | |
def main(): | |
f = StringIO.StringIO('language,greeting\nenglish,hello\nspanish,hola') | |
for _dict in csv.DictReader(f): | |
print _dict | |
if __name__ == '__main__': |
This file contains hidden or 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 argparse | |
import os | |
import glob | |
def main(): | |
#Does not currently have support to read files from folders recursively | |
parser = argparse.ArgumentParser(description='Read in a file or set of files, and return the result.', formatter_class=argparse.ArgumentDefaultsHelpFormatter) | |
parser.add_argument('path', nargs='+', help='Path of a file or a folder of files.') | |
parser.add_argument('-e', '--extension', default='', help='File extension to filter by.') | |
args = parser.parse_args() |