Skip to content

Instantly share code, notes, and snippets.

@24HOURSMEDIA
24HOURSMEDIA / output.txt
Created Oct 8, 2021
test php deferred destruction when callbacks are injected
View output.txt
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)
@24HOURSMEDIA
24HOURSMEDIA / auto_decompress_kernel
Last active May 14, 2021
auto_decompress_kernel for ubuntu20.04 server / rpi usb boot (improved)
View auto_decompress_kernel
#!/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 / country_currency_map.php
Created Feb 6, 2021
Array of country codes to ISO-4217 currency codes as php array
View country_currency_map.php
<?php
return [
'AD' => 'EUR',
'AE' => 'AED',
'AF' => 'AFN',
'AG' => 'XCD',
'AI' => 'XCD',
'AL' => 'ALL',
'AM' => 'AMD',
@24HOURSMEDIA
24HOURSMEDIA / aws-s3-examples.php
Created Jan 28, 2019
Some quick examples in php to read and store data and files on AWS S3
View aws-s3-examples.php
<?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 / ec2-describe-instances-policy.json
Last active Nov 4, 2018
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
View ec2-describe-instances-policy.json
{
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:DescribeInstances",
"ec2:DescribeTags"
],
"Resource": "*"
}
@24HOURSMEDIA
24HOURSMEDIA / gist:dae8bd4d8db7467144102a9ed6555371
Created Nov 3, 2018
normalize a string in bash to uppercase with underscores examples
View gist:dae8bd4d8db7467144102a9ed6555371
#!/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 / .env
Last active Oct 18, 2018
Get contents through proxy using curl or guzzle - tested wit bestproxyandvpn.com
View .env
PROXY_USER=...
PROXY_PASS=....
PROXY_IP=185.XXX.XXX.XXX
PROXY_PORT=37257
View gist:c4baa35dba727cd8f03412e5de02fcba
```
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 / gist:de04071ffa4221a9c3ce2f1c67c148b2
Created Aug 16, 2017
count number of ips in nginx access log
View gist:de04071ffa4221a9c3ce2f1c67c148b2
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:9888936
Created Mar 31, 2014
delete backuop files older than 90 days
View gist:9888936
#!/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`