This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* @param string $str The string to compute number of bytes | |
* | |
* @return The length in bytes of the given string. | |
*/ | |
function getSizeStringBytes($str){ | |
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 443; | |
server_name api.project_name.pe; | |
ssl on; | |
ssl_certificate /etc/nginx/ssl/server.crt; | |
ssl_certificate_key /etc/nginx/ssl/server.key; | |
access_log /var/log/nginx/api.project_name.access.log; | |
error_log /var/log/nginx/api.project_name.error.log; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Newbie programmer | |
def factorial(x): | |
if x == 0: | |
return 1 | |
else: | |
return x * factorial(x - 1) | |
print factorial(6) | |
#First year programmer, studied Pascal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#How to convert yyyy-MM-ddTHH:mm:ssZ to yyyy-MM-dd HH:mm:ss | |
date_default_timezone_set("America/Lima"); | |
echo date('Y-m-d H:i:s', strtotime('2012-09-10T10:30:00Z'));//date format UTC +00.00 | |
#convert date format UTC to timezone America/Lima | |
date_default_timezone_set("UTC");//server configured UTC | |
$date = strtotime(date('Y-m-d H:i:s')); | |
echo(date_default_timezone_get() . "<br />");//output: UTC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Generate GUID v4 | |
public static function generateGuidv4() | |
{ | |
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', | |
// 32 bits for "time_low" | |
mt_rand(0, 0xffff), mt_rand(0, 0xffff), | |
// 16 bits for "time_mid" | |
mt_rand(0, 0xffff), | |
// 16 bits for "time_hi_and_version", | |
// four most significant bits holds version number 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//declaramos la funcion : randomString | |
function randomString($length, $type = '') { | |
// Seleccionamos el tipo de caracteres que deseas que devuelva el string | |
switch ($type) { | |
case 'num': | |
// Solo cuando deseas que devuelva numeros. | |
$salt = '1234567890'; | |
break; | |
case 'lower': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to generate your dhparam.pem file, run in the terminal | |
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// apache_request_headers replicement for nginx | |
if (!function_exists('apache_request_headers')) { | |
function apache_request_headers() { | |
foreach($_SERVER as $key=>$value) { | |
if (substr($key,0,5)=="HTTP_") { | |
$key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5))))); | |
$out[$key]=$value; | |
}else{ | |
$out[$key]=$value; | |
} |