Skip to content

Instantly share code, notes, and snippets.

@jerblack
jerblack / Pitch Black Theme.reg
Created March 23, 2022 20:39 — forked from AveYo/. Pitch Black Theme.reg
Pitch Black Theme.reg - now for Ctrl+Alt+Del (and logon on 11) as well
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 / reddit_blacklist.js
Last active April 29, 2023 03:30
reddit blacklist. automatically hide any posts or comments with blacklisted text.
/* Use an extension like "User Javascript and CSS" from the Chrome Web Store to load this JS. */
/* https://chrome.google.com/webstore/detail/user-javascript-and-css/nbhcbdghjpllgmfilhnhkllmkecfmpld */
const blacklist = [
"stock", "bitcoin", "gamestop", "gme", "wallstreetbets", "wsb", "crypto"
]
window.addEventListener("load", () => {
new UrlWatcher()
})
@jerblack
jerblack / user32.py
Last active May 2, 2023 13:26
Find and move windows in Windows with ctypes and user32 in Python
import ctypes
user32 = ctypes.windll.user32
# get screen resolution of primary monitor
res = (user32.GetSystemMetrics(0), user32.GetSystemMetrics(1))
# res is (2293, 960) for 3440x1440 display at 150% scaling
user32.SetProcessDPIAware()
res = (user32.GetSystemMetrics(0), user32.GetSystemMetrics(1))
# res is now (3440, 1440) for 3440x1440 display at 150% scaling
@jerblack
jerblack / Prevent_flask_production_environment_warning.py
Last active May 11, 2023 05:35
Disable ability for Flask to display warning about using a development server in a production environment.
"""
Flask will display a warning everytime you startup your application if you are not using it in behind a separate WSGI server.
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
This was not relevant for my scenario and I wanted the message gone,
so using this method will remove their ability to print that message
@jerblack
jerblack / twitter.css
Last active May 30, 2023 02:37
Twitter: Hide blue check, affiliate badges, subscription ui, promoted tweets...
/* Use an extension like "User Javascript and CSS" from the Chrome Web Store to load this CSS. */
/* https://chrome.google.com/webstore/detail/user-javascript-and-css/nbhcbdghjpllgmfilhnhkllmkecfmpld */
/*hide promoted tweets (ads)*/
div[data-testid="cellInnerDiv"]:has(div[data-testid="top-impression-pixel"]) {
display: none;
}
/*hide subscribe ads (tweet previews) in tl*/
div[data-testid="cellInnerDiv"]:has(a[href*="superfollows"]) {
@jerblack
jerblack / timestamp.py
Last active September 6, 2023 02:47
Convert a Postgres style timestamp to a datetime object in Python
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 / 1. Detecting dark mode change in Windows 10.md
Last active February 22, 2024 06:01
Golang: Detect dark mode change in Windows 10

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 / Elevate when needed in Go.md
Last active April 9, 2024 15:14
Relaunch Windows Golang program with UAC elevation when admin rights needed.

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 / tee.go
Last active April 29, 2024 08:50
Golang: Mirror all writes to stdout and stderr in program to log file
package main
import (
"fmt"
"io"
"log"
"os"
)
func main() {
@jerblack
jerblack / 1. Dark Mode in OSX with Go.md
Last active April 29, 2024 17:22
Golang: Detect dark mode change in OSX

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