Skip to content

Instantly share code, notes, and snippets.

View benjamingwynn's full-sized avatar
💡

Benjamin Gwynn benjamingwynn

💡
  • United Kingdom
  • 03:42 (UTC)
View GitHub Profile
@benjamingwynn
benjamingwynn / current_booted_gen.sh
Created September 15, 2024 20:31
Gets the currently booted nixos generation
#!/usr/bin/env bash
# based on https://github.com/NixOS/nixpkgs/issues/163936#issuecomment-1069797072
resolvesTo=`cat /proc/cmdline | sed -n 's/^.*init=\(.*\)\/init.*$/\1/p'`
directory="/nix/var/nix/profiles/"
for symlink in "$directory"/*; do
if [ -L "$symlink" ]; then
resolved_path=$(readlink -f "$symlink")
if [ "$resolved_path" == "$resolvesTo" ]; then
@benjamingwynn
benjamingwynn / README.md
Created July 11, 2024 23:07 — forked from Gadgetoid/README.md
Raspberry Pi Zero / Windows 10 automatic RNDIS driver install for composite gadgets

Preface

I owe my very rapid learning journey in the world of ConfigFs to several key sources which aren't necessarily relevant to this result, but I feel deserve a mention anyway.

# note to self: packages for building on fedora(ish) are
# autoconf automake libtool glib2-devel json-glib-devel systemd-devel libus1-devel libX11-devel libXrandr-devel jansson-devel
# read. worth noting that no registers ever changed between input swapping HDMI1 and DP. also maybe worth noting that i dont think --i1 x50 would do anything here, but im no expect i literally discovered ddc existed today
$ ddcutil getvcp scan --i1 x50
VCP code 0x02 (New control value ): One or more new control values have been saved (0x02)
VCP code 0x0b (Color temperature increment ): Invalid value: 0
VCP code 0x0c (Color temperature request ): 3000 + 35 * (feature 0B color temp increment) degree(s) Kelvin
VCP code 0x0e (Clock ): current value = 50, max value = 100
@benjamingwynn
benjamingwynn / index.js
Last active October 19, 2022 13:54
Generate a random hexadecimal colour in Javascript
function generateRandomColour () {
return '#'+(Math.random() * 0xffffff | 0).toString(16).padStart(6, '0')
}
@benjamingwynn
benjamingwynn / location-calc.js
Created October 11, 2020 19:14
Calculate how often Google Location data is recorded/sent to Google using Location History.json from Google Takeout
// use nodejs to load location history.json from your google takeout folder -b
var data=require('./Location History')
var times=data.locations.map(d=>parseInt(d.timestampMs))
var between=times.map((t,i) => times[i-1] ? t-times[i-1] : 0 )
var mean=between.reduce((a,v)=>a+v)/between.length
var meanInMinutes=mean/1000/60
console.log("Google location data reported every " + meanInMinutes + " minutes.")
@benjamingwynn
benjamingwynn / open
Last active March 20, 2023 05:59
macOS open command for WSL (Windows Subsystem for Linux)
#!/bin/bash
# open
# macOS open command for WSL (Windows Subsystem for Linux)
# written by benjamin gwynn (https://benjamingwynn.com)
# get latest version here: https://gist.github.com/benjamingwynn/a778aa6cf2dd461dc18978f245bd90c1
#
# You can run this on WSL wuth no prior setup or changes to host Windows.
#
# See: * https://docs.microsoft.com/en-us/windows/wsl/interop#run-windows-tools-from-linux
# * https://stackoverflow.com/a/501295
@benjamingwynn
benjamingwynn / google-home-bluetooth-windows-10-repair.py
Created May 31, 2020 23:31
Actually gets Google Home's bluetooth to connect reliably on Windows 10. Fixes pairing issues, stuck paired issue and just makes the whole process a lot less awful.
# Actually gets Google Home's bluetooth to connect reliably on Windows 10.
# Unpairs Windows AND Google Home using MAC address, then sets everything up for a one-click connection.
# * Prevents Google Home from getting stuck paried using bttool, which is apparently the only way to fix that?
# * Uses some code from Stack Overflow to get the IP from the MAC address so you don't have to dick around with static IP's
# * Connects reliably by repairing bluetooth on Google Home using the "secret" REST API (https://rithvikvibhu.github.io/GHLocalApi)
# * Opens control legacy panel after setting up Google for pairing
#
# Needs btpair installed first, get it from http://bluetoothinstaller.com/bluetooth-command-line-tools/
/** Image object for WebAppManifest */
declare interface WebAppManifestIcon {
/** A string containing space-separated image dimensions. */
sizes: string,
/** The path to the image file. If src is a relative URL, the base URL will be the URL of the manifest. */
src: string,
/** A hint as to the media type of the image. The purpose of this member is to allow a user agent to quickly ignore images of media types it does not support. */
type: string,
}
@benjamingwynn
benjamingwynn / theme.css
Last active December 5, 2017 14:16
ProtonMail Modern Theme
/**
White modern theme for ProtonMail
Work-in-progress (v2) - Copyright Benjamin Gwynn, 2017 (http://benj.pw)
*/
body {
--font: "Roboto", "Cantarell", "Segoe UI", "Ubuntu", sans-serif;
font-family: var(--font);
}
// copy current children except a certain child while keeping all refs - a pain in the ass.
let i = oldParent.childNodes.length - 1
for (; i >= 0; i -= 1) {
const c = oldParent.childNodes[i]
// whatever, your condition here
if (c.nodeName.toLowerCase() !== "slot") {
newParent.appendChild(c)