Skip to content

Instantly share code, notes, and snippets.

View windviki's full-sized avatar
🍻
Loving craft beer

windviki

🍻
Loving craft beer
View GitHub Profile
@shazow
shazow / meta.py
Created December 17, 2009 00:59
BaseModel object for SQLAlchemy declarative object abstractions (with query statistics tracking and JSON decoder).
"""SQLAlchemy Metadata and Session object"""
from sqlalchemy import MetaData
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.orm.session import Session as SessionBase
from sqlalchemy.interfaces import ConnectionProxy
from datetime import datetime
import time
__all__ = ['Session', 'metadata', 'BaseModel']
@windviki
windviki / beyondcompare-diff.sh
Created November 29, 2011 02:28 — forked from ecerulm/diffmerge-diff.sh
Cygwin Git: wrappers for beyond compare, diffmerge and winmerge
#!/bin/sh
# Use BeyondCompare as difftool for git in cygwin.
# git config --global difftool.bc.cmd "beyondcompare-diff.sh \"\$LOCAL\" \"\$REMOTE\""
# git difftool -t bc branch1..branch2
# Reference: http://www.tldp.org/LDP/abs/abs-guide.pdf
library=~/gittool/githelperfunctions.sh
#[ -f $library ] && . $library
@smitec
smitec / Example
Created February 20, 2012 03:13
Python boolean statement to RPN
parse("( S < 16 and T = \"P\" ) or ( S > 16 and L = 50 )") => ['S<16', 'T="P"', 'and', 'S>16', 'L=50', 'and', 'or']
@techtonik
techtonik / caller_name.py
Created March 21, 2012 19:29
Python - inspect - Get full caller name (package.module.function)
# Public Domain, i.e. feel free to copy/paste
# Considered a hack in Python 2
import inspect
def caller_name(skip=2):
"""Get a name of a caller in the format module.class.method
`skip` specifies how many levels of stack to skip while getting caller
name. skip=1 means "who calls me", skip=2 "who calls my caller" etc.
@codeb2cc
codeb2cc / gist:3302754
Created August 9, 2012 09:48
Sqlalchemy get_or_create implement
# -*- coding: utf-8 -*-
from sqlalchemy.exc import IntegrityError
from sqlalchemy.sql.expression import ClauseElement
def _get_or_create(session, model, defaults=None, **kwargs):
try:
query = session.query(model).filter_by(**kwargs)
instance = query.first()
@mrluanma
mrluanma / requirements.txt
Created September 4, 2012 14:40
Python 登录新浪微博(requests 真的比 urllib2 强了 2^^32 倍 pip install requests)
requests==2.4.3
rsa==3.1.4
@babakness
babakness / caselessDictionary.py
Created October 16, 2012 18:46 — forked from bloomonkey/caselessDictionary.py
A Python dictionary sub-class that is case-insensitive when searching, but also preserves the keys as inserted.
class CaselessDictionary(dict):
"""Dictionary that enables case insensitive searching while preserving case sensitivity
when keys are listed, ie, via keys() or items() methods.
Works by storing a lowercase version of the key as the new key and stores the original key-value
pair as the key's value (values become dictionaries)."""
def __init__(self, initval={}):
if isinstance(initval, dict):
for key, value in initval.iteritems():
@volkanongun
volkanongun / index.html
Created November 28, 2012 10:18
A CodePen by Volkan Ongun. Nebular - Nebula generator. Includes star clustering, background stars, nebula clouds and interstellar dust. Click canvas to re-draw.
<!-- click canvas to draw a new nebula -->
<div id="status">&nbsp;</div>

Moved

Now located at https://github.com/JeffPaine/beautiful_idiomatic_python.

Why it was moved

Github gists don't support Pull Requests or any notifications, which made it impossible for me to maintain this (surprisingly popular) gist with fixes, respond to comments and so on. In the interest of maintaining the quality of this resource for others, I've moved it to a proper repo. Cheers!

@toroidal-code
toroidal-code / pacat.c
Created February 4, 2014 05:54
PulseAudio example with callbacks
/***
This file is part of PulseAudio.
Copyright 2004-2006 Lennart Poettering
Copyright 2006 Pierre Ossman <[email protected]> for Cendio AB
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.