Skip to content

Instantly share code, notes, and snippets.

View gnrfan's full-sized avatar

Antonio Ognio gnrfan

View GitHub Profile
@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 / goroutines.py
Created November 25, 2015 16:15
Playing with goroutines in Python with Goless
#!/usr/env/bin python
# -*- coding: utf8 -*-
import random
import requests
import goless
MIN = 10000
MAX = 99999
@gnrfan
gnrfan / php-get-redirector.php
Created November 25, 2015 00:16
Redirects all GET query parameters to given URI.
<?php
define("BASE_URL", 'http://localhost/index.php');
if (array_key_exists('QUERY_STRING', $_SERVER) && strlen(trim($_SERVER['QUERY_STRING']))>0) {
$url = sprintf("%s?%s", BASE_URL, $_SERVER['QUERY_STRING']);
} else {
$url = BASE_URL;
}
header('Status: 301 Moved Permanently', false, 301);
@gnrfan
gnrfan / kylo.py
Last active November 11, 2015 19:49
KYLO (REN) AS CIPHERTEXT WITH KEY "SKYWALKER" USING THE VIGENERE CYPHER (THANK YOU JJ ABRAMS)
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""
According to Wikipedia [1], the Vigènere cipher is a method of
encrypting alphabetic text by using a series of different Caesar
ciphers based on the letters of a keyword. It is a simple form
of polyalphabetic substitution.
An eastern egg based on cryptography is something you could expect [2]
from JJ Abrahams for the upcoming "Starwars: The Force Awakens" movie.
@gnrfan
gnrfan / custom_status_code.php
Created September 16, 2015 00:23
Custom Status Code in PHP
<?php
// Works in PHP 5.3
header("Content-Type: application/json", true, 500);
$doc = array(
"status" => "error",
"message" => "El correo no se pudo enviar"
);
echo json_encode($doc, JSON_PRETTY_PRINT);
?>
@gnrfan
gnrfan / install-git-completion.sh
Last active September 10, 2015 20:44 — forked from johngibb/install-git-completion.sh
Mac OS X - Install Git Completion
URL="https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash"
PROFILE="$HOME/.bash_profile"
echo "Downloading git-completion..."
if ! curl "$URL" --silent --output "$HOME/.git-completion.bash"; then
echo "ERROR: Couldn't download completion script. Make sure you have a working internet connection." && exit 1
fi
@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
a = 10
b = 20
print a + b
@gnrfan
gnrfan / quicksort.py
Created September 20, 2014 18:58
Quicksort en Python
def quicksort(array, debug=False):
if array:
left = quicksort([x for x in array[1:] if x < array[0]])
right = quicksort([x for x in array[1:] if x >= array[0]])
if debug:
print "left", left
print "right", right
print "array[:1]", array[:1]
return left + array[:1] + right
return []
@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)