Skip to content

Instantly share code, notes, and snippets.

View niran's full-sized avatar

Niran Babalola niran

View GitHub Profile
@niran
niran / WordPress category object structure.php
Created July 20, 2009 20:33
WordPress category object structure
<?php
# If you haven't played around with WordPress much and you're trying to find out what
# exactly this "category object" thing that's referenced in many places is. You might
# look for a category table in the database for some clues, but there isn't one. That's
# because WordPress uses "terms" to handle both categories and tags, each of which are
# "taxonomies". Looking in those tables will give you want you want, or you could just
# print a category object.
#
# More info: http://codex.wordpress.org/WordPress_Taxonomy
@niran
niran / mail.py
Created February 23, 2011 19:33
Multiple email connections in Django
from django.conf import settings
import django.core.mail
class MissingConnectionException(Exception):
pass
def get_connection(label=None, **kwargs):
if label is None:
label = getattr(settings, 'EMAIL_CONNECTION_DEFAULT', None)
niran@matryoshka:~/tribune$ mkvirtualenv --no-site-packages armstrong_test
New python executable in armstrong_test/bin/python
Installing setuptools............done.
virtualenvwrapper.user_scripts Creating /home/niran/.virtualenvs/armstrong_test/bin/predeactivate
virtualenvwrapper.user_scripts Creating /home/niran/.virtualenvs/armstrong_test/bin/postdeactivate
virtualenvwrapper.user_scripts Creating /home/niran/.virtualenvs/armstrong_test/bin/preactivate
virtualenvwrapper.user_scripts Creating /home/niran/.virtualenvs/armstrong_test/bin/postactivate
virtualenvwrapper.user_scripts Creating /home/niran/.virtualenvs/armstrong_test/bin/get_env_details
(armstrong_test)niran@matryoshka:~/tribune$ mkdir armstrong_test
(armstrong_test)niran@matryoshka:~/tribune$ cd armstrong_test/
(armstrong_test)niran@matryoshka:~/tribune/armstrong_test$ pip install -U git+https://github.com/armstrong/armstrong.core.arm_sections@master#egg=armstrong.core.arm_sections
Downloading/unpacking armstrong.core.arm-sections from git+https://github.com/armstrong/armstrong.core.arm_sections@master
Cloning https://github.com/armstrong/armstrong.core.arm_sections (to master) to /home/niran/.virtualenvs/armstrong_test/build/armstrong.core.arm-sections
Running setup.py egg_info for package armstrong.core.arm-sections
Before install bootstrap.
Scanning installed packages
Setuptools installation detected at /home/niran/.virtualenvs/armstrong_test/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg
Egg installation
Patching...
Renaming /home/niran/.virtualenvs/armstrong_test/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg into /home/niran/.virtualenvs/armstrong_test/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg.OLD.1311700981.18
(armstrong_test)niran@matryoshka:~/tribune/armstrong_test$ pip install -U git+https://github.com/armstrong/armstrong.core.arm_sections@master#egg=armstrong.core.arm_sections
Downloading/unpacking armstrong.core.arm-sections from git+https://github.com/armstrong/armstrong.core.arm_sections@master
Cloning https://github.com/armstrong/armstrong.core.arm_sections (to master) to /home/niran/.virtualenvs/armstrong_test/build/armstrong.core.arm-sections
Running setup.py egg_info for package armstrong.core.arm-sections
no previously-included directories found matching 'build/*'
Downloading/unpacking django==1.3.0 (from armstrong.core.arm-sections)
Downloading Django-1.3.tar.gz (6.5Mb): 6.5Mb downloaded
Running setup.py egg_info for package django
Downloading/unpacking armstrong.utils.backends (from armstrong.core.arm-sections)
Downloading armstrong.utils.backends-0.2.0.tar.gz
@niran
niran / generic.py
Created October 14, 2011 22:47
A couple of utility class-based views we use at The Texas Tribune.
from django.http import HttpResponse
from django.shortcuts import redirect
from django.views.generic.detail import BaseDetailView, \
SingleObjectTemplateResponseMixin
from tt.url.unicode import urlencode
class CanonicalUrlBaseDetailView(BaseDetailView):
@niran
niran / log
Created March 22, 2012 16:32
Heroku idling
2012-03-22T06:32:11+00:00 heroku[web.1]: State changed from created to starting
2012-03-22T06:32:17+00:00 heroku[web.1]: Starting process with command `django-admin.py run_gunicorn -b 0.0.0.0:10411 -w 3`
2012-03-22T06:32:18+00:00 app[web.1]: 2012-03-22 01:32:18 [1] [INFO] Starting gunicorn 0.14.2
2012-03-22T06:32:18+00:00 app[web.1]: 2012-03-22 01:32:18 [1] [INFO] Listening at: http://0.0.0.0:10411 (1)
2012-03-22T06:32:18+00:00 app[web.1]: 2012-03-22 01:32:18 [1] [INFO] Using worker: sync
@niran
niran / ssh_config
Created August 4, 2012 00:57
Remote port forwarding on boot
Host celes-forward
HostName celes.niran.org
User portforwarder
IdentityFile /root/.ssh/keyfile
RemoteForward 2222 localhost:22
RemoteForward 2280 localhost:80
RemoteForward 9091 localhost:9091
@niran
niran / date_url.py
Created October 8, 2012 02:03
Django template tag for reversing date-based URLs.
from django import template
from django.template import defaulttags, Parser, FilterExpression
from django.template.defaulttags import URLNode
register = template.Library()
class DateURLNode(URLNode):
def __init__(self, *args, **kwargs):
super(DateURLNode, self).__init__(*args, **kwargs)
@niran
niran / New-Property-Decorator.sublime-snippet
Created December 9, 2013 17:07
Override Sublime Text's terrible default @Property autocomplete
<snippet>
<content><![CDATA[property]]></content>
<tabTrigger>property</tabTrigger>
<scope>source.python</scope>
<description>New Property Decorator</description>
</snippet>