Skip to content

Instantly share code, notes, and snippets.

View Linnk's full-sized avatar

Ignacio Benavides Linnk

View GitHub Profile
@Linnk
Linnk / midcolor.js
Created August 25, 2017 18:19
Find a middle color between two colors given.
/**
* From hex to dec.
*/
function hex(hex)
{
var result = 0
for (var i = 0; i < hex.length; i++)
{
result = result * 16 + '0123456789abcdefgh'.indexOf(hex[i].toLowerCase());
}
@Linnk
Linnk / asymmetric-crypto-backup.sh
Last active November 26, 2015 00:37
The following script generates a compressed encrypted backup given a "fileinput" with a big and pretty much random symmetric secret key; then, this unique key will be encrypted using a asymmetric public key given a "recipient".
#!/usr/bin/env bash
#
# ASYMMETRIC CRYPTO BACKUP
#
# The following script generates a compressed encrypted backup given a "fileinput"
# with a big and pretty much random symmetric secret key; then, this unique key
# will be encrypted using an asymmetric public key given a "recipient".
#
# To decrypt an asymmetric crypto backup do:
#
@Linnk
Linnk / redis_vs_file_get_contents.php
Created September 3, 2015 21:43
Simple performance test to compare Redis with PHP function file_get_contents() while constantly reading a simple “set” of data.
<?php
/**
* Checktime class
*
* This static class can make “speed” time marks secuentially. You start
* your time counter with Checktime::start() and then you can save all
* the marks you want by calling Checktime::mark('YOLO').
*/
class Checktime
{
@Linnk
Linnk / nginx_cakephp.dev.conf
Created September 2, 2015 18:44
NGINX configuration file for CakePHP projects with subdirectory
# NGINX Configuration for CakePHP projects with url subdirectories.
#
# In a classic-default-generic CakePHP project you can have as many
# independent applications as you want just by copying the app/
# directory. Apache and the .htaccess files will make the magic, but
# in a nginx server you will need a touch to your virtualhost conf.
#
# So, in order to make this:
#
# example.com/ —> ~/cakephp.dev/app/webroot/index.php
@Linnk
Linnk / nginx-add-cakephp
Created October 27, 2014 22:55
Script to add virtualhost for CakePHP 2.x
#!/bin/bash
if [ -z $1 ]
then
read -e -p "Please enter your local domain name: " DOMAIN
if [ -z $DOMAIN ]
then
echo "You must specify a local domain name (example: name.dev)."
exit 1
fi
#!/usr/bin/python
#
# DATOS INICIALES
#
import locale
distancia = 6430 # metros
altitud = 61 # metros
peso = 70 # kilogramos
<?php
/**
* DATOS INICIALES
*/
$distancia = 6430; // metros
$altitud = 61; // metros
$peso = 70; // kilogramos
$minutos_kilometro = 6.75; // Trotar a 6:40 minutos por/ kilómetro
@Linnk
Linnk / .gitignore-cakephp
Created February 14, 2013 22:19
My .gitignore for CakePHP projects.
# OS X & Windows
.DS_Store
Thumbs.db
# App content files (normally uploaded by users)
/app/webroot/files/*
!/app/webroot/files/
!/app/webroot/files/empty
# CakePHP database.php
@Linnk
Linnk / mamp-add-virtualhost.sh
Created December 17, 2012 10:30
Add a virtualhost for MAMP and local domain in /etc/hosts in one command.
#!/bin/bash
if [ -z $1 ]
then
read -e -p "Please enter your local domain name: " DOMAIN
if [ -z $DOMAIN ]
then
echo "You must specify a local domain name (example: name.dev)."
exit 1
fi
@Linnk
Linnk / isset_empty_extended.php
Last active October 13, 2015 20:08
Extending isset() and empty() functionality and the new is_recursively_set() for checking recursively an array with several keys of depth.
<?php
/**
* Usage:
*
* Instead of:
* if(isset($array['element1']) && isset($array['element2']) && isset($array['element3']) && isset($array['element4'] && isset($array['element5']))
*
* Use:
* if(is_set_in($array, 'element1', 'element2', 'element3', 'element4', 'element5'))
*