Skip to content

Instantly share code, notes, and snippets.

View drealecs's full-sized avatar
😒

Alexandru Pătrănescu drealecs

😒
View GitHub Profile
@drealecs
drealecs / benchmark.php
Created October 20, 2023 11:31
benchmark function that iterates multiple times through the callables received and benchmark their speed
<?php
function benchmark(callable ...$functions): void
{
$times = array_combine(array_keys($functions), array_fill(0, count($functions), 0.));
$baseTime = 0.;
$baseCallable = fn() => null;
$start = hrtime(true);
$count = 0;
@drealecs
drealecs / browser_bookmark_jquery_inject.js
Created April 3, 2022 04:40
script that can be configured as bookmark in the browser to easily inject jQuery in any page
javascript:(function(s){e=document.createElement('script');e.src=s;e.onload=function(){$jq=jQuery.noConflict(true);console.log('jQuery injected as $jq: ' + $jq.fn.jquery)};document.head.appendChild(e)})('//code.jquery.com/jquery-git.min.js')
@drealecs
drealecs / keybase.md
Created June 17, 2020 13:11
keybase.md

Keybase proof

I hereby claim:

  • I am drealecs on github.
  • I am drealecs (https://keybase.io/drealecs) on keybase.
  • I have a public key whose fingerprint is DF3A CCE7 864B EA64 AE03 84CF E1B5 CA70 5BC6 5BD2

To claim this, I am signing this object:

@drealecs
drealecs / gc_test.php
Last active March 7, 2019 13:24
PHP 7.3 non recursive GC performance comparison
<?php
class Node
{
/** @var Node */
public $previous;
/** @var Node */
public $next;
}
@drealecs
drealecs / JsonCsvEscapingTest.java
Created April 27, 2018 08:34
json csv escaping
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import java.io.IOException;
public class JsonCsvEscapingTest {
public static void main(String[] args) throws IOException {
int intColumnValue = 5;
@drealecs
drealecs / CachedNotRewindableIteratorAggregate.php
Last active February 26, 2021 13:23
Cached Iterator wrapper over iterators that does not support rewinding, like a Generator that emits value objects.
<?php
class CachedNotRewindableIteratorAggregate implements IteratorAggregate {
private Iterator $iterator;
private array $cache = [];
public function __construct(Iterator $iterator) {
$this->iterator = $iterator;
}
public function getIterator(): Iterator {
$index = 0;
@drealecs
drealecs / check1.php
Created February 26, 2017 20:35
search files and filter
<?php
if ($argc < 2) {
die("Please pass a directory as argument\n");
}
$path = $argv[1];
if (!(new SplFileInfo($path))->isDir()) {
die("'{$path}' is not directory!\n");
@drealecs
drealecs / hs-death-level.php
Created December 11, 2016 13:38
hearthstone global level
<?php declare(strict_types = 1);
$game = new GameState(5000);
for ($i = 0; $i < 100; $i++) {
$game->step(100);
}
$game->resetDeathLevels();
for ($i = 0; $i < 1000; $i++) {