Skip to content

Instantly share code, notes, and snippets.

@eusonlito
eusonlito / arrayMapRecursive.php
Last active Jan 24, 2022
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.
View arrayMapRecursive.php
<?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 Jan 18, 2022
Script to create SSH deploy keys to github
View github-ssh.sh
#!/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 Dec 22, 2021
Disable and Enable Oppo ColorOS bloatware. AVOID TO UNINSTALL PACKAGES OR YOUR PHONE CAN BE BRICKED ON FUTURE UPDATES.
View oppo-coloros-bloatware-disable
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 Nov 26, 2021
Javascript to randomize every number in a HTML page
View randomize-numbers-html.js
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 Oct 17, 2021
Convert SVG to PNG using inkscape CLI
View svg2png.sh
#!/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
View factorial-attendance.js
(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 Sep 29, 2021
Convert, resize and paint images from JPG to PNG using imagemagick
View convert-jpg-png.sh
#!/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 Sep 23, 2021
PHP Array Whitelist and Blacklist functions
View array-keys.php
<?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 Aug 31, 2021
Create a new MySQL database and user
View mysql-database-user.sql
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 Jun 17, 2021
Simple PHP CSV parser
View CsvRead.php
<?php declare(strict_types=1);
class CsvRead
{
/**
* @var array
*/
protected array $csv;
/**