Skip to content

Instantly share code, notes, and snippets.

Lito eusonlito

Block or report user

Report or block eusonlito

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@eusonlito
eusonlito / json-pretty
Last active Jan 17, 2020
Prettify json using python or jq if available
View json-pretty
#!/bin/bash
# Install as /usr/local/bin/json-pretty with +xr permissions
#
# Usage:
#
# * `json-pretty file.json` generate a prettified file-pretty.json file
# * `json-pretty file.json new-file.json` generate a prettified new-file.json file
if [ "$1" == "" ] || [ ! -f "$1" ]; then
View mysql-bulk-gzip-import.sh
#!/bin/bash
PREFIX='20200107\-'
SUFIX='\.sql\.gz'
for file in *.gz; do
db=$(echo $file | sed 's/^'$PREFIX'//; s/'$SUFIX'$//')
echo -e "\n\nImporting file $file into $db\n"
@eusonlito
eusonlito / git-update-all.sh
Last active Jan 13, 2020
Update all git branches from remote on all repositories
View git-update-all.sh
#!/bin/bash
HERE=$(pwd)
for env in api web; do
echo -e "\nUpdating $env\n"
cd $HERE/$env
CURRENT=$(git rev-parse --abbrev-ref HEAD)
@eusonlito
eusonlito / README.md
Last active Oct 8, 2019
Laravel Auth and Session without database. Using a remote API as Auth and Data provider.
View README.md

This is an example of a web that uses a remote API as a database wrapper.

The remote API is stateless and the web uses cookies to maintain session persistence.

The API authentication endpoint returns a TOKEN that allows the web to make each request to the API with the user authentication header.


Este es un ejemplo de web que usa una API remota como wrapper de base de datos.

@eusonlito
eusonlito / array_filter_recursive.php
Last active Sep 19, 2019
PHP array_filter_recursive helper
View array_filter_recursive.php
<?php declare(strict_types=1);
if (!function_exists('array_filter_recursive')) {
/**
* @param array $array
* @param ?callable $callback = null
*
* @return array
*/
function array_filter_recursive(array $array, ?callable $callback = null): array
@eusonlito
eusonlito / facebook-img-alt.js
Last active Jul 11, 2019
Show Facebook alt titles generated to images
View facebook-img-alt.js
setInterval(function () {
document.querySelectorAll('div.img-title').forEach(function (title) {
title.parentNode.removeChild(title);
});
document.querySelectorAll('img.img').forEach(function (img) {
if (!img.alt) {
return;
}
View generate.php
<?php declare(strict_types=1);
namespace App\Services\Opcache;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use RecursiveRegexIterator;
use RegexIterator;
class Generate
@eusonlito
eusonlito / 01-docker-iptables.txt
Created Jun 13, 2019 — forked from bborysenko/01-docker-iptables.txt
Default Iptables rules after starting Docker servuce
View 01-docker-iptables.txt
```
[root@node-01 ~]# iptables-save
# Generated by iptables-save v1.4.21 on Thu May 3 20:27:51 2018
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:DOCKER - [0:0]
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
@eusonlito
eusonlito / float2hex.php
Last active Sep 15, 2019
Convert a HEXADECIMAL value into a FLOAT
View float2hex.php
<?php declare(strict_types=1);
/**
* @param float $value
*
* @return string
*/
function float2hex(float $value): string
{
$pack = pack('f', $value);
$hex = '';
@eusonlito
eusonlito / drop-column-if-exists.sql
Last active Jan 16, 2020
Drop table column only if exists in a MySQL database
View drop-column-if-exists.sql
DROP PROCEDURE IF EXISTS `DropColumnIfExists`;
DELIMITER $$
CREATE PROCEDURE `DropColumnIfExists` (`@TABLE` VARCHAR(100), `@COLUMN` VARCHAR(100))
`DropColumnIfExists`: BEGIN
DECLARE `@EXISTS` INT UNSIGNED DEFAULT 0;
SELECT COUNT(*) INTO `@EXISTS`
FROM `information_schema`.`columns`
You can’t perform that action at this time.