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 / sortedcoteiners-words.py
Created August 22, 2015 20:55
Gera um texto aleatório.
import sys
import random
import string
LINES, WORDS, CHARS = [int(sys.argv[x]) for x in (range(1,1+3))]
randomize = random.Random()
random_number = randomize.randint
choice_one = randomize.choice
possible_letters = string.ascii_letters
@paulohrpinheiro
paulohrpinheiro / sortedcoteiners-refactor.py
Created August 22, 2015 20:58
Primeira refatorado do programa.
import sys
def distrincha():
words = set()
plain_text = list()
codded_text= list()
# need for speed
_words_add = words.add
_codded_text_append = codded_text.append
@paulohrpinheiro
paulohrpinheiro / sortedcoteiners-cprofile1.sh
Created August 22, 2015 21:01
Saída da primeira medição.
$ python3 -m cProfile distrincha.py < test.txt
Total of words: 42740
120568 function calls in 229.015 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
102 0.002 0.000 0.004 0.000 codecs.py:297(decode)
1 0.181 0.181 229.015 229.015 distrincha.py:1()
5000 0.184 0.000 0.325 0.000 distrincha.py:12()
@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]
@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:
[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 / 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
@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
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 / 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