Skip to content

Instantly share code, notes, and snippets.

@zmcghee
zmcghee / FakeQuerySet.py
Created June 30, 2011 10:43
Fake Django QuerySet
from django.db.models.query import EmptyQuerySet
class FakeQuerySet(EmptyQuerySet):
"""Turn a list into a Django QuerySet... kind of."""
def __init__(self, model=None, query=None, using=None, items=[]):
super(FakeQuerySet, self).__init__(model, query, using)
self._result_cache = items
def count(self):
return len(self)
@zmcghee
zmcghee / gist:1243366
Created September 26, 2011 20:49
Croddy (to the tune of Shaft)
[4:47pm] dslipakoff: You see this cat Croddy is a bad mother--
[4:47pm] cmheisel: Shut your croddy
[4:47pm] dslipakoff: But I'm talking about Croddy
[4:47pm] cmheisel: Then we can croddy it
[4:47pm] dslipakoff: He's a complicated man
[4:47pm] cmheisel: And no one understands him but his TTY
[4:48pm] mchace: That's a sex machine to all the chicks
[4:48pm] cmheisel: Croddy!
[4:48pm] dslipakoff: Who's the white Ops Guys
[4:48pm] dslipakoff: that's a HotFixing machine to all the servers ?
@zmcghee
zmcghee / lilsb.py
Created December 19, 2011 15:38
Grab lyrics from the song generator at phantomlyrics.org to tweet
"""
Script to grab lyrics from the song generator at phantomlyrics.org,
take 5 random verses from which you can choose, and make them ready
for Twitter.
"""
from httplib import HTTPConnection
from random import choice as random_choice
from sys import exit
from urllib import urlencode
@zmcghee
zmcghee / nycreleases.txt
Created December 29, 2011 19:01
Breakdown of movies released commercially in NYC since '98
1998: 471
1999: 472
2000: 461
2001: 453
2002: 489
2003: 480
2004: 549
2005: 592
2006: 643
2007: 647
from django.test.simple import DjangoTestSuiteRunner
class NoDbDjangoTestSuiteRunner(DjangoTestSuiteRunner):
def setup_databases(self, **kwargs):
return [], []
def teardown_databases(self, old_config, **kwargs):
pass
@zmcghee
zmcghee / drafthouse_vegan.md
Created April 18, 2012 14:54
Drafthouse - Vegan menu items

I was told by a manager these items are vegan:

  • Red pepper hummus
  • Chips and salsa
  • Nachos no cheese, no sour cream, no chicken... I'm vegetarian and often get the nachos and add green chiles. So delicious and I imagine they would still be good with no cheese. We could also sub tofu.
  • One of the vegetarian pizzas with no cheese. I think the "Big Fat Greek Pizza" has the most veggies.
  • House salad with any of the following dressings: spicy peanut, balsamic vinaigrette, jalapeno-lime vinaigrette, red wine shallot vinaigrette or lemon vinaigrette.
  • Asian salad sub tofu
  • Once Upon a Time in Mexico salad sub tofu and no cotija cheese.
  • Black bean burger with no dijon ailoi (bun is vegan)
@zmcghee
zmcghee / timestamp.js
Created June 4, 2013 21:31
JavaScript date format from UNIX timestamp
function date_str_from_unix(unix_timestamp) {
// var my_date_str = date_str_from_unix(1370383708);
// my_date_str returns "2013-06-04 17:08"
var leading_zero = function(i) {
return i.toString().length < 2 ? "0" + i : i
}
var date = new Date(unix_timestamp * 1000);
var date_str = date.getFullYear() + "-" + leading_zero(date.getMonth() + 1)
+ "-" + leading_zero(date.getDate()) + " "
+ leading_zero(date.getHours()) + ":"
@zmcghee
zmcghee / get_spreadsheet_id.py
Last active August 29, 2015 14:21
Fetch the first sheet of a Google Sheet file and work with it in Python.
def get_spreadsheet_id(user_input):
"""Accepts any form of Google Sheet URL or just the raw ID"""
if user_input.__contains__("spreadsheets/d"):
parts = user_input.split("/", 7)
if parts[4] == 'd':
return parts[5]
raise Exception("Couldn't get spreadsheet ID")
return user_input
if __name__ == "__main__":
@zmcghee
zmcghee / mobile-app-icon-tags.html
Last active August 29, 2015 14:21
Mobile app icon tags
<link rel="icon" sizes="192x192" href="nice-highres.png" />
<link rel="icon" sizes="128x128" href="niceicon.png" />
<link rel="apple-touch-icon" href="ios/AppIcon.appiconset/Icon-60@2x.png" />
<link rel="apple-touch-icon" sizes="180x180" href="ios/AppIcon.appiconset/Icon-60@3x.png" />
<link rel="apple-touch-icon" sizes="76x76" href="ios/AppIcon.appiconset/Icon-76.png" />
<link rel="apple-touch-icon" sizes="152x152" href="ios/AppIcon.appiconset/Icon-76@2x.png" />
<link rel="apple-touch-icon" sizes="58x58" href="ios/AppIcon.appiconset/Icon-Small@2x.png" />
/*
Based on https://developers.google.com/speed/docs/insights/OptimizeCSSDelivery
Further reading:
Preventing a Flash of Invisible Text
https://www.filamentgroup.com/lab/font-events.html
Detecting a stylesheet has loaded
https://viget.com/inspire/js-201-run-a-function-when-a-stylesheet-finishes-loading