Tag Archives: python

Vagas

Pro­jeto

Nosso pro­jeto vai mudar o mundo. E ele esta’ usando as seguintes tecnologias:

Front-end

* Javascript

* JQuery

* HTML5

* CSS

* Jinja2

Back-end

* pylons / pyramid

* mon­godb

* rab­bitmq

Geral

* Scrum

Per­fil minimo — Webmaster

Gostar de Javascript.

Saber JQuery!!!

Ter a mente aberta para apren­der todo dia uma coisa nova.

Ter dinam­ica de grupo. E gostar de rir.

Gostar de ir no Out­Back toda sexta-feira.

Per­fil min­imo — Desen­volve­dor Python

Gostar de Python.

Ter a mente aberta para apren­der todo dia uma coisa nova.

Ter dinam­ica de grupo. E gostar de rir.

Gostar de ir no Out­Back toda sexta-feira.

Ambi­ente

Esta­mos perto do metro Sao Judas, temos horario super flexivel!
Temos Red­Bull, Coca-Cola, Cafe’ e mais algu­mas coisas a von­tade para acabar com sua sede/fome!
Vio­lao, con­tra baixo, som ambiente…
Video-games…
Ficou com von­tade de tra­bal­har nesse pro­jeto que ira’ mudar o mundo?
Mande seu CV para umgeher.taborda@vitalbox.com.br e vamos mar­car uma hora.
Obs: Per­gun­tar sobre grana antes mesmo de man­dar CV = sem entrevista.

 

UGravatar

Sim­ple object to use Gravatar’s service.

> pip install ugravatar
> python
>>> from ugravatar import UGravatar
>>> o = UGravatar(email="umgeher@mitgnu.com")
>>> print o

http://www.gravatar.com/avatar/891f287c39ec64eb072fdf2b96c26c20?s=40

Source code: http://bitbucket.org/umgeher/ugravatar/ 

Dojo: Poker Hand

Hoje (quarta) e’ dia de Dojo (python) na Mas­ter­saf, estou apli­cando algu­mas coisas la’. O primeiro foi o clas­sico FizzBuzz  (que irei escr­ever um post mais tarde sobre). Hoje foi o Poker Hand, segue o texto usado.

Prob­lema

Voce e’ um cuprie que tem difi­cul­dades de ver que mao o jogador tem com rapi­dez. Voce deside fazer um algo­ritimo que resolva seu prob­lema, colo­cando os val­ores das car­tas e retor­nando o valor daquela mao.

Exem­plo 1

input > TD,JD,KD,AD,QD

result > Royal Straight Flush

Regras do poker

Poker deck con­tem 52 car­tas. Cada carta tem um naipe que sao:

  • copas / hearts ( H )
  • ouros / dia­monds ( D )
  • paus / clubs ( C )
  • espadas / spades ( S )

E um valor, que sao:

  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10 (T)
  • Valete / Jack (J)
  • Dama / Queen (Q)
  • Rei / King (K)
  • As / Ace (A)

(Estao em ordem de val­ores, menor para maior.)
A Poker Hand e’ com­posta por 5 car­tas vin­das do deck. Sao elas (do menor valor ao maior):

  • High Card: Ganha quem tiver a carta mais alta.
  • Pair: sao 2 car­tas iguais e tres difer­entes, Caso empate ganha aquele que pos­suir o maior par, caso empate ganha aquele que pos­suir a maior carta.
  • Two Pairs: sao 2 pares de car­tas, caso empate ganha aquele com maior par maior, se empatar ganha o que pos­suir o maior par menor, caso empate ganha aquele que pos­suir a maior carta.
  • Three of a Kind: sao 3 car­tas iguais mais duas car­tas diferentes.
  • Straight: sao 5 car­tas seguidas sem impor­tar o naipe.
  • Flush: sao 5 car­tas do mesmo naipe sem serem seguidas, caso dois jogadores pos­suam Flush ganha aquele que pos­suir uma outra carta mais alta.
  • Full House: uma trinca e um par, caso de empate ganha o jogador com o trinca mais alta, caso per­maneça o empate ganha aquele com o maior par.
  • Four of a Kind: sao 4 car­tas iguais (mesmo valor numerico)
  • Straight Flush: sao 5 car­tas seguidas do mesmo naipe.
  • Royal Straight Flush: sao 5 car­tas seguidas do mesmo naipe (ouros) do 10 até ao As.

