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 / staticfiles.py
Created November 24, 2011 12:28 — forked from specialunderwear/staticfiles.py
Use django collectstatic with apps that have 'media' folders instead of 'static' folders. Also make run server serve files in the MEDIA_ROOT automatically, even if it is inside STATIC_ROOT.
import os
from django.conf import settings
from django.contrib.staticfiles.finders import BaseFinder, AppDirectoriesFinder
from django.contrib.staticfiles.storage import AppStaticStorage
from django.core.files.storage import FileSystemStorage
from django.utils._os import safe_join
class AppMediaStorage(AppStaticStorage):
@luzfcb
luzfcb / bootstrap.sh
Created November 25, 2011 19:23 — forked from anonymous/bootstrap.sh
Django on Heroku with Celery and Sentry
virtualenv --no-site-packages .
source bin/activate
bin/pip install Django psycopg2 django-sentry
bin/pip freeze > requirements.txt
bin/django-admin.py startproject mysite
cat >.gitignore <<EOF
bin/
include/
lib/
EOF
@luzfcb
luzfcb / wtf.rb
Created December 1, 2011 16:38 — forked from actsasbuffoon/wtf.rb
def aireplay(essid,iface)
system("aireplay-ng -3 -e #{essid} #{iface}")
end
def airmon(iface,channel)
system ("airmon-ng start #{iface} #{channel}")
end
def airodump(iface)
system("airodump-ng --ivs #{iface}")

Sass/Less Comparison

In this document I am using Sass's SCSS syntax. You can choose to use the indented syntax in sass, if you prefer it, it has no functional differences from the SCSS syntax.

For less, I'm using the ruby version because this is what they suggest on the website. The javascript version may be different.

Variables

# --*-- coding: utf-8 --*--
from django.db import models
# Create your models here.
class TipoLicencaDeUso(models.Model):
nome = models.CharField(max_length=255)
descricao = models.TextField(verbose_name=u"Descrição")
sigla = models.CharField(max_length=20)
@luzfcb
luzfcb / group_users_form.py
Created January 31, 2012 19:25 — forked from rafaelnovello/group_users_form.py
Select users to the group in group form on Django Admin.
# -*- coding: utf-8 -*-
from django.forms import ModelForm
from django import forms
from django.contrib.auth.models import Group, User
class GroupAdminForm(ModelForm):
class Meta:
model = Group
group_users = forms.ModelMultipleChoiceField(label=u'Usuários deste Grupo', queryset=User.objects.all())
@luzfcb
luzfcb / gist:3230225
Created August 1, 2012 20:03 — forked from gmorada/gist:3228519
Helper para gerar relatório em pdf a partir de um html
from django.template.loader import get_template
from django.template import Context
import cStringIO as StringIO
import cgi
import ho.pisa as pisa
def render_to_pdf(template_src, context_dict):
template = get_template(template_src)
context = Context(context_dict)
html = template.render(context)
@luzfcb
luzfcb / __init__.py
Last active October 10, 2015 04:08
Registra no admin automaticamente todos os models de todas as apps descritas no settings.py
#Registra no admin automaticamente todos os models de todas as apps descritas
#nos settings.py
#
#Baseado em http://djangosnippets.org/snippets/2066/
#Modificado por: Fabio C. Barrioneuvo da Luz
#2012-09-05
#https://gist.github.com/3629920
#Coloque este codigo no arquivo __ini__.py do modulo que contem o settings.py do seu projeto
@luzfcb
luzfcb / autoadmin.py
Created September 5, 2012 10:12 — forked from fabiocerqueira/autoadmin.py
Register on admin models for modules without the admin.py file
from django.conf import settings
from django.db.models import get_models
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule
from django.contrib.admin.sites import AlreadyRegistered
from django.contrib import admin
def autodiscover():
for app in settings.INSTALLED_APPS:
@luzfcb
luzfcb / time_dict_value_max.py
Created December 4, 2012 03:28 — forked from perone/time_dict_value_max.py
Python max dict value
import timeit
t = timeit.Timer("v=sorted(d.items(), key=lambda x: x[1])[-1]",
"d = {'a': 1000, 'b': 3000, 'c':100}")
print t.timeit()
# 1.648s
t = timeit.Timer("v=max(d.iteritems(), key = operator.itemgetter(1))[0]",
"import operator; d = {'a': 1000, 'b': 3000, 'c':100}")
print t.timeit()