Skip to content

Instantly share code, notes, and snippets.

@eusonlito
eusonlito / arrayMapRecursive.php
Last active January 24, 2022 16:22
PHP helper to recursive iterate over an array. Method will send `$value` and `$key` to callback. `$values_only` option allow to send only final values to callback.
<?php declare(strict_types=1);
/**
* @param array $array
* @param callable $callback
* @param bool $values_only = true
*
* @return array
*/
public function arrayMapRecursive(array $array, callable $callback, bool $values_only = true): array
@eusonlito
eusonlito / github-ssh.sh
Last active January 18, 2022 11:00
Script to create SSH deploy keys to github
#!/bin/bash
# Install:
# wget https://gist.githubusercontent.com/eusonlito/39f15118cfa7a3fcab88cc80b4ef7ca8/raw/github-ssh.sh -O /usr/local/bin/github-ssh
# chmod 755 /usr/local/bin/github-ssh
# Usage:
# github-ssh "https://github.com/eusonlito/Password-Manager"
url="$1"
@eusonlito
eusonlito / oppo-coloros-bloatware-disable
Last active March 23, 2024 18:23
Disable and Enable Oppo ColorOS bloatware. AVOID TO UNINSTALL PACKAGES OR YOUR PHONE CAN BE BRICKED ON FUTURE UPDATES.
pm disable-user --user 0 com.caf.fmradio
pm disable-user --user 0 com.coloros.activation
pm disable-user --user 0 com.coloros.activation.overlay.common
pm disable-user --user 0 com.coloros.alarmclock
pm disable-user --user 0 com.coloros.appmanager
pm disable-user --user 0 com.coloros.assistantscreen
pm disable-user --user 0 com.coloros.athena
pm disable-user --user 0 com.coloros.avastofferwall
pm disable-user --user 0 com.coloros.backuprestore
pm disable-user --user 0 com.coloros.backuprestore.remoteservice
@eusonlito
eusonlito / randomize-numbers-html.js
Created November 26, 2021 22:54
Javascript to randomize every number in a HTML page
document.querySelectorAll('body *').forEach(function (e) {
const html = e.innerHTML;
if (!html || !html.match(/^[0-9\-\.\,\s]+$/)) {
return;
}
const chars = html.split('');
for (i = 0; i < chars.length; i++) {
@eusonlito
eusonlito / svg2png.sh
Last active October 17, 2021 18:47
Convert SVG to PNG using inkscape CLI
#!/bin/bash
for svg in */*.svg; do
width=$(grep -m 1 -o -h 'width="[0-9]\+"' $svg | sed 's/[^0-9]//g')
height=$(grep -m 1 -o -h 'height="[0-9]\+"' $svg | sed 's/[^0-9]//g')
png=$(echo $svg | sed 's/svg/png/')
echo "Converting $svg to $png with size ${width}x${height}"
inkscape -w "$width" -h "$height" $svg -o $png 2>/dev/null
(async function(){
const endpointShifts = 'https://api.factorialhr.com/attendance/shifts';
const endpointPeriods = 'https://api.factorialhr.com/attendance/periods';
const year = new Date().getFullYear();
const month = new Date().getMonth() + 1;
const times = [[ '08:00', '14:00' ], [ '15:30', '17:30' ]];
const allowFuture = true;
@eusonlito
eusonlito / convert-jpg-png.sh
Last active September 29, 2021 13:57
Convert, resize and paint images from JPG to PNG using imagemagick
#!/bin/bash
set -e
if [ "$1" == "" ] || [ ! -d "$1" ]; then
echo "Invalid Path $1"
exit 1
fi
LC_NUMERIC="en_US.UTF-8"
@eusonlito
eusonlito / array-keys.php
Created September 23, 2021 09:45
PHP Array Whitelist and Blacklist functions
<?php
if (!function_exists('array_keys_whitelist')) {
function array_keys_whitelist(array $array, array $whitelist): array
{
return array_intersect_key($array, array_flip($whitelist));
}
}
if (!function_exists('array_keys_blacklist')) {
@eusonlito
eusonlito / mysql-database-user.sql
Created August 31, 2021 20:16
Create a new MySQL database and user
CREATE DATABASE `DB` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE USER "USR"@"localhost" IDENTIFIED BY "PWD";
CREATE USER "USR"@"127.0.0.1" IDENTIFIED BY "PWD";
GRANT ALL ON `DB`.* TO "USR"@"localhost";
GRANT ALL ON `DB`.* TO "USR"@"127.0.0.1";
FLUSH PRIVILEGES;
@eusonlito
eusonlito / CsvRead.php
Last active June 17, 2021 15:10
Simple PHP CSV parser
<?php declare(strict_types=1);
class CsvRead
{
/**
* @var array
*/
protected array $csv;
/**