Skip to content

Instantly share code, notes, and snippets.

View gnrfan's full-sized avatar

Antonio Ognio gnrfan

View GitHub Profile
@gnrfan
gnrfan / timeout.php
Created March 27, 2014 00:33
A script that takes the number of seconds it must wait to render a simple text message. Useful for testing web server timeout configurations.
<?php
$seconds = 60 * 2; // nginx default is 60 seconds
set_time_limit (60*60*24); // PHP keeps waiting for a whole day!
if (array_key_exists('s', $_REQUEST)) {
$seconds = intval($_REQUEST['s']);
}
@gnrfan
gnrfan / models.py
Created September 10, 2012 16:12
An example of chained foreign keys using django-smart-selects from PyPi.
from django.conf import settings
from django.contrib.gis.db import models
from smart_selects.db_fields import ChainedForeignKey
from common.models import AuditableModel
from ubigeos import strings
class Department(models.Model):
"""
A peruvian department.
@gnrfan
gnrfan / base62uuid.py
Created June 2, 2014 03:14
Base62 UUID based on uuid.uuid4() and a numbers, lowercase, uppercase alphabet.
import uuid
import hashlib
import baseconv
ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
def base62uuid():
converter = baseconv.BaseConverter(ALPHABET)
uuid4_as_hex = str(uuid.uuid4()).replace('-','')
uuid4_as_int = int(uuid4_as_hex, 16)
@gnrfan
gnrfan / es_ubuntu_14.04
Created July 10, 2015 17:08
Install ElasticSearch 1.6.0 on Ubuntu 14.04
# Install PPA tool
echo "Installing software for working with PPA packages..."
sudo apt-get install -y python-software-properties software-properties-common
# Install Oracle Java 8
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
echo "Installing ORACLE Java8..."
sudo apt-get install -y oracle-java8-installer
@gnrfan
gnrfan / update
Created March 3, 2016 22:31
Git hook for deployment in production and staging environments
BRANCH="$1"
if [ $BRANCH == "refs/heads/master" ]; then
echo "Deploying changes to production environment."
GIT_WORK_TREE=/Users/gnrfan/code/git-tests/production-environment git checkout -f
elif [ $BRANCH == "refs/heads/staging" ]; then
echo "Deploying changes to staging environment."
GIT_WORK_TREE=/Users/gnrfan/code/git-tests/staging-environment git checkout -f
fi
@gnrfan
gnrfan / applicant_name_crawler.py
Last active December 26, 2015 09:28
Grabs unique names from the San Marcos University (Peru) applicant listings.
import urllib2
import re
from collections import Counter
url = 'http://profe-alexz.blogspot.com/2013/09/resultados-examen-admision-san-marcos-2014-i.html'
NAME_COUNT_LIMIT = 1000000
def grab_page(url):
website = urllib2.urlopen(url)
return website.read()
@gnrfan
gnrfan / sample_django_wsgi.py
Created September 23, 2013 20:48
An example of a Django 1.5 wsgi.py file running under VirtualEnv.
"""
WSGI config for renovaciones project.
This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.
Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
@gnrfan
gnrfan / square_root_newton.go
Created September 22, 2013 04:14
Square root calculation in Go using Newton's iteration algorithm.
package main
import (
"fmt"
"math"
)
func Average(x, y float64) float64 {
return (x + y) / 2.0
}
@gnrfan
gnrfan / junar_munilima_demo.py
Created September 17, 2013 21:00
Un ejemplo sencillo de como acceder de forma programática, usando Python. a los datos de la Municipalidad de Lima. Más información en http://lima.datosabiertos.pe/
#!/usr/bin/env python
#
# This is a demo script on how to use the Junar API provided by http://lima.datosabiertos.pe/
# More info un Junar APIs here: http://wiki.junar.com/index.php/API
#
# Steps to install the Junar API client in a virtual environment:
#
# virtualenv --no-site-packages env
# source env/bin/activate
# pip install git+git://github.com/Junar/junar-api-python-client.git
@gnrfan
gnrfan / fsjumps.sh
Created August 19, 2013 08:18
Easily remember a directory and jump back to it from anywhere in the UNIX filesystem. This version is optimized for Mac OS X. Source: http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
### Filesystem jumping
### Usage: Just add a line to your ~/.bashrc or ~/.bash_profile with "source /path/to/fsjumps.sh".
export MARKPATH=$HOME/.marks
function jump {
cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
}