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 / pg-backup.sh
Last active January 17, 2024 19:25
Rotating PostgreSQL Backup Script
#!/bin/bash
# for use with cron, eg:
# 0 3 * * * postgres /var/db/pg-backup.sh foo_db
if [[ -z "$1" ]]; then
echo "Usage: $0 <db_name> [pg_dump args]"
exit 1
fi
num_args=$#
max_runs=$1
sleep=$2
cmd=$3
shift 3
args=("$@")
runs=0
[[ $num_args -le 2 ]] && echo "Usage retry.sh <sleep> <retry_times> <command>" && exit 0;
until [[ $runs -ge $max_runs ]]
do
class Errors {
/**
* Create a new Errors instance.
*/
constructor() {
this.errors = {};
}
/**
@ghostwriter
ghostwriter / wip.md
Created September 20, 2023 18:14
Generating and submitting fake data to phishing sites is illegal and unethical

Generating and submitting fake data to phishing sites is illegal and unethical, even if they are engaged in phishing activities.

Preventative measures such as educating others about phishing attacks, using strong and unique passwords, enabling two-factor authentication, and being cautious when clicking on suspicious links or providing personal information online is not enough.

If we come across a phishing site, who are the appropriate authorities taking necessary actions to address the issue?

@ghostwriter
ghostwriter / issue.phpt
Created August 25, 2023 04:18
PHPUnit 10 Issue - Testdox missing error messages
--TEST--
Testdox: Missing force-covers-annotation error messages "This test does not define a code coverage target but is expected to do so".
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--testdox';
$_SERVER['argv'][] = '--display-errors';
$_SERVER['argv'][] = '--display-notices';
$_SERVER['argv'][] = '--display-warnings';
$_SERVER['argv'][] = '--display-deprecations';
@ghostwriter
ghostwriter / FooTest.php
Created August 25, 2023 03:14
#PHPUnit `expect*()` replacement.
<?php
declare(strict_types=1);
namespace Foo\Tests\Unit;
final class FooTest extends TestCase
{
public function testFoo(): void
{
@ghostwriter
ghostwriter / README.md
Created August 23, 2023 20:45
Here is subset of the commands (and some variations) for copilot-voice

copilot-voice commands list

https://githubnext.com/projects/copilot-voice/ - formerly known as "Hey, GitHub!"

  • cancel selection
  • clear chat history
  • copy file path to clipboard
  • copy relative file path to clipboard
  • cursor down
  • cursor right
@ghostwriter
ghostwriter / isPHPUnit.php
Created August 15, 2023 20:31
is PHPUnit running?
<?php
declare(strict_types=1);
public function isPHPUnit(): bool
{
return \defined('PHPUNIT_COMPOSER_INSTALL') || \defined('__PHPUNIT_PHAR__');
}
@ghostwriter
ghostwriter / benchmark.php
Created July 23, 2023 12:15
Benchmark `match`, `switch`, and `if` Statements
<?php
use PhpBench\Benchmark\Metadata\Annotations\BeforeClassMethods;
use PhpBench\Benchmark\Metadata\Annotations\Iterations;
use PhpBench\Benchmark\Metadata\Annotations\Revs;
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
use PhpBench\Benchmark\Metadata\Annotations\OutputTimeUnit;
class StatementBenchmark
{
<?php
declare(strict_types=1);
use Rector\CodingStyle\Rector\ArrowFunction\StaticArrowFunctionRector;
use Rector\CodingStyle\Rector\Closure\StaticClosureRector;
use Rector\Config\RectorConfig;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector;
use Rector\Php70\Rector\FuncCall\RandomFunctionRector;