Skip to content

Instantly share code, notes, and snippets.

View ghostwriter's full-sized avatar
🐘
while(!succeed=try())

Nathanael Esayeas ghostwriter

🐘
while(!succeed=try())
  • 0.0.0.0
View GitHub Profile
@ghostwriter
ghostwriter / GaussGenerator.php
Created April 2, 2026 21:07
GaussGenerator in PHP
<?php
declare(strict_types=1);
/**
* #BlackLivesMatter - github.com/ghostwriter
**/
use Random\Engine\Mt19937;
use Random\Randomizer;
@ghostwriter
ghostwriter / PythonRandom.php
Last active April 2, 2026 21:04
PythonRandom in PHP
<?php
declare(strict_types=1);
/**
* #BlackLivesMatter - github.com/ghostwriter
**/
final class PythonRandom
{
@ghostwriter
ghostwriter / commit-msg
Created March 7, 2026 00:42
Automatically adds a Signed-off-by line to the message.
#!/bin/sh
set -o pipefail
set -o errtrace
set -o nounset
set -o errexit
# Automatically add a Signed-off-by line to the message.
SOB="Signed-off-by: $(git config user.name) <$(git config user.email)>"
@ghostwriter
ghostwriter / traits-dont-make-classes-cleaner.md
Created January 6, 2026 16:46
Traits Don’t Make Classes Cleaner, They Just Hide the Mess

Traits are often justified with a single, seductive argument:

“It makes the class look cleaner.”

Fewer lines. Less scrolling. A tidy façade.

This post explains why that argument is wrong—and why traits frequently increase complexity, coupling, and long-term maintenance cost, especially in PHP.


@ghostwriter
ghostwriter / ConfigurationExtension.php
Last active November 23, 2025 19:18
Configuration Extension for ghostwriter/container
<?php
declare(strict_types=1);
namespace Ghostwriter\Wip\Container\Ghostwriter\Config;
use Ghostwriter\Config\Configuration;
use Ghostwriter\Config\Interface\ConfigurationInterface;
use Ghostwriter\Container\Interface\ContainerInterface;
use Ghostwriter\Container\Interface\Service\ExtensionInterface;
<?php
use Doctrine\DBAL\Connection;
final class JoinMapping
{
/**
* @param non-empty-string $idFieldAlias DB column alias for ID
* @param array<non-empty-string, non-empty-string> $fieldMap alias => outputKey
* @param array<non-empty-string, self> $children outputKey => mapping
@ghostwriter
ghostwriter / example.php
Created July 4, 2025 18:57
Cooperative Multitasking with PHP Fibers
<?php
final class Deployment
{
/**
* @param array<string, list<string>> $pipelineStages
*/
public function run(array $pipelineStages): void
{
$pipeline = new Fiber(function (array $pipelineStages): string {
@ghostwriter
ghostwriter / ConfigProvider.php
Created March 31, 2025 13:55
A custom middleware that delegates authentication to a specific adapter.
<?php
return [
'dependencies' => [
'factories' => [
'BasicAuthMiddleware' => function (ContainerInterface $container): CustomAuthenticationMiddleware {
$adapter = $container->get(BasicAuthAdapter::class);
return new CustomAuthenticationMiddleware($adapter);
},
'OAuth2Middleware' => function (ContainerInterface $container): CustomAuthenticationMiddleware {
@ghostwriter
ghostwriter / Functor.php
Last active September 28, 2024 18:32
Polynomial Functors in PHP
<?php
interface Functor
{
/**
* Maps a function over the functor.
*
* @template A
* @template B
* @param callable(A): B $f
@ghostwriter
ghostwriter / build-and-test-php-extension.yml
Created September 13, 2024 20:22
Build & Test PHP Extensions via GitHub Actions
# BlackLivesMatter
name: Build & Test Extension
on:
push:
pull_request:
jobs:
qa:
runs-on: ubuntu-latest