Skip to content

Instantly share code, notes, and snippets.

@rafaelhdr
rafaelhdr / removeItem.js
Created February 23, 2013 18:30
jQuery remove item function
function removeItem(item, lista) {
lista = jQuery.grep(lista, function(value) {
return value != item;
});
return lista;
}
@rafaelhdr
rafaelhdr / gist:6058469
Created July 22, 2013 23:00
ZF2 Mail Service It is possible to embed a layout and template for the e-mail
<?php
/*
* Original: https://gist.github.com/devmatheus/38cd250c3bb46f0ad2c8
*
* Changes:
* - It is not necessary define page on __construct
* - Set layout for embed template
*
* Problem:
@rafaelhdr
rafaelhdr / get_brcep.py
Last active August 29, 2015 14:08
Get Brazilizian Postal Code (CEP)
# Added on http://www.rafaelhdr.com.br/blog/python/pegar-cep-do-site-dos-correios-em-python at 25/10/2014
#
# This is a simple function to get data at brazilian correios
# It searches at http://www.buscacep.correios.com.br/ and return as a dict the
# information retrieved.
#
# Before use it, you need install the following libs:
# pip install beautifulsoup4
# pip install requests
@rafaelhdr
rafaelhdr / fileToArray2D.js
Created May 22, 2015 13:22
Read file and convert to Array X Array
var fs = require('fs');
var outputArray = [];
var content = fs.readFileSync('map.txt').toString('utf8');
var lines = content.split('\n');
lines.forEach(function(line){
var cells = line.split(' ');
var newArray = [];
cells.forEach(function(cell){
newArray.push(parseInt(cell));
@rafaelhdr
rafaelhdr / amazon-signed-url.py
Last active August 29, 2015 14:22
Generate signed URL for Amazon Associates
from time import gmtime, strftime
import urllib2
import hmac
import hashlib
import base64
"""
Code to generate signed URL for Amazon Associate
I hope it is simple to understand
# Install pip on Ubuntu
# Source: http://www.saltycrane.com/blog/2010/02/how-install-pip-ubuntu/
sudo apt-get install python-pip python-dev build-essential
sudo pip install --upgrade pip
sudo pip install --upgrade virtualenv
# Install Cassandra on Ubuntu
# Source: https://www.digitalocean.com/community/tutorials/how-to-install-cassandra-and-run-a-single-node-cluster-on-ubuntu-14-04
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-set-default
echo "deb http://www.apache.org/dist/cassandra/debian 22x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
echo "deb-src http://www.apache.org/dist/cassandra/debian 22x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
gpg --keyserver pgp.mit.edu --recv-keys F758CE318D77295D
@rafaelhdr
rafaelhdr / Python urllib2.urlopen like Chrome
Last active October 21, 2019 17:30
Make a urlopen on Python with headers like Chrome
import urllib2
link = "http://example.com"
r = urllib2.Request(url=link)
# r.add_header('Cookie', 'sessionid=13cxrt4uytfc6ijvgeoflmb3u9jmjuhil; csrftoken=jdEKPN8iL62hdaq1hmMuID9DMALiiDIq')
r.add_header('Upgrade-Insecure-Requests', '1')
r.add_header('Accept-Encoding', 'gzip, deflate, sdch, br')
r.add_header('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36')
r.add_header('Connection', 'keep-alive')
r.add_header('Cache-Control', 'max-age=0')
@rafaelhdr
rafaelhdr / cherrypyserver.py
Last active February 7, 2024 19:04
Cherrypy server with Flask application
# Reason for choosing cherrypy
# https://blog.appdynamics.com/engineering/a-performance-analysis-of-python-wsgi-servers-part-2/
#
# Flask application based on Quickstart
# http://flask.pocoo.org/docs/0.12/quickstart/
#
# CherryPy documentation for this
# http://docs.cherrypy.org/en/latest/deploy.html#wsgi-servers
# http://docs.cherrypy.org/en/latest/advanced.html#host-a-foreign-wsgi-application-in-cherrypy
# Install: pip install cherrypy
@rafaelhdr
rafaelhdr / longwrite.sh
Created July 4, 2017 14:38
Shell long write to file
#!/bin/sh
#
# Command examples:
# time ./write.sh
# time ./write.sh 1000
#
# This will print time taken (default test, max=100000)
# real 0m1.258s
# user 0m0.816s
# sys 0m0.438s