Skip to content

Instantly share code, notes, and snippets.

View ziadoz's full-sized avatar

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / readme.txt
Last active July 25, 2023 15:54
Register UT99 UMod Extension
Replace path to UT99 with your install path, then run the .reg file.
https://steamcommunity.com/sharedfiles/filedetails/?id=272924930
https://ut99.org/viewtopic.php?t=6020
@ziadoz
ziadoz / raw_sql.php
Last active September 21, 2023 09:41
Laravel - QueryExecuted To Raw SQL
<?php
// Before Laravel 10.15.0
function prepareQuery(QueryExecuted $query): string
{
return count($query->bindings) > 0
? vsprintf(str_replace(['%', '?'], ['%%', '%s'], $query->sql), array_map(fn ($value) => (is_numeric($value) ? $value : "'" . $value . "'"), $query->bindings))
: $query->sql;
}
prepareQuery($query);
@ziadoz
ziadoz / MyCommand.php
Created July 5, 2023 13:58
Laravel - Keep Database Connection Alive in Artisan Commands
<?php
namespace App\Console\Commands;
class MyCommand extends Command
{
protected $signature = 'app:my-command';
public function handle(): int
{
@ziadoz
ziadoz / enum-next-prev.php
Last active July 3, 2023 15:01
PHP Enum Next/Previous Case
<?php
enum Foo: string
{
case A = 'A';
case B = 'B';
case C = 'C';
public function next(): self
{
@ziadoz
ziadoz / regexp-primes.php
Last active June 21, 2023 10:28
PHP - Regular Expression Prime Numbers
<?php
// @see: https://www.noulakaz.net/2007/03/18/a-regular-expression-to-check-for-prime-numbers/
// @see: https://web.archive.org/web/20220522073029/http://montreal.pm.org/tech/neil_kandalgaonkar.shtml#this_vs_mine
// @see: https://web.archive.org/web/20220513113609/http://neilk.net/blog/2000/06/01/abigails-regex-to-test-for-prime-numbers/
// @see: https://web.archive.org/web/20080111215127/http://www.mit.edu:8008/bloom-picayune.mit.edu/perl/10138
// @see: https://news.ycombinator.com/item?id=36413260
function regexp_prime(int $num): bool
{
return preg_match('/^1?$|^(11+?)\1+$/x', str_repeat('1', $num), $matches) !== 1;
@ziadoz
ziadoz / sort-assoc.php
Created June 6, 2023 12:09
PHP Sort Associative Array
<?php
final class SortAssoc
{
public function __construct(private readonly array $array, private readonly array $columns = [])
{
}
public function __invoke(): array
{
$array = $this->array;
@ziadoz
ziadoz / 15mins.sql
Last active May 22, 2023 14:58
MySQL Select 15 Minute Time Series
with recursive 15min_windows as (
select
curdate() + interval 8 hour as start,
curdate() + interval 8 hour + interval 15 minute as end
union
select
end,
end + interval 15 minute
from 15min_windows
where end < curdate() + interval 16 hour
@ziadoz
ziadoz / test.sh
Created March 22, 2023 13:52
Laravel - Install Composer dependencies via Docker for testsuite
# Put this inside /bin/test.sh to install Laravel's dependencies before running testsuite in Docker.
docker run \
-it \
--rm \
-w /data \
-v ${PWD}:/data:delegated \
--entrypoint /bin/sh \
registry.gitlab.com/grahamcampbell/php:8.1-base -c 'curl -o /tmp/composer-setup.php https://getcomposer.org/installer && php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer && composer install'
@ziadoz
ziadoz / docker-compose.yml
Created March 21, 2023 23:23
Miniflux Docker Compose
version: '3.4'
services:
miniflux:
image: miniflux/miniflux:latest
ports:
- "80:8080"
depends_on:
- db
environment:
- DATABASE_URL=postgres://miniflux:secret@db/miniflux?sslmode=disable
@ziadoz
ziadoz / FooTest.php
Last active August 4, 2023 10:41
PHPUnit 10 - Replacement for deprecated withConsecutive() method
<?php
// @see: https://github.com/sebastianbergmann/phpunit/issues/4026
// Use `$this->with(...$this->consecutiveParams($args1, $args2))` instead of `$this->withConsecutive($args1, $args2)`.
use PHPUnit\Framework\TestCase;
class FooTest extends TestCase
{
use ConsecutiveParams;