Skip to content

Instantly share code, notes, and snippets.

View nschum's full-sized avatar

Nikolaj Schumacher nschum

View GitHub Profile
@nschum
nschum / README.md
Created September 21, 2014 20:44
OS X Yosemite Messages database merger

OS X Yosemite Messages database merger

Early betas of OS X Yosemite had a bug where the library of old messages wasn't migrated. Instead a new library was created and all old messages were gone.

The bug has been fixed, but if you were affected, you still have two separate libraries. This script merged them for me. Use it at your own risk! You might end up worse than before. Backup everything beforehand. Twice.

This is what your ~/Library/Messages folder will look like if you're affected:

  • chat.db
@nschum
nschum / Precondition.swift
Created July 10, 2015 19:06
Testing precondition (or assert) in Swift
/// Our custom drop-in replacement `precondition`.
///
/// This will call Swift's `precondition` by default (and terminate the program).
/// But it can be changed at runtime to be tested instead of terminating.
func precondition(@autoclosure condition: () -> Bool, @autoclosure _ message: () -> String = "", file: StaticString = __FILE__, line: UWord = __LINE__) {
preconditionClosure(condition(), message(), file, line)
}
/// The actual function called by our custom `precondition`.
var preconditionClosure: (Bool, String, StaticString, UWord) -> () = defaultPreconditionClosure
@nschum
nschum / gist:2626303
Created May 7, 2012 06:44
better "enum class" indent in Emacs
;; This hack fixes indentation for C++11's "enum class" in Emacs.
;; http://stackoverflow.com/questions/6497374/emacs-cc-mode-indentation-problem-with-c0x-enum-class/6550361#6550361
(defun inside-class-enum-p (pos)
"Checks if POS is within the braces of a C++ \"enum class\"."
(ignore-errors
(save-excursion
(goto-char pos)
(up-list -1)
(backward-sexp 1)
@nschum
nschum / indent.swift
Last active July 18, 2016 15:25
Indenting chained methods
// 1
myvariable.mymethod(bla)
.mymethod(bla, bla, bla)
.mymethod(bla, bla)
.mymethod() {
doSomething()
}
// 2
myvariable.mymethod(bla)
@nschum
nschum / NSString+UUID.h
Created January 1, 2011 21:52
UUID and unique file names on iOS
@interface NSString(UUID)
+ (NSString *)stringWithUUID;
+ (NSString *)stringWithUniquePath;
@end