Skip to content

Instantly share code, notes, and snippets.

View eusonlito's full-sized avatar
🤗

Lito eusonlito

🤗
View GitHub Profile
@eusonlito
eusonlito / install.sh
Created September 2, 2025 15:12
Setup script (Ubuntu 22.04 + Apache + PHP 8.4 + MySQL)
#!/usr/bin/env bash
set -Eeuo pipefail
### CONFIG #################################################################
PHP_VERSION="8.4"
SYSTEM_LOCALE="en_US.UTF-8" # final user is English-speaking
TIMEZONE="${TIMEZONE:-UTC}" # override by exporting TIMEZONE before running
USE_PHP_FPM="1" # 1 = Apache + PHP-FPM (recommended), 0 = mod_php
MYSQL_APT_DEB="mysql-apt-config_0.8.34-1_all.deb" # latest as of 2025-09-02
@eusonlito
eusonlito / 01-README.md
Last active August 14, 2025 23:03
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');
@eusonlito
eusonlito / JwtToken.php
Last active April 17, 2023 11:48
Simple PHP JWT Service over https://github.com/lcobucci/jwt
<?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