Skip to content

Instantly share code, notes, and snippets.

View eusonlito's full-sized avatar
🤗

Lito eusonlito

🤗
View GitHub Profile
@eusonlito
eusonlito / 01-README.md
Last active November 10, 2024 14:36
SQLite optimization for Laravel

The SQLite optimizations must be carried out at two different times: once in a unique and permanent way for the database and another time for each connection that is made. Below are the configurations that should be made in each case.

Unique and Permanent Configurations

These configurations are set only once and affect the database persistently, meaning they do not need to be reconfigured each time a connection is established:

PRAGMA journal_mode = WAL;

Sets the database journal mode to "WAL" (Write-Ahead Logging), which improves performance in concurrent operations.

@eusonlito
eusonlito / oom_score_adj.sh
Created March 26, 2024 08:46
This script identifies the second most memory-intensive PHP process, resets the Out-Of-Memory (OOM) priority of the previously adjusted process if still running, sets the current process's OOM priority to be more likely killed, and logs its PID and timestamp.
#!/bin/bash
APP="php"
CURRENT_HIGHEST=$(ps -eo pid,comm --sort=-%mem | grep "$APP" | head -n 2 | tail -n 1)
CURRENT_HIGHEST_PID=$(echo $CURRENT_HIGHEST | awk '{print $1'})
LAST_PID_FILE="/tmp/oom-kill-previous"
if [ -f "$LAST_PID_FILE" ]; then
LAST_PID=$(cat $LAST_PID_FILE)
@eusonlito
eusonlito / postgresql-table-size-rows.sql
Last active February 5, 2024 12:26
List PostgreSQL database tables by size and rows
SELECT
"s"."relname" AS "table_name",
pg_total_relation_size("s"."schemaname" || '.' || "s"."relname") / 1024 / 1024 AS "total_size",
pg_relation_size("s"."schemaname" || '.' || "s"."relname") / 1024 / 1024 AS "table_size",
(pg_total_relation_size("s"."schemaname" || '.' || "s"."relname") - pg_relation_size("s"."schemaname" || '.' || "s"."relname")) / 1024 / 1024 AS "index_size",
"s"."n_live_tup" AS "table_rows"
FROM
"pg_stat_user_tables" "s"
JOIN
"pg_class" "c" ON "s"."relid" = "c"."oid"
@eusonlito
eusonlito / apps-load.sh
Created December 18, 2023 21:25
Show Linux OS Apps Load
ps -eo comm,rss | awk '{arr[$1]+=$2} END {for (i in arr) print arr[i], i}' | sort -nr | head
@eusonlito
eusonlito / generateUniqueSlug.php
Created November 30, 2023 12:34
Generate unique slugs
<?php
protected static function generateUniqueSlug(string $title): string
{
$slug = str_slug($title);
if (static::query()->where('slug', $slug)->doesntExist()) {
return $slug;
}
@eusonlito
eusonlito / ipset-find.sh
Created November 3, 2023 09:30
Find IP in ipset lists
ip="XXX.XXX.XXX.XXX"
for set in $(ipset list -n); do
ipset test $set $ip &> /dev/null && echo "IP $ip found in $set"
done
@eusonlito
eusonlito / benchmark.php
Last active October 6, 2023 14:47
PHP ReflectionFunction and ReflectionClass benchmarks
<?php
/**
* Benchmark: Reflection Performance
*/
define('TESTS', 1000000);
header('Content-type: text/plain');
<?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
#!/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
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