Skip to content

Instantly share code, notes, and snippets.

View saagarjha's full-sized avatar

Saagar Jha saagarjha

View GitHub Profile
@saagarjha
saagarjha / pause4debug.c
Last active March 22, 2019 04:48
Simple dynamic library that, when injected, pauses programs during initialization
// Dynamic library that pauses a short lived program during launch so that a
// debugger can attach to it. To use it, compile it on macOS:
// clang -dynamiclib pause4debug.c -o pause4debug.dylib
// On Linux:
// gcc -shared -fPIC pause4debug.c -o pause4debug.so
// To use it, make the dynamic linker inject it using DYLD_INSERT_LIBRARIES or
// LD_PRELOAD, depending on your platform. On macOS:
// DYLD_INSERT_LIBRARIES=/path/to/pause4debug.dylib debugme
// On Linux,
// LD_PRELOAD=/path/to/pause4debug.so debugme
@saagarjha
saagarjha / WBSAutoFillQuirks.plist
Last active April 17, 2019 18:02
List of password generation quirks that MobileSafari uses when generating passwords
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DomainsWithAssociatedCredentials</key>
<array>
<array>
<string>comcast.net</string>
<string>xfinity.com</string>
</array>
@saagarjha
saagarjha / webserver.sh
Created May 26, 2019 06:09
OpenRC init script to run a webserver
#!/sbin/openrc-run
start() {
start-stop-daemon --start --chdir /share --background --exec /usr/bin/python3 -- -m http.server 80
}
stop() {
start-stop-daemon --stop --chdir /share --exec /usr/bin/python3 -- -m http.server
}
@saagarjha
saagarjha / screensaver.swift
Last active September 26, 2019 20:26
Simple script for manipulating the screensaver setting on macOS
import Foundation
let arguments = CommandLine.arguments
switch arguments.count {
case 1:
let moduleDict = CFPreferencesCopyAppValue("moduleDict" as CFString, "com.apple.screensaver" as CFString)
print(moduleDict?["moduleName"] as! String)
print(moduleDict?["path"] as! String)
case 3:
let moduleDict = (CFPreferencesCopyAppValue("moduleDict" as CFString, "com.apple.screensaver" as CFString) as? NSDictionary)?.mutableCopy() as? NSMutableDictionary
@saagarjha
saagarjha / hn_timestamps.py
Created August 6, 2019 16:25
Grab timestamps for all your Hacker News comments
#!/usr/bin/env python3
import json
import re
import urllib.request
if __name__ == "__main__":
comments = json.load(urllib.request.urlopen("https://hacker-news.firebaseio.com/v0/user/saagarjha.json"))["submitted"][::-1]
for comment in comments:
timestamp = json.load(urllib.request.urlopen("https://hacker-news.firebaseio.com/v0/item/" + str(comment) + ".json"))["time"]
@saagarjha
saagarjha / GmailLabelArchive.gs
Created October 20, 2016 02:04
Google Apps Script to archive old emails in a label
function shouldStop(startTime) {
return new Date().getTime() - startTime.getTime() > 300000; // 5 minutes
}
function archive() {
var days = 7; // How old a message must be to be archived
var startTime = new Date();
var date = new Date();
date.setDate(date.getDate() - days);
var label = GmailApp.getUserLabelByName("[LABEL NAME]");
#define _XOPEN_SOURCE 700
#include <ctype.h>
#include <ftw.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// djb2 because it's short
unsigned int hash(char *string) {
unsigned int hash = 5381;
@saagarjha
saagarjha / iterm-set-profile.m
Last active February 8, 2021 23:51
Set the correct iTerm profile based on whether dark mode is enabled or not
// Compile with clang -F/System/Library/PrivateFrameworks -framework SkyLight iterm-set-profile.m
#import <Foundation/Foundation.h>
BOOL SLSGetAppearanceThemeLegacy(void);
int main() {
if (SLSGetAppearanceThemeLegacy()) {
printf("\033]50;SetProfile=Solarized Dark\a");
} else {
printf("\033]50;SetProfile=Solarized Light\a");
@saagarjha
saagarjha / AppKit Abusers
Created May 21, 2018 05:38
Apps that have special-case workarounds in Apple's core frameworks, sorted by number of exceptions (from https://worthdoingbadly.com/appkitcompat/)
22 com.apple.iWork.Keynote
18 com.apple.iWork.Pages
16 com.apple.iWork.Numbers
15 com.apple.iPhoto
13 com.microsoft.Powerpoint
9 com.microsoft.Excel
9 com.apple.logic.pro
9 com.adobe.Photoshop
8 com.microsoft.Outlook
7 com.microsoft.Word
@saagarjha
saagarjha / myutr.py
Created January 18, 2021 23:01
Add people to lists on the UTR website
#!/usr/bin/env python3
import getpass
import json
import pathlib
import sys
import urllib.parse
import urllib.request