Skip to content

Instantly share code, notes, and snippets.

@dangra
dangra / delayspider.py
Created May 24, 2012 14:04
Scrapy - delay requests in spider callbacks
from scrapy.spider import BaseSpider
from twisted.internet import reactor, defer
from scrapy.http import Request
DELAY = 5 # seconds
class MySpider(BaseSpider):
name = 'wikipedia'
@drawks
drawks / graphite
Created February 14, 2012 21:24
Graphite on uwsgi/nginx
#This is the "site config" for nginx
upstream django {
# Distribute requests to servers based on client IP. This keeps load
# balancing fair but consistent per-client. In this instance we're
# only using one uWGSI worker anyway.
ip_hash;
server unix:/tmp/uwsgi.sock;
}
server {
@dryan
dryan / cron.py
Created September 6, 2009 18:59
Django script for backing up database to S3
from django.core.management import setup_environ
import settings
setup_environ(settings)
# database backup routine
def database_backup():
import tarfile,subprocess,tempfile,os,S3
from datetime import datetime
@stevenwilkin
stevenwilkin / gist:2587565
Created May 3, 2012 17:49 — forked from dhh/gist:2492118
How DHH tamed the 500-line routes.rb file in the new Basecamp
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session

Inheritance is a key concept in most object-oriented languages, but applying it skillfully can be challenging in practice. Back in 1989, M. Sakkinen wrote a paper called Disciplined inheritance that addresses these problems and offers some useful criteria for working around them. Despite being more than two decades old, this paper is extremely relevant to the modern Ruby programmer.

Sakkinen's central point seems to be that most traditional uses of inheritance lead to poor encapsulation, bloated object contracts, and accidental namespace collisions. He provides two patterns for disciplined inheritance and suggests that by normalizing the way that we model things, we can apply these two patterns to a very wide range of scenarios. He goes on to show that code that conforms to these design rules can easily be modeled as ordinary object composition, exposing a solid alternative to tradi

@recamshak
recamshak / gist:4124194
Created November 21, 2012 10:35
Install graphite in a virtualenv (for my webfaction server)
# this script will install whisper, carbon and graphite-web on the current directory
sudo apt-get python-dev
mkvirtualenv --system-site-packages graphite
pip install twisted
pip install django
pip install django-tagging
pip install gunicorn
server {
listen 80;
server_name <url>;
root /var/www/html;
location / {
@rittersebastian
rittersebastian / examples.py
Created May 6, 2012 15:46
good practices
'''
Defining dictionaries
'''
my_dict = {
'key_1': 'notice the space after colon',
'key_2': 'but not before the colon',
'key_3': 'we are exactly 4 spaces indented'
}
@stan
stan / 0_instructions.txt
Created May 19, 2011 02:25 — forked from sgruhier/0_instructions.txt
Sprocket 2 in Rails 3.0.x ala Rails 3.1
Some brief instructions on how to use Sprocket 2 in Rails to get CoffeeScript
powered JS and SASS powered CSS with YUI compression all via the magic of rack.
This stuff will be native in Rails 3.1 and the layout of the files on the
filesystem will be different but this guide will get you working with it
while we wait for all that to finalize.
Ignore the number prefixes on each file. This is just to ensure proper order in the Gist.
It's based on eric1234 gist https://gist.github.com/911003. ijust made it 3.1 compliant in terms of convention
@mikegehard
mikegehard / gist:954537
Created May 4, 2011 00:35
Waiting until all jquery ajax calls are done
//Useful if you have a slow CI server...
When /^I wait until all Ajax requests are complete$/ do
wait_until do
page.evaluate_script('$.active') == 0
end
end