Skip to content

Instantly share code, notes, and snippets.

View g105b's full-sized avatar

Greg Bowler g105b

View GitHub Profile
@g105b
g105b / curlpool.sh
Last active March 11, 2024 06:17
Pool 100 parallel curl requests at a time
#!/bin/bash
target=${1:-http://example.com}
while true # loop forever, until ctrl+c pressed.
do
for i in $(seq 100) # perfrom the inner command 100 times.
do
curl $target > /dev/null & # send out a curl request, the & indicates not to wait for the response.
done
wait # after 100 requests are sent out, wait for their processes to finish before the next iteration.
@g105b
g105b / product-list.php
Last active July 31, 2023 13:23
Stripe usage
<?php
namespace App\Payment;
use Iterator;
use Stripe\Collection;
use Stripe\Price as StripePrice;
use Stripe\StripeClient;
use Stripe\Product as StripeProduct;
/** @implements Iterator<Product> */
@g105b
g105b / test.php
Created April 20, 2023 15:19
Promise implementation and basic HTTP client in one file
<?php
$http = new HHttp();
//$http->fetch("https://api.github.com/orgs/phpgt/repos")
$http->fetch("https://raw.githubusercontent.com/PhpGt/Fetch/master/broken.json")
->then(function(RResponse $response) {
echo "Got a response!", PHP_EOL;
sleep(1);
return $response->json();
})->then(function(object|array $json) {
@g105b
g105b / Gnome-Terminal.md
Last active January 27, 2023 10:45
Gnome Terminal Settings
  1. Make a backup: dconf dump /org/gnome/terminal/ > gnome-terminal-settings.cfg
  2. Reset settings: dconf reset -f /org/gnome/terminal/
  3. Restore from backup: dconf load /org/gnome/terminal/ &lt; gnome-terminal-settings.cfg
@g105b
g105b / decrypt.bash
Last active July 18, 2022 17:49
Encrypt-decrypt using openssl on the commandline
#!/bin/bash
key="sup3r_s3cr3t_p455w0rd"
decrypted=$(openssl enc \
-aes-256-ctr \
-d \
-k "$key" \
-iv "504914019097319c9731fc639abaa6ec" \
-in encrypted.txt)
@g105b
g105b / key-sync.sh
Created January 27, 2017 15:09
Sync authorized_keys with Github public keys
#!/bin/bash
GITHUB_USERNAME=#PUT_YOUR_USERNAME_HERE
TMP=/tmp/existing_cron
crontab -l > $TMP
echo "*/10 * * * * /usr/bin/wget https://github.com/$GITHUB_USERNAME.keys -O ~/.ssh/authorized_keys" >> $TMP
crontab $TMP
rm $TMP
<?php
/**
* Serve Wordpress locally without having to configure a web server.
*
* You need to have the database served as configured in wp-config.php, then
* run php -S 0.0.0.0:8080 wp-router.php to serve, and access localhost:8080 or
* your.computers.ip:8080 in a browser.
*
* Make sure in the database that within the `wp_options` table, the `siteurl`
* and `home` values are both "/".
@g105b
g105b / cdn.php
Last active March 20, 2021 12:34
Nginx configuration for CDN
<?php
$host = $_SERVER["SERVER_NAME"];
$cacheDir = $_SERVER["DOCUMENT_ROOT"];
$uriPath = $_SERVER["REQUEST_URI"];
$uriPath = strtok($uriPath, "?");
$uriFull = "https://" . $host . $uriPath;
$cacheFilepath = $cacheDir . "/" . ltrim($uriPath, "/");
if(substr($cacheFilepath, -1) === "/") {
$cacheFilepath .= "index.html";
@g105b
g105b / README.md
Last active March 19, 2021 15:25
Fail2ban rules to stop naughty use of my servers

This fail2ban configuration is stored here for reference by myself in the future, but anyone is free to take a look at my custom rules.

The rules are highly specific to weird/dodgy traffic I get on my servers. Currently, the biggest "threat" is from a service called "Site24x7", who are constantly barraging my servers with broken requests ("G" requests, not "GET" requests). Sorry, I've got to block you!

Amongst others, there are a lot of attempts at using Wordpress features, or other old fashioned CMSes. As soon as one of these requests come in, block 'em!

@g105b
g105b / example.sql
Created February 17, 2021 10:09
Converting a MySQL question mark parameter to a named parameter for reuse in the same query
select
(@param1 := ?),
value,
timestamp,
Field.name,
Site.id
from
Field_Value