Skip to content

Instantly share code, notes, and snippets.

@tored
tored / git-clean-merged.php
Created May 16, 2025 08:07
Git clean merged branches locally and optionally remote
#!/usr/bin/env php
<?php
/**
* Git cleanup script: deletes merged branches locally (and optionally on remote).
*
* Usage:
* php git-clean-merged.php [--with-remote] [--help]
*
* Options:
function execute(string $cmd, ?string $stdin = null): array
{
$proc = proc_open($cmd, [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);
if ($stdin !== null) {
fwrite($pipes[0], $stdin);
}
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
@tored
tored / README.md
Last active December 3, 2024 12:11
Manual WAMP setup for Windows, Apache, MySQL and PHP

Manual WAMP setup for Windows, Apache, MySQL and PHP

There many ways to setup a PHP development environment for Windows, WSL, Docker, Virtual Machine, WAMP and similar pre-packaged installers, etc, all of them works fine. I prefer somewhat old school approach to setup everything manually. Here is how

Preparation

I will setup this environment for 64 bit Windows. If you are on 32 bit you have to download the appropriate packages for that. I also setup everything for a local User, if you prefer to make it global for everyone you can do that as well (e.g install everything in C:\Wamp).

Create a directory somewhere called Wamp (or whatever). I will put mine at %OneDrive%\Program\Wamp. That way I can share my development environment between machines. (My %OneDrive%\Program directory consist of various Windows programs and tools I share between my machines, thus it makes sense to create a subdirectory there).

@tored
tored / bcmath.php
Last active January 11, 2022 13:44
PHP bcceil, bcfloor and bcround for bcmath
<?php
declare(strict_types=1);
// https://stackoverflow.com/a/1653826
// updated for PHP 8
function bcceil(string $number): string
{
if (str_contains($number, '.')) {
if (preg_match("~\.[0]+$~", $number)) {
@tored
tored / getOptions.php
Last active September 30, 2021 17:33
getOptions: experimental command line parser for PHP by using attributes
<?php
declare(strict_types=1);
#[Attribute(Attribute::TARGET_FUNCTION | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
final class Option
{
public function __construct(
public string|null $short = null,
public string|null $long = null,
public bool $required = false,
@tored
tored / asciiTable.php
Last active August 11, 2021 09:18
asciiTable
<?php
declare(strict_types=1);
function asciiTable(array $rows, array $columns, ?callable $mapper = null): string
{
if ($mapper === null) {
$mapper = function (string $column, $value) {
return $value;
};
}
@tored
tored / php.cmd
Last active May 2, 2020 15:26
Configurable execution of PHP scripts in Windows
@echo off
if "%PHP%"=="" (
echo %%PHP%% is NOT defined
exit /b
)
%PHP% %*
@tored
tored / phps.php
Last active April 30, 2020 11:03
Auto-download composer dependencies for php script
#!/usr/bin/env php
<?php
declare(strict_types=1);
const PHPS = 'phps';
const COMMENT = '#';
const BANG = '!';
if (empty($argv[1])) {
throw new RuntimeException("Missing php file");
@tored
tored / msn.ps1
Created June 21, 2017 11:34
MSN block
New-NetFirewallRule -DisplayName "Block Microsoft Edge News Feed by IP" -RemoteAddress "204.79.197.203" -Action "Block" -Direction "Outbound" -Package "S-1-15-2-3624051433-2125758914-1423191267-1740899205-1073925389-3782572162-737981194"
@tored
tored / fork.php
Last active September 20, 2016 08:55
fork - simple fork for both Windows (with PowerShell) and Un*x (with Bash) in PHP. Returns PID.
<?php
function fork($program, ...$args): int
{
if (strtoupper(php_uname('s')) === 'WINDOWS NT') {
$cmd = [
'powershell.exe',
'-Command',
'$proc',
'=',