Skip to content

Instantly share code, notes, and snippets.

View alexandre's full-sized avatar
🎯
Focusing

Alexandre Souza alexandre

🎯
Focusing
View GitHub Profile
@alexandre
alexandre / dec2bin.py
Last active August 29, 2015 14:03
converter um valor em decimal para binário
conv = []
def dec2bin(num):
(num/2 > 0 and (dec2bin(int(num/2)), conv.append(num%2)))
dec2bin(int(input('Decimal: ')))
print(''.join(map(str, conv)))
@alexandre
alexandre / exprbool.py
Created July 12, 2014 20:36
exemplo de substituição de instruções de controle (if, else) por expressões booleanas.
# Versão utilizando if/else
if x == 10:
fun_add(x)
else:
fun_del(x)
# utilizando expressões booleanas apenas...
(x == 10 and fun_add(x)) or (fun_del(x))
@alexandre
alexandre / avl_if_bool.py
Last active August 29, 2015 14:03
avaliando o tempo de execução entre if e uma expressão booleana
# lista para guardar o processo de conversão
conv = []
def dec2bin(num):
(num / 2 > 0 and (dec2bin(int(num/2)), conv.append(num % 2)))
def dec2bin_if(num):
if num/2 > 0:
@alexandre
alexandre / fibseq.py
Created July 15, 2014 02:44
brincando com fibseq...
seq = [0,1]
def fibseq(maxnum, item=1):
(item <= maxnum and
(seq.append(item), fibseq(maxnum, item + seq[-2])))
fibseq(input('Max. Element.: '))
print(seq)
@alexandre
alexandre / multiples_3_5.py
Created July 26, 2014 21:03
the sum of multiples of 3 and 5 below 1000.
'''
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.
https://projecteuler.net/problem=1
'''
# is a multiple of 5?
# list(str(N))[-1] in ('0','5') => should return True if N is a multiple of 5.
# is a multiple of 3?
@alexandre
alexandre / unpacking_example.py
Created August 7, 2014 13:00
yet another code example...
'''
unpacking nested list
'''
year = datetime.date.today().year
month = datetime.date.today().month
# My nested list
cal = calendar.Calendar(6).monthdatescalendar(year, month)
@alexandre
alexandre / restful_python_ops.md
Last active June 6, 2022 19:08
Algumas opções em Python para criar APIs Restful
@alexandre
alexandre / multilib_slack_14-1.sh
Last active August 29, 2015 14:06
apenas reunindo os comandos especificados pelo Alien Bob para multilib...
SLACKVER=14.1
mkdir multilib
cd multilib
lftp -c "open http://taper.alienbase.nl/mirrors/people/alien/multilib/ ; mirror -c -e ${SLACKVER}"
cd ${SLACKVER}
upgradepkg --reinstall --install-new *.t?z
upgradepkg --install-new slackware64-compat32/*-compat32/*.t?z
@alexandre
alexandre / bashrc.sh
Created September 16, 2014 09:17
a piece of my .bashrc
export PATH=$PATH:~/bin/:~/bin/node/bin/
alias dev='cd $HOME/Devel'
alias ls='ls --color'
alias ll='ls -l'
alias ltr='ls -ltr'
alias la='ls -a'
alias tibia='cd $HOME/Games/Tibia;./Tibia'
alias dwn='cd $HOME/Downloads'
alias git='hub'
@alexandre
alexandre / sieve-of-eratosthenes.py
Last active August 29, 2015 14:07
Sieve of Eratosthenes
#!/usr/bin/python3
from math import sqrt
def sieve(limit, limit_list=[]):
'''
Sieve of Eratosthenes - The sieve of Eratosthenes is one of the most
efficient ways to find all of the smaller primes (below 10 million or so).
>>> sieve(30)
[2, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]