Skip to content

Instantly share code, notes, and snippets.


Florian Reuschel loilo

View GitHub Profile
loilo / reset.js
Last active Nov 3, 2017
Reset a single form element
View reset.js
// Resets a given form element
function resetInput (input) {
// 1. Remember the <input> position by grabbing sibling and parent
const next = input.nextSibling
const parent = input.parentNode
// 2. Create a temporary <form> element, put the <input> there and reset that form
const tmpForm = document.createElement('form')
loilo / HashStateManager.js
Last active May 11, 2018
Synchronize shareable key-value state to the window.location.hash as human-readable as possible
View HashStateManager.js
class HashStateManager {
constructor ({ global = window, prefix = '!' } = {}) {
this.window = global
this.prefix = prefix
this.callbacks = new Set
this.urlListenerEnabled = true
this.boundUrlListener = this.urlListener.bind(this)
this.internalState = this.parseState()
this.publicState = this.createState()
loilo /
Last active Jun 9, 2018
Parses column-formatted UNIX output

PHP Column Parser

This PHP class takes a block of column-styled UNIX output (e. g. from composer show) and dissects it into lines and columns.

Take this excerpt from running the mentioned command in a Symfony project:

doctrine/cache               v1.7.1 Caching library offering an object-oriented API for many cache backends
doctrine/inflector           v1.2.0 Common String Manipulations with regard to casing and singular/plural rules.
illuminate/contracts         v5.5.2 The Illuminate Contracts package.
illuminate/support           v5.5.2 The Illuminate Support package.
loilo / vue.config.js
Created Aug 3, 2018
Activate Object Spread in Templates of a Vue CLI v3 Project
View vue.config.js
// Store this as vue.config.js in your project root
// to enable object spread in templates.
// Note that you'll need to provide an Object.assign()
// polyfill for legacy browsers.
module.exports = {
chainWebpack: config => {
loilo /
Last active Aug 30, 2018
Create an installation ISO file for macOS High Sierra
  1. Prerequisites:
    • You need a running macOS system.
    • I assume you're familiar with using the terminal.
    • All the examples below refer to installing macOS High Sierra, you may need to adjust them to your needs if you want to install another macOS version.
  2. Download macOS High Sierra from the AppStore.
  3. The macOS installer will start after the download finiashes. We don't need it, so we can close it.
  4. We need an empty image where we'll put the installer. Let's create one using the macOS DiskUtil CLI:
    hdiutil create -o /tmp/HighSierra -size 8G -layout SPUD -fs HFS+J -type SPARSE
loilo / DNode.php
Last active Aug 31, 2018
DNode Comfort Interface (Node.js Server, PHP Client)
View DNode.php
require_once __DIR__ . "/vendor/erasys/dnode-php-sync-client/DnodeSyncClient.php";
class DNode
protected $connection;
public static function connect($host, $port)
loilo /
Last active Oct 3, 2018
ReactPHP debounce

ReactPHP Debouncer

A simple & classic debounce function. You provide a callable and specify a $wait timer and get a callable (closure) back.

The closure takes the same arguments as the provided callable, but will only be executed $wait seconds after being invoked. Invoking the closure again before $wait seconds have passed will refresh the execution delay to the full $wait seconds again.

This can be useful for example for detecting if a socket hasn't received data in, let's say, 10 seconds:

$loop = React\EventLoop\Factory::create();
loilo /
Created Oct 24, 2018
Structural Extraction of PHP Arrays

Structural Extraction of PHP Arrays

Extract structures from PHP arrays, kind of like an advanced pluck.


The provided xtract function takes a $source (usually an array) and a $target, which is the structure to transform the $source into:

mixed xtract( mixed $source, mixed $target )

Simple Examples

loilo /
Last active Dec 5, 2018
(An Approach to) Vue.js Template Variables

(An Approach to) Vue.js Template Variables

This has first been published as an article on

The Problem

From time to time, I have the need to temporarily store the results of a method call in Vue templates. This is particularly common inside loops, where we cannot easily use computed properties.

Basically what we'd want to avoid is this:

<!-- List.vue -->
loilo /
Last active Jan 9, 2019
Wozu Entwickler async/await brauchen

Besseres Scoping mit async/await


Wie greife ich auf frühere Ergebnisse in der Promise-Chain zurück?

    .then(response => {
      //  ^ man beachte diese Variable
      return expensiveEvaluation(
You can’t perform that action at this time.