This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let handle = dlopen("/System/Library/PrivateFrameworks/Calculate.framework/Calculate", RTLD_LAZY) | |
let CalculatePerformExpression = unsafeBitCast(dlsym(handle, "CalculatePerformExpression"), to: | |
(@convention(c) (UnsafePointer<CChar>, Int, Int, UnsafePointer<CChar>) -> Bool).self) | |
let expression = Array(CommandLine.arguments.dropFirst()).joined(separator: " ") | |
let answer = Array<CChar>(repeating: 0, count: 100) | |
if CalculatePerformExpression(expression, 16, 1, answer) { | |
print(String(cString: answer)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Logic necessary to implement a "closing handler" for a NSDocument | |
// | |
// This is inspired by: | |
// - https://stackoverflow.com/questions/49343307/best-practice-to-implement-canclosewithdelegateshouldclosecontextinfo | |
// - https://github.com/keith/radars/blob/master/NSDocumentSwiftAnnotations/NSDocumentSwiftAnnotations/Document.swift | |
// Keith's supporting documentation for his radar submission: http://www.openradar.me/33422662 | |
// Documentation: | |
// - https://developer.apple.com/library/content/releasenotes/AppKit/RN-AppKitOlderNotes/ | |
// Paragraph called: "Advice for Overriders of Methods that Follow the delegate:didSomethingSelector:contextInfo: Pattern" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
int overridden_strncasecmp(const char *s1, const char *s2, size_t n) { | |
if (n != 6 || strncmp(s2, "bright", n)) { | |
return strncasecmp(s1, s2, n); | |
} else { | |
return !0; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import iterm2 | |
async def set_theme(connection, theme): | |
# Themes have space-delimited attributes, one of which will be light or dark. | |
parts = theme.split(" ") | |
if "dark" in parts: | |
preset = await iterm2.ColorPreset.async_get(connection, "Fixed Solarized Dark") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Python Web Server | |
After=network.target | |
[Service] | |
Type=simple | |
Restart=always | |
User=root | |
WorkingDirectory=/share | |
ExecStart=/usr/bin/python3 -m http.server 80 |