Skip to content

Instantly share code, notes, and snippets.

View Leechael's full-sized avatar
🐹
Working from home

Leechael Leechael

🐹
Working from home
View GitHub Profile
@obeattie
obeattie / db_utils.py
Created October 14, 2009 12:51
Exposes SQLAlchemy's sessions and transactions as context managers (so they will be managed automatically inside blocks), and also provides a transaction decorator, which wraps an entire function in a transaction
"""Utilities for managing database sessions."""
from __future__ import with_statement
import contextlib
import functools
@contextlib.contextmanager
def temp_session(session_cls, **kwargs):
"""Quick and dirty context manager that provides a temporary Session object
to the nested block. The session is always closed at the end of the block.
@dahnielson
dahnielson / UUID.php
Last active September 1, 2024 11:34
Pure PHP UUID generator
<?php
/**
* UUID class
*
* The following class generates VALID RFC 4122 COMPLIANT
* Universally Unique IDentifiers (UUID) version 3, 4 and 5.
*
* UUIDs generated validates using OSSP UUID Tool, and output
* for named-based UUIDs are exactly the same. This is a pure
* PHP implementation.
@berinhard
berinhard / ipdb_breakpoint.vim
Created August 13, 2010 19:30
A script to enable easy ipdb usage for Vim users.
" Author: Bernardo Fontes <[email protected]>
" Website: http://www.bernardofontes.net
" This code is based on this one: http://www.cmdln.org/wp-content/uploads/2008/10/python_ipdb.vim
" I worked with refactoring and it simplifies a lot the remove breakpoint feature.
" To use this feature, you just need to copy and paste the content of this file at your .vimrc file! Enjoy!
python << EOF
import vim
import re
ipdb_breakpoint = 'import ipdb; ipdb.set_trace()'
function F(){}
Object.defineProperty(F.prototype, 'foo', {
get: function(){ return F._foo; },
set: function(value){ F._foo = value; }
});
var obj = new F();
obj.foo; // undefined
obj.foo = 1;
function! Jump2PrevDiffText()
let line=line(".")
let idx=col(".")-1
if synIDattr(diff_hlID(line, idx), "name")=="DiffChange" || synIDattr(diff_hlID(line, idx), "name")=="DiffText"
while idx>0
if synIDattr(diff_hlID(line, idx), "name")=="DiffText" && synIDattr(diff_hlID(line, idx-1), "name")!="DiffText"
call setpos(".", [0,line,idx])
break
elseif idx==1
let line=line(".")
@parente
parente / runinenv.sh
Created February 15, 2011 01:54
run a command in virtualenv, useful for supervisord
#!/bin/bash
VENV=$1
if [ -z $VENV ]; then
echo "usage: runinenv [virtualenv_path] CMDS"
exit 1
fi
. ${VENV}/bin/activate
shift 1
echo "Executing $@ in ${VENV}"
exec "$@"
@cowboy
cowboy / javascript-type-stuff.js
Created February 16, 2011 16:13
JavaScript Type Stuff
// ============================================================
// Objects vs Primitives
// To make a long story short, use primitives wherever you can.
// ============================================================
// Primitive types: Null, Undefined, Number, Boolean, String.
var num1 = 9000,
num2 = new Number( 9000 ),
str1 = "hello world",
@mrdoob
mrdoob / RequestAnimationFrame.js
Created February 22, 2011 14:50
Provides requestAnimationFrame in a cross browser way.
/**
* Provides requestAnimationFrame in a cross browser way.
* @author paulirish / http://paulirish.com/
*/
if ( !window.requestAnimationFrame ) {
window.requestAnimationFrame = ( function() {
return window.webkitRequestAnimationFrame ||
@abbas-obscurus
abbas-obscurus / pytc.c.patch
Created December 2, 2011 09:23
pytc rangefwm function now accept pefixes with embedded null bytes
--- pytc.c.orig 2011-12-01 02:31:54.000000000 +0400
+++ pytc.c 2011-12-01 02:32:21.000000000 +0400
@@ -1555,14 +1555,15 @@
int max;
TCLIST *list;
char *prefix;
+ int prefix_len;
static char *kwlist[] = {"prefix", "max", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "si:rangefwm", kwlist,
@myobie
myobie / mountain-lion-brew-setup.markdown
Created February 18, 2012 20:14
Get Mountain Lion and Homebrew to Be Happy

Get Mountain Lion and Homebrew to Be Happy

1) Install XCode 4.4 into /Applications

Get it from the App Store.

2) Install Command Line Tools

In XCode's Preferences > Downloads you can install command line tools.