Parte 2

O pro­grama agora dev­era’ com­parar 2 ou mais Hands e indicar qual e’ o vence­dor e mostrar a lista de Hands em ordem de valor (maior para menor).

03.01.2011

About FS:

* func­tional test [ ok ]

* bet­ter api returns [ ok ]

* sign in [ ok ]

* remove md5 method [ ok ]

* app’s check method return­ing App Obj [ ok ]

* admin [ todo ]

* “pylons” client [ todo ]

==

About Viking Soft­ware Development:

* write about it [ todo ]

* scrum x viking [ todo ]

pyCPF: CPF para python

Segue como uti­lizar o pyCPF.

Quero gerar um CPF valido.

> from pycpf import CPF
> x = CPF()

O seu objeto ja’ ira’ ser cri­ado com um CPF valido.

Quero val­i­dar um CPF.

> from pycpf import CPF
> x = CPF('124.835.178-03')
> y = CPF('12483517803')
> x.valid()
True
> y.valid()
True

Quero com­parar dois CPFs.

> from pycpf import CPF
> x = CPF('124.835.178-03')
> y = CPF('12483517803')
> z = CPF('124.835.178-02')
> x.__eq__(y)
True
> x.__eq__(z)
False

Quero usar ape­nas os numeros (tipo int) do CPF.

> from pycpf import CPF
> x = CPF('124.835.178-03')
> int(x)
12483517803L

Quero usar o CPF com formatacao.

> from pycnpj import CPF
> x = CPF('12483517803')
> str(x)
'124.835.178-03'

Uti­lize, ajude e mel­hore o pyCPF.  http://bitbucket.org/umgeher/pycpf

pyCNPJ: CNPJ para Python

Segue como uti­lizar o pyCNPJ.

Quero gerar um CNPJ valido.

> from pycnpj import CNPJ
> x = CNPJ()

O seu objeto ja’ ira’ ser cri­ado com um CNPJ valido.

Quero val­i­dar um CNPJ.

> from pycnpj import CNPJ
> x = CNPJ('67.923.223/6782-38')
> y = CNPJ('67923223678238')
> x.valid()
True
> y.valid()
True

Quero com­parar dois CNPJs.

> from pycnpj import CNPJ
> x = CNPJ('67.923.223/6782-38')
> y = CNPJ('67923223678238')
> z = CNPJ('12345678901234')
> x.__eq__(y)
True
> x.__eq__(z)
False

Quero usar ape­nas os numeros (tipo int) do CNPJ.

> from pycnpj import CNPJ
> x = CNPJ('67.923.223/6782-38')
> int(x)
67923223678238L

Quero usar o CNPJ com formatacao.

> from pycnpj import CNPJ
> x = CNPJ('67923223678238')
> str(x)
'67.923.223/6782-38'

Uti­lize, ajude e mel­hore o pyC­NPJ.  http://bitbucket.org/umgeher/pycnpj

pyCNPJ

Criei um val­i­dador e ger­ador de CNPJ. Estou lidando com isso agora e sen­tir falta de um objeto sim­ples que valide CNPJ em python. Pub­lico ele usando a “FreeBSD License” (style) e hospedando o Bit­Bucket (nao gosto do github).

Mais tarde devo escr­ever como usar, muito sim­ples, porem tenho de escrever.

http://bitbucket.org/umgeher/pycnpj

Euler’s Problem: 20

n! means n * (n-1) * … * 3 * 2 * 1

Find the sum of the dig­its in the num­ber 100!

#!/usr/bin/env python

t = 1
x = 0

for i in range(1,101):
    t = t * i

for i in str(t):
    x = x + int(i)

