Skip to content

Instantly share code, notes, and snippets.

View loilo's full-sized avatar

Florian Reuschel loilo

View GitHub Profile
@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 / 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 / xtract.md
Created October 24, 2018 14:17
Structural Extraction of PHP Arrays

Structural Extraction of PHP Arrays

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

Signature

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
loilo / readme.md
Last active December 5, 2018 08:29
(An Approach to) Vue.js Template Variables

(An Approach to) Vue.js Template Variables

This has first been published as an article on dev.to.

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
loilo / NodePathResolver.md
Last active April 10, 2023 16:26
Node Path Resolver in PHP
@loilo
loilo / compare-files.js
Last active December 2, 2022 03:43
Compare File Lists in Node.js
import revHash from 'rev-hash'
import { readFileSync, statSync } from 'fs'
import { resolve } from 'path'
/**
* Calculate the rev hash for a file
*
* @param {string} file The path to the file to hash
* @returns {string}
*/
@loilo
loilo / readme.md
Created January 9, 2019 11:41
Access PHP Variables in Nested Closures

Access PHP Variables in Nested Closures

This post was inspired by having to pass around ReactPHP's event loop all day.

😑 Are you tired of managing loads of use (...) constructs because you need some local variable inside a deeply nested closure?

🤯 Use the following tiny function abusing Closure::bind() to bend variable scope to your will!

function run_scoped(Closure $callback, $init = [])
@loilo
loilo / portfinder.md
Last active May 3, 2024 06:41
Find Free Port with PHP

Find Free Port with PHP

This is a quick way to find a random free port on a system using PHP:

$port = find_free_port();

Benchmarked locally, where finding a port always took around 0.15ms.

@loilo
loilo / ResponsiveContainer.md
Last active October 19, 2021 19:48
A Container-Query-like Responsive Container in Vue.js

Vue Responsive Container

A container component reacting to breakpoints on its own width or height, powered by ResizeObserver and scoped slots.

It is similar to things like vue-resize in that you can use it to observe a component's size. However the ResponsiveContainer will not emit any events, its whole point is to work as declaratively as possible, taking a predefined set of breakpoints you can access in your component.

Basic Usage

@loilo
loilo / moxy.js
Last active January 21, 2020 10:06
Moxy – a function that mocks an object's properties and methods with a proxy
/**
* Mock an object with a proxy, overriding methods and properties
*
* @param {object} object An object to mock
* @param {object} implementations The properties/methods to virtually "merge" into the mocked object
*/
function moxy(object, implementations) {
return new Proxy(object, {
get(target, key, receiver) {
if (key in implementations) {