Skip to content

Instantly share code, notes, and snippets.

Avatar
Focusing

Mario César mariocesar

Focusing
View GitHub Profile
@mariocesar
mariocesar / fields.py
Created Dec 27, 2011
Django JSONField, that don't suck!
View fields.py
"""
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 Jan 24, 2012
Test fprint with dbus
View fprint_dbus.py
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 Dec 12, 2019
Parse a raw email
View email_parse.py
"""
$ 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 Oct 23, 2012
Runs the django dev server along with ´compass watch´ command. For fun and profit
View runserver.py
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 Oct 24, 2012
Django: Sync new permissions for specified apps with the database, or all apps if no args are specified
View update_permissions.py
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 Nov 25, 2012
Update a Route53 Record if your public IP changes. Like DynDNS
View dyndns_route53.py
"""
Requeriments:
$ sudo pip install boto dnspython
Edit ~/.boto to use your AWS credentials
"""
import time
import sys
@mariocesar
mariocesar / jenkins.sh
Last active Jan 5, 2016
Jenkins build script for a Django project
View jenkins.sh
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 Dec 11, 2015
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)
View calc_ansl.py
"""
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 Dec 11, 2015
matchMedia polyfill for testing media queries in JS / both matchMedia and matchMedia.addListener in one script
View matchMedia.js
/*! 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 Dec 11, 2015
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
View wsgi.py
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