Skip to content

Instantly share code, notes, and snippets.

@rgl
rgl / Remove-VirtualBoxHostOnlyNetworkInterfaces.ps1
Created October 22, 2016 23:21
Remove all VirtualBox Host-Only network interfaces (Windows)
# NB this depends on devcon. you must install it from chocolatey with choco install -y devcon.portable
$devcon = "$ENV:ProgramData\Chocolatey\Lib\devcon.portable\Devcon$(if ($ENV:PROCESSOR_ARCHITECTURE -like '*64') {'64'} else {'32'}).exe"
Get-NetAdapter `
| Where-Object {$_.Virtual} `
| Where-Object {$_.DriverFileName -like 'VBox*.sys'} `
| ForEach-Object {
Write-Host "Removing the $($_.InterfaceAlias) interface..."
$result = &$devcon remove "@$($_.PnPDeviceID)"
@rgl
rgl / python-embedded.md
Last active March 18, 2024 15:33
notes about python embedded in windows

The gist is:

  1. install the normal python from python.org
  2. install everything into a venv
  3. copy the venv into python embed.

A raw example

unzip python-3.8.0-embed-amd64.zip
@rgl
rgl / wait_for_http_200.sh
Last active March 7, 2024 17:08
Wait for an HTTP endpoint to return 200 OK with Bash and curl
bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:9000)" != "200" ]]; do sleep 5; done'
# also check https://gist.github.com/rgl/c2ba64b7e2a5a04d1eb65983995dce76
@rgl
rgl / http-server-shutdown.go
Created December 23, 2020 07:02
go http server with graceful shutdown
package main
import (
"context"
"flag"
"log"
"net/http"
"os"
"os/signal"
"time"
@rgl
rgl / ss.go
Last active February 9, 2024 20:15 — forked from mitchellh/ss.go
take a screenshot of a specific Windows application window in pure Go
// +build windows
package screen
import (
"fmt"
"image"
"reflect"
"syscall"
"unsafe"
@rgl
rgl / qemu-arm.md
Last active December 23, 2023 02:26
run emulated arm under qemu

This will show how to run an emulated arm64 virtual machine under qemu.

It first shows how to launch a typical amd64 virtual machine to make sure we have cloud-init working.

Then it shows how to launch the arm64 (aka aarch64) virtual machine.

NB In my humble i3-3245 amd64 host this is way too slow to run anything useful as it takes about 6m to allow you to finally login, and after that, its slow too. You are really better off with a proper physical arm64 machine, like:

@rgl
rgl / proxmox-set-vm-tpm-state.py
Created November 27, 2023 19:00
set the tpm state of a proxmox vm
import json
import requests
import urllib3
api_url = 'https://192.168.1.21:8006/api2/json'
username = 'root@pam'
password = 'PASSWORD'
node = 'pve'
vm_id = 105
@rgl
rgl / qemu-qmp.md
Last active September 10, 2023 16:24
qemu qmp

QEMU Machine Protocol (QMP) socket

Start QEMU with QMP UNIX socket and connect:

qemu-system-x86_64 -qmp unix:test.socket,server,nowait ...
nc -U test.socket
qmp-shell test.socket    # use the raw qmp interface. see https://github.com/0xef53/qmp-shell
qmp-shell -H test.socket # use the human interface.   see https://github.com/0xef53/qmp-shell
@rgl
rgl / nexus-provision.groovy
Last active June 16, 2023 18:59
provision nexus users that can push or deploy to any repository (e.g. NuGet or Maven)
// see https://books.sonatype.com/nexus-book/3.0/reference/scripting.html
// see https://github.com/sonatype/nexus-book-examples/tree/nexus-3.0.x/scripting/nexus-script-example
import groovy.json.JsonOutput
import org.sonatype.nexus.security.user.UserSearchCriteria
import org.sonatype.nexus.security.authc.apikey.ApiKeyStore
import org.sonatype.nexus.security.realm.RealmManager
import org.apache.shiro.subject.SimplePrincipalCollection
import org.sonatype.nexus.scheduling.TaskScheduler
import org.sonatype.nexus.scheduling.schedule.Daily
@rgl
rgl / uup-dump-scrape.js
Last active March 28, 2023 14:24
scrape uupdump.net for a windows server 2022 iso creation pack
// scrape https://uupdump.net/known.php?q=feature+update+server+operating+system+20348+amd64
// NB there's a better way, using the API, e.g. https://api.uupdump.net/listid.php?search=feature+update+server+operating+system+20348+amd64
// see https://github.com/uup-dump/json-api
// see https://github.com/uup-dump/website/blob/master/known.php
// see https://github.com/uup-dump/website/blob/master/get.php
// each scraped line is a tab separated string with 4 fields alike:
// "Feature update to Microsoft server operating system, version 21H2 (20348.643) amd64\tx64\t2022-04-12 17:04:01 UTC\tb8e204fd-4e2b-4722-95d7-aad633ad7379"
const updateIdEl = Array.prototype.find.call(document.querySelectorAll('th'), el => el.innerText == "Update ID");
const buildsTableEl = updateIdEl.parentElement.parentElement.parentElement;
const builds = buildsTableEl.querySelector('tbody').innerText