Skip to content

Instantly share code, notes, and snippets.

View kobus1998's full-sized avatar
😳
-10x programmer

Kobus kobus1998

😳
-10x programmer
View GitHub Profile
@kobus1998
kobus1998 / guzzle-history-mw.php
Created September 20, 2022 11:44
middleware class for guzzlehttp
<?php
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\Client;
class History
{
@kobus1998
kobus1998 / debounce.js
Last active September 7, 2022 08:21
debounce
function doAThing(a) {
console.log('aaaa', a);
}
function doBThing(a, b) {
console.log('bbb', a, b);
}
// var timeoutdebounce
@kobus1998
kobus1998 / simpleCalculator.php
Created May 16, 2022 14:50
simple calculator
<?php
(new class {
const SCALE = 14;
public function __invoke()
{
while(true) {
$i = $this->parseFloat(readline("number: "));
$operator = trim(readline("operator: "));
@kobus1998
kobus1998 / parse-argv.php
Created April 28, 2022 11:17
parse argv arguments
<?php
(new class {
public function __invoke()
{
$aArgs = $this->parseArgv($GLOBALS['argv']);
var_dump($aArgs);
die("\n");
@kobus1998
kobus1998 / round.php
Last active March 7, 2022 15:32
round
<?php
function round($f, $to = 2)
{
list($major, $decimals) = explode('.', $f);
$digits = str_split($decimals);
$digits = array_reverse($digits);
$count = count($digits) - 1;
@kobus1998
kobus1998 / wtf.php
Created November 24, 2021 13:03
wtf
<?php
echo sprintf("%2\$s's balance: %3\$s %1$'910s\n", '1', 'john doe', html_entity_decode('&euro;'));
@kobus1998
kobus1998 / readme.md
Created November 5, 2021 13:41
os x productivity
@kobus1998
kobus1998 / while-polling.php
Created October 22, 2021 12:45
while, polling
<?php
$i = 0;
$var = function () use (&$i) {
$i++;
return $i;
};
$iSeconds = 0;
while(($i2 = $var()) < 4 && $iSeconds <= 4) {
@kobus1998
kobus1998 / ping.php
Created September 13, 2021 13:59
average ping from server
#!/usr/local/bin/php -q
<?php
// php ping.php google.com
$sHost = escapeshellarg($argv[1] ?? 'localhost');
$sCmd = "ping {$sHost}";
echo $sCmd . "\n";
@kobus1998
kobus1998 / Container.php
Last active August 16, 2021 14:45
minimal di-container
<?php
class Container {
public $config;
public $cache = [];
public function __construct($config)
{
$this->config = $config;