Skip to content

Instantly share code, notes, and snippets.

@nolanw
nolanw / NSObject+ProcObservation.h
Created January 6, 2010 08:32
Slight alteration of Any Matuschak's BlockObservation for MacRuby.
//
// NSObject+ProcObservation.h
// Version 1.0
//
// Andy Matuschak
// andy@andymatuschak.org
// Public domain because I love you. Let me know how you use it.
//
// NTW 2009-Oct-21: Added selectors with an options argument.
// NTW 2009-Oct-30: Transplanted new observation key from MYUtilities's KVUtils.
@nolanw
nolanw / ios-configure
Created January 26, 2011 01:48
Compile a library for iOS 4.3 using its configure script
#!/bin/bash
# ios-configure runs a "configure" script using the iOS 4.3 SDK, generating a
# static library that will load and run on your choice of iPhone, iPad, and
# their respective simulators.
#
# Simply run in the same directory as a "configure" script.
# You can run this script for multiple targets and use lipo(1) to stitch them
# together into a universal library.
#
@nolanw
nolanw / NSBundle+StopAutoloadingNibs.m
Created February 5, 2011 23:04
Prevent NSApp from autoloading a nib at launch.
#import <Foundation/Foundation.h>
// NSApplication has this weird habit of trying very hard to load a nib at
// launch. If there are none in the app bundle, it'll wander off into the
// frameworks until it finds one, then try to use it.
//
// You know this is what's happening if you get four log messages at launch
// saying "Could not connect the action buttonPressed: to target of class
// NSApplication". You've deleted MainMenu.nib and removed the "Main nib file
@nolanw
nolanw / c99_runtime_check.c
Created April 2, 2011 19:21
Check for at least C99 at runtime.
static int IsC99()
{
return (2//* */2
== 2);
}
@nolanw
nolanw / gist:954361
Created May 3, 2011 22:04
TextMate bundle command to nicely wrap contiguous single-line comments
#!/usr/bin/env ruby
def wrap text, sigil, indent
text = text.map do |line|
line.match(/^\s*\S (.*)$/)[1]
end.join ' '
lines = []
while text and not text.empty?
cut = [text.length, 78 - indent].min
if cut < text.length and text[cut, 1] != ' '
@nolanw
nolanw / fscript.rb
Last active September 26, 2015 22:38
Inject F-Script into any app on OS X 10.7 or 10.8. (Yet another F-Script Anywhere replacement.)
#!/usr/bin/env ruby
FSCRIPT_PATH = "/Library/Frameworks/FScript.framework"
if ARGV.empty?
puts "Usage: #{$0} process_name"
exit
end
GDB = IO.popen("gdb", 'w')
@nolanw
nolanw / isequal.m
Created September 27, 2011 02:02
Timing isEqual: and isEqualToString:
// clang -framework Foundation isequal.m
#include <mach/mach_time.h>
#include <stdint.h>
#include <stdio.h>
#import <Foundation/Foundation.h>
// Convert from mach time to seconds (gets set in main() below).
double ticksToNanos = 0;
// Run some code many times, timing how long it took, and announce the average
@nolanw
nolanw / AttributedNumberFormatter.swift
Last active February 22, 2019 15:16
An NSNumberFormatter for iOS that usefully implements attributedStringForObjectValue…
import Foundation
/// A number formatter that usefully implements `attributedString(for:withDefaultAttributes:)`, which iOS's NumberFormatter does not.
final class AttributedNumberFormatter: NumberFormatter {
override func attributedString(for obj: Any, withDefaultAttributes defaultAttributes: [NSAttributedString.Key : Any]? = nil) -> NSAttributedString? {
guard
let number = obj as? NSNumber,
let plain = string(from: number)
else { return nil }
@nolanw
nolanw / pbxproj-lint.swift
Created October 26, 2016 13:09
Xcode project file plist linter
#!/usr/bin/env swift
// Swift 3.0
import Foundation
func main() -> Int32 {
if CommandLine.arguments.count < 2 {
print("")
print("Usage: \(CommandLine.arguments[0]) (path_to_pbxproj | path_to_xcodeproj)")
@nolanw
nolanw / crashlytics-download.py
Created October 30, 2016 19:21
Script to download/update Crashlytics.framework and Fabric.framework without having to install Fabric.app or use CocoaPods
#!/usr/bin/env python
from __future__ import print_function
import json
from io import BytesIO
import logging
import os
import sys
try:
from urllib.request import Request, urlopen # py3
from urllib.parse import quote