Skip to content

Instantly share code, notes, and snippets.

View loilo's full-sized avatar

Florian Reuschel loilo

View GitHub Profile
@loilo
loilo / Debouncer.md
Last active November 21, 2022 08:24
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
loilo / high-sierra-iso.md
Last active January 12, 2023 05:26
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
loilo / vue.config.js
Created August 3, 2018 20:29
Activate Object Spread in Templates of a Vue CLI v3 Project
// 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 => {
config.module
.rule('vue')
.use('vue-loader')
@loilo
loilo / pass-slots.md
Last active June 4, 2024 02:12
Vue: Pass Slots through from Parent to Child Components

Vue: Pass Slots through from Parent to Child Components

The Situation

  • We've got some components A, B and C which provide different slots.
    const A = {
      template: `<div><slot name="a">Default A Content</slot></div>`
    }

const B = {

@loilo
loilo / DNode.php
Last active August 31, 2018 06:54
DNode Comfort Interface (Node.js Server, PHP Client)
<?php
require_once __DIR__ . "/vendor/erasys/dnode-php-sync-client/DnodeSyncClient.php";
class DNode
{
protected $connection;
public static function connect($host, $port)
{
@loilo
loilo / HashStateManager.js
Last active May 11, 2018 12:42
Synchronize shareable key-value state to the window.location.hash as human-readable as possible
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
loilo / DomKeepAlive.md
Last active October 2, 2023 13:48
Keep pre-existing DOM nodes alive inside Vue components

Keep pre-existing DOM alive in Vue

For my use cases, Vue has one critical pitfall: I frequently have/want to use Vue components with <slot>s as wrappers for content from a CMS which I don't have control over. That is, the content comes over the wire via HTML, and I have to activate Vue for some of it.

<interactive-element>
  <p>Slot content I don't have control over</p>
</interactive-element>

I need to activate the Vue component <interactive-element>.

@loilo
loilo / split-pull-requests.md
Last active April 3, 2024 07:24
Split a large pull request into two
@loilo
loilo / magic-methods.js
Last active April 25, 2024 13:58
PHP Magic Methods in JavaScript
function magicMethods (clazz) {
// A toggle switch for the __isset method
// Needed to control "prop in instance" inside of getters
let issetEnabled = true
const classHandler = Object.create(null)
// Trap for class instantiation
classHandler.construct = (target, args, receiver) => {
// Wrapped class instance
@loilo
loilo / argstr.md
Last active September 27, 2019 21:11
Build a command line arguments string from a PHP associative array

PHP arg string generator

Generate a command line arg string from an associative array.

This is purely built for functionality, not for beauty: no grouping of shorthand flags, all args will be escaped and wrapped in single quotes, no matter if needed or not.

Usage

Associative key-value pairs will be treated as command line options while array entries with no/integer keys will be used as regular arguments.