Skip to content

Instantly share code, notes, and snippets.

View mittmannv8's full-sized avatar

Cleiton Junior Mittmann mittmannv8

  • AvenueCode [https://www.avenuecode.com/]
  • Lisbon, Portugal
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<title>React.js learn</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
@mittmannv8
mittmannv8 / bin_string.py
Created September 14, 2015 19:51
Convert string to bin and reverse
import binascii
# Bin to string
def tostring(b):
b = int(b, 2)
return binascii.unhexlify('%x' % b)
# String to bin
def tobin(s):
return bin(int(binascii.hexlify(s), 16))
@mittmannv8
mittmannv8 / promocoes.py
Last active August 29, 2015 14:21
Excercício ppqsp8: Criar um decorator que carregue automaticamente todas as promoções
from utils import promo
@promo
def fidelity_promo(order):
"""5% discount for customers with 1000 or more fidelity points"""
return order.total() * .05 if order.customer.fidelity >= 1000 else 0
@promo
@mittmannv8
mittmannv8 / strategy_best.py
Created May 15, 2015 05:19
Excercício ppqsp8: Criar um decorator que carregue automaticamente todas as promoções
# strategy_best.py
# Strategy pattern -- function-based implementation
# selecting best promotion from static list of functions
"""
>>> joe = Customer('John Doe', 0)
>>> ann = Customer('Ann Smith', 1100)
>>> cart = [LineItem('banana', 4, .5),
... LineItem('apple', 10, 1.5),
... LineItem('watermellon', 5, 5.0)]