Skip to content

Instantly share code, notes, and snippets.

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 / 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
View clear_requests.php
<?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
View gist:d958041e7b1c19356e721de1eda1e6f8
# 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
# ######################################################################
@voku
voku / DotNotation.php
Created February 4, 2016 02:03 — forked from antonmedv/DotNotation.php
Dot notation for access multidimensional arrays.
View DotNotation.php
<?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]
*
View disallow_ssh_exec.php
#!/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
View VdmgReturnIntValueCheckSniff.php
<?php
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
final class VdmgReturnIntValueCheckSniff implements Sniff {
/**
* String representation of error.
*
View VdmgNoDuplicateNegativIfConditionRule.php
<?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"
View global_js_error_handling.html
<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"
@voku
voku / StringLib.php
Created May 2, 2018 07:07
simple, small and dependency-free version of https://github.com/voku/portable-utf8
View StringLib.php
<?php
/**
* Class StringLib
*
* @see https://github.com/voku/portable-utf8
*/
class StringLib {
/**
@voku
voku / validation_date.php
Created June 5, 2014 05:55
date format validation: Validate a date in "YYYY-MM-DD" format. - From http://snippetlib.com/php/date_format_validation
View validation_date.php
<?php
/**
* check for date-format
*
* @param string $date valid is only "YYYY-MM-DD"
*
* @return bool
*/
function checkDateFormat($date)
@voku
voku / code_check_git_hook.php
Created December 10, 2018 23:05
A pre-commit-hook example with Code Sniffer + Code Fixer + PHPStan
View code_check_git_hook.php
#!/usr/bin/php
<?php
/**
* //
* // add something like this in your "composer post-update-cmd && post-install-cmd"
* //
* echo "\n\n";
* echo "Run force \"code_check_git_hook.php\" as pre-commit-hook ...";
* $force_pre_commit_hook_cmd = 'ln -sf YOUR_PATH_TO_CODE_CHECK_SCRIPTS/code_check_git_hook.php YOUR_PATH_TO_PROJECT_ROOT/.git/hooks/pre-commit';