Skip to content

Instantly share code, notes, and snippets.

View keith's full-sized avatar

Keith Smiley keith

View GitHub Profile
@keith
keith / CopyDatabase.m
Last active August 11, 2017 17:57
Some code for dealing with replacing pre-populated Core Data databases that are subject to change version by version. Place this in your `- (NSPersistentStoreCoordinator *)persistentStoreCoordinator` method.
// Main database location
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"<#(DatabaseNameAndType)#>"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// The Build/Bundle Version number of the application on launch
NSString *versionNumber = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey];
// Instead of using your app's bundle version create a custom key in your Info.plist for the database version. This is probably a better idea
@keith
keith / newSite.rb
Created September 25, 2012 18:03
Quickly create a new site complete with boilerplate
#!/usr/bin/ruby
#
# Purpose:
# This script is for easily creating new websites with different boilerplates
# to minimize the amount of wasted time downloading and renaming files
#
# Installation:
# 1. Put this script somewhere permanent where you can call it from
# 2. In terminal run `chmod 755 newSite.rb` # Or whatever you name the script
@keith
keith / methods.rb
Created September 26, 2012 19:08
Prints ObjC method names to a file
#!/usr/bin/ruby
#
# This is a simple script for printing out the methods in your Objective-C .h or .m file.
# It reads the passed file and stores just the method names in a text file
#
# Default filename and type for the file output
$DEFAULT_FILENAME = "out_file"
$DEFAULT_FILE_EXTENSION = "txt"
@keith
keith / googleReaderOPML.rb
Created October 11, 2012 19:57
A Ruby script to export your Google Reader subscriptions to OPML
#!/usr/bin/env ruby
#
# => This script will authorize your Google credentials and download your Google Reader subscriptions
# => Usage: ./SCRIPTNAME GOOGLEUSERNAME PASSWORD
#
# The required networking shenanigans
require 'uri'
require 'net/http'
@keith
keith / FinderWindows.applescript
Created November 6, 2012 15:16
Align your Finder windows side-by-side
-- By: @SmileyKeith
-- Vertically distributes your open finder windows for easy file movements
-- Thanks to @elasticthreads
tell application "Finder"
-- Get the number of Finder windows
set window_count to (count every Finder window)
-- Make sure there is an open Finder window
if window_count > 0 then
@keith
keith / Rakefile
Created November 20, 2012 23:34
A rakefile to build your xcodeproject and place the result in your applications folder.
#!/usr/bin/env rake
require 'rubygems'
require 'fileutils'
# This requires the 'colorize' gem. Install with `[sudo] gem install colorize`
require 'colorize'
task :default => [:build]
@keith
keith / domainr.rb
Last active October 13, 2015 06:58
Use the Domai.nr API to see what domains are available.
#!/usr/bin/env ruby
# A tiny script to check available domain names
# Uses the Domai.nr API http://domai.nr/api/docs/json
# A blatent ripoff of http://blog.jerodsanto.net/2012/11/a-domainr-cli-in-less-than-15-lines-of-ruby/
require 'rubygems'
require 'open-uri'
# `[sudo] install colorize json`
@keith
keith / showHideMainWindow.m
Last active December 10, 2015 05:58
Global shortcut show hide window method
- (void)showHideMainWindow {
NSNumber *wasActive = @NO;
if ([[NSRunningApplication currentApplication] isActive]) {
wasActive = @YES;
NSNumber *wasOpen = @NO;
if ([self.window isVisible]) {
wasOpen = @YES;
[self.window close];
[[NSApplication sharedApplication] hide:self];
} else if (![wasOpen boolValue]) {
@keith
keith / SpawniTerm.applescript
Last active July 22, 2022 19:37
Spawn a new iTerm window in the pwd
on run argv
tell application "iTerm"
set t to make new terminal
tell t
activate current session
launch session "Default Session"
tell the last session
write text "cd \"" & item 1 of argv & "\"; clear; pwd"
end tell
end tell
@keith
keith / goodVimKeysSandbox.mm
Last active December 10, 2015 20:28
http://smileykeith.com/2013/01/08/nstableview-vim-keys/ Override keyDown to use vim keys in something. Like an NSTableView. Only goodVimKeysSandbox.mm works perfectly in the OS X sandbox.
if ([theEvent keyCode] == 38) { // j
unichar down = NSDownArrowFunctionKey;
NSString *downString = [NSString stringWithCharacters:&down length:1];
NSEvent *newEvent =[NSEvent keyEventWithType:NSKeyDown
location:theEvent.locationInWindow
modifierFlags:theEvent.modifierFlags
timestamp:theEvent.timestamp
windowNumber:theEvent.windowNumber
context:nil
characters:downString