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

Keybase proof

I hereby claim:

  • I am nvie on github.
  • I am nvie (https://keybase.io/nvie) on keybase.
  • I have a public key whose fingerprint is 9B5C 55F6 2651 625C C4EE 7C8F 4DAB 9440 5EA5 AAF0

To claim this, I am signing this object:

@nvie
nvie / magic.awk
Last active August 29, 2015 14:07
Different highlights of this piece of code that is valid C, C++, awk, perl, Python, sh, bash and tcl: https://github.com/stedolan/hax/blob/master/twisty_code/megascript.c
#ifdef _not_defined
#\
"exit`[ -z $BASH ] && t=sh; [ -z $BASH ] || t=$(basename $BASH); echo Hello, World from $t > /dev/tty;`";
"[puts {Hello, World from Tcl}; {exit}]";
from operator import concat;
exec concat(concat(concat(chr(109),chr(61)),chr(39)),chr(39));
m,""" ";/,;s/;//;
#else
#include <stdio.h>
#define BEGIN int main(int nargs,char** args)
def lookup_table(values, key=None, keyval=None, unique=False, use_lists=False):
"""
Builds a dict-based lookup table (index) elegantly.
Supports building normal and unique lookup tables. For example:
>>> lookup_table(['foo', 'bar', 'baz', 'qux', 'quux'],
... lambda s: s[0])
{
'b': {'bar', 'baz'},
'f': {'foo'},
'q': {'quux', 'qux'}
#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} ?!
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
print f1.x # {5:5,6:6}, too!
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'