Skip to content

Instantly share code, notes, and snippets.

@JanTvrdik
JanTvrdik / bench.php
Last active October 10, 2018 06:41
PHP quick benchmark skeleton
<?php
$runCount = 1000;
$dataSets = [
'setA' => [$runCount, 123],
];
$tests = [
'testA' => function ($count, $n) {
DELIMITER ;;
DROP PROCEDURE IF EXISTS `normalize_foreign_key_name`;;
CREATE PROCEDURE `normalize_foreign_key_name`(IN `param_database_name` varchar(100) CHARACTER SET 'ascii', IN `param_table_name` varchar(100) CHARACTER SET 'ascii', IN `param_column_name` varchar(100) CHARACTER SET 'ascii')
BEGIN
DECLARE var_constraint_name_current VARCHAR(100);
DECLARE var_constraint_name_new VARCHAR(100);
DECLARE var_constraint_target_table VARCHAR(100);
@JanTvrdik
JanTvrdik / do
Last active August 29, 2015 14:28
Nette Dev Kit
#!/bin/env bash
while read dir
do
sh -c "cd \"$dir\" && echo && pwd && $*"
done

Keybase proof

I hereby claim:

  • I am JanTvrdik on github.
  • I am jantvrdik (https://keybase.io/jantvrdik) on keybase.
  • I have a public key whose fingerprint is E42B 2FFA 3D04 F044 087B BB87 424D C177 9989 AB3A

To claim this, I am signing this object:

@JanTvrdik
JanTvrdik / loadCacheFile.php
Last active December 13, 2016 21:51
General purpose thread-safe cache function
<?php
/**
* @param string $file
* @param callable $tryLoad (string $file, mixed & $data): bool
* @param callable $isExpired (string $file): bool
* @param callable $fallback (string $file): string
* @return mixed
*/
function loadCacheFile($file, $tryLoad, $isExpired, $fallback)
@JanTvrdik
JanTvrdik / .bashrc
Last active June 14, 2022 04:14 — forked from gsomoza/.bashrc
ssh-agent support for Git Bash / MinGW / msys / Windows
# put this in ~/.bashrc
export SSH_AUTH_SOCK=/tmp/.ssh-socket
ssh-add -l > /dev/null
if [ $? = 2 ]; then
rm -f $SSH_AUTH_SOCK
echo Starting new ssh-agent...
eval $(ssh-agent -a $SSH_AUTH_SOCK) > /dev/null
ssh-add && echo "ssh-agent set up successfully with the following keys:" && ssh-add -l
fi
@JanTvrdik
JanTvrdik / bench.md
Created October 26, 2014 16:31
StaticRouter benchmark

Benchmark for Nextras\StaticRouter

Source code

Test __construct:
  StaticRouter                21 ms         +0 %
  Route + RouteList         1392 ms      +6529 %
 Route + global filter 244 ms +1062 %
<?php
function createParagraphs($html)
{
$html = '<meta http-equiv="content-type" content="text/html;charset=utf-8"><body>' . $html;
$document = new DOMDocument();
$document->loadHTML($html);
$body = $document->getElementsByTagName('body')->item(0);
$inlineTags = ['a', 'b', 'del', 'em', 'i', 'img', 'ins', 'small', 'span', 'strong'];
$create = TRUE;
@JanTvrdik
JanTvrdik / Dumper.php
Last active August 29, 2015 13:58
JSOND - JSON compatibility test
<?php
/**
* This file is part of the Tracy (http://tracy.nette.org)
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/
namespace Tracy;
use Tracy;
{
"bold_folder_labels": true,
"close_windows_when_empty": true,
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"default_line_ending": "unix",
"enable_tab_scrolling": false,
"ensure_newline_at_eof_on_save": true,
"fallback_encoding": "Central European (Windows 1250)",
"font_face": "Consolas",
"font_size": 12,