Skip to content

Instantly share code, notes, and snippets.

View berlotto's full-sized avatar

Sérgio Berlotto Jr berlotto

View GitHub Profile
@berlotto
berlotto / restapi.py
Last active September 21, 2015 03:31
2nd version of restapi rest for the blog post.
# -*- encoding: utf-8 -*-
# RESTFul api test for blog post
# Author: Sérgio Berlotto <[email protected]>
# Site: http://blog.programadorlivre.com
# restapi.py
import falcon
try:
import ujson as json
except Exception, e:
import json
@berlotto
berlotto / restapidb.py
Last active September 21, 2015 03:05
Script para criação do banco de dados RethinkDB para testes da API
# -*- encoding: utf-8 -*-
# RESTFul api test for blog post
# Author: Sérgio Berlotto <[email protected]>
# Site: http://blog.programadorlivre.com
# restapi-db.py
TOTAL_FRASES = 1000
DBNAME = "restapi"
TABLENAME = "frases"
HOST = "localhost"
@berlotto
berlotto / restapi.py
Created September 19, 2015 04:47
RESTFul API example for blog post of http://blog.programadorlivre.com
# -*- encoding: utf-8 -*-
# RESTFul api test for blog post
# Author: Sérgio Berlotto <[email protected]>
# Site: http://blog.programadorlivre.com
# restapi.py
import falcon
try:
import ujson as json
except Exception, e:
import json
@berlotto
berlotto / gentoken.py
Created April 20, 2015 01:38
Generate tokens in Python
#http://wyattbaldwin.com/2014/01/09/generating-random-tokens-in-python/
import os
import hashlib
print hashlib.sha1(os.urandom(128)).hexdigest()
@berlotto
berlotto / deamonize.py
Created February 23, 2015 04:25
Damonize a process in Python
#-*- coding: utf-8 -*-
import os
import sys
import resource
def create_daemon(stdout, stderr, working_dir):
"""
cria um daemon
"""
@berlotto
berlotto / benchmark.sh
Created January 21, 2015 21:07
Teste performance API http request
#Faz 10000 requisições com 100 usuários em parelelo/concorrência
ab -n 10000 -c 100 http://localhost/
#http://httpd.apache.org/docs/2.0/programs/ab.html
@berlotto
berlotto / getgitdiff
Created December 3, 2014 18:21
getgitdiff - Script that archive the files from range of commits in git repo
#!/bin/bash
VERSION="0.1"
IDENT="latest"
if [ $# -lt 2 ] ; then
printf "getgidiff - created by [email protected]\n"
printf "Version:$VERSION\n"
printf "Usage:\n\tgetgitdiff {earlier-commit} {some-commit} [package-identification]\n"
exit 1;
@berlotto
berlotto / virsh.sh
Created November 18, 2014 22:31
virt-manager (libvirt / virsh) commands
#Listar as virtual machines
virsh list --all
#Iniciar máquina virtual
virsh start Guest
#Abrir o visualizador gráfico da máquina virtual
virt-viewer Guest
#DEsligar a máquina forçado
@berlotto
berlotto / move-virtio-disk.txt
Created November 11, 2014 13:40
Move VirtIO disk (virt-manager) to other path - Ubuntu
gksudo gedit /etc/libvirt/qemu/<your-disk-name>.xml
Find and change the path:
<source file='/home/connor/ubuntu-kvm/<your-disk-name>.qcow2'/>
mv ~/<your-disk-name>.qcow2 ~/VirtualMachines/.
restart the libvirt service
sudo /etc/init.d/libvirt-bin restart
@berlotto
berlotto / .bashrc
Created November 10, 2014 18:57
Meu .basrhc
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
alias ls='ls --color=auto'
PS1='[\u@\h \W]\$ '