Skip to content

Instantly share code, notes, and snippets.

sudo gem update rails
sudo gem install rubygems
sudo gem install addressable
sudo gem install activesupport
sudo gem install activeresource
sudo gem sources -a http://gems.github.com
sudo gem install Caged-lighthouse-api
var DIRTY = false;
// If an input has changed confirm navigation.
window.onbeforeunload = function() {
if (DIRTY) {
return 'You have unsaved changes.';
}
}
$(document).ready(function() {
require 'rubygems'
require 'Lighthouse'
# Update these settings to reflect your project:
Lighthouse.account = 'account'
Lighthouse.token = 'token'
project_id = 'your project id'
now = Time.now
current = nil # Will the the current milestone.
from django.db.models.query import CollectedObjects
def update_related_field(obj, value, field):
"""
Set `field` to `value` for all objects related to `obj`.
Based on delete object code of `CollectedObjects`:
http://code.djangoproject.com/browser/django/trunk/django/db/models/query.py
"""
# Collect all related objects.
collected_objs = CollectedObjects()
from django.db.models.query import CollectedObjects
from django.db.models.fields.related import ForeignKey
def duplicate(obj, value, field):
"""
Duplicate all related objects of `obj` setting
`field` to `value`. If one of the duplicate
objects has an FK to another duplicate object
update that as well. Return the duplicate copy
of `obj`.
def update_owner(obj, user):
"Change `owner` of all model instances related to `obj` to `user`."
return update_related_field(obj, user, 'owner')
# Official API:
>>> import api
>>> DA = api.DaApi()
>>> tree = DA.getTreeFromFile('DeviceAtlas.json') # What the juice?
>>> ua = 'SonyEricssonW850i/R1GB Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1'
>>> DA.getProperties(tree, ua)
{u'gprs': '1', u'mpeg4': '1', u'drmOmaForwardLock': '1', ...
# Awesome API:
>>> from deviceatlas import DeviceAtlas
>>> class Person(models.Model):
... name = models.CharField(max_length=20)
... parent = models.ForeignKey('self', null=True)
>>>
>>> p1 = Person.objects.create(name="Grandpa")
>>> p2 = Person.objects.create(name="Dad", parent=p1)
>>> p3 = Person.objects.create(name="Child", parent=p2)
>>> who_has_a_grandpa = Person.objects.filter(parent__parent__name="Grandpa")
>>> who_has_a_grandpa.name
u'Child'
SELECT person.id, person.name, person.parent_id
FROM person
INNER JOIN person T2 ON (person.parent_id = T2.id)
INNER JOIN person T3 ON (T2.parent_id = T3.id) WHERE T3.name = "Grandpa"
from mechanize import Browser
from lxml import html as HTML
import pprint
ENDPOINT = "https://apps.cra-arc.gc.ca/ebci/rhpd/startLanguage.do?lang=English"
class PayrollCalculator(object):
def __init__(self):