print x
/home/umgeher/war/hg/euler/python> time python 20.py
648

Time spent in user mode   (CPU seconds) : 0.016s
Time spent in kernel mode (CPU seconds) : 0.008s
Total time                              : 0:00.02s
CPU utilisation (percentage)            : 50.0%
Times the process was swapped           : 0
Times of major page faults              : 0
Times of minor page faults              : 649
/home/umgeher/war/hg/euler/python>

Euler’s Problem: 112

Work­ing from left-to-right if no digit is exceeded by the digit to its left it is called an increas­ing num­ber; for exam­ple, 134468.

Sim­i­larly if no digit is exceeded by the digit to its right it is called a decreas­ing num­ber; for exam­ple, 66420.

We shall call a pos­i­tive inte­ger that is nei­ther increas­ing nor decreas­ing a “bouncy” num­ber; for exam­ple, 155349.

Clearly there can­not be any bouncy num­bers below one-hundred, but just over half of the num­bers below one-thousand (525) are bouncy. In fact, the least num­ber for which the pro­por­tion of bouncy num­bers first reaches 50% is 538.

Sur­pris­ingly, bouncy num­bers become more and more com­mon and by the time we reach 21780 the pro­por­tion of bouncy num­bers is equal to 90%.

Find the least num­ber for which the pro­por­tion of bouncy num­bers is exactly 99%.

#!/usr/bin/env python

def calc(x):
    a = d = False
    x = str(x)

    for y in range(len(x)-1):
        if x[y+1] > x[y]:
            a = True
        elif x[y+1] < x[y]:
            d = True

        if a and d:
            return True

    return False

x = 21780
p = 0.90
b = x * p

while p != 0.99:
    x+= 1 

    if calc(x):
        b+= 1

    p = float(b)/x

print x
/home/umgeher/war/hg/euler/python> time python 112.py
1587000

Time spent in user mode   (CPU seconds) : 5.449s
Time spent in kernel mode (CPU seconds) : 0.007s
Total time                              : 0:05.46s
CPU utilisation (percentage)            : 99.6%
Times the process was swapped           : 0
Times of major page faults              : 0
Times of minor page faults              : 649
/home/umgeher/war/hg/euler/python>

DreamPie

Peo­ple, check this python shell! DreamPie. Very nice, if you’re using stack­less or jython, it’s works just fine!

Fea­tures:

  • DreamPie fea­tures a new con­cept for an inter­ac­tive shell: the win­dow is divided into the his­tory box, which lets you view pre­vi­ous com­mands and their out­put, and the code box, where you write your code. This allows you to edit any amount of code, just like in your favorite edi­tor, and exe­cute it when it’s ready. You can also copy code from any­where, edit it and run it instantly.
  • The Copy code only com­mand will copy the code you want to keep, so you can save it in a file. The code is already for­mat­ted nicely with a four-space indentation.
  • Fea­tures auto­matic com­ple­tion of attrib­utes and file names.
  • Auto­mat­i­cally dis­plays func­tion argu­ments and documentation.
  • Keeps your recent results in the result his­tory, for later user.
  • Can auto­mat­i­cally fold long out­puts, so you can con­cen­trate on what’s important.
  • Lets you save the his­tory of the ses­sion as an HTML file, for future ref­er­ence. You can then load the his­tory file into DreamPie, and quickly redo pre­vi­ous commands.
  • Auto­mat­i­cally adds paren­the­ses and option­ally quotes when you press space after func­tions and meth­ods. For exam­ple, exec­file fn auto­mat­i­cally turns into execfile(“fn”).
  • Sup­ports inter­ac­tive plot­ting with mat­plotlib. (You have to set “inter­ac­tive: True” in the mat­plotli­brc file for this to work.)
  • Sup­ports Python 2.5, 2.6, 2.7, Jython 2.5, Iron­Python 2.6 and Python 3.1.
  • Works on Win­dows, Linux and Mac. (Mac sup­port requires MacPorts.)
  • Extremely fast and responsive.