Skip to content

Instantly share code, notes, and snippets.

View mgrouchy's full-sized avatar

Mike Grouchy mgrouchy

View GitHub Profile
@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/
}
@mgrouchy
mgrouchy / .gitconfig
Created May 24, 2011 19:31
gitconfig
[alias]
lo = log --oneline
lwg = log --graph --pretty=format:'%Cred%h%Creset %C(yellow)%an%d%Creset %s %Cgreen(%cr)%Creset' --date=relative
st = status
p = push
ra = remote add
rrm = remote rm
[user]
name =
email =
# the basics
: ${HOME=~}
: ${LOGNAME=$(id -un)}
: ${UNAME=$(uname)}
# complete hostnames from this file
: ${HOSTFILE=~/.ssh/known_hosts}
# readline config