Skip to content

Instantly share code, notes, and snippets.

Avatar
Focusing

Mario César mariocesar

Focusing
View GitHub Profile
@mariocesar
mariocesar / .htaccess
Last active Aug 29, 2015
Mock a REST Api authorization token. Just for testing
View .htaccess
# Solo permite acceder a quienes dan el token correcto
SetEnvIf Authorization "^Token QprcGo242MmjsB1ZoCwAq5EYs5e9Mjsnj1gug3YBxAIIE6of$" HTTP_SAFE_USE=1
Order Deny,Allow
Deny from All
Allow from env=HTTP_SAFE_USE
# No permite que ninguna respuesta sea cacheada
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
@mariocesar
mariocesar / models.py
Last active Aug 29, 2015
Workflow Model Helper for Django
View models.py
from django.db import models
from .workflow import Workflow, StateField
class SaleOrder(Workflow, models.Model):
DRAFT = 'draft'
QUOTATION = 'quotation'
CONFIRMED = 'confirmed'
@mariocesar
mariocesar / README.md
Last active Aug 29, 2015
Ubuntu Server + Nginx + Dropbox + uwsgi Apps
View README.md

Install

Create a websites user.

sudo adduser --disabled-password --home /src/websites websites

Login and install dropbox.

sudo -s su - websites
@mariocesar
mariocesar / itertools.md
Last active Aug 29, 2015
Python Itertools Notes
View itertools.md

Itertools Notes

from itertools import *

Infinite Iterators

count(start, [step])

@mariocesar
mariocesar / setup_utils.py
Last active Aug 29, 2015
Setup.py util to get common description variables like version, author, etc from packages without importing the modules. (To avoid circular imports and related errors)
View setup_utils.py
__version__ = "0.1"
__author__ = "mariocesar"
def get_module_meta(module_path):
import re
with open(module_path) as cakebet_meta:
meta = cakebet_meta.read()
return dict(re.findall('(?P<key>__.+__)\s=\s["\' ](?P<value>.+)["\' ]', meta))
@mariocesar
mariocesar / contact.md
Last active Aug 29, 2015
How to send an email in Django, do a basic preflight html optimization for the message, attach documents and attach image inline and also convert markdown to html.
View contact.md

Hello we got a message from {{ name }}!

-- {{ message|wordwrap:60}}

@mariocesar
mariocesar / app_middlewares.py
Created Jul 27, 2015
WSGI Python middleware to simple log all requests and responses to later debug.
View app_middlewares.py
class RequestLogMiddleware(object):
"""
Log requests to the application, a simple wsgi middleware.
"""
def __init__(self, application):
self.application = application
def __call__ (self, environ, start_response):
@mariocesar
mariocesar / server.py
Created Sep 15, 2015
wsgi application dummy demo
View server.py
import os
index_tpl = open('index.html', 'r').read()
def application(environ, response):
response('200 OK', [('Content-Type', 'text/html')])
yield '<ul>'
@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()