Skip to content

Instantly share code, notes, and snippets.

View gnrfan's full-sized avatar

Antonio Ognio gnrfan

View GitHub Profile
@gnrfan
gnrfan / nginx_timeout.html
Created March 27, 2014 00:41
Example of Nginx's timeout page
<html>
<head><title>504 Gateway Time-out</title></head>
<body bgcolor="white">
<center><h1>504 Gateway Time-out</h1></center>
<hr><center>nginx/1.4.4</center>
</body>
</html>
@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 / timeout.html
Last active August 29, 2015 13:57
Example of an Nginx time page
<HTML><HEAD>
<TITLE>Network Error</TITLE>
</HEAD>
<BODY>
<FONT face="Helvetica">
<big><strong></strong></big><BR>
</FONT>
<blockquote>
<TABLE border=0 cellPadding=1 width="80%">
<TR><TD>
@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"
}
@gnrfan
gnrfan / ws_callback_redirector.php
Created March 27, 2013 00:36
You can upload this simple PHP script to a public server on the Internet and receive there callbacks from webservices like Facebook's Graph API and have it redirect the request to localhost or any other non-public URI.
<?php
define('APP_PREFIX', '/path/to/subfolder/if/any/');
define('REDIRECT_TARGET', 'http://localhost:8000/');
if (array_key_exists('redirect_target', $_REQUEST)) {
$redirect_base = $_REQUEST['redirect_target'];
} else {
$redirect_base = REDIRECT_TARGET;
}
@gnrfan
gnrfan / README.md
Last active December 15, 2015 07:49
A gevent demo making DNS queries both in a blocking and non-blocking way.

gevent demo

Non-blocking IO using co-routines in Python.

Installing gevent under OSX using MacPorts

sudo port install libevent

virtualenv --no-site-packages env