Skip to content

Instantly share code, notes, and snippets.

@vhenzl
vhenzl / find-imports.mjs
Created May 19, 2023 03:19
Script to find all imports from a module in JS/TS code
#! /usr/bin/env node
// Based on https://github.com/montlebalm/find-js-imports
import { readFileSync } from 'fs';
import { basename } from 'path';
import glob from 'glob';
import { fileURLToPath } from 'url';
// https://gist.github.com/manekinekko/7e58a17bc62a9be47172
const IMPORT_RX = /^import (?:["'\s]*([\w*{}\n, ]+) from\s*)?["'\s]*([.@\w\/_-]+)["'\s]*;?/gm;
@vhenzl
vhenzl / MapBench.php
Last active September 18, 2021 05:05
`array_map()` vs `foreach` vs an utility (PHP benchmark)
<?php declare(strict_types=1);
namespace GraphQL\Benchmarks;
function identity($value, $key = null)
{
return $value;
}
@vhenzl
vhenzl / dotfiles
Last active January 24, 2021 21:10
Installation script for https://github.com/vhenzl/dotfiles
git clone --bare git@github.com:vhenzl/dotfiles.git $HOME/.dotfiles
function dotfiles {
git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME $@
}
mkdir -p .dotfiles-backup
dotfiles checkout
if [ $? = 0 ]; then
echo "Checked out dotfiles.";
else
echo "Backing up pre-existing dot files.";
@vhenzl
vhenzl / index.php
Last active September 17, 2020 03:23
PHP: static variable vs static field
<?php
// https://3v4l.org/ZoCO0
class X
{
static $y = 0;
static $z = 0;
public static function test()
@vhenzl
vhenzl / _readme.md
Last active February 21, 2022 09:29
Awesome whatever (PHP, DDD, CQRS, events & messaging, Doctrine, REST & APIs, PHPStorm,... links)

Awesome whatever

Collection of various links – blogs, articles, libraries/frameworks & repos, etc. Not necessarily really awesome.

Content

@vhenzl
vhenzl / key-checks.sql
Last active May 12, 2016 01:02
MySQL database keys checks
set @table_schema = 'zhf';
-- ### Find missing foreign keys ###
-- select all columns ending with 'Id' (are supoused to be FK) which don't have key starting with 'FK_'
select c.table_schema, c.table_name, c.column_name, c.column_type
from information_schema.columns c
left join information_schema.key_column_usage k on (
c.table_schema = k.table_schema and
c.table_name = k.table_name and
c.column_name = k.column_name and
@vhenzl
vhenzl / cleanup.md
Created May 11, 2016 22:22
Docker clean-up
@vhenzl
vhenzl / .gitignore
Last active March 1, 2016 20:23
Sublime Text settings
# Ignore everything
*
# But not these files...
!.gitignore
!Default (Windows).sublime-keymap
!Preferences.sublime-settings
!Package Control.sublime-settings
!PHP.sublime-settings
!phpfmt.sublime-settings
@vhenzl
vhenzl / excel-user-functions.md
Created July 16, 2015 12:56
Zjištění úrovně odsazení v Excelu pomocí vlastní funkce

V Excelu pomocí Alt+F11 otevřít Microsoft Visual Basic for Applications, zde vytvořit nový modul (Insert a Module) a vložit kód požadované funkce (v tomto případě funkce, která zjistí úroveň odsazení textu):

Function indent(r As Range) As Integer
  indent = r.IndentLevel
End Function

Po přepnutí zpět do Excelu je dostupná jako jakákoliv jiná funkce: =indent(A1).