Skip to content

Instantly share code, notes, and snippets.

View ramalho's full-sized avatar
🚄
operador de trem

Luciano Ramalho ramalho

🚄
operador de trem
View GitHub Profile
@ramalho
ramalho / guess2.py
Last active December 22, 2015 20:49
Simple number guessing game
#!/usr/bin/env python3
# guess.py: a simple number guessing game
from random import randint
print('Hello, please type your name:')
name = input()
print('Hi, ', name, '!', sep='')
print("I will select a number from 1 to what number? You can choose, dear user.")
@ramalho
ramalho / Display3digits.ino
Last active December 23, 2015 02:28
Controle de um display de 3 dígitos de 7 segmentos, anodo comum, modelo CPS03631BR.
/*
Display3digits
Controle de um display de 7 segmentos com 3 digitos, anodo comum.
*/
int pinos_digitos[] = {4, 3, 2};
int NUM_DIGITOS = 3;
// segmentos datasheet A B C D E F G
int pinos_segmentos[] = {8, 6, 10, 12, 13, 7, 9};
@ramalho
ramalho / cleanup_element_list.py
Created September 25, 2013 20:29
Cleans up the list of chemical elements from the editable source of the Wikipedia article: http://en.wikipedia.org/wiki/List_of_elements, generating just a list of atomic number and element names
file = open('List_of_Elements.wiki', encoding='utf-8')
text = file.read()
# print(len(text), 'chars in the text')
lines = text.split('\n') # split by newlines
# print(len(lines), 'lines in the text')
for line in lines:
cells = line.split('||')
if len(cells) < 3 or not cells[2].startswith(' [['):
>>> class Coisa:
... __slots__ = ('tamanho', 'sabor')
...
>>> c = Coisa()
>>> c.tamanho
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: tamanho
>>> c.tamanho = 'G'
>>> c.tamanho
@ramalho
ramalho / tombola.py
Last active August 29, 2015 13:58
Solução do Theo Alves
from random import shuffle
class Tombola(object):
'''Sorteia itens sem repetir'''
def carregar(self, seq):
self.itens = list(seq)
def misturar(self, misturadora=None):
if misturadora: # LR: isso funciona mas é melhor sempre testar explicitamente argumento is None
@ramalho
ramalho / tombola.py
Created April 8, 2014 23:28
Solução do Daniel Bastos
from random import shuffle
class Tombola(object):
'''Sorteia itens sem repetir'''
def carregar(self, seq):
self.itens = list(seq)
def misturar(self, pairswap=None):
pairswap(self.itens) if pairswap else shuffle(self.itens) # LR: funciona mas é melhor testar explicitamente arg is None
@ramalho
ramalho / tombola.py
Last active August 29, 2015 13:58
Solução do Leonardo Couy
from random import shuffle
class Tombola(object):
from inplace import pairswap # LR: esse import é desnecessário, e este é um lugar estranho para fazer imports
'''Sorteia itens sem repetir'''
def carregar(self, seq):
self.itens = list(seq)
@ramalho
ramalho / gist:10420071
Last active August 29, 2015 13:58
Open issue with Dropbox support
I am a happy paying customer of Dropbox, but the news that you have
appointed Condoleezza Rice to your board is extremely disturbing and
I will ditch your service if this decision is not reversed.
Dr. Rice defends warrantless wiretapping. How am I supposed to trust
Dropbox with my personal files if your management cannot understand
the implications of this appointment? And if they do understand
-- which may well be the case -- then I am very sorry I ever shared
any of my files with you.
@ramalho
ramalho / statevalue.py
Last active August 29, 2015 14:00
Value object for Pingo.io pin states
class State(object):
def __init__(self, value):
self.value = value
def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.value)
def __str__(self):
return state.value
@ramalho
ramalho / steps.txt
Last active August 29, 2015 14:01
Turtle graphics on the Raspberry Pi
Double-click LXTerminal and type:
$ idle -n
(the IDLE window appears)
>>> from turtle import *
>>> fd(100)
(a window with a line appears)
How to draw a square:
>>> fd(100)
>>> rt(90)
>>> fd(100)