Skip to content

Instantly share code, notes, and snippets.

@Kos
Kos / closures.js
Created January 18, 2013 20:09
This snippet is a piece of trivia that illustrates some behaviour of closures in JS. Remember: With great power comes great responsibility! For details, see my blog post: http://kos.gd/2013/01/closures-the-cute-pets-that-bite/
// This snippet is a piece of trivia that illustrates some behaviour of closures in JS.
// Remember: With great power comes great responsibility!
// For details, see my blog post:
// http://kos.gd/2013/01/closures-the-cute-pets-that-bite/
// Setup
if (typeof(print) === 'undefined') print = console.log.bind(console);
// For starters:
// Here's a function that calculates a sum of every N-th element of a given array.
@Kos
Kos / shaderlines.py
Created January 15, 2013 18:40
This module shows... a) how GLSL error locations are presented depending on how the shader source is passed (one string vs array of strings), b) whether a single token can spread across several source strings.
'''
This module shows...
a) how GLSL error locations are presented depending on how the shader source is passed
(one string vs array of strings),
b) whether a single token can spread across several source strings.
'''
import ctypes
from OpenGL import GL
@Kos
Kos / slicing.py
Created January 6, 2013 13:36
Slicing gotchas in Python 2
# Some setup...
import sys
def throws(msg, f):
try:
f()
except Exception, e:
return msg in str(e)
else:
@Kos
Kos / gist:4442668
Created January 3, 2013 11:02
How to make your coworkers angry: Decorators. (Who likes nested functions?)
import operator
commands = {}
@operator.attrgetter('__get__')
def command(name, func):
commands[name] = func
return func