Skip to content

Instantly share code, notes, and snippets.

@florentx
florentx / pep8q.py
Last active August 29, 2015 13:59
Run pep8 in parallel, adapted from https://github.com/jcrocholl/pep8/pull/230 by @jdahlin
#!python
# -*- coding: utf-8 -*-
# Adapted from a contribution of @jdahlin on jcrocholl/pep8/pull/230
import collections
import multiprocessing
import pep8
@florentx
florentx / pgutil.py
Created April 16, 2014 13:28
OpenERP - create missing indexes on Foreign Keys
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import contextlib
__all__ = ['savepoint', 'create_missing_indexes']
@contextlib.contextmanager
def savepoint(cr, name, quiet=False):
@florentx
florentx / better_zip.py
Last active April 26, 2017 07:22
CSV import alternative - (partial implementation) - Odoo 6.1
# -*- coding: utf-8 -*-
# Example of CSV import usage
from openerp import SUPERUSER_ID
from openerp.osv.orm import Model, fields
from openerp.addons.my_base.openerp_tools import convert_csv_import
class BetterZip(Model):
"""Zip object."""
@florentx
florentx / checksums.py
Last active August 29, 2015 14:17
Validate IBAN or Post Account
POST_TABLE = (0, 9, 4, 6, 8, 2, 7, 1, 3, 5)
IBAN_TABLE = dict([(c, str(idx))
for (idx, c) in enumerate('0123456789abcdefgh'
'ijklmnopqrstuvwxyz')])
def validate_postaccount(value):
"""Check the Post Account."""
if not value:
raise ValueError('Post Account cannot be empty')
@florentx
florentx / util.py
Created February 6, 2016 17:57
Finalizer objects for Python 2 and Python <= 3.3
"""Backport weakref.finalize from Python 3.5, simplified."""
import atexit
import sys
import weakref
class finalize(object):
"""Class for finalization of weakrefable objects