Skip to content

Instantly share code, notes, and snippets.

@varenc
varenc / pet-snippet.toml
Last active May 8, 2024 01:15
description
[[snippets]]
description = "my personal snippets. Relies on many of my own functions. If you're interested in pmset/disabling assertions, see: https://gist.github.com/varenc/627f6be2a5ec9d52dab3cf0d157be62f"
command = ""
output = ""
[[snippets]]
description = "start dev file syncer. uses fswatch to know when to run rsync. does not sync .git file. Sort like a write-through cache network file system with only eventual consistency guarantees."
command = "fswatch -0 --exclude \"\\.git\" --exclude \"\\.xml\" --exclude \"___\" -o /Users/chris/Documents/workspace/lingt_chris_dev_rsync_checkout/myproject | xargs -0 -n 1 -I {} rsync --progress --exclude '*.pyc' --exclude '*.git' --recursive ~/workspace/lingt_chris_dev_rsync_checkout/myproject dev@dev.server:/home/user/webapps/dev_chris/myproject"
output = ""
@varenc
varenc / system-wide-clipboard.zsh
Last active March 30, 2024 00:49 — forked from welldan97/system-wide-clipboard.zsh
Zsh copy & paste system wide for OS X, like in emacs
## 2020-05-16: Changed `echo` to `printf` so that backslashes are not interpretted by echo
## and so that CUTBUFFER shows up exactly in the pasteboard without modification
pb-kill-line () {
zle kill-line
printf '%s' $CUTBUFFER | pbcopy
}
pb-kill-whole-line () {
zle kill-whole-line
@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 March 21, 2024 04:40
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;
@varenc
varenc / srt_to_sentences.lua
Last active February 11, 2024 07:48
Combine sentences in a .srt input subtitle. Lua script that works as a command line/terminal utility.
#!/usr/bin/env lua
-------------------------------------
-- This script takes an .srt file as an argument, and outputs an srt file with the sentences combined.
-- Output is sent to STDOUT. So to convert a .srt file, you can do something like this
--
-- $ chmod +x ./srt_to_sentences.lua
-- $ ./srt_to_sentences.lua input.srt > input-sentences.srt
--
-- Optimized for my use case. Try tweaking the options below if you have issues.
-- note: the key property of this over other solutions I found is that the outputed srt timecodes are a strict
@varenc
varenc / make_usable.js
Created January 19, 2024 02:04
Force iccsafe.org code text to be selectable and copyable
function __unblockEvents(){for(var i=0;i<arguments.length;i++){document.addEventListener(arguments[i],function(e){e.stopPropagation();console.log("event received and unblocked:",e);},true);}};
__unblockEvents('keydown','keyup','keypress','copy','contextmenu','beforeprint','afterprint');
document.head.appendChild(Object.assign(document.createElement("style"), {textContent: "* { user-select: initial !important; }"}));
// TODO: disabling 'beforeprint' doesnt seem to work. Fix that so its printable. Use Chrome Dev tools to remove that event handler manually in the mean time.
@varenc
varenc / weather_app_open.sh
Created December 17, 2023 00:05
Automatically open the macOS Weather app from the the terminal/shell for a given GPS lat/long
open -a Weather "https://weather.apple.com/?city=Boston&lat=42.3226734&lng=-71.0924375"
# the 'city' arg can be any string, only the lat/lng is used to look up weather
# You can make the string somethng silly and it gets displayed in the app
open -a Weather "https://weather.apple.com/?city=Bawston&lat=42.3226734&lng=-71.0924375"
# Or if you exclude 'city' arg then Apple just looks up the name based on the lat/long
open -a Weather "https://weather.apple.com/?lat=42.3226734&lng=-71.0924375"
# Also all of these have `weather://` scheme equivalents, like this:
@varenc
varenc / _ugrep
Created May 10, 2023 22:36
ugrep zsh completion automatically generated
#compdef ugrep
# zsh completions for 'ugrep'
# automatically generated with http://github.com/RobSis/zsh-completion-generator
local arguments
arguments=(
{-A,--after-context}'[output NUM lines of trailing context after matching lines. Places]'
{-a,--text}'[process a binary file as if it were text. This is equivalent to]'
'--and[PATTERN ... -e PATTERN]'
@varenc
varenc / unbreak_snapchat.user.js
Last active December 2, 2023 22:02
Unbreak Snapchat web. Disable focus tracking and screenshot prevention
// ==UserScript==
// @name Unbreak Snapchat web. Disable focus tracking and screenshot prevention
// @namespace http://tampermonkey.net/
// @version 0.1.1
// @description This userscript improves the Snapchat web experience by disabling screenshot prevention features which don't prevent screenshots but do actively harm the usability.
// @homepage https://gist.github.com/varenc/20e4dbfe8e7a2cc305043ffcbc5454d0
// @author https://github.com/varenc
// @match https://web.snapchat.com/*
// @icon http://snapchat.com/favicon.ico
// @license MIT