Skip to content

Instantly share code, notes, and snippets.

View mariocesar's full-sized avatar

Mario-César mariocesar

View GitHub Profile
@mariocesar
mariocesar / .htaccess
Last active August 29, 2015 14:02
Mock a REST Api authorization token. Just for testing
# 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 August 29, 2015 14:02
Workflow Model Helper for Django
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 August 29, 2015 14:04
Ubuntu Server + Nginx + Dropbox + uwsgi Apps

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 August 29, 2015 14:13
Python Itertools Notes

Itertools Notes

from itertools import *

Infinite Iterators

count(start, [step])

@mariocesar
mariocesar / setup_utils.py
Last active August 29, 2015 14:15
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)
__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 August 29, 2015 14:24
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.

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

-- {{ message|wordwrap:60}}

@mariocesar
mariocesar / app_middlewares.py
Created July 27, 2015 13:50
WSGI Python middleware to simple log all requests and responses to later debug.
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 September 15, 2015 20:17
wsgi application dummy demo
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 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()