Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'highline'
require 'net/http'
h = HighLine.new
count = 0
while true
body = Net::HTTP.get URI.parse('http://feeds.gawker.com/kotaku/full')
# 21 Mar. 2010: Pulled from tedb's fork to add cache_and_render method.
class ApplicationController < ActionController::Base
# Other random stuff.
protected
def cache_and_render(key, opts = {})
cached = cache(key, opts)
render :text => cached
class Project
include MongoMapper::Document
key :name, String, :required => true
key :description, String, :default => ''
key :status, Symbol, :required => true, :default => :open
key :client_id, ObjectId, :required => true
belongs_to :client
many :tasks, :dependent => :destroy
# heavily based off difflib.py - see that file for documentation
# ported from Python by Bill Atkins
# This does not support all features offered by difflib; it
# implements only the subset of features necessary
# to support a Ruby version of HTML Differ. You're welcome to finish this off.
# By default, String#each iterates by line. This isn't really appropriate
# for diff, so often a string will be split by // to get an array of one-
# character strings.
<?php
$now = microtime(true);
for($i = 0; $i < 1000000; $i++){
$str = 2 + 'characters';
}
echo microtime(true) - $now;
$now = microtime(true);
for($i = 0; $i < 1000000; $i++){
$str = 2 . 'characters';
}
@dirk
dirk / simple_constrictor_application.py
Created April 18, 2009 18:21
Extremely simple Constrictor app, connects to database, grabs the user table, and returns a list of users.
# Suggested directory structure:
# /myapp/this_file.py
# /constrictor
# This is to load the path above it to add constrictor directory to the path.
import os, sys
sys.path.append(os.path.join(os.getcwd(), os.pardir))
# Recommended to make pathing easier. (Note: Requires os module)
from constrictor.utils import set_path
@dirk
dirk / diff.rb
Created November 27, 2008 14:58
require 'diff-0.4/lib/algorithm/diff'
a = 'testing
sled
123
testing'
ab = a.dup
b = 'testing
sledding across the white snow
123error