Skip to content

Instantly share code, notes, and snippets.

View luzfcb's full-sized avatar

Fábio C. Barrionuevo da Luz luzfcb

View GitHub Profile
@luzfcb
luzfcb / Python Notepad Bookmarklet
Last active August 29, 2015 13:58 — forked from jakeonrails/Ruby Notepad Bookmarklet
This bookmarklet gives you a code editor in your browser with a single click.
data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/python");</script>
.table-container th.asc:after {
content: '\0000a0\0025b2';
}
.table-container th.desc:after {
content: '\0000a0\0025bc';
}
.pagination {
text-align: center;
}
from django.db.models.signals import post_syncdb
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import Permission
def add_view_permissions(sender, **kwargs):
"""
This syncdb hooks takes care of adding a view permission too all our
content types.
"""
# for each of our content types
# -*- coding: utf-8 -*-
"""Add permissions for proxy model.
This is needed because of the bug https://code.djangoproject.com/ticket/11154
in Django (as of 1.6, it's not fixed).
When a permission is created for a proxy model, it actually creates if for it's
base model app_label (eg: for "article" instead of "about", for the About proxy
model).
@luzfcb
luzfcb / htmlToPDF.py
Last active December 28, 2015 03:29 — forked from anonymous/htmlToPDF.py
html to pdf using phantomjs
import uuid
from os import system
# code from http://www.dextra.com.br/how-to-criar-relatorios-em-pdf-a-partir-de-html/
#BaseHTTPServer module has been merged into http.server in Python 3.
#Earlier versions should use "from BaseHTTPServer" instead
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
class HtmlToPDF(BaseHTTPRequestHandler):
def do_GET(self):
import io, chardet
from chardet.universaldetector import UniversalDetector
f = open('file.txt')
# Jeito mais simples e menos preciso.
encoding = chardet.detect(f.read())['encoding']
# Maneira mais precisa de se detectar o encoding.
# Servirá de fallback, caso a primeira tentativa não dê resultados.

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

#!/bin/bash
#
# Install Postgres 9.1, PostGIS 2.0 and pgRouting on a clean Ubuntu 12.04 install (64 bit)
# updated to PostGIS 2.0.1
# references:
# http://lists.osgeo.org/pipermail/postgis-users/2013-October/037710.html
# http://postgis.refractions.net/docs/postgis_installation.html
# http://postgis.net/install
# http://abdulzahraalameri.blogspot.com.br/2011/05/create-templatepostgis-database.html
# http://gis.stackexchange.com/questions/19432/why-does-postgis-installation-not-create-a-template-postgis

NOT EXACTLY TIM THE ENCHANTER

Django has always been hailed as having great, awesome documentation. And, for the most part, this distinction has been deserved. But every once in a while, you find an area that's just...lacking. An area that you know exists but you've never gone into because it didn't come up and no one else used it but then you finally got a reason to use it...and then you find out it's so lacking in documentation that you have to dive into the source code.

This is one of those areas. Welcome to Django Form Wizard.

What is Django Form Wizard? At it's most basic, Django's Form Wizard (DFW from now on, OK?) is a way to auto-generate a set of views w/ a single form in each view. Most of the time it uses one template but you can have a different template for each view. Most wizards have numbered steps but you can have named ones if you want. Also, most wizards deal with standard forms (highly recommended) but can, of course, use formsets and model forms.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 João Paulo Dubas <http://aval.io>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE