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
#! /usr/bin/python | |
import operator | |
import re | |
import numpy as np | |
class Perudo(): | |
def __init__(self): | |
print "-- New Game --\nNumber of players?" | |
num_players = int(self.user_input()) |
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
#! /usr/bin/python | |
import bs4 | |
import json | |
import urllib2 | |
import html2text | |
import nltk | |
import collections | |
# to do, lets turn this into a full class (that can be imported) | |
# and use argparse (which invokes serializing it to a file) |
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
# this simple example recurses over a mixed data structure of tuples, lists, and dicts, and returns a copy. | |
num_recursions = 0 | |
def r(current): | |
global num_recursions | |
num_recursions += 1 | |
if isinstance(current, list): | |
return [r(i) for i in current] | |
elif isinstance(current, dict): |
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 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 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 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 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 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 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 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 |
OlderNewer