Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
# encoding: utf-8
"""
Example of friendships computing for mapreduce
inspired by this post : http://stevekrenzel.com/finding-friends-with-mapreduce
"""
__author__ = "Tim Bart"
__copyright__ = "No copyright"
# saved from http://github.com/jhsu/ubstatus/blob/master/main.rb for reference
require 'sinatra'
require 'sinatra/activerecord'
require 'net/http'
require 'haml'
require 'lib/models/site.rb'
require 'lib/models/user.rb'
configure do
require 'rubygems'
require 'sinatra'
enable :sessions
get '/' do
session["value"] ||= "Hello world!"
"The cookie you've created contains the value: #{session["value"]}"
end
# Depends on the OS X "say" command
import time, datetime, subprocess, math, sys
def say(s):
subprocess.call(['say', str(s)])
def seconds_until(dt):
return time.mktime(dt.timetuple()) - time.time()
if (!navigator.geolocation) {
navigator.geolocation = (function (window) {
function getCurrentPosition(callback) {
// NOTE: for some reason, chaging the url is *allowed* with this service. Useful, but random
// source: http://www.maxmind.com/app/javascript_city
// The source is open source, as per: http://www.maxmind.com/app/api, but doesn't discuss specific license use. Hopefully it's just free to use - yay internet!
var geourl = 'http://j.maxmind.com/app/geoip.js_' + Math.random(),
iframe = document.createElement('iframe'),
doc, win;
@pims
pims / gist:295757
Created February 5, 2010 12:46 — forked from dhotson/gist:295737
<?php
/**
* A little Object Relational Mapper in PHP
* @author dennis.hotson@gmail.com
*/
class Post
{
public $title;
@pims
pims / virtualenv.txt
Created February 24, 2010 17:01 — forked from hugs/virtualenv.txt
# Install virtualenv
sudo pip install virtualenv
# Create the virtual environment
virtualenv sandbox
# Play around with Python inside the new 'sandbox'
cd sandbox
./bin/python
cd ..
#pseudo code
#option 1
class User:
screen_name = ''
email = ''
class UserManager:
def validate(user):
if user.screen_name == '':
<?php
$english = arr(
strr('Hello X'),
strr('Goodbye X')
);
$pirate = $english
->replace('/Hello/', 'Avast')
->replace('/Goodbye/', 'Was good te see ye')
math:{
add: (a,b)-> a+b
mean: (data)->
data.reduce(math.add) / data.length
square: (x)-> x*x
sqrt: Math.sqrt
sum: (data)-> data.reduce(math.add)
stddev: (data)->
_mean: math.mean(data)
_dev_from_mean: (i-_mean) for i in data