Skip to content

Instantly share code, notes, and snippets.

@eusonlito
eusonlito / JwtToken.php
Last active April 17, 2023 11:48
Simple PHP JWT Service over https://github.com/lcobucci/jwt
View JwtToken.php
<?php declare(strict_types=1);
namespace App\Services\Jwt;
use DateTimeImmutable;
use Lcobucci\JWT\Encoding\ChainedFormatter;
use Lcobucci\JWT\Encoding\JoseEncoder;
use Lcobucci\JWT\Signer\Key\InMemory;
use Lcobucci\JWT\Signer\Hmac\Sha256;
use Lcobucci\JWT\Token\Builder;
@eusonlito
eusonlito / auth-log-ip-locate.sh
Last active April 13, 2023 07:55
Add IP Location to auth.log entries
View auth-log-ip-locate.sh
#!/bin/bash
echo -e "\nSTART: $(date "+%Y-%m-%d %H:%M:%S")\n\n"
logs="/root/logs/auth-log-ip-locate"
if [ ! -d "$logs" ]; then
install -d "$logs"
fi
@eusonlito
eusonlito / all.sh
Created February 27, 2023 14:31
PHP 8.2 extension
View all.sh
apt install php8.2 php8.2-amqp php8.2-apcu php8.2-ast php8.2-bcmath php8.2-bz2 php8.2-cgi php8.2-cli php8.2-common php8.2-curl php8.2-dba php8.2-decimal php8.2-dev php8.2-ds php8.2-enchant php8.2-excimer php8.2-fpm php8.2-gd php8.2-gmp php8.2-gnupg php8.2-grpc php8.2-http php8.2-igbinary php8.2-imagick php8.2-imap php8.2-inotify php8.2-interbase php8.2-intl php8.2-ldap php8.2-libvirt-php php8.2-lz4 php8.2-mailparse php8.2-maxminddb php8.2-mbstring php8.2-memcache php8.2-memcached php8.2-mongodb php8.2-msgpack php8.2-mysql php8.2-oauth php8.2-odbc php8.2-opcache php8.2-pcov php8.2-pgsql php8.2-phpdbg php8.2-pinba php8.2-protobuf php8.2-ps php8.2-pspell php8.2-psr php8.2-raphf php8.2-rdkafka php8.2-readline php8.2-redis php8.2-rrd php8.2-smbclient php8.2-snmp php8.2-soap php8.2-sqlite3 php8.2-ssh2 php8.2-stomp php8.2-swoole php8.2-sybase php8.2-tideways php8.2-tidy php8.2-uopz php8.2-uuid php8.2-vips php8.2-xdebug php8.2-xhprof php8.2-xml php8.2-xmlrpc php8.2-xsl php8.2-yaml php8.2-zip php8.2-zmq php8.2-zstd
@eusonlito
eusonlito / custom-keyring-batch.sh
Created December 5, 2022 10:59
Batch migration from /etc/apt/trusted.gpg to custom keyring
View custom-keyring-batch.sh
#!/bin/bash
for KEY in $(apt-key --keyring /etc/apt/trusted.gpg list | grep -E "(([ ]{1,2}(([0-9A-F]{4}))){10})" | tr -d " " | grep -E "([0-9A-F]){8}\b" ); do K=${KEY:(-8)}; apt-key export $K | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/imported-from-trusted-gpg-$K.gpg; done
@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.
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 January 18, 2022 11:00
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 December 22, 2021 11:34
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 November 26, 2021 22:54
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 October 17, 2021 18:47
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;