http://[bit rate].[encoder format].[file format].[call letters].live
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) |
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
package main | |
import ( | |
"fmt" | |
"io" | |
"log" | |
"os" | |
) | |
func main() { |
package main | |
import ( | |
"fmt" | |
"golang.org/x/sys/windows" | |
"golang.org/x/sys/windows/registry" | |
"log" | |
"os" | |
"strings" | |
"syscall" |
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
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
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:\ |
/* 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"]) { |
/* 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() | |
}) |