Skip to content

Instantly share code, notes, and snippets.

@ieure
ieure / python-pylint.el
Created February 12, 2010 18:49
Run pylint on Python source in Emacs.
;;; python-pylint.el --- minor mode for running `pylint'
;; Copyright (c) 2009, 2010 Ian Eure <[email protected]>
;; Author: Ian Eure <[email protected]>
;; Keywords: languages python
;; Last edit: 2010-02-12
;; Version: 1.01
@ieure
ieure / python-pep8.el
Created February 12, 2010 18:49
Run pep8.py on Python source in Emacs.
;;; python-pep8.el --- minor mode for running `pep8'
;; Copyright (c) 2009, 2010 Ian Eure <[email protected]>
;; Author: Ian Eure <[email protected]>
;; Keywords: languages python
;; Last edit: 2010-02-12
;; Version: 1.01
<?php
error_reporting(E_ALL | E_STRICT);
class Foo
{
public static function test()
{
echo "Hi!\n";
}
@ieure
ieure / save.py
Created November 16, 2009 22:28
from contextlib import contextmanager
@contextmanager
def save(obj, attrs=None):
"""Save attributes of an object, then restore them.
Example:
import breakfast
with save(breakfast, ('eggs', 'bacon')):
breakfast.Eggs = lambda: "Eggs"
# -*- coding: utf-8 -*-
import threading
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
def query():
engine = create_engine("mysql://testing:[email protected]/testing",
pool_size=20, strategy="threadlocal")
Session = scoped_session(sessionmaker(bind=engine))
# -*- coding: utf-8 -*-
import threading
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
engine = create_engine("mysql://testing:[email protected]/testing",
pool_size=20, strategy="threadlocal")
Session = scoped_session(sessionmaker(bind=engine))
# -*- coding: utf-8 -*-
# foo()'s a_value is unmodified.
def foo():
a_value = "Hello"
def bar():
a_value = "Goodbye"
bar()
@ieure
ieure / retry.py
Created September 29, 2009 23:49
from functools import partial
from itertools import imap
from operator import or_
def retry(ntimes=3, ignore=None, trap=None):
"""Retry an operation some number of times.
The ignore and trap arguments may be a sequence (or a single)
exception class. If the decorated function raises an exception
matching ignore, it will be raised.
@ieure
ieure / error_debug.py
Created September 25, 2009 03:40
Context manager to enter the Python debugger when an exception is raised
# -*- coding: utf-8 -*-
#
# Author: Ian Eure <http://github.com/ieure>, <http://atomized.org>
#
"""Enter the debugger on exceptions.
example:
from __future__ import with_statement
@ieure
ieure / star.py
Created September 14, 2009 20:23
Functional version of the Python */** operators
# -*- coding: utf-8 -*-
#
# Author: Ian Eure <[email protected]>
#
"""Star function."""
from functools import partial
import unittest