Skip to content

Instantly share code, notes, and snippets.

View mariocesar's full-sized avatar

Mario-César mariocesar

View GitHub Profile
@mariocesar
mariocesar / fields.py
Created December 27, 2011 23:59
Django JSONField, that don't suck!
"""
Works with SOUTH, and output on the same widget an HTML list with the value of the field
class MyModel(models.Model):
data = JSONField()
You will need simplejson installed with pip, Django 1.3+
"""
from django.db.models.fields import Field
@mariocesar
mariocesar / fprint_dbus.py
Created January 24, 2012 01:48
Test fprint with dbus
import sys
import time
import gobject
import dbus, dbus.service
from dbus.mainloop.glib import DBusGMainLoop
dbus_loop = DBusGMainLoop()
dbus.set_default_main_loop(dbus_loop)
loop = gobject.MainLoop()
@mariocesar
mariocesar / email_parse.py
Last active February 25, 2023 13:41
Parse a raw email
"""
$ cat source.email | python email_parse.py
"""
import fileinput
import email
from email.Utils import parseaddr
def parse():
raw_message = ''.join([line for line in fileinput.input()])
@mariocesar
mariocesar / runserver.py
Created October 23, 2012 11:18
Runs the django dev server along with ´compass watch´ command. For fun and profit
import os
import subprocess
import atexit
import signal
from optparse import make_option
from django.conf import settings
from django.core.management.base import BaseCommand
from django.core.management.commands.runserver import Command as RunserverCommand
@mariocesar
mariocesar / update_permissions.py
Created October 24, 2012 14:24
Django: Sync new permissions for specified apps with the database, or all apps if no args are specified
from django.core.management.base import BaseCommand
from django.db.models import get_models, get_app
from django.contrib.auth.management import create_permissions
class Command(BaseCommand):
args = '<app app ...>'
help = 'Sync new permissions for specified apps with the database, or all apps if no args are specified'
def handle(self, *args, **options):
@mariocesar
mariocesar / dyndns_route53.py
Created November 25, 2012 06:08
Update a Route53 Record if your public IP changes. Like DynDNS
"""
Requeriments:
$ sudo pip install boto dnspython
Edit ~/.boto to use your AWS credentials
"""
import time
import sys
@mariocesar
mariocesar / jenkins.sh
Last active January 5, 2016 12:11
Jenkins build script for a Django project
export PIP_DOWNLOAD_CACHE=/var/lib/jenkins/pip-cache
export AQUIPAGO_ENVIRONMENT=testing
make
env/bin/pip install -r requirements/base.txt --download-cache=/var/lib/jenkins/pip-cache --use-mirrors --timeout 1
env/bin/pip install -r requirements/project.txt --download-cache=/var/lib/jenkins/pip-cache --use-mirrors --timeout 1
env/bin/python runtests.py || :
env/bin/pylint --rcfile=.pylintrc aquipago --ignore=test > reports/pylint.txt || :
@mariocesar
mariocesar / calc_ansl.py
Last active December 11, 2015 18:09
Formula para el calculo del Aporte Nacional Solidario Laboral, un aporte obligatorio en Bolivia, para usar como una regla salarial en OpenERP (hr.salary.rule)
"""
Formula para el calculo del Aporte Nacional Solidario Laboral
Esta es la explicación legal del calculo de la formula:
* 10% de la diferencia del total ganado solidario menos Bs. 35.000 de diferencia positiva
* 5% de la diferencia del total ganado solidario menos Bs. 25.000 de diferencia positiva
* 1% de la diferencia del total ganado solidario menos Bs. 13.000 de diferencia positiva
"""
@mariocesar
mariocesar / matchMedia.js
Last active December 11, 2015 22:08
matchMedia polyfill for testing media queries in JS / both matchMedia and matchMedia.addListener in one script
/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas.
Dual MIT/BSD license https://github.com/paulirish/matchMedia.js */
window.matchMedia = window.matchMedia || (function( doc, undefined ) {
"use strict";
var bool,
docElem = doc.documentElement,
refNode = docElem.firstElementChild || docElem.firstChild,
// fakeBody required for <FF4 when executed in <head>
@mariocesar
mariocesar / wsgi.py
Last active December 11, 2015 22:18
Django wsgi patch. Every time it starts updates two files. changeset.txt with the current mercurial changeset, wsgistart_info.txt with the host and date of start
import os
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "crowddeals.settings")
def touch_wsgistart_info():
from mercurial import hg, ui
import time