Skip to content

Instantly share code, notes, and snippets.

View monokrome's full-sized avatar
😻
meow

Bailey Stoner monokrome

😻
meow
View GitHub Profile
{% for person in people %}
{% with profile as people.get_profile %}
{{ person.username }} has {{ profile.points }} points.
{% endwith %}
{% endfor %}
class GenericModel(models.Model):
model_type = models.CharField(max_length=16)
def __init__(self, *args, **kwargs):
for related_object in self._meta.get_all_related_objects():
if not issubclass(related_object.model, self.__class__):
continue
self.model_type = '{0}.{1}'.format(self._meta.app_label, related_object.__class__.__name__.lower())
@monokrome
monokrome / gist:798921
Created January 27, 2011 18:10
GitHub Global GitIgnore
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# ExperimenterInterface/
# MonkeyInterfaceModules/
nothing added to commit but untracked files present (use "git add" to track)
@monokrome
monokrome / gist:902933
Created April 5, 2011 02:49
A basic command-line weather interface in Python
#!/usr/bin/python
# <Knio> all of the things that remain constant (license, partner, whatever) should me the make class
# <Knio> and then when you ask it something it should return a Results object
# <Knio> and that object has .getTemp() or whatever
# <ScottG> Knio: I thought I had a good reason for setAttr but I don't see it now
# <Knio> so yeah, main class, SearchResults, and WeatherResults
# <Knio> unless searchresults is just like a list of strings, then it doesn't need to be a class
#TODO: Check for version numbers
import urllib
import sys
@monokrome
monokrome / factories.py
Created April 5, 2011 04:31
A basic idea of how you can implement factories in Python, and what they are used for.
#!/usr/bin/env python
# Here, we are going to implement a Robot. This robot has a lot of attributes - and
# we are going to want to make these accessible through a public interface.
# CHANGE LIST:
# - Added an object that we are using in order to map strings to indexes
# in our data source. This is useful for making things a bit more user
# friendly in some cases. Usually with more complicated data sources.
#
@monokrome
monokrome / overlayzip.py
Created May 14, 2011 23:21
A zip file which happens to let content overlay it's files. Use with a dash of StringIO for grand results.
import zipfile
class OverlayZipFile(zipfile.ZipFile):
""" Adds a method for overlaying a zip file with a given directory, or another
zip file. """
def overlay(self, content):
""" Overlays content over the zip file represented by 'self'.
Receives a zip file, and write's it's entire content over the zip file which
@monokrome
monokrome / analyze.py
Created June 7, 2011 03:32
Recursively loops through a directory (./audio) looking for audio and analyzes it with the EchoNest API.
#!/usr/bin/env python
#
# This is a small script which can be used to recursively loop through
# a directory and analyze every piece of audio in that directory using
# the impressive EchoNest API (http://the.echonest.com/).
#
# After completion, it will write a file in this script's directory
# which contains a mapping of every absolute file path analyzed and
# the related MD5 and title attributes of the resulting track. You
@monokrome
monokrome / fix-www-permissions.sh
Created June 19, 2011 01:59
Fixes permissions for /var/www on my Ubuntu machine
#!/usr/bin/env bash
chown -R www-data:www-data /var/www
chmod -R 660 /var/www
find /var/www -type d -exec chmod 770 {} \;
@monokrome
monokrome / layout2.jade
Last active September 26, 2015 18:28 — forked from kmiyashiro/layout2.jade
!!! 5
//if lt IE 7
<html class="no-js lt-ie9 lt-ie8 lt-ie7">
//if IE 7
<html class="no-js lt-ie9 lt-ie8">
//if IE 8
<html class="no-js lt-ie9">
// [if gt IE 8] <!
html(class="no-js", lang="en")
// <![endif]