Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Chun-Sheng, Li peter279k

🎯
Focusing
Block or report user

Report or block peter279k

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@odan
odan / SameSiteCookieMiddleware.php
Last active Sep 7, 2019
SameSite Cookie Middleware (PSR-15)
View SameSiteCookieMiddleware.php
<?php
namespace App\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
/**
@Seldaek
Seldaek / ext-requires.txt
Last active Sep 23, 2019
PHP Extension Requirements on Packagist.org
View ext-requires.txt
Taken from packagist.org
Packages with a master branch update since June 1st 2018: 98977
Of those, package having requires on PHP extensions: 11676 (11.79%)
As only ~12% of packages declare their extension requirements,
and even then it might not be a complete list, take all this with
a big grain of salt, it is informative but definitely not a
complete picture of the most used extensions.
@odan
odan / slim4-getbaseurl.md
Created Aug 31, 2019
Slim 4 - getBaseUrl middleware
View slim4-getbaseurl.md

Slim 4 - getBaseUrl middleware

It looks like the App::getBaseUrl method has been removed in Slim 4 (because it's not part of PSR-7).

As replacement you could use this Middleware to detect the baseUrl:

<?php

namespace App\Middleware;
@bessarabov
bessarabov / gist:674ea13c77fc8128f24b5e3f53b7f094
Last active Oct 21, 2019
One-liner to generate data shown in post 'At what time of day does famous programmers work?' — https://ivan.bessarabov.com/blog/famous-programmers-work-time
View gist:674ea13c77fc8128f24b5e3f53b7f094
git log --author="Linus Torvalds" --date=iso | perl -nalE 'if (/^Date:\s+[\d-]{10}\s(\d{2})/) { say $1+0 }' | sort | uniq -c|perl -MList::Util=max -nalE '$h{$F[1]} = $F[0]; }{ $m = max values %h; foreach (0..23) { $h{$_} = 0 if not exists $h{$_} } foreach (sort {$a <=> $b } keys %h) { say sprintf "%02d - %4d %s", $_, $h{$_}, "*"x ($h{$_} / $m * 50); }'
View zipbomp-detector.php
<?php
$filename = '42.zip';
echo 'Filename: ' . $filename . "\n";
$zip = new ZipArchive();
$zip->open($filename, ZIPARCHIVE::CHECKCONS);
$i=0;
$size = 0;
View gist:c48704ebe850b0f7f34c7bac2b5d6ee6
public function byId(string $id)
{
$query = [
'source' => [
'query' => [
'query_string' => [
'fields' => ['id'],
'query' => $id,
],
],
@peter279k
peter279k / Dockerfile
Last active Apr 30, 2019
This is Docker image about the PHP+MSSQL enviroment
View Dockerfile
# Install required packages
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN apt-get install -y python-software-properties
RUN LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
RUN apt-get update
RUN apt-get install -y apt-transport-https apt-utils curl php7.1-cli php7.1-mysql php7.1-curl
RUN apt-get install -y php7.1-xml php7.1-dom php7.1-xsl php7.1-json php7.1-odbc php7.1-dev
RUN apt-get install -y libcurl3-openssl-dev
@heineiuo
heineiuo / lint.js
Created Aug 29, 2018
use standardjs with pre-commit hook
View lint.js
const { exec } = require('shelljs')
const path = require('path')
const exit = () => {
console.log('JavaScript Standard Style errors were detected. Aborting commit.')
process.exit(1)
}
const gitdiff = exec(`git diff --name-only --cached --relative`)
if (gitdiff.stderr) {
@nicolas-grekas
nicolas-grekas / rfc-secure-unserialize.md
Last active Jul 18, 2019
RFC for a Secure Unserialization Mechanism in PHP
View rfc-secure-unserialize.md

RFC for a Secure Unserialization Mechanism in PHP

Scope

PHP serialization/unserialization has several drawbacks [^1].

On the serialization side, the Serializable interface:

  • breaks hard and soft references inside serialized data structures;
You can’t perform that action at this time.