Skip to content

Instantly share code, notes, and snippets.

@24HOURSMEDIA
24HOURSMEDIA / gist:9888936
Created March 31, 2014 09:49
delete backuop files older than 90 days
#!/bin/sh
#
# Delete backup more than 90 days old.
#
backupDir="/var/lib/psa/dumps/tmp"
#
daysToKeep=90
echo "Checking for files older than $daysToKeep days in $backupDir"
listOfFiles=`find $backupDir -mtime +$daysToKeep`
@24HOURSMEDIA
24HOURSMEDIA / gist:de04071ffa4221a9c3ce2f1c67c148b2
Created August 16, 2017 05:50
count number of ips in nginx access log
Count IP's and sort in nginx access log
from: https://www.mkyong.com/nginx/count-ip-address-in-nginx-access-logs/
```
sudo awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -nr
```
@24HOURSMEDIA
24HOURSMEDIA / gist:c4baa35dba727cd8f03412e5de02fcba
Created June 7, 2018 17:48
get php-fpm memory usage in linux
```
user='USER'
pname='php-fpm'
# get total memory usage of php-fpm
ps -U $user --no-headers -o rss -o command | grep $pname | awk '{ sum+=$1} END {print int(sum/1024) "MB"}'
# get total number of php-fpm processes + 1
ps aux | grep $pname | wc -l
@24HOURSMEDIA
24HOURSMEDIA / .env
Last active December 6, 2021 08:35
Get contents through proxy using curl or guzzle - tested wit bestproxyandvpn.com
PROXY_USER=...
PROXY_PASS=....
PROXY_IP=185.XXX.XXX.XXX
PROXY_PORT=37257
@24HOURSMEDIA
24HOURSMEDIA / gist:dae8bd4d8db7467144102a9ed6555371
Created November 3, 2018 21:10
normalize a string in bash to uppercase with underscores examples
#!/bin/bash
## Convert 'this/is a:string 123' to THIS_IS_A_STRING_123
##
# converting a hard coded string to all uppercase with underscoree
echo "this/is a:string 123" | iconv -t ascii//TRANSLIT | sed -r s/[^a-zA-Z0-9]+/_/g | sed -r s/^-+\|-+$//g | tr a-z A-Z
# output: THIS_IS_A_STRING_123
# using variables variable
@24HOURSMEDIA
24HOURSMEDIA / ec2-describe-instances-policy.json
Last active November 4, 2018 09:46
aws ec2 get instance and ami tags and write them to a file. here is the file and the policy for the AWS role needed om the instances
{
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:DescribeInstances",
"ec2:DescribeTags"
],
"Resource": "*"
}
@24HOURSMEDIA
24HOURSMEDIA / aws-s3-examples.php
Created January 28, 2019 15:50
Some quick examples in php to read and store data and files on AWS S3
<?php
// assume aws sdk is in composer: "aws/aws-sdk-php": "^3.0",
require __DIR__ . '/../../vendor/autoload.php';
// load $AWS_KEY, $AWS_SECRET
require __DIR__ . '/../../local/credentials.php';
$bucket = 'BUCKETNAME'
$awsCredentials = new \Aws\Credentials\Credentials($AWS_KEY, $AWS_SECRET);
@24HOURSMEDIA
24HOURSMEDIA / country_currency_map.php
Created February 6, 2021 10:18
Array of country codes to ISO-4217 currency codes as php array
<?php
return [
'AD' => 'EUR',
'AE' => 'AED',
'AF' => 'AFN',
'AG' => 'XCD',
'AI' => 'XCD',
'AL' => 'ALL',
'AM' => 'AMD',
@24HOURSMEDIA
24HOURSMEDIA / auto_decompress_kernel
Last active May 14, 2021 07:45
auto_decompress_kernel for ubuntu20.04 server / rpi usb boot (improved)
#!/bin/bash -e
# Put this script in the root of the boot partition (i.e. system-boot) and chmod it with +x
# Set Variables
BTPATH=/boot/firmware
CKPATH=$BTPATH/vmlinuz
DKPATH=$BTPATH/vmlinux
#Check if compression needs to be done.
if [ -e $BTPATH/check.md5 ]; then
@24HOURSMEDIA
24HOURSMEDIA / output.txt
Created October 8, 2021 07:40
test php deferred destruction when callbacks are injected
output:
no callback: testing...destruct...
with callback: testing...callback...destruct...
with callback 2: testing...callback...destruct...was unset...
(destruct was always called so that's ok)