Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am davedelong on github.
* I am davedelong (https://keybase.io/davedelong) on keybase.
* I have a public key ASBPhXPG-DfGDYTWePezV32Zhv_iOJVF2cqJVVvmtzdCHQo
To claim this, I am signing this object:
@davedelong
davedelong / autologin.sh
Last active August 10, 2016 13:03
Programmatically switch to another user
#!/bin/bash
# A script to automatically switch to another user in macOS
# Invoke like this: `autologin.sh {user} {password}`
uid=`id -u $1`
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID "$uid"
osascript <<EOD
@davedelong
davedelong / UpdateRepositories.swift
Last active January 30, 2017 12:43
A headless Swift program that keeps a directory of git repositories up-to-date
#!/usr/bin/swift
import Foundation
func scanForRepositories(directory: NSURL, root: NSURL) {
let fileManager = NSFileManager.defaultManager()
let options: NSDirectoryEnumerationOptions = .SkipsSubdirectoryDescendants | .SkipsPackageDescendants
if let contents = fileManager.contentsOfDirectoryAtURL(directory, includingPropertiesForKeys: [NSURLIsDirectoryKey], options: options, error: nil) {
let urls = contents as Array<NSURL>
@davedelong
davedelong / gist:8342577
Created January 9, 2014 21:41
Find non-Mac App Store apps
mdfind "kMDItemAppStoreIsAppleSigned !=1 && kMDItemContentType = \"com.apple.application-bundle\" && kMDItemCFBundleIdentifier != "com.apple.*"" -onlyin /Applications
@davedelong
davedelong / gist:7371853
Last active May 16, 2020 02:51
Delegate proxying (`protocol_methodForEach()` is a custom function that does just what its name implies)
@interface DDDelegateProxy : NSProxy
+ (id)proxyForDelegate:(id)delegate conformingToProtocol:(Protocol *)protocol;
@property (weak, readonly) id delegate;
@property (strong, readonly) Protocol *protocol;
/*!
* Set a default return value for a method on the delegate's protocol.
* \param value This must be a block that returns the default value. Bad Things will happen if it's not.
@davedelong
davedelong / main.m
Created August 28, 2013 23:02
Making sure I get how base-64 encoding works.
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *str = @"Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding.";
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
char table[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
@davedelong
davedelong / gist:6270317
Last active May 16, 2020 02:51
A straight-forward way to inject NSViewControllers into the AppKit responder chain
@interface DDControlledView : NSView
@property (weak) IBOutlet NSViewController *viewController;
@end
@implementation DDControlledView
- (void)setNextResponder:(NSResponder *)aResponder {
NSViewController *controller = self.viewController;
__block void(^block)(int) = ^(int i) {
printf("%d", i);
if (i > 0) {
block(i-1);
} else {
block = nil;
}
};
block(9);
xlog = log --graph --pretty=format:\"%C(yellow)%h%Creset %ad %s%C(cyan)%d%Creset %C(green)[%an]%Creset\" --date=short
@davedelong
davedelong / gist:4114242
Created November 19, 2012 21:48
Removing unused tags from Evernote
//
// main.m
// Tag Cleaner
//
// Created by Dave DeLong on 11/17/12.
// Copyright (c) 2012 Dave DeLong. All rights reserved.
//
// requires https://github.com/evernote/evernote-sdk-mac