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 / 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
@ghostwriter
ghostwriter / abnf-to-regex.txt
Last active September 13, 2024 20:50
abnf-to-regex generator output (https://github.com/ghostwriter/abnf)
(?(DEFINE)
# Basic components
(?<ALPHA>[A-Za-z])
(?<BIT>[01])
(?<DIGIT>[0-9])
(?<HEXDIG>[0-9A-Fa-f])
(?<CHAR>[\x01-\x7F])
(?<VCHAR>[\x21-\x7E])
(?<SP>[\x20])
(?<WSP>[\x20\x09])
@ghostwriter
ghostwriter / dump.php
Created August 25, 2024 22:39
list of characters to avoid
<?php
/*
Conflicts with file systems: :, *, ", <, >, |
Conflicts with shell variables: $
Conflicts with bash brace expansion {, }
*/
@ghostwriter
ghostwriter / gh_codecov.sh
Created June 12, 2024 15:21
Using the `gh` to query repositories and set secrets for each non-fork repository.
#!/bin/bash
# GitHub username/organization
USERNAME="ghostwriter"
# Secret name and value
SECRET_KEY="CODECOV_TOKEN"
SECRET_VALUE="global-upload-token"
# Get the list of repositories for the user
@ghostwriter
ghostwriter / obfuscate.php
Last active June 12, 2024 15:27
Obfuscate a string to prevent spam-bots from sniffing it.
<?php
#BlackLivesMatter
/**
* Obfuscate a string to prevent spam-bots from sniffing it.
*/
function obfuscate(string $value): string
{
$safe = '';
@ghostwriter
ghostwriter / Workflow.yml
Created December 2, 2023 14:27
Ubuntu removed mongo from their default installed database packages on Ubuntu 22.04
- name: 🍃 Install mongosh
run: |
sudo apt-get update
sudo apt-get install -y wget gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt-get update
sudo apt-get install -y mongodb-mongosh
<?php
function getOpenBinary(): string
{
return match (PHP_OS_FAMILY) {
// Using PowerShell allows us to open the file in the background
'Windows' => 'powershell Start-Process',
'Darwin' => 'open',
'Linux' => 'xdg-open',