Skip to content

Instantly share code, notes, and snippets.

View gpoole's full-sized avatar

Greg Poole gpoole

  • Sydney, AU
View GitHub Profile
@gpoole
gpoole / isAssetUploading.ts
Created September 5, 2023 01:19
Detecting a Sanity asset that's currently being uploaded
// Doesn't seem to be officially documented so I had to borrow this from Sanity:
// https://github.com/sanity-io/sanity/blob/30ab832179f8c8dfc6e1e61938ee784c0709cb25/packages/sanity/src/core/preview/components/_extractUploadState.ts#L4
const isAssetUploading = (asset: any) => asset?._upload?.progress != null;
@gpoole
gpoole / MinimalPortableRichText.tsx
Created January 10, 2023 21:45
Minimal implementation of @portabletext/react in TypeScript
import { PortableText, PortableTextMarkComponent, PortableTextBlockComponent, PortableTextListComponent, PortableTextListItemComponent } from '@portabletext/react'
import { PortableTextBlock, TypedObject } from '@portabletext/types'
import { FC } from 'react'
interface LinkProps extends TypedObject {
href: string
openInNewTab: boolean
}
const Link: PortableTextMarkComponent<LinkProps> = ({ value, children }) => {
@gpoole
gpoole / container-export.sh
Last active November 13, 2022 00:53
Tool to help backup the contents of Docker volumes to a tar file on the Docker host
#!/bin/bash
# based on https://docs.docker.com/storage/volumes/#back-up-restore-or-migrate-data-volumes
container_name="$1"
volume_path="$2"
backup_path="$3"
function usage() {
echo "container-export.sh container_name container_path backup_path"
@gpoole
gpoole / reset-virtualdub-settings.md
Created August 12, 2022 05:25
Delete or reset all VirtualDub user preferences to the defaults

How to reset VirtualDub settings to default

auxsetup.exe claims to have a button to delete settings from the registry but the version I had deletes settings under a different (HKEY_USERS\*\Software\Freeware\VirtualDub\) which I think might be out of date.

The settings live under this key: Computer\HKEY_USERS\<UID>\SOFTWARE\VirtualDub.org

Deleting that key and restarting VirtualDub will reset everything to defaults.

import Benchmark from "benchmark";
import SMath from "smath";
const suite = new Benchmark.Suite();
const smath = new SMath();
let result1 = 0;
suite.add('SMath.sin', () => {
result1 += smath.sin(Math.random());
@gpoole
gpoole / funkwhale-watch.service
Created April 17, 2021 02:54
Watch service for systemd running outside Funkwhale all-in-one container
[Unit]
Description=Funkwhale watch changes service
[Service]
Type=simple
ExecStart=docker exec -t funkwhale manage import_files <LIBRARY_ID> /music --watch --recursive --noinput --in-place
Restart=on-failure
[Install]
WantedBy=multi-user.target
@gpoole
gpoole / tampermonkey-hide-youtube-comments.js
Last active June 7, 2023 15:17
Tampermonkey userscript to hide comments on YouTube with a toggle on/off button
// ==UserScript==
// @name Hide YouTube comments
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Hides YouTube comments
// @author gpoole
// @match https://www.youtube.com/*
// @run-at document-end
// @grant none
// ==/UserScript==
@gpoole
gpoole / hide-facebook-distractions-tampermonkey.js
Last active November 1, 2020 11:08
Tampermonkey userscript to remove the Facebook feed and flashing notifications
// ==UserScript==
// @name Facebook distractions off
// @author gpoole
// @version 1.0
// @description Removes distracting, attention-grabbing features like the feed and notifications from Facebook
// @include /https?:\/\/www.facebook.com\/*/
// @noframes
// @run-at document-end
// @grant none
// ==/UserScript==
@gpoole
gpoole / clean-unreferenced-files.ps1
Created July 6, 2020 00:55
Delete image files that don't have any name references in source files
function FindAny() {
param($name)
$found = Get-ChildItem . -Recurse -Include *.js, *.css, *.html, *.xml |
? { $_.FullName -notmatch "node_modules" -and $_.FullName -notmatch "bower_components" } |
Select-String $name
return ($found | Measure-Object -Line).Lines -gt 0;
}
Get-ChildItem "web\images" | ? { -Not (FindAny $_.Name) } | rm
@gpoole
gpoole / README.md
Last active April 10, 2024 02:41
Xen/XCP-ng script to attach physical USB devices via passthrough to a VM

XCP-ng USB passthrough tools

A set of command line tools and a service to make setting up passthrough USB devices easier:

  • add-custom-usb-policies - script to store and apply custom USB policies required for specific devices
  • attach-usb-devices - script and service to automatically connect USB devices to VMS when XCP-ng boots up
  • plug-usb - attach a physical USB device to a VM in one command
  • unplug-usb - remove a physical USB device from a VM in one command

To set up, copy the files onto your server and run install.sh to copy everything and set up the service.