Skip to content

Instantly share code, notes, and snippets.

View squio's full-sized avatar

Johannes la Poutre squio

View GitHub Profile
@squio
squio / watchman-reset.sh
Created March 5, 2024 15:18
Reset watchman
#!/bin/sh
# for issue https://stackoverflow.com/a/71779949/885397
watchman watch-del-all
watchman shutdown-server
@squio
squio / semver2number.sh
Created September 10, 2019 08:44
Parse a semantic version string to a 32 bit integer and reverse
#!/bin/bash
# NOTE this works only with bash, not dash
# Based on:
# https://gist.github.com/dislick/914e67444f8f71df3900bd77ccec6091
# NOTE: first digit is MSB contrary to the Javascript version linked above.
# This does not work for non-numerical strings but this should be easy to remedy
# https://semver.org/#semantic-versioning-specification-semver
# Semantic Version string to numerical version
semver2num() {
@squio
squio / tweetdelete.js
Last active May 9, 2023 16:05
Delete all your tweets and retweets from your browser's debug console
// Delete all your tweets and retweets (based on https://stackoverflow.com/a/74878105/885397)
// 1. Open Inspector in your browser
// 2. Switch to the Console tab
// 3. Copy and paste the code below after the >> prompt
// 4. leave your browser tab open, sit back and enjoy seeing all your tweets going one by one ;-)
(async () => {
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
@squio
squio / audio2mp3.sh
Created April 16, 2023 10:15
convert any file containing an audio stream to MP3
#!/bin/sh
# convert any file containing an audio stream to MP3
while [ -s "$1" ]
do
FILE="$1"
BASE=${FILE%.*}
ffmpeg -i "$FILE" -ab 128k -ac 2 -codec:a libmp3lame "${BASE}.mp3"
shift
@squio
squio / rem_to_pixels.ts
Created April 19, 2022 07:59
Convert size in rem to pixel size based on computedStyle
export function convertRemToPixels(rem: number) {
if (document?.documentElement) {
return rem * parseFloat(getComputedStyle(document.documentElement).fontSize);
} else {
console.warn('No "document" context, unable to calculate effective pixel size');
return rem;
}
}
@squio
squio / submit_line.html.md
Last active April 7, 2022 14:11
Override Django Admin submit_line.html

Enhancing https://stackoverflow.com/posts/65938495/

It is also possible to override/extend the innermost {% block submit-row %} like so:

{% extends 'admin/submit_line.html' %}
{% load i18n admin_urls %}

{% block submit-row %}
 {% if extra_button_allowed %}
@squio
squio / app-resume.service.spec.ts
Last active April 5, 2022 10:35
Ionic App Resume
import { TestBed } from '@angular/core/testing';
import { AppResumeService } from './app-resume.service';
describe('AppResumeService', () => {
let service: AppResumeService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(AppResumeService);
@squio
squio / docker-compose.yml
Last active March 25, 2022 18:50
Run HomeAssistant, PiHole, ESPHome and Mosquitto on a Raspberry PI 4
version: '3'
services:
# https://www.home-assistant.io/docs/installation/docker/#docker-compose
homeassistant:
container_name: home-assistant
image: homeassistant/raspberrypi4-homeassistant:stable
volumes:
- './homeassistant/config:/config'
environment:
- TZ=Europe/Amsterdam
@squio
squio / ipv4toint.js
Created March 25, 2022 14:32
Translate an IPv4 address into an integer
const ip='192.168.1.123';
const decimal_ip = ip.split('.').reverse().map((e,i) => parseInt(e)*(2**(8*i))).reduce((sum, n) => sum + n);
// decimal_ip = 3232235899
@squio
squio / RoundRobinArray.js
Last active November 26, 2021 11:43
Round robin array iterator in Javascript
/**
* Round robin array iterator
* @param {string | any[]} arr
*/
function* RoundRobinArray(arr) {
let idx = 0;
for (;;) {
yield arr[idx];
idx++;
if (idx >= arr.length) {