Skip to content

Instantly share code, notes, and snippets.


Niklas Keller kelunik

View GitHub Profile
bwoebi /
Last active Dec 15, 2021
fread() on non-blocking sockets

Reading of non-blocking TCP sockets in PHP

As a short heads-up for those unfamiliar:

  • There is a PHP level buffer. Whenever more is actually read from the socket (default chunk size is 8192), than the user requests in his PHP code, the data is stored there.
  • There is an OS level buffer. There all incoming network data lands. The event loop only knows of that one and checks that one for being non-empty.

Trivial single read

The trivial reading function in PHP is fread($socket, $maxSize).

halfnibble / HashFunction.ts
Last active Oct 6, 2020
Hash function to debug absolute paths sent to the update chunk hash method in webpack.
View HashFunction.ts
import * as crypto from 'crypto';
import * as fs from 'fs';
import * as path from 'path';
* Interface for Webpack's hashFunction
export interface IHashFunction {
update: (data: string | Buffer, encoding: string) => IHashFunction;
digest: (encoding: string) => string | Buffer;
theseer /
Created Mar 24, 2019
What happend to the `If-Modified-Since` header?

If-Modified-Since, PHP CLI Server and Firefox


When sending the cache control header Cache-Control: no-cache, must-revalidate along with a Last-Modified timestamp, the browser is required to send along an If-Modified-Since header for the next request to the same URL.

The server then is entitled to return HTTP/1.1 304 Not modified in case the content didn't change and the stored copy may still be used.

Sample Code

liamnewmarch / format-relative.js
Last active Apr 7, 2021
Relative time strings using the web platform
View format-relative.js
* The target language. [Browser support is good][1] but "en-US" is a safe default.
* [1]:
* @type {string}
const { language = "en-US" } = navigator;
OvalPa / amp_client.php
Created Dec 14, 2017
Performance testing for php-asio and Amp
View amp_client.php
require_once __DIR__ . '/../vendor/autoload.php';
use Amp\Loop;
Loop::run(function () {
global $start_time;
$start_time = microtime(true);
$socket = stream_socket_client('tcp://');
silkentrance / MyComponent.ts
Last active Mar 10, 2021
vue-router typescript integration fails
View MyComponent.ts
import Vue from 'vue';
import Component from 'vue-class-component';
name : 'component'
export default class MyComponent extends Vue {
beforeCreate() {
haskaalo /
Last active Dec 29, 2021
Tar usage / Tar Cheat Sheet

Tar Usage / Cheat Sheet

Compress a file or directory

e.g: tar -czvf name-of-archive.tar.gz /path/to/directory-or-file

  • -c: Create an archive.
  • -z: Compress the archive with gzip.
  • -v: makes tar talk a lot. Verbose output shows you all the files being archived and much.
  • -f: Allows you to specify the filename of the archive.
hikari-no-yume / example.php
Created Mar 20, 2017
function chaining for PHP 7
View example.php
<?php declare(strict_types=1);
require_once "✨.🐘";
rambabusaravanan / .gitconfig
Last active Jan 4, 2022
Git Diff and Merge Tool - IntelliJ IDEA
View .gitconfig
# Linux
# add the following to "~/.gitconfig" file
tool = intellij
[mergetool "intellij"]
cmd = /usr/local/bin/idea merge $(cd $(dirname "$LOCAL") && pwd)/$(basename "$LOCAL") $(cd $(dirname "$REMOTE") && pwd)/$(basename "$REMOTE") $(cd $(dirname "$BASE") && pwd)/$(basename "$BASE") $(cd $(dirname "$MERGED") && pwd)/$(basename "$MERGED")
trustExitCode = true
DaveRandom / .gitignore
Created Aug 2, 2016
Default repository layout - PHP web application
View .gitignore
vendor # ignore composer data
# ignore PHP Storm config
# you may want to ignore your IDE config and you may want to commit it, up to you