Skip to content

Instantly share code, notes, and snippets.

@varenc
varenc / chrome_dev_tools_snippets_backup.sh
Last active April 13, 2025 01:42
Backup your Chrome Developer tools saved snippets
## Use the path below for macOS.
# On linux it may be `~/.config/chromium/Default/Preferences` or `~/snap/chromium/common/chromium/Default/Preferences``
# Find yours by opening chrome://version/, finding the "Profile Path" line, and appending `/Preferences` to it.
cat "$HOME/Library/Application Support/Google/Chrome/Default/Preferences" \
| jq -r '
.devtools.preferences["script-snippets"]
| fromjson[]
| [.name, (.content | @base64)]
| @tsv
@varenc
varenc / tailscale.30s.sh
Last active April 12, 2025 22:12
Swiftbar plug-in for displaying Tailscale's --accept-routes and --exit-node status
#!/bin/sh
# Swiftbar plugin for displaying Tailscale's --accept-routes and --exit-node status
#
# Status indicators:
# ✅ = accepting routes
# ❌ = not accepting routes (or accepting, but no peers advertising routes)
# ➡️ = using an exit node
# ❓ = Tailscale not running
#
# Possible outputs:
@varenc
varenc / nextdns_archive_dns_fix.sh
Created December 24, 2024 19:05
Fix nextdns archive.is domains with manual overrides, updating
function nextdns_fix_domains() {
function nextdns_existing_rules() { curl -sS 'https://api.nextdns.io/profiles/7dd729/rewrites' \
-H 'accept: */*' \
-H 'accept-language: en-US,en;q=0.9' \
-H "$(chromeCookies.py https://api.nextdns.io)"\
-H 'dnt: 1' \
-H 'origin: https://my.nextdns.io' \
-H 'priority: u=1, i' \
-H 'referer: https://my.nextdns.io/' \
@varenc
varenc / suno_song_scrap.sh
Last active March 1, 2025 17:39
Suno AI song generation, download songs from suno.com (this script requires 'zsh')
# extra comments for you arthur! but FYI you need 'pup' or 'htmlq' you can get with `brew install htmlq`
function sunoScrape() {
# interate over every url passed in as an argument. Each url will be in the variable '$u'
for u in $@; do
# get the title of the song by extracting the '<meta property="og:title" content="...">' tag from the html of the page
local TITLE="";
[[ $+commands[pup] ]] && {
TITLE="$(curl -sS "$u" | pup 'meta[property="og:title"] attr{content}' | perl -MHTML::Entities -pe 'decode_entities($_)' )";
} || { [[ $+commands[htmlq] ]] && {
TITLE="$(curl -sS "$u" | htmlq -a content "meta[property=\"og:title\"]" )";
@varenc
varenc / varen_christmas_2024.py
Last active September 20, 2024 21:41
Varen siblings + partners gift exchange pairings for Christmas 2024
import random
import pandas as pd
from tabulate import tabulate
SIBLINGS = ["McKenzie", "Reagan", "Danni", "Alex", "Thomas", "Ben", "Shane", "Eric", "Chris"]
PARTNERS = ["Emilie", "Julia", "Courtney", "Kirstyn", "Stefanie", "Rilka"]
sibling_partner_mapping = {
"Alex": "Emilie",
"Thomas": "Julia",
# Workaround for https://github.com/tailscale/tailscale/issues/12244 on macOS
### Usage
# Just put this in a shell RC file (~/.zshrc) and run `tailscaleDNSHack`
# With no params it sets the tailscale DNS to what your `NET_SERVICE`'s DNS is.
# Or pass in an argument to set that as the DNS
function tailscaleDNSHack () {
local NET_SERVICE="Wi-Fi"
if [ -z $1 ]
@varenc
varenc / !README.md
Last active July 15, 2024 12:12
Install iCloud3 v3.0.5.2 quick fix for Home Assistant 2024.7.x

This script just automates the fix described in gcobb321/icloud3#356 by @gcobb321 for fixing iCloud v3.0.5.2 compatability with Home Assistant 2024.7.x

I took some attempts to be safe but use at your own risk!

To run it just ssh into your HA server, then fetch the file below and evaluate it with bash.

$ wget "https://gist.githubusercontent.com/varenc/243eeed5622f0e749367b2f9e9d73a38/raw/icloud3_quick_fix.sh"
$ bash icloud3_quick_fix.sh
@varenc
varenc / extract_firebase_access_token.sh
Last active March 24, 2024 20:27
on macOS extract a firebase user accessToken from your active Chrome session. Demoing with partiful.com
function partifulToken() {
# some overly terse JS that extracts the Firebase access token from indexedDB and assigns it to `window.__FB_KEY`
local SOME_JS="indexedDB.open('firebaseLocalStorageDb').onsuccess=event=>(((event.target.result.transaction('firebaseLocalStorage','readonly').objectStore('firebaseLocalStorage').getAll().onsuccess=e=>console.log('FIREBASE_TOKEN:',window.__FB_KEY=e.target.result[0].value.stsTokenManager.accessToken)),null))";
echo "Getting partiful firebase token..." >&2
# This requires that automation access is enabled on Chrome
# It first finds an active partiful.com tab and runs the JS there.
# NOTE: Right now this only checks that tabs in the FIRST window. Should be improved to check all windows/tabs.
@varenc
varenc / README.md
Last active April 14, 2025 07:51
Keep your Mac from waking by disabling the `InternalPreventSleep` assertion from `com.apple.powermanagement.acwakelinger`

Disable AC Wake lingering in macOS using undocumented pmset features

Every time your Mac wakes from sleep powerd creates an InternalPreventSleep assertion labeled com.apple.powermanagement.acwakelinger with a 45 second timeout. That assertion ensures that even if your Mac needs to wake for 2 seconds to recieve a push notification that it stays on for 45 seconds. Seemingly there's no way to control this. And recent versions of macOS love to wake quite frequently.

Forunately we can disable this. The built in pmset tool has many undocumented features but thankfully it's open source

Cruicially there's an undocumented pmset disabledassertion feature that just makes macOS ignore certain power assertions. To effectively disable acwakelinger we just run this:

$ sudo pmset disableassertion InternalPreventSleep
@varenc
varenc / 2048_masher.js
Last active March 21, 2024 00:38
2048 button masher to show how artless the game is
// This script just mashes Up and Left until its stuck, and then it presses Right. Plays decently, which is the sad part.
//
// tested on https://2048game.com/
// To use this just go to that page, open dev tools, and paste this JS in the console. Refresh the page to stop it.
const simulateKeyPress = (keyCode) => {
document.dispatchEvent(new KeyboardEvent('keydown', { keyCode, which: keyCode }));
};
const upArrowKeyCode = 38, leftArrowKeyCode = 37, rightArrowKeyCode = 39;