Skip to content

Instantly share code, notes, and snippets.

<!doctype html>
<html>
<head>
<title>websockets chat</title>
<link type="text/css" href="/upload/js/jquery-ui/css/smoothness/jquery-ui-1.8.2.custom.css" rel="stylesheet" />
<script src="/upload/js/jquery-1.4.2.js"></script>
<script src="/upload/js/jquery.embedly.js"></script>
<script src="/upload/js/jquery-ui/js/jquery-ui-1.8.2.custom.min.js"></script>
<script>
<!doctype html>
<html>
<head>
<title>Reddit Pics</title>
<meta charset="utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
function qs( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
"""
Takes a WTForm and saves it into a mongodb collection... who needs an ODM, we've got
WTForms!
"""
from wtforms import *
from wtforms.fields import Field
from wtforms.widgets import TextInput, TextArea
from flask import (Flask, abort, request, flash, redirect,
url_for, render_template)
"""Converts Restructured Text into a HTML5 friendly format"""
from docutils.writers.html4css1 import HTMLTranslator, Writer
from docutils.core import publish_parts
from docutils import frontend, nodes, utils, writers, languages, io
import re
class HTML5Translator(HTMLTranslator):
def visit_section(self, node):
self.section_level += 1

RESTful web services have been talked about ad-nauseum for a decade. In fact, REST felt like such a hipster's architecture that I pawned it off as a fad and waited this long to only begin to understand it. Prior to understanding a technology, I have to ask myself, "What motivates people to use this technology over others?". I think I may have figured it out.

The key to benefit of REST is the fact that it lives within the confines of HTTP/1.1. Within this world a RESTful web service benefits from all the solutions already solved by the HTTP/1.1 spec. A brief

var httpProxy = require("http-proxy");
var http = require("http");
var render = require("./render").render;
var XMLHttpRequest = require("./XMLHttpRequest").XMLHttpRequest;
function GET(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onreadystatechange = function(e) {
if(xhr.readyState == 4) {
@ericmoritz
ericmoritz / craiglist-average.js
Created January 8, 2011 00:38
Calculates the average price for a craigslist search
(function() {
var total = 0;
var count = 0;
jQuery("p > a").each(function(i) {
var $this = jQuery(this);
var bits = $this.html().split(/ /);
var price = new Number(bits[0].substring(1));
if(!isNaN(price)) {
total += price;
@ericmoritz
ericmoritz / riakmicromodels.py
Created January 14, 2011 15:59
I really simple, stupid MixIn to enable r/w of micromodels in Riak
class RiakModelMixIn(object):
"""Simply define a property "key" that generates a key
based on the model's fields and you can store them in riak
Example::
class MyModel(micromodels.Model):
slug = micromodels.CharField()
title = micromodels.CharField()
@ericmoritz
ericmoritz / defer-until.js
Created March 14, 2011 16:39
Defers execution of a callback until a condition is true
var defer_until = function(conditional,
callback,
timeout) {
timeout = timeout || 10; // Default the timeout to 10ms
// Build a closure for this defer job
var timeout_callback = function() {
// If the conditional is true, fire off the callback
if(conditional()) {
callback();
import riak
from pprint import pprint
client = riak.RiakClient(port=8098)
query = client.add("goog") # Add the goog bucket
query.map("""function(value, keyData, arg){
var data = Riak.mapValuesJson(value)[0];
var month = value.key.split('-').slice(0,2).join('-');
var obj = {};