Skip to content

Instantly share code, notes, and snippets.

View henriquebastos's full-sized avatar
😏

Henrique Bastos henriquebastos

😏
View GitHub Profile
import sys
import argparse
from getpass import getpass
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
def navigate(card_number, user_name, passkey):
try:
browser = webdriver.Firefox()
@henriquebastos
henriquebastos / magic_indexes.py
Created December 12, 2015 11:19
IPython Magic to show sequence's indexes
"""
IPython Magic to show sequence's indexes.
Useful to demonstrate how python indexes works with strings.
Example:
>>> %indexes henrique
0 1 2 3 4 5 6 7
h e n r i q u e
#!/usr/bin/python -tt
# coding: utf-8
import argparse
from collections import Counter
import tkinter as tk
from tkinter.filedialog import askopenfile
from tkinter.scrolledtext import ScrolledText
def load(file):
@henriquebastos
henriquebastos / Memoize.ipynb
Last active March 22, 2016 20:09
Estudo memoize com fib
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/python -tt
import argparse
from collections import Counter
import re
def purge(word):
if not word.isalpha():
word = ''.join(ch for ch in word if ch.isalpha())
return word
def main():
deck = Deck()
assert deck
assert len(deck) == 52
assert Card(rank='2', suit='spades') == Card(rank='2', suit='spades')
assert deck[0] == Card(rank='2', suit='spades')
assert deck[:2] == [Card('2', 'spades'), Card('3', 'spades')]
assert deck[12::13] == [Card('A', 'spades'), Card('A', 'diamonds'),
def main():
assert Vector(2, 4)
assert (Vector(2, 4).x, Vector(2, 4).y) == (2, 4)
assert repr(Vector(2, 4)) == 'Vector(2, 4)'
assert str(Vector(2, 4)) == '(2, 4)'
assert Vector(2, 4) == Vector(2, 4)
assert Vector(2, 4) + Vector(1, 2) == Vector(3, 6)
assert Vector(2, 4) * 2 == Vector(4, 8)
# Exemplo com closure
def crazy_sum():
acc = 0
def wrapped(t):
nonlocal acc
sum_with_acc = sum(t) + acc
acc = max(0, sum_with_acc - 9)
@henriquebastos
henriquebastos / large.py
Last active August 29, 2015 14:18
HappyNumbers in Python
def happy(number):
string = str(number)
digits = [int(char) for char in string]
squares = [digit**2 for digit in digits]
n = sum(squares)
if n >= 10:
return happy(n)
if n in (1, 7):
@henriquebastos
henriquebastos / mf2gnc.py
Created March 27, 2015 22:36
MyFinance to GNUCash Sample Script
# coding: utf-8
"""
Hackish Script to import MyFinance data into GNUCash
The order of things:
1) Load and Fix the MyFinance dataset
2) Separete the data into intermediary parts.
3) Define GNUCash helper function.
4) Define conversion highlevel functions.