Skip to content

Instantly share code, notes, and snippets.

@eusonlito
eusonlito / 404-download.sh
Last active December 9, 2020 10:52
Download remote resources based on 404 errors on local Apache access log
#!/bin/bash
# Copy this file into your project root
# Configure LOG path, DOMAIN and WEB folder (from project root)
# Set execution permissions with: chmod 755 404-download.sh
# View some page on your local environment
# Launch the script with ./404-download.sh
LOG="/var/log/apache2/access.log"
HOST="https://domain.com"
@eusonlito
eusonlito / date-timezone-legacy.js
Created July 28, 2020 07:38
Simple function to return the Date object with a fake UTC to customize time as TimeZone .
function dateLocal(timezone) {
var date = new Date().toLocaleString('en-US', {
timeZone: timezone,
hour12: false
}).match(/^([0-9]+)\/([0-9]+)\/([0-9]+), ([0-9]+):([0-9]+):([0-9]+)$/);
return new Date(Date.UTC(date[3], date[1] - 1, date[2], date[4], date[5], date[6]));
}
@eusonlito
eusonlito / README.md
Last active January 1, 2024 11:36
Strong iptables and ipset protection

Protect your server with a strong iptables rules and ipset lists.

1. Install ipset to manage ipstables lists

apt install ipset

2. Install iptables-persistent to preserve iptables rules on reboot

@eusonlito
eusonlito / ipset-locate.sh
Last active October 18, 2021 02:51
Script to execute as a cronjob and generate json files with the IPs added to ipset
#!/bin/bash
echo -ne "\nSTART: $(date "+%Y-%m-%d %H:%M:%S")"
logs="/root/logs/ipset-locate"
if [ ! -d "$logs" ]; then
install -d "$logs"
fi
@eusonlito
eusonlito / updated-at.sql
Last active April 21, 2024 21:47
Use trigger to change `updated_at` on all PostgreSQL tables
#
# Delete previous function definition (if exists)
#
DROP FUNCTION IF EXISTS before_update_updated_at() CASCADE;
#
# Create function to update updated_at timestamp if changed values on update
#
CREATE OR REPLACE FUNCTION before_update_updated_at() RETURNS trigger AS
$BODY$
@eusonlito
eusonlito / apt-dist-upgrade.sh
Last active June 21, 2022 06:28
Execute automated apt dist-upgrade
# Save on /usr/local/bin/apt-dist-upgrade with 700 permissions to root
# Execute: sudo apt-dist-upgrade
export DEBIAN_FRONTEND=noninteractive
export NEEDRESTART_MODE=a
export DEBIAN_PRIORITY=critical
apt clean
apt autoclean
@eusonlito
eusonlito / backup-phone.sh
Last active September 1, 2020 10:49
Android Phone Backup with adb-sync https://github.com/google/adb-sync
#!/bin/bash
# Require adb-sync https://github.com/google/adb-sync
MOUNT="/mnt/backup"
NAME="Xiaomi-Mi-A2"
e () {
echo -e "\n$(date '+%Y-%m-%d %H:%M:%S'): $1\n"
}
@eusonlito
eusonlito / uniqid.php
Last active July 1, 2022 01:04
Generate unique strings. Tested over 100.000.000 iterations without duplicates.
<?php declare(strict_types=1);
if (!function_exists('uniqidReal')) {
/**
* @param int $length
*
* @return string
*/
function uniqidReal(int $length): string
{
@eusonlito
eusonlito / .htaccess
Created February 4, 2020 15:17
Accept all CORS requests on Apache and nginx. Improve website performance accepting all OPTIONS requests.
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
# Allow Access Control Headers
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET,PUT,POST,DELETE,PATCH,OPTIONS"
Header set Access-Control-Allow-Headers "Accept, Accept-Datetime, Accept-Language, App-Version, Authorization, Cache-Control, Content-Type, Date, Device-Token, Location, Origin, Time-Zone, User-Agent, X-Requested-With"
Header set Access-Control-Allow-Credentials "true"
@eusonlito
eusonlito / json-pretty
Last active January 17, 2020 16:37
Prettify json using python or jq if available
#!/bin/bash
# Install as /usr/local/bin/json-pretty with +xr permissions
#
# Usage:
#
# * `json-pretty file.json` generate a prettified file-pretty.json file
# * `json-pretty file.json new-file.json` generate a prettified new-file.json file
if [ "$1" == "" ] || [ ! -f "$1" ]; then