Skip to content

Instantly share code, notes, and snippets.

@jerblack
jerblack / Pitch Black Theme.reg
Created Mar 23, 2022 — forked from AveYo/Pitch Black Theme.reg
Pitch Black Theme.reg - now for Ctrl+Alt+Del (and logon on 11) as well
View Pitch Black Theme.reg
Windows Registry Editor Version 5.00
; Pitch Black Theme preset by AveYo, AccentPalette idea by /u/Egg-Tricky
; for Ctrl+Alt+Del, Logon, Taskbar, Start Menu, Action Center, Title Bar (10 & 11)
[-HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent]
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent]
"AccentColorMenu"=dword:1f000000 ; Window borders and titlebar
"StartColorMenu"=dword:1f202020 ; Modals in UWP ex. Apply new refresh rate in 10
"AccentPalette"=hex:\
@jerblack
jerblack / 1. Detecting dark mode change in Windows 10.md
Last active Oct 8, 2022
Golang: Detect dark mode change in Windows 10
View 1. Detecting dark mode change in Windows 10.md

I wanted to be able to detect when Dark mode was turned on or off in my Go program so I can swap icons in my tray app on Windows so I wrote this.
When Dark Mode is turned on or off, it writes to a pair of registry keys, both of which Windows allows you to set independently in Settings > Personalization > Colors.

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize  

SystemUsesLightTheme  DWORD 0 or 1 // Changes the taskbar and system tray color  
AppsUseLightTheme     DWORD 0 or 1 // Changes app colors  

Mine is a tray app, so I am monitoring the first one. I did not want to just periodically poll the registry key and I wanted to be able to react immediately when the registry key is changed, so I am using the win32 function RegNotifyChangeKeyValue in advapi32.dll to tell the OS to notify my app so I can swap out the icon for a color-appropriate one.
I start the monitor function in main, which loads the RegNotifyChangeKeyValue function from advapi32 and starts a gorouti

@jerblack
jerblack / 1. Dark Mode in OSX with Go.md
Last active Nov 3, 2022
Golang: Detect dark mode change in OSX
View 1. Dark Mode in OSX with Go.md

I wanted to be able to detect when Dark mode was turned on or off in my Go program so I can swap icons in my tray app, but the Apple-blessed methods all use Swift and ObjectiveC. To work around this I figured out the following:

  • When dark mode is set, a property called "AppleInterfaceStyle" is set to "Dark" for the user.
  • When dark mode is disabled, that property is removed.
  • You can see this by running "defaults read -g AppleInterfaceStyle"
// Dark Mode On  
defaults read -g AppleInterfaceStyle  
 Dark 
@jerblack
jerblack / PendingFileRenameOperations.go
Created Dec 1, 2019
GoLang: Using PendingFileRenameOperations in the Windows Registry to delete/rename files on reboot with Go.
View PendingFileRenameOperations.go
package main
import (
"fmt"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry"
"log"
"os"
"strings"
"syscall"
@jerblack
jerblack / tee.go
Last active Nov 17, 2022
Golang: Mirror all writes to stdout and stderr in program to log file
View tee.go
package main
import (
"fmt"
"io"
"log"
"os"
)
func main() {
@jerblack
jerblack / Elevate when needed in Go.md
Last active Sep 30, 2022
Relaunch Windows Golang program with UAC elevation when admin rights needed.
View Elevate when needed in Go.md

I'm buiding a command line tool in Go that has an option to install itself as a service on Windows, which it needs admin rights for. I wanted to be able to have it reliably detect if it was running as admin already and if not, relaunch itself as admin. When the user runs the tool with the specific switch to trigger this functionality (-install or -uninstall in my case) they are prompted by UAC (User Account Control) to run the program as admin, which allows the tool to relaunch itself with the necessary rights.

To detect if I was admin, I tried the method described here first:
https://coolaj86.com/articles/golang-and-windows-and-admins-oh-my/
This wasn't accurately detecting that I was elevated, and was reporting that I was not elevated even when running the tool in CMD prompt started with "Run as Administrator" so I needed a more reliable method.

I didn't want to try writing to an Admin protected area of the filesystem or registry because Windows has the ability to transparently virtualize those writes

@jerblack
jerblack / StreamURI.md
Created Sep 2, 2019 — forked from chrisjmendez/StreamURI.md
Triton Audio streams for Classical KUSC and Classical KDFC
View StreamURI.md

Stream URL's for Classical KUSC and Classical KDFC

New URL Pattern:

http://[bit rate].[encoder format].[file format].[call letters].live

Old URL Pattern:

@jerblack
jerblack / args.py
Created Jul 8, 2019
Parse command line arguments in python using only built-in packages
View args.py
import sys, re
'''
parse command line arguments in python
parse for known flags
support arbitrary number of arguments and values per argument
'-' specifies parameter, but also handle '--','/','\'
-x 30 -args 2 3 4 -d -c
--becomes->
{'x': '30', 'args': ['2', '3', '4'], 'd': None, 'c': None}
@jerblack
jerblack / timestamp.py
Last active May 16, 2019
Convert a Postgres style timestamp to a datetime object in Python
View timestamp.py
import datetime
import re
timestamp = '2019-05-15 22:37:55.276407'
def parse_timestamp(timestamp):
return datetime.datetime(*[int(x) for x in re.findall(r'\d+', timestamp)])
# returns datetime.datetime(2019, 5, 15, 22, 37, 55, 276407)
@jerblack
jerblack / Installing Python 3.7 from source on Ubuntu 18.04.md
Last active Oct 25, 2022
Installing Python 3.7 from source on Ubuntu 18.04
View Installing Python 3.7 from source on Ubuntu 18.04.md

Installing Python 3.7 from source on Ubuntu 18.04

# update system
sudo apt update && sudo apt upgrade -y

# install build tools and python prerequisites
sudo apt install build-essential libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev tk-dev libffi-dev

# download and extract python