Skip to content

Instantly share code, notes, and snippets.

Noah Kantrowitz coderanger

View GitHub Profile
View lifetime_blues.user.js
// ==UserScript==
// @name Lifetime blues
// @namespace http://startrekonline.com/
// @include http://forums.startrekonline.com/showthread.php*
// ==/UserScript==
var snapAlt2 = document.evaluate("//table//td[@class='alt2']//span", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = snapAlt2.snapshotLength - 1; i >= 0; i--) {
var elm = snapAlt2.snapshotItem(i);
View gist:356928
import os
def walkfiles(d):
for base, dirnames, filenames in os.walk(d):
for name in filenames:
yield os.path.join(base, name)
@coderanger
coderanger / coverage.py
Created May 7, 2010
A Django command to generate a test coverage report
View coverage.py
from __future__ import absolute_import
import os
import sys
import webbrowser
from django.conf import settings
from django.core.management import setup_environ
from django.core.management.commands import test
from django.utils.importlib import import_module
from django.db.models.loading import cache
@coderanger
coderanger / db.py
Created May 12, 2010
A subclass to allow splitting Django models into a package without manually specifying app_label for every one.
View db.py
from django.db.models import base
from django.conf import settings
class ModelBase(base.ModelBase):
def __new__(cls, name, bases, attrs):
parents = [b for b in bases if isinstance(b, ModelBase)]
if not parents:
# Don't run our fixup on the model base class itself.
return super(ModelBase, cls).__new__(cls, name, bases, attrs)
@coderanger
coderanger / tree.py
Created Jul 8, 2010
A simple function to print a tree in response to a reddit question.
View tree.py
from StringIO import StringIO
tree1 = ("Root", ("Child 1", ("Child 2", None)))
get_label1 = lambda x: x[0]
def get_children1(node):
if node[1] is not None:
yield node[1]
class Node(object):
@coderanger
coderanger / admin.py
Created Aug 31, 2010
Pagination for admin inlines
View admin.py
class MyInline(admin.TabularInline):
model = MyModel
extra = 0
template = 'admin/edit_inline/list.html'
def get_formset(self, request, obj=None, **kwargs):
FormSet = super(ActivationKeyInline, self).get_formset(request, obj, **kwargs)
class NewFormSet(FormSet):
def _construct_forms(self, *args, **kwargs):
qs = self.get_queryset()
@coderanger
coderanger / db_server.rb
Created Oct 20, 2010
Create postgres users and databases from Chef
View db_server.rb
#
# Cookbook Name:: atari
# Recipe:: db_server
#
# Copyright 2010, Atari
#
# All rights reserved
#
include_recipe "postgresql::server"
@coderanger
coderanger / bittentest.py
Created Oct 28, 2010
XML report generation for Django unittests
View bittentest.py
import os
from django.conf import settings
from south.management.commands import test
class Command(test.Command):
help = test.Command.help.rstrip('.') + ' with special output for Bitten.'
def handle(self, *test_labels, **options):
View preseed.cfg
# This is the entire preseed config file used on an example Lucid system. See the preseed
# documentation for more information on the options here. This will use US English by default.
#
# https://help.ubuntu.com/10.04/installation-guide/amd64/preseed-contents.html
#
# This preseed will automatically install Ubuntu 10.04 with default options. Understand what
# it is doing before you use it.
#
# Boot Options line:
#
@coderanger
coderanger / plans.txt
Created Nov 21, 2010
Cell plan prices. Family is for 2 lines, all plans assume "unlimited" data (2GB for AT&T).
View plans.txt
T-Mobile:
unlimited - personal = $100
1500 - personal = $80
1000 - personal = $90
500 - personal = $80
unlimited - family = $180
3000 - family = $150
1500 - family = $160
750 - family = $140
You can’t perform that action at this time.