Skip to content

Instantly share code, notes, and snippets.

# Instalando no Mac Os
$ sudo easy_install pip
# Instalando no Ubuntu:
$ sudo apt-get install python-pip
# Instalando no Fedora:
# coding: utf-8
import unittest
class Discount(object):
def __init__(self, customer_type, value):
self.customer_type = customer_type
self.value = value
# coding: utf-8
class Discount(object):
def __init__(self, customer_type, value):
self.customer_type = customer_type
self.value = value
def twenty_percent(self, value):
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
# coding: utf-8
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
>>> a = [1,3,5,7]
>>> b = [2,4,6,8]
>>> zip(a,b)
[(1, 2), (3, 4), (5, 6), (7, 8)]
@fernandovalente
fernandovalente / PgsqlAdapter.php
Created October 12, 2012 21:09
Post CodeIgniter2 + Sparks + Php-ActiveRecord com PostgreSQL 01
public function query_column_info($table)
{
$sql = <<<SQL
SELECT
a.attname AS field, a.attlen, t.typname AS type,
format_type(a.atttypid, a.atttypmod) AS complete_type,
a.attnotnull AS not_nullable,
(SELECT 't' FROM pg_index WHERE c.oid = pg_index.indrelid
AND a.attnum = ANY (pg_index.indkey)
AND pg_index.indisprimary = 't') IS NOT NULL AS pk,
@fernandovalente
fernandovalente / tombola.py
Created September 28, 2012 17:14
2a lista de exercícios do curso OOPY - Oficinas Turing
from random import shuffle
from inplace import pairswap
class Tombola(object):
'''Sorteia itens sem repetir'''
def __iter__(self):
return IteratorTombola(self.itens)
def carregar(self, seq):
@fernandovalente
fernandovalente / lista_01_oop.py
Created September 19, 2012 17:34
Lista de exercícios do curso OOPY
# coding: utf-8
"""
Código inicial usado na Lista de Exercícios 1 do curso
"Objetos Pythonicos" de Luciano Ramalho, Oficinas Turing.
"""
__all__ = ('Contador', 'ContadorAmigavel', 'ContadorTotalizador', 'ContadorTotalizadorAmigavel')
class Contador(object):
@fernandovalente
fernandovalente / quadro_4_tuplas.py
Created August 24, 2012 14:50
Quadro 4 - Tuplas. Post sobre listas em Python - www.fernandovalente.com.br/blog
>>> t = (4, 3, 6, 7, 8)
# Diferente do sort(), o sorted() cria uma cópia e não altera no local
>>> t2 = sorted(t)
>>> t2
[3, 4, 6, 7, 8] # sorted gerou uma lista ordenada com os itens copiados da tupla
>>> type(t2)
<type 'list'>
# transformando a lista em tupla
>>> t2 = tuple(t2)