Skip to content

Instantly share code, notes, and snippets.

View g105b's full-sized avatar

Greg Bowler g105b

View GitHub Profile
@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 / 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 / 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 / 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
@g105b
g105b / getall.php
Created December 28, 2020 18:05
Git clone and composer install all repositories from a Github organisation
<?php
if(count($argv) <= 1) {
echo "Usage: getall.php OrganisationName [PathToParentDir]", PHP_EOL;
exit(1);
}
$org = $argv[1];
$path = $argv[2] ?? getcwd();
$path = realpath($path);
@g105b
g105b / example.php
Last active November 21, 2020 12:50
Example Async functionality with Promises using PHP.Gt/Async and PHP.Gt/Promise
<?php
/**
* This example counts the number of vowels and the number of consonants
* in example.txt, showing how concurrent slow file reads can use Promises
* to defer work, with a future callback when the work is complete.
*
* A PeriodicLoop is used with a purposefully long period with the file
* reading code being done one byte at a time, to simulate a slow connection.
*
* Note: This is an example wrapped in a class, showing an example of how a
@g105b
g105b / nginx-server.conf
Last active April 1, 2020 14:40
Redirects things from a CSV of old paths
server {
server_name example.com www.example.com;
listen 80;
location / {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
include fastcgi_params;
fastcgi_param SERVER_NAME $host;
fastcgi_param SCRIPT_FILENAME /var/www/path/to/router.php;
}