Skip to content

Instantly share code, notes, and snippets.

View squio's full-sized avatar

Johannes la Poutre squio

View GitHub Profile
@squio
squio / hex2str.js
Created May 17, 2021 09:08
Space separated hex dump to ascii in javascript
let chs = "7b 22 72 65 73 22 3a 22 6c 6f 67 69 6e 22 2c 22 73 74 61 74 22 3a 34 30 33 2c 22 6d 73 67 22 3a 22 43 6f 64 65 20 65 78 70 69 72 65 64 22 7d"
let str = chs.split(" ").map(ch => String.fromCharCode(parseInt(ch, 16))).join("")
@squio
squio / base62.cpp
Last active September 24, 2021 11:05
Base62 encoding / decoding
// Base62 encoding / decoding
// Test: `g++ -Wall -g -std=c++11 base4.cpp && ./a.out`
#include <iostream>
#include <algorithm>
#include <time.h>
#include <assert.h>
static const char alphanum[] =
"0123456789"
@squio
squio / account_adapter.py
Created May 10, 2021 12:56
Use configured Site name instead of request host Django (Rest) Auth
from allauth.account.adapter import DefaultAccountAdapter
from django.contrib.sites.shortcuts import get_current_site
from django.contrib.sites.models import Site
class AccountAdapter(DefaultAccountAdapter):
def get_email_confirmation_url(self, request, emailconfirmation):
""" Override to get domain name from Sites configuration instead of request """
# when 'request' is empty, the url from Sites is used
try:
// Insert geoseach JS after leaflet JS files from yii2-leaflet-extension
// https://github.com/2amigos/yii2-leaflet-extension
// https://github.com/smeijer/leaflet-geosearch
$this->registerJsFile('https://unpkg.com/leaflet-geosearch@3.0.0/dist/geosearch.umd.js', [
'depends' => [\dosamigos\leaflet\LeafLetAsset::class]
]);
// Create a customized SVG pin icon on the fly
// uses vars: lat, lon, color, title
// map is leaflet Map object
const color = '#cc0000';
const svg = `<?xml version="1.0" encoding="UTF-8"?><svg width="27" height="53.5" version="1.1" viewBox="-31 -22 22 18" xmlns="http://www.w3.org/2000/svg"><path d="m-20 8.8889c-2-20-10-22-10-30a10 10 0 1 1 20 0c0 8-8 10-10 30zm-2-30a2 2 0 1 1 4 0 2 2 0 1 1-4 0" fill="${color}" stroke="#000" stroke-width=".8"/></svg>`;
const iconUrl = 'data:image/svg+xml;base64,' + btoa(svg);
const icon = L.icon({
iconUrl: iconUrl,
iconAnchor: [13.5, 53],
@squio
squio / pihole-hiseeu-webcam.txt
Last active December 28, 2020 21:43
A blocklist for all domains used by the Hiseeu webcam
MOVED: https://github.com/squio/oneliners/blob/main/pi-hole/pihole-hiseeu-webcam.txt
@squio
squio / docker-compose.yml
Created December 27, 2020 15:19
Quick & dirty installation of Wordpress on RPI 4 using Docker and Docker Compose
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
environment:
@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

Delete all files from a git commit

Warning this permanently deletes all files from an older commit, regardles if they were added, deleted or modified!

Fitrst, list all files with full paths:

git diff-tree --no-commit-id --name-only -r 39f96f9 > files.txt

Then, for each file from files.txt

@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() {