Skip to content

Instantly share code, notes, and snippets.

View mgrouchy's full-sized avatar

Mike Grouchy mgrouchy

View GitHub Profile
def override_urls(self):
return [
url(r'^offer/(?P<offer_id>\d+)/(?P<resource_name>%s)/(?P<offer_transaction_id>\d+)/$' % self._meta.resource_name, self.wrap_view('get_offer_transaction_id'), name="api_get_offer_transaction_id"),
url(r'^offer/(?P<offer_id>\d+)/(?P<resource_name>%s)/$' % self._meta.resource_name, self.wrap_view('get_offer_transaction'), name="api_get_offer_transaction"),
]
@mgrouchy
mgrouchy / funkypatterns.py
Created February 16, 2011 21:02
funky url patterns
patterns = [
(r'^(?P<resource_name>offer)/(?P<pk_list>\w[\w/;-]*)/$', someview),
(r'^offer/(?P<offer_id>\d+)/(?P<resource_name>transaction)/$', someotherview),
(r'^offer/(?P<offer_id>\d+)/(?P<resource_name>transaction)/(?P<offer_transaction_id>\d+)/$', someview),
]
@mgrouchy
mgrouchy / .bashrc
Created February 21, 2011 15:51 — forked from henrik/.bashrc
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
from django.models import Model
from django.auth.models import User
class Achievement(Model):
user = models.foreignKey(User)
created_at = models.DateTimeField()
def fetch_achievement(self):
#do some achievement logic in here
from django.auth.models import User
from django.shortcuts import get_object_or_404
#this view would be publicly accessable
def hook(request, username=None):
user = get_object_or_404(User, username=username) #cant remember the syntax
if not isinstance(User, user):
return user #this returns a 404
#now we know what user we are dealing with
class Container(models.Model):
children = models.OneToManyField(Child) #I know this one to many field does not exist
class Child(models.Model):
random_field = models.IntegerField(default=1)
#in your forms
#if you are using django.contrib.auth.views.login
#pass EmailAuthenticationForm to the authentication_form argument.
class EmailAuthenticationForm(AuthenticationForm):
"""
Extends the standard django AuthenticationForm, to support 75 character
usernames. 75 character usernames are needed to support the EmailOrUsername
auth backend.
"""
@mgrouchy
mgrouchy / show
Created April 28, 2011 19:21 — forked from tekacs/show
This does something essentially equivalent to showoff.io if you have a publicly facing server...
# Usage: show <local-port> <subdomain>
function show() {
DOMAIN=".tekacs.com"
REMOTE="$2$DOMAIN"
ssh -tR 1080:127.0.0.1:$1 vps "sudo ssh -Nl \$USER -L $REMOTE:80:127.0.0.1:1080 localhost"
}
@mgrouchy
mgrouchy / gist:977027
Created May 17, 2011 18:17
dropshare
#copy target folder or file to public folder in your dropbox
function dropshare()
{
cp -Rv $1 ~/Dropbox/Public/
}