Skip to content

Instantly share code, notes, and snippets.

View voku's full-sized avatar
:octocat:
There is nothing good unless you do it.

Lars Moelleken voku

:octocat:
There is nothing good unless you do it.
View GitHub Profile
@voku
voku / popstate_reload.js
Created January 7, 2016 15:08
reload on history-back with "history.pushState" usage
/**
* reload on history-back with "history.pushState" usage
*
* Necessary hack because WebKit fires a popstate event on document load
* https://code.google.com/p/chromium/issues/detail?id=63040
* https://bugs.webkit.org/process_bug.cgi
*/
$(window).bind('load', function() {
if (Modernizr.history) {
setTimeout(function() {
@voku
voku / gist:4ad5a27836ae7c5100b746848e30d278
Last active October 11, 2023 21:48
Me as chat bot. 😁
Respond with tree of thought reasoning in the persona of a senior php developer and architect "Lars Moelleken" (github.com/voku) who does code reviews and curses a lot. He writes modern / strict php code with types and if needed with phpdoc annotations from phpstan (for example : generics, array shapes, int-ranges, non-empty-strings or class-strings). He already applied php-cs-fixer, php-sniffer and phpstan max level and fixed all reported problems in the generated code. He prefers real objects instead of arrays, immutable classes, final methods, private or readonly / typed properties and always applies best practice OOP design patterns in the code while beng very concise and calculative like this:
📉Kanban:"A kanban table of the project state with todo, doing, done columns."
🧐Problem: "A {system 2 thinking} description of the problem in first principles and super short {system 1 thinking} potential solution."
🌳Root Cause Analysis (RCA):"Use formal troubleshooting techniques like the ones that electricians, m
@voku
voku / clean_code.md
Created September 1, 2023 10:53 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@voku
voku / DotNotation.php
Created February 4, 2016 02:03 — forked from antonmedv/DotNotation.php
Dot notation for access multidimensional arrays.
<?php
/**
* Dot notation for access multidimensional arrays.
*
* $dn = new DotNotation(['bar'=>['baz'=>['foo'=>true]]]);
*
* $value = $dn->get('bar.baz.foo'); // $value == true
*
* $dn->set('bar.baz.foo', false); // ['foo'=>false]
*
@voku
voku / clear_requests.php
Last active October 30, 2022 03:59
a php-function that will fixing utf-8 problems from inputs and prevent XSS attacks
<?php
// require
//
// "Portable UTF-8" -> https://packagist.org/packages/voku/portable-utf8
// "HTMLPurifier" -> https://packagist.org/packages/ezyang/htmlpurifier
use voku\helper\UTF8;
// init HTMLPurifier (TODO: move this e.g. to a WrapperClass)
@voku
voku / gist:d958041e7b1c19356e721de1eda1e6f8
Last active September 8, 2022 11:35
.htaccess with many options + description
# Apache Server Configs v5.1.0 | MIT License
# https://github.com/h5bp/server-configs-apache
# (!) Using `.htaccess` files slows down Apache, therefore, if you have
# access to the main server configuration file (which is usually
# called `httpd.conf`), you should add this logic there.
#
# https://httpd.apache.org/docs/current/howto/htaccess.html
# ######################################################################
#!/usr/bin/php
<?php
$output = [];
exec('[ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] && echo "remote" || echo "local"', $output);
if ($output[0] != 'local') {
echo "Run this script only on your computer!\n\n";
// @codingStandardsIgnoreStart
exit(1);
// @codingS
<?php
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
final class VdmgReturnIntValueCheckSniff implements Sniff {
/**
* String representation of error.
*
<?php
declare(strict_types=1);
namespace vdmg\App\scripts\githooks\StandardVdmg\PHPStan;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
@voku
voku / global_js_error_handling.html
Last active November 25, 2021 10:16
global js error handling via "window.onerror"
<script type="text/javascript">
var one_error_reported_via_onerror = false;
var globalErrorReportHelper = function(msg, url, line, col, error) {
// fallback for e.g.: IE
if (
!error
&&
typeof Error === "function"