Skip to content

Instantly share code, notes, and snippets.

View AnthonyNystrom's full-sized avatar

Anthony Nyström AnthonyNystrom

View GitHub Profile
{
took: 5
timed_out: false
_shards: {
total: 5
successful: 5
failed: 0
}
hits: {
total: 64
package mapreduce
func MapReduce(mapper func(interface{}, chan interface{}),
reducer func(chan interface{}, chan interface{}),
input chan interface{},
pool_size int) interface{}
{
reduce_input := make(chan interface{});
reduce_output := make(chan interface{});
worker_output := make(chan chan interface{}, pool_size);
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
total = 0
N = 300
start_time = time()
for a in 0:(N - 1)
for b in 0:(N - 1)
for c in 0:(N - 1)
if a^2 + b^2 == c^2
total = total + 1
# coding=UTF-8
import nltk
from nltk.corpus import brown
# This is a fast and simple noun phrase extractor (based on NLTK)
# Feel free to use it, just keep a link back to this post
# http://thetokenizer.com/2013/05/09/efficient-way-to-extract-the-main-topics-of-a-sentence/
# Create by Shlomi Babluki
# May, 2013
import csv
csvFile = 'SMALLTEST.csv'
xmlFile = 'myDataSmall.xml'
csvData = csv.reader(open(csvFile))
xmlData = open(xmlFile, 'w')
xmlData.write('<?xml version="1.0"?>' + "\n")
# there must be only one top-level tag
import os
def split(filehandler, delimiter=',', row_limit=10000,
output_name_template='output_%s.csv', output_path='.', keep_headers=True):
"""
Splits a CSV file into multiple pieces.
A quick bastardization of the Python CSV library.
Arguments:

#Map Reduce is Simple (in Javascript)

##The Implementation

var mf = function (item){return item;};//Sample MAP FUNCTION -- this one does nothings to the initial values of the DATA array 
    //For more information, check out https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map
 
var rf = function (iv,current) {iv.push(current);return iv;};//Sample REDUCE FUNCTION -- this one simply adds mapped values to the INITIAL VALUE array
 //For more information, check out https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/reduce

Python Number Conversion Chart

From To Expression
#!/usr/bin/env python
# encoding: utf-8
import tweepy #https://github.com/tweepy/tweepy
import csv
#Twitter API credentials
consumer_key = ""
consumer_secret = ""
access_key = ""