Skip to content

Instantly share code, notes, and snippets.

View juanparati's full-sized avatar

Juan Lago juanparati

  • Aarhus (Denmark)
View GitHub Profile
@juanparati
juanparati / gist:e171e04e84b086a2e22f
Created August 14, 2014 09:22
getInstaceOf from the same class, so we can retrieve the var name thas contains the object
/**
* Get instance names of an object
*
* Returns instances
*/
function getInstancesOf()
{
var instances = [];
for(var v in window) {
var swipeFunc = function() {
this._swipe_direction = ['left','right'];
this._y_diff = -1;
this._x_diff = -1;
this._x_min_length = 30;
this.touches = {
'touchstart': {'entered':false,'x':-1, 'y':-1},
'touchmove' : {'entered':false,'x':-1, 'y':-1},
'touchend' : false,
'direction' : 'undetermined'
function unicode2utf8($c)
{
$output="";
if($c < 0x80)
{
return chr($c);
}
else if($c < 0x800)
{
@juanparati
juanparati / colors.php
Last active June 6, 2017 07:44
Color palette generator
/**
* Class Colors.
* Pallete Generator Helper.
*/
class Colors implements \Iterator, \ArrayAccess
{
const COL_MIN_AVG = 64;
const COL_MAX_AVG = 192;
@juanparati
juanparati / gist:ceb20f45d81f0a2c9a1b97bd0597d07f
Last active July 4, 2017 10:46
Laravel AES-256-CBC decryption implemented directly on MYSQL
-- Direct SELECT version
SELECT
FROM_BASE64(JSON_UNQUOTE(JSON_EXTRACT(CONVERT(FROM_BASE64(email) USING utf8), '$.iv'))) AS iv,
JSON_UNQUOTE(JSON_EXTRACT(CONVERT(FROM_BASE64(email) USING utf8), '$.value')) AS value,
FROM_BASE64('mysecretkey') AS pkey,
AES_DECRYPT(FROM_BASE64(JSON_UNQUOTE(JSON_EXTRACT(CONVERT(FROM_BASE64(email) USING utf8), '$.value'))), FROM_BASE64('mysecretkey'), FROM_BASE64(JSON_UNQUOTE(JSON_EXTRACT(CONVERT(FROM_BASE64(email) USING utf8), '$.iv')))) AS decrypted
-- Function version
CREATE FUNCTION `LARAVEL_DECRYPT`(
@juanparati
juanparati / mysql_laravel_decrypt.sql
Created October 12, 2017 11:46
Laravel decrypt implementation as MySQL function
CREATE DEFINER=`%`@`%` FUNCTION `LARAVEL_DECRYPT`(
`encstr` TEXT,
`raw_key` VARCHAR(255)
)
RETURNS varchar(255) CHARSET utf8 COLLATE utf8_unicode_ci
LANGUAGE SQL
DETERMINISTIC
READS SQL DATA
SQL SECURITY DEFINER
@juanparati
juanparati / simpleupload.vue
Created October 20, 2017 13:32
Vue 2.x Simple Upload component
// Simple upload from http://laravel-tricks.com/tricks/vuejs-simple-upload
<template>
<div>
<small>Change/Upload</small>
<input type="file" @change="onFileChange">
<button class="btn btn-success btn-xs" @click="upload">Upload</button>
</div>
</template>
@juanparati
juanparati / memory_size_convert.php
Last active January 16, 2018 22:08
Convert human readable memory size Like a Pro™️
<?php
function convertMemorySize($strval, string $to_unit = 'b')
{
$strval = strtolower(str_replace(' ', '', $strval));
$val = floatval($strval);
$to_unit = strtolower(trim($to_unit))[0];
$from_unit = str_replace($val, '', $strval);
$from_unit = empty($from_unit) ? 'b' : trim($from_unit)[0];
$units = 'kmgtph'; // (k)ilobyte, (m)egabyte, (g)igabyte and so on...
@juanparati
juanparati / csvreader.php
Created February 19, 2018 10:54
CSV reader that support field maps
<?php
/**
* Class Model_CSVReader
*
* Parse and read CSV files as a stream keeping a low memory footprint
*/
class Model_CSVReader
{
location /foo/ {
proxy_pass https://site.com/;
proxy_redirect off;
proxy_set_header Host site.com;
proxy_ssl_session_reuse off;
proxy_ssl_server_name on;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Accept-Encoding "";
sub_filter "https://site.com" "https://reflected.to/foo";