Skip to content

Instantly share code, notes, and snippets.

View padcom's full-sized avatar

Matthias Hryniszak padcom

View GitHub Profile
@padcom
padcom / example.js
Last active July 7, 2025 08:40
wait-for and sleep with interruption implementation using AbortSignal
let count = 0
try {
console.log(await waitFor(async () => {
console.log('cb: sleep', await sleep(100))
return ++count == 3
}))
} catch (e) {
console.log(e)
}
@padcom
padcom / Example.ce.vue
Last active November 7, 2024 08:35
Example how to use `defineModel()` and `useHost()` in Vue.js 3.5 in a custom webcomponent
<template>
<!--
First things first, the `:value` cannot be `v-model="value"` because it would
break reactivity. It's the same as assigning things directly to `value.value`
and as explained below, assigning the value needs to be done through the host
element (`host.value = '...'`).
Secondly, the `<select>` element emits its own `input` event that bubbles.
Unfortunately, the event is disguised under the custom element, and not the
`<select>` that actually triggered the value. This is due to the `shadowRoot`
@padcom
padcom / vbox-headless-install.sh
Created November 10, 2012 18:42
Automatic headless VirtualBox installation script
#!/bin/sh
# -------------------------------------------------------------------
# Headless VirtualBox installation script with PhpVirtualBox
# -------------------------------------------------------------------
# 1. Add VirtualBox source
echo "deb http://download.virtualbox.org/virtualbox/debian precise contrib" > virtualbox.list
sudo mv virtualbox.list /etc/apt/sources.list.d/
wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -
@padcom
padcom / index.mjs
Created April 17, 2024 09:33
Streams using async generators
import { pipeline } from 'stream/promises'
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
const colorsGenerator = async function* () {
const values = [ 'yellow', 'orange', 'red', 'blue', 'purple', 'green' ]
for await (const color of values) {
yield color
await sleep(1000)
@padcom
padcom / dump.txt
Created December 10, 2017 17:46
iNAV 1.8.0 F3 OMNIBUS Setup
Entering CLI Mode, type 'exit' to return, or 'help'
# dump
# version
# INAV/OMNIBUS 1.8.0 Nov 1 2017 / 06:14:28 (912d1315)
# resources
@padcom
padcom / Execute.java
Last active June 16, 2023 12:20
Running a process and reading its output in Java
// All credits goes to http://stackoverflow.com/users/572129/senthil
// http://stackoverflow.com/questions/5711084/java-runtime-getruntime-getting-output-from-executing-a-command-line-program
Runtime rt = Runtime.getRuntime();
String[] commands = { "system.exe", "-get t" };
Process proc = rt.exec(commands);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(proc.getInputStream()));
String s = null;
@padcom
padcom / README.md
Last active September 20, 2022 23:54
A command that deletes all node_modules folders recursively.

Cleaning up node_modules

Working with node.js is great. NPM may not be the best package manager on the planet, but it is good enough. However, if you have a number of projects on the disk then the copies of modules keep piling up...

This command does the cleaning. It's interactive!

@padcom
padcom / index.js
Created March 16, 2022 23:34
Utility function to create a new array with elements being initialized by calling an initializer
/**
* Create an array by calling an initializer on each element
*
* @param length {Number} length of the created array
* @param init {Function} callback to call on each element of the array
*/
function array(length, init = index => 0) {
return Array.apply(null, { length }).map(Function.call, init)
}
@padcom
padcom / index.html
Last active February 10, 2022 16:50
Example completely custom Vue 3 component with contenteditable and v-model support
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
box-sizing: border-box;