Skip to content

Instantly share code, notes, and snippets.

@TylerBrock
TylerBrock / five_stars.py
Created September 19, 2011 22:33
Max Sum Sublist
#!/usr/bin/python
"""
Tyler Brock for Five Stars - 2011
Write function f in python, that given a list of numbers
L returns i, j such that L[i:j] has maximal sum.
For example, if L = [1, -2, 3, 4, 5, -1] then f(L) should return (2, 5).
"""
@TylerBrock
TylerBrock / handlers.py
Created September 19, 2011 22:54
Handlers from ReadrBoard
from piston.handler import AnonymousBaseHandler
from django.http import HttpResponse, HttpResponseBadRequest
from django.db.models import Count
from decorators import status_response, json_data
from exceptions import JSONException
from utils import *
from userutils import *
from authentication.token import *
from settings import BASE_URL
from django.forms.models import model_to_dict
@TylerBrock
TylerBrock / mr.js
Created January 13, 2012 21:19
Map Reduce for Free-5947
db.logs.remove()
db.logs.insert(
{"name":"James Carr",
"log" : [
{
"comment" : "",
"time" : ISODate("2011-11-01T21:37:44.897Z"),
"user" : "Brad ************",
"action" : "Call",
@TylerBrock
TylerBrock / hack.sh
Created April 2, 2012 19:22 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@TylerBrock
TylerBrock / orphanage.js
Created May 10, 2012 01:33
MongoDB Sharded Cluster Orphaned (Duplicate) Document Finder/Remover
/*
*
* orphanage.js -- Utility to find and remove orphaned documents
* 10gen 2012 -- Tyler Brock
*
* Script Orphan Finder Procedure:
* - Set up a connection to each shard
* - Turn of the balancer
* - For each chunk of data
* - Query each shard that is not in config
@TylerBrock
TylerBrock / mongodb_sharding.txt
Created May 13, 2012 23:09 — forked from squarism/mongodb_sharding.txt
MongoDB sharded cluster install
OS Setup
- Install VMs (base OS = Ubuntu 11.04)
- 6GB disk is not enough. Probably 20-40GB would be good. Mongo has a lot of compression and cleanup features coming.
- Create user to run MongoDB as
- Get DNS or Hosts file set up so all nodes in the cluster can talk to each other
- Generate ssh-keygen -t rsa
- Copy ssh public keys from each node to node01. Then cat all keys to authorized_keys. Then copy that file to each node. Each node will have ssh key trust now. You will also want to ssh from node01 to 02,03,04; from node02 to 01,03,04 etc to test it out.
- Create an initial architecture:
node01: master (replica set 1)
node02: slave (replica set 1)
@TylerBrock
TylerBrock / import.sh
Created June 6, 2012 20:38
Twitter MapReduce with MongoDB+Hadoop Streaming Adapter
curl https://stream.twitter.com/1/statuses/sample.json -u<login>:<password> | mongoimport -d test -c live
curl https://stream.twitter.com/1/statuses/sample.json -u<login>:<password> | mongoimport -d twitter -c in
#!/usr/bin/env ruby
require 'mongo-hadoop'
MongoHadoop.map do |document|
{ :_id => document['user']['time_zone'], :count => 1 }
end
#!/usr/bin/env ruby
require 'mongo-hadoop'
MongoHadoop.reduce do |key, values|
count = sum = 0
values.each do |value|
count += 1
sum += value['num']
end