Skip to content

Instantly share code, notes, and snippets.

View chockenberry's full-sized avatar

Craig Hockenberry chockenberry

View GitHub Profile
@chockenberry
chockenberry / README
Created April 6, 2022 17:32
A simple AppleScript to start up a web server in the folder where the script is located.
1) Add this code to a new file in Script Editor
2) Export the script as "Application" and make sure it's code signed
3) Put "Startup.app" in the root folder of the test website (e.g. where index.html is located)
4) Make sure that "Startup.app" has Full Disk Access in System Preferences > Security & Privacy > Privacy
@chockenberry
chockenberry / Fix Terminal Windows.scpt
Created January 23, 2022 22:33
Fix Terminal Windows
tell application "Terminal"
set ws to windows
if (true) then -- set to false to see current window positions
set c to 80
set ps to {{4215, 27}, {3629, 27}, {3043, 27}, {3043, 734}, {2457, 734}, {3629, 734}, {4215, 734}}
set r to 48
set ix to 1
repeat with p in ps
set w to item ix of ws
#!/bin/sh
if [ -z "$1" ]; then
echo "usage: $0 <package_name>"
echo ""
echo "<package_name> is the Name under Archives in the Organizer"
exit
fi
app=$1
@chockenberry
chockenberry / gist:30608eae03f63750363fc1470991f166
Last active October 21, 2021 18:10
vImage_Buffer Unsafe Mutable Pointers
let srcRowBytes = workingBuffer.buffer.rowBytes
let srcData: UnsafeMutablePointer<Pixel_8> = workingBuffer.buffer.data!.assumingMemoryBound(to: Pixel_8.self)
let srcIndex = y * srcRowBytes + x * workingBuffer.bytesPerPixel
var srcPointer = srcData[srcIndex]
withUnsafeMutablePointer(to: &srcPointer) { srcPointer in
// srcPointer is (UnsafeMutablePointer<Pixel_8>)
var srcBuffer = vImage_Buffer(data: srcPointer, height: vImagePixelCount(h), width: vImagePixelCount(w), rowBytes: srcRowBytes)
Braccio:~ craig$ brew install mtr
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 52, done.
remote: Counting objects: 100% (52/52), done.
remote: Compressing objects: 100% (28/28), done.
remote: Total 742888 (delta 29), reused 42 (delta 24), pack-reused 742836
Receiving objects: 100% (742888/742888), 299.21 MiB | 3.00 MiB/s, done.
Resolving deltas: 100% (492001/492001), done.
Error: Invalid formula: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/step.rb
#!/bin/sh
# usage: waitfor.sh myserver.example.com
ping_func(){
host="$1"
$(ping -c 1 -t 1 "$host" &> /dev/null)
return $?
}
result=2
// UIFont+CharacterWidth.m
- (CGFloat)characterWidth
{
CGFloat characterWidth = 0.0;
// get the width of a character by doing a layout with two spaces and measuring the position of the second glyph
NSAttributedString *measureAttributedString = [[NSAttributedString alloc] initWithString:@" " attributes:@{ NSFontAttributeName: self }];
CTLineRef lineRef = CTLineCreateWithAttributedString((CFAttributedStringRef)measureAttributedString);
CFArrayRef arrayRef = CTLineGetGlyphRuns(lineRef);
@chockenberry
chockenberry / tot.sh
Last active March 9, 2025 22:28
A shell script for Tot
#!/bin/sh
basename=`basename $0`
if [ -z "$*" ]; then
echo "usage: ${basename} <dot> [ -o | -r | <file> | - ]"
echo ""
echo "options:"
echo " -o open dot in window with keyboard focus"
echo " -r read contents of dot"
@chockenberry
chockenberry / ScreenRecordingDetection.m
Created November 21, 2019 22:38
Detecting Screen Recording Permission in macOS Catalina
BOOL canRecordScreen = YES;
if (@available(macOS 10.15, *)) {
canRecordScreen = NO;
NSRunningApplication *runningApplication = NSRunningApplication.currentApplication;
NSNumber *ourProcessIdentifier = [NSNumber numberWithInteger:runningApplication.processIdentifier];
CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
NSUInteger numberOfWindows = CFArrayGetCount(windowList);
for (int index = 0; index < numberOfWindows; index++) {
// get information for each window
@chockenberry
chockenberry / Slack Formatting Bar Feedback.txt
Last active October 22, 2020 19:26
Slack Formatting Bar Feedback
There are a couple of problems with the new formatting bar:
1) The icon to turn it on/off doesn't make sense. It's a toolbar, and the "Aa" doesn't get that concept across. It's in a strange place, next to "@" and ":-)", icons that cause an element to come up over the text field without changing it. A lot of smart folks aren't figuring this out (and let's face it, no one reads the fricken' manual.) Don't believe me, check out the replies to this tweet:
https://twitter.com/chockenberry/status/1196992017143779328
2) Once you have the epiphany to turn it off, it doesn't turn off the functionality. I've been using Markdown since it was just a glint in John Gruber's eye, and it's actually easier for me to _read_ text *like this* even when it contains `code`.
If I opt out of the formatting bar, it feels like I should be opting out the fancy completion stuff, too.