Skip to content

Instantly share code, notes, and snippets.

@bjhomer
bjhomer / currentTrack.swift
Last active March 20, 2024 02:21
Using ScriptingBridge from Swift.
#! /usr/bin/swift
import ScriptingBridge
@objc protocol iTunesTrack {
optional var name: String {get}
optional var album: String {get}
}
@objc protocol iTunesApplication {
@bjhomer
bjhomer / instructions.md
Last active January 17, 2023 23:03
How to make the Day One command line tool automatically write to Day One 2

Using the Day One CLI with Day One 2

The dayone command line tool was originally written to work with Day One Classic, and by default writes its entries to the default Day One Classic journal directory1. If you want to use the dayone tool to write entries in to Day One 2 instead, there are a couple options.




Option 1. Use this option if you don't use Day One Classic at all.

@bjhomer
bjhomer / cross-view-lines.swift
Last active November 5, 2022 05:31
Creating cross-view lines in SwiftUI
//
// ContentView.swift
// SwiftUIPlayground
//
// Created by BJ Homer on 4/26/21.
//
import SwiftUI
@bjhomer
bjhomer / .gitconfig
Created March 13, 2015 18:15
A git alias to delete branches whose remote tracking branches are gone
# Drop this into your ~/.gitconfig
[alias]
delete-merged = !bash -c '\
REMOTE=$1 && \
REMOTE=${REMOTE:="origin"} && \
echo "Fetching $REMOTE" && \
git fetch $REMOTE --prune && \
git branch -vv | grep "gone]" | awk \"{ print \\$1 }\" | xargs git branch -d' -
@bjhomer
bjhomer / movewindow.m
Last active July 14, 2021 18:51
Why not -[NSView mouseDownCanMoveWindow]?
// You might think that a view could trigger window movement by overriding -[NSView mouseDownCanMoveWindow]
@interface DraggyView : NSView
@end
@implementation DraggyView
- (BOOL)mouseDownCanMoveWindow {
return YES;
}
@end
@bjhomer
bjhomer / gist:9393869
Last active July 7, 2021 20:26
Starting and stopping VoiceOver from the terminal
//The very slow, but more semantically correct way
osascript -e 'tell application "VoiceOver" to activate'
osascript -e 'tell application "VoiceOver" to quit'
// The really fast way. (96 is the keycode for F5.)
osascript -e 'tell application "System Events" to key code 96 using command down'
@bjhomer
bjhomer / UIWebView+AccessoryHiding.m
Created March 16, 2012 05:03
Hiding the inputAccessoryView of a UIWebView
#import <objc/runtime.h>
#import <UIKit/UIKit.h>
@interface UIWebView (HackishAccessoryHiding)
@property (nonatomic, assign) BOOL hackishlyHidesInputAccessoryView;
@end
@implementation UIWebView (HackishAccessoryHiding)
static const char * const hackishFixClassName = "UIWebBrowserViewMinusAccessoryView";
@bjhomer
bjhomer / config.fish
Last active March 20, 2019 21:30
This is a modified version of the built-in fish git prompt. It uses the colors I like. :)
if status --is-interactive
set -gx PATH /usr/local/bin ~/Applications/ $PATH;
set -gx EDITOR "subl -nw"
end
# My colors
set -g fish_color_autosuggestion 444444
set -g fish_color_command 00ff00
set -g fish_color_comment red
set -g fish_color_cwd cyan
@bjhomer
bjhomer / enumFilter.swift
Created January 15, 2019 16:42
Is there a better way to do this?
enum Thing {
case empty
case int(Int)
}
let things: [Thing] = [.empty, .int(3), .int(7)]
// Surely there's a more concise way to write this `filter` closure?
let intThings = things.filter({
if case Thing.int = $0 { return true }
@bjhomer
bjhomer / 0_explanation.md
Created April 23, 2012 19:32
Putting "*.m diff=objc" in <repo_root>/.gitattributes

Running echo "*.m diff=objc" >> .gitattributes in a git repo tells git to use the obj-c diff algorithm when running git diff. For the most part, this isn't much different from the standard diff algorithm. However, it adds one key benefit.

In a unified git diff, added lines are prefixed with a +, and removed lines are prefixed with a -. Unchanged lines are provided for context, and have no prefix. As added context, though, unified diffs have a @@-prefixed line at the beginning of each hunk. Minimally, the @@ lines specify which lines in the file are being changed. It can also contain a label, if git can determine an appropriate label for that section of code.

By default, the label on a hunk context line is the name of the enclosing C function. That works great for C-ish code, but completely misses Obj-C method signatures. As a result, when diffing Obj-C files, the context label is either empty, or falls back to the last C-ish declaration it could find. This is usually entirely useless.

Adding