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 window.CounterView extends Backbone.View | |
initialize: -> | |
@counter = new Counter() | |
@counter.bind('change', @render) | |
el: $('#counter') | |
events: | |
'click button#inc-count' : 'inc' |
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
from flask import Module, render_template, request, current_app, jsonify, session | |
mod = Module(__name__) | |
@mod.route('/') | |
def home(): | |
return render_template("base.html") | |
@mod.route('/api/counter', methods=['GET']) | |
def read(): |
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
from flask import Blueprint, render_template, request, current_app, jsonify, session | |
from flask.views import MethodView, View | |
blueprint = Blueprint('www', __name__) | |
class MyView(MethodView): | |
def get(self): | |
return request.method |
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 mongoose | |
mongoose = require('mongoose') | |
# connect | |
db = mongoose.connect('mongodb://localhost/test') | |
# define the schema |
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
# define the map function | |
# this function will be called for every basket and | |
# is used to emit whatever information that we want | |
# about the contents each basket, although the data | |
# must be in the format (key, value) although | |
# value can be an object if nescessary | |
mapFunc = -> | |
key = @fruit | |
values = { |
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
# now let's feed all the baskets into the MapReduce | |
# notice that you must convert the mapFunc and | |
# reduceFunc to strings or else they will not work | |
# the 'out' bit is described here http://www.mongodb.org/display/DOCS/MapReduce#MapReduce-Overview | |
Basket.collection.mapReduce mapFunc.toString(), reduceFunc.toString(), { out : "results" }, (err, val) -> | |
if err | |
err # do something with the error |
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
# define the reduce function | |
# this function is called for every emit emitted | |
# from the map function above | |
# in this example we'll count all the fruit by | |
# type and also keep a tally for the baskets | |
reduceFunc = (key, values) -> | |
count = 0 | |
baskets = 0 | |
values.forEach (value) -> |
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
from multiprocessing import Pool | |
def mapFunction(value): | |
# work on values | |
return a_tuple | |
def partition(tuples): | |
# marshalll tuples into a dictionary of lists of tuples | |
return mapping | |
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
from multiprocessing import Pool | |
import string | |
import random | |
def mapFunction(letter): | |
return (letter, 1) | |
def partition(tuples): | |
mapping = {} | |
for t in tuples: |
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
letters: ['D', 'Q', 'Q', 'J', 'W', 'D', 'Q', 'N', 'U', 'B', 'T', 'A', 'S', 'Z', 'M', 'V', 'E', 'N', 'Y', 'N', 'S', 'Q', 'Y', 'M', 'Y', 'M', 'C', 'C', 'L', 'Y'] | |
tuples: [('D', 1), ('Q', 1), ('Q', 1), ('J', 1), ('W', 1), ('D', 1), ('Q', 1), ('N', 1), ('U', 1), ('B', 1), ('T', 1), ('A', 1), ('S', 1), ('Z', 1), ('M', 1), ('V', 1), ('E', 1), ('N', 1), ('Y', 1), ('N', 1), ('S', 1), ('Q', 1), ('Y', 1), ('M', 1), ('Y', 1), ('M', 1), ('C', 1), ('C', 1), ('L', 1), ('Y', 1)] | |
mapping: {'A': [('A', 1)], 'C': [('C', 1), ('C', 1)], 'B': [('B', 1)], 'E': [('E', 1)], 'D': [('D', 1), ('D', 1)], 'J': [('J', 1)], 'M': [('M', 1), ('M', 1), ('M', 1)], 'L': [('L', 1)], 'N': [('N', 1), ('N', 1), ('N', 1)], 'Q': [('Q', 1), ('Q', 1), ('Q', 1), ('Q', 1)], 'S': [('S', 1), ('S', 1)], 'U': [('U', 1)], 'T': [('T', 1)], 'W': [('W', 1)], 'V': [('V', 1)], 'Y': [('Y', 1), ('Y', 1), ('Y', 1), ('Y', 1)], 'Z': [('Z', 1)]} | |
The letter Y appeared 4 times | |
The letter Q appeared 4 times | |
The letter N appeared 3 times | |
The letter M appeared 3 tim |