This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # ====================================================================== | |
| # | |
| # Function: lnsp | |
| # Creates a symbolic link to a folder inside current site-packages. If | |
| # the file already exists, ask for override. | |
| # Works ok with virtualenv. | |
| # | |
| # Parameters: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf8 -*- | |
| """ | |
| Template tag to stop template rendering to debug. | |
| It's useful to know what is in the context. | |
| Just put this file in a templatetags module inside your app and | |
| insert this code in your templates where you want to debug: | |
| {% load pdbdebug %}{% pdbdebug %} | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.db import models | |
| from query import QuerySet | |
| class CustomQuerySet(QuerySet): | |
| def published(self): | |
| return self.filter(published=True) | |
| class Content(models.Model): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.utils.safestring import SafeData, mark_safe | |
| from django.template import TemplateSyntaxError | |
| @register.filter | |
| def truncate(value, arg): | |
| """ | |
| Truncates a string after a given number of chars | |
| Argument: Number of chars to truncate after | |
| """ | |
| mark_safe_if_safe = lambda v: mark_safe(v) if isinstance(value, SafeData) else v |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- 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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from functools import wraps | |
| def cached_property(fn): | |
| @wraps(fn) | |
| def wrapper(self): | |
| cache_var = '_%s' % fn.__name__ | |
| if not hasattr(self, cache_var): | |
| setattr(self, cache_var, fn(self)) | |
| return getattr(self, cache_var) | |
| return property(wrapper) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fib(quantidade): | |
| a, b = 0, 1 | |
| for i in xrange(quantidade): | |
| yield b | |
| a, b = b, a + b | |
| class Fib(object): | |
| def __init__(self, quantidade): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # -*- coding: utf-8 -*- | |
| import json | |
| cars = json.loads(open('./fixtures/fipe_carro.json').read()) | |
| tree = {} | |
| for v in cars: | |
| for name in v['translated_names']: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # coding: utf8 | |
| import imp | |
| import sys, os | |
| module_name = sys.argv[1] | |
| bits = module_name.split('.') | |
| name = imp.find_module(bits[0])[1] | |
| if len(bits) > 1: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return this.getStringA() + " - " + this.getStringB(); |