Skip to content

Instantly share code, notes, and snippets.

View gchacaltana's full-sized avatar
🎯
Focusing

Gonzalo Chacaltana gchacaltana

🎯
Focusing
  • Perú
View GitHub Profile
@gchacaltana
gchacaltana / getSizeStringBytes.php
Last active January 4, 2016 04:09
Count the number of bytes of a given string. Input string is expected to be ASCII or UTF-8 encoded. Warning: the function doesn't return the number of chars in the string, but the number of bytes.
<?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
@gchacaltana
gchacaltana / configuration nginx file with php-fpm
Last active January 3, 2016 14:19
configuration nginx file with php-fpm
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;
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
@gchacaltana
gchacaltana / date_default_timezone_set.php
Last active December 20, 2021 08:15
Use datetime format, date_default_timezone_set php
#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
@gchacaltana
gchacaltana / generateGuidv4.php
Last active January 2, 2016 12:08
Get GUID v4
//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
@gchacaltana
gchacaltana / randomString.php
Last active January 2, 2016 12:09
Get random string
<?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':
@plentz
plentz / nginx.conf
Last active April 24, 2024 11:15
Best nginx configuration for improved security(and performance)
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
// 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;
}