Skip to content

Instantly share code, notes, and snippets.

View paulohrpinheiro's full-sized avatar
🏠
Working from home

Paulo Henrique Rodrigues Pinheiro paulohrpinheiro

🏠
Working from home
View GitHub Profile
@paulohrpinheiro
paulohrpinheiro / 000_novice-solved.py
Last active February 15, 2016 00:41
Solução da primeira lista de exercícios do Test Driven Learning - 000_novice-python3
"""
Test Driven Learning Project.
Desenvolva TDD e programação com TDD e programação!
Módulo novice.
The MIT License (MIT)
Copyright (c) 2016 Paulo Henrique Rodrigues Pinheiro <paulo@sysincloud.it>
Permission is hereby granted, free of charge, to any person obtaining a copy
@paulohrpinheiro
paulohrpinheiro / rand_one_second.py
Last active February 6, 2016 01:53
Quantos números pseuso-aleatórios posso gerar em um segundo?
import random
import signal, os
# Xupinskado de https://docs.python.org/2/library/signal.html#signal.setitimer
def handler(signum, frame):
print('Acabando....', signum)
raise NameError("Acaboooooouuuuuuuuu!!!!")
# Set the signal handler and a 1-second alarm
@paulohrpinheiro
paulohrpinheiro / ex_4_cap_3.hs
Last active December 29, 2015 11:44
Exercício 4 do capítulo 3 de Haskell: uma abordagem Prática, Cláudio Cesar de Sá & Márcio Ferreira da Silva
--ep4
fatorial x | (x==1) = 1
| otherwise = x * fatorial (x-1)
e_x x n | (n==0) = 1
| otherwise = ( (x**n) / fatorial n ) + (e_x x (n-1) )
delta x = delta' x 0
where delta' x n | (exp_x - (e_x x n)) < 0.001 = 0
| otherwise = 1 + delta' x (n+1)
@paulohrpinheiro
paulohrpinheiro / gist:fc2438629ccac5da804b
Created December 10, 2015 20:08
Tirando as quebras de linha
>>> a = "<h1>Titulo</h1>\n<br><p>paragrafo</p>\n<br>\n"
>>> print a
<h1>Titulo</h1>
<br><p>paragrafo</p>
<br>
>>> b = a.replace('\n','')
>>> b.replace('\r','')
'<h1>Titulo</h1><br><p>paragrafo</p><br>'
>>> print b
import unittest
import inspect
import importlib
import app_config # my config for this application
class RequirementsTestCase(unittest.TestCase):
def test_requirement_exist(self):
@paulohrpinheiro
paulohrpinheiro / mysql-parallel-restore.sh
Last active November 1, 2015 17:15
MySQL Parallel Restore
#!/usr/bin/env bash
DB="DATABASE_NAME"
DB_AUTH="-uroot -ptoor"
DB_BACKUP_DIR="/some/location"
DB_GLOB_FOR_BACKUP="dump-*.gz"
MAX_JOBS=30
cd $DB_BACKUP_DIR || exit
@paulohrpinheiro
paulohrpinheiro / perlbrew_run.sh
Last active September 9, 2015 17:46
Install a new perl from perlbrew
[data]$ perlbrew available
perl-5.22.0
perl-5.20.2
perl-5.18.4
perl-5.16.3
perl-5.14.4
perl-5.12.5
perl-5.10.1
perl-5.8.9
perl-5.6.2
[data]$ echo 'source $OPENSHIFT_DATA_DIR/perlbrew/etc/bashrc' >> .bash_profile
[data]$ echo 'alias perlbrew=$PERLBREW_ROOT/bin/perlbrew' >> .bash_profile
[data]$ echo 'alias patchperl=$PERLBREW_ROOT/bin/patchperl' >> .bash_profile
[data]$ cat .bash_profile
# Warning: Be careful with modifications to this file,
# Your changes may cause your application to fail.
source $OPENSHIFT_DATA_DIR/perlbrew/etc/bashrc
alias perlbrew=$PERLBREW_ROOT/bin/perlbrew
alias patchperl=$PERLBREW_ROOT/bin/patchperl
@paulohrpinheiro
paulohrpinheiro / start.sh
Last active September 9, 2015 15:29
Primeiros comandos ao entrar no openshift
phrp@paulaum:~$ rhc ssh diy
Connecting to 55e5156a7628e1d752000132@diy-sysincloudit.rhcloud.com ...
Enter passphrase for key '/home/phrp/.ssh/id_rsa':
*********************************************************************
You are accessing a service that is for use only by authorized users.
If you do not have authorization, discontinue use at once.
Any use of the services is subject to the applicable terms of the
agreement which can be found at:
@paulohrpinheiro
paulohrpinheiro / sortedcoteiners-final.py
Created August 22, 2015 21:03
Programa final com o sortedcontainers.
import sys
import sortedcontainers
words = sortedcontainers.SortedSet()
plain_text = list()
codded_text= list()
# read content
plain_text = [l.strip().split() for l in sys.stdin]