Skip to content

Instantly share code, notes, and snippets.

View nvie's full-sized avatar
🍀
Simplifying things

Vincent Driessen nvie

🍀
Simplifying things
View GitHub Profile
@nvie
nvie / .bashrc
Created December 17, 2009 09:15 — 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)]/"
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
class Foo:
x = {}
def __init__(self, id):
self.x[id] = id
f1 = Foo(5)
print f1.x # {5:5}, as expected
f2 = Foo(6)
print f2.x # {5:5,6:6} ?!
print f1.x # {5:5,6:6}, too!
class Foo:
x = 3
def __init__(self, id):
self.x = id
f1 = Foo(5)
print f1.x # 5, as expected
f2 = Foo(6)
print f2.x # 6, as expected
class Bar:
x = {}
print Bar.x # {}
class Foo:
x = {}
def __init__(self, id):
self.x = { id: id }
f1 = Foo(5)
print f1.x # { 5:5 }, as expected
f2 = Foo(6)
print f2.x # { 6:6 }, as expected
require 'formula'
class GitFlow <Formula
url 'git://github.com/nvie/gitflow.git'
version '0.2'
homepage 'http://github.com/nvie/gitflow'
md5 'da3d5ff107f8fec1dad9aa3c0bc357a3'
depends_on 'git'
>>>True,False=False,True
>>>False
True
>>>1==2
False
>>>(1==2)==True
True
>>> # This shows how setting True/False is nothing more than a simple (yet scary!)
>>> # variable assignment in the local scope:
@nvie
nvie / gist:727282
Created December 3, 2010 17:56 — forked from hmarr/gist:727195
from mongoengine import *
from mongoengine import DENY, CASCADE, NULLIFY, DO_NOTHING
from mongoengine import DeleteForbidden # or something equivalent
from mongoengine.queryset import QuerySet
class Post(Document):
title = StringField()
@classmethod