Skip to content

Instantly share code, notes, and snippets.

View maurobaraldi's full-sized avatar

Mauro Navarro Baraldi maurobaraldi

View GitHub Profile
@maurobaraldi
maurobaraldi / nina.zsh-theme
Created January 27, 2016 17:08 — forked from nnja/nina.zsh-theme
My zshell prompt theme, a bastardization of robbyrussel & kolo themes
autoload -Uz vcs_info
zstyle ':vcs_info:*' stagedstr '%F{green}●'
zstyle ':vcs_info:*' unstagedstr '%F{yellow}●'
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{11}%r'
zstyle ':vcs_info:*' enable git svn
theme_precmd () {
if [[ -z $(git ls-files --other --exclude-standard 2> /dev/null) ]] {
zstyle ':vcs_info:*' formats '%c%u%B%F{green} '
@maurobaraldi
maurobaraldi / echo.py
Created February 1, 2016 13:11 — forked from benburry/echo.py
Python 2 - mock & unittest example for Popen
from subprocess import Popen, PIPE
def shell_out(command):
return Popen(command.split(' '), stdout=PIPE,stderr=PIPE).communicate()[0].strip('\n').split('\n')
def main():
return shell_out('echo one\ntwo\nthree\n')
@maurobaraldi
maurobaraldi / bbtree.py
Created February 3, 2016 22:23 — forked from olomix/bbtree.py
Balanced binary tree in Python
#!/usr/bin/env python2.7
import random
import subprocess
class Node(object):
def __init__(self, key, value):
self.key = key
self.value = value
@maurobaraldi
maurobaraldi / life.py
Created February 20, 2016 10:53 — forked from jsbueno/life.py
Game of Life (Python + Pygame)
# coding: utf-8
import pygame
import random
rr = random.randrange
SIZE = 800, 600
cellsize = 20
try:
  1. Plain Strings (207): foo
  2. Anchors (208): k$
  3. Ranges (202): ^[a-f]*$
  4. Backrefs (201): (...).*\1
  5. Abba (169): ^(.(?!(ll|ss|mm|rr|tt|ff|cc|bb)))*$|^n|ef
  6. A man, a plan (177): ^(.)[^p].*\1$
  7. Prime (286): ^(?!(..+)\1+$)
  8. Four (199): (.)(.\1){3}
  9. Order (198): ^[^o].....?$
  10. Triples (507): (^39|^44)|(^([0369]|([147][0369]*[258])|(([258]|[147][0369]*[147])([0369]*|[258][0369]*[147])([147]|[258][0369]*[258])))*$)
@maurobaraldi
maurobaraldi / senado.py
Last active March 28, 2016 18:01
Download lista de senadores em exercício no ano do site do Senado
#!/usr/bin/env python3
"""
Para esse script é necessaŕio as bibliotecas requests e xmltodict
pip install requests xmltodict
"""
import requests
import xmltodict
@maurobaraldi
maurobaraldi / test_temp_directory.py
Created April 2, 2016 11:22 — forked from odyniec/test_temp_directory.py
An example Python unittest test case that creates a temporary directory before a test is run and removes it when it's done.
import shutil, tempfile
from os import path
import unittest
class TestExample(unittest.TestCase):
def setUp(self):
# Create a temporary directory
self.test_dir = tempfile.mkdtemp()
def tearDown(self):
@maurobaraldi
maurobaraldi / encrypt_recipe.txt
Created April 15, 2016 12:42
Encrypt tar.gz file on create
To encrypt:
# Generate public and private keys
openssl genrsa -out maurobaraldi.pem 2048
openssl rsa -in key.pem -out key-public.pem -outform PEM -pubout
# Generate random passphrase and save in file
echo -n "`python -c "import uuid; print uuid.uuid4().hex"`" > key.txt
# Encrypt file with passphase
@maurobaraldi
maurobaraldi / staircase.py
Last active April 27, 2016 18:29
hackerhank staircase solution (worse)
n = int(input())+1
for i in range(1,n):
print(''.ljust(n-i-1)+('#'*i))
@maurobaraldi
maurobaraldi / response_true.py
Created May 6, 2016 12:50
Simple HTTP response handler
#!/usr/bin/env python3
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write('{"repsonse": "true"}')
return