Skip to content

Instantly share code, notes, and snippets.

@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' -
protocol FooProtocol {
func blah()
}
struct Foo : FooProtocol {
func blah() {}
}
@bjhomer
bjhomer / odd.swift
Last active August 29, 2015 14:10
Swift shorthand argument syntax oddities
// The Swift Programming Language book from Apple states the following:
//
// Swift automatically provides shorthand argument names to inline closures,
// which can be used to refer to the values of the closure’s arguments by the
// names $0, $1, $2, and so on.
// In Xcode 6.1 and 6.2b1, it appears that this is only true IF the last argument
// is referenced using shorthand syntax somewhere in the closure body. See below
// for details.
@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 / gist:cc3f3155d3b109f61601
Created October 31, 2014 17:06
LLDB and Swift Arrays are not friends.
// What I would expect:
(lldb) p newPaths
([AnyObject]) $R1 = 2 values {
[0] = "This is a string",
[1] = "This is another string"
}
@bjhomer
bjhomer / 1 badDiff.diff
Last active August 29, 2015 14:05
Semantically poor lines shouldn't match
context
context
-AAAA
-AAAA
-AAAA
+BBBB
+BBBB
+BBBB
+BBBB
{
@bjhomer
bjhomer / broken.swift
Last active August 29, 2015 14:05
This does not compile.
class Foo {
var closure: () -> () = {}
init() {}
func nothing() {}
func setupClosure() {
closure = {
[weak self] in
self?.nothing() // <-- this returns a "Void?", which means that the rhs's
@bjhomer
bjhomer / betterMyImageView.m
Last active August 29, 2015 14:05
NSImageView gobbling dragging methods
@implementation MyImageView
- (void)registerForDraggedTypes:(NSArray *)newTypes {
if (self.editable) {
[super registerForDraggedTypes:newTypes];
}
}
- (void)setEditable:(BOOL)editable
{
@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:b0345c44dfbdb8cb7398
Last active August 29, 2015 14:04
Nil-fallback operator suggestions
// Looking for a Swift replacement for the following ObjC code:
// id x = foo ?: bar
//
// Which of the following do you like, if any? Any other suggestions?
// (Note that '?' cannot be used in a custom operator.)
x = foo !|| bar
x = foo |< bar
x = foo ||< bar