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.
This gist is an ES module which provides functions to import and export data from an IndexedDB database as JSON. It's based on Justin Emery's indexeddb-export-import
package, but applies some adjustments that reflect better on the current browser landscape (i.e. better developer ergonomics but no support for Internet Explorer).
For each of the provided functionalities, you need a connected IDBDatabase
instance.
import { idb } from 'some-database'
/** | |
* Convert between Uint8Array and Base64 strings | |
* Allows for any encoded JS string to be converted (as opposed to atob()/btoa() which only supports latin1) | |
* | |
* Original implementation by madmurphy on MDN | |
* @see https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_1_–_JavaScript%27s_UTF-16_%3E_base64 | |
*/ | |
function b64ToUint6(nChr) { | |
return nChr > 64 && nChr < 91 |
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 |
This is a Sass mixin to handle a 3-way dark mode. It relies on a data-theme
attribute on your <html>
element with a value of light
or dark
. If data-theme
is absent (i.e. it's neither light
nor dark
), the system's preferred mode is used.
body {
// matches data-theme="light" or data-theme="auto" with system instructing light mode
@include light {
background: white;
color: black;
This is about how to split a GitHub pull request, following a real in-the-wild example.
So it happened that I once wanted to fix a bug (#832) on the shelljs
repository.
I forked the repository, cloned it and created a new branch called ln-directory-dest
. I fixed the bug, created a pull request, and implemented initial review feedback.
At this point, I had added the commits A, B, C, D, E and [F](https://github.com/Loilo/shelljs/commit/946ab48bf5cf9c8aac03407
import { readonly, ref, watch } from 'vue' | |
import { useMutationObserver } from '@vueuse/core' | |
export function useQuerySelector(selector, { root = document } = {}) { | |
selector = ref(selector) | |
root = ref(root) | |
const result = ref(null) | |
// Find first matching element inside a root element |
ATTENTION!
I keep this Gist for archival reasons, however I strongly recommend against using it. As I discovered after several weeks in production usage, these BEM mixins cause unexpected, unfixable and hard-to-debug selectors in some cases (especially when nested in some ways).
This is a utility with three simple Sass mixins for writing BEM as DRY as possible, heavily inspired by Hugo Giraudel's article on CSS Tricks.
It exposes three Sass mixins: block
, element
and modifier
.
<?php | |
// In your AppServiceProvider's boot() method, put this: | |
Blade::directive('buffer', function () { | |
return '<?php ob_start(); ?>'; | |
}); | |
Blade::directive('endbuffer', function (string $name) { | |
if ($name === '') { | |
return '<?php ob_end_clean(); ?>'; |