Skip to content

Instantly share code, notes, and snippets.

@jonathanpenn
jonathanpenn / js.swift
Last active October 25, 2016 11:34
So the JavaScript developers feel right at home...
class NaNClass {}
let NaN = NaNClass()
@infix func == (n1: NaNClass, n2: NaNClass) -> Bool {
return false
}
@infix func != (n1: NaNClass, n2: NaNClass) -> Bool {
return true
}
@jonathanpenn
jonathanpenn / objcfmt
Created October 29, 2013 18:30
If you have uncrustify on your machine, this script will format all .h and .m files that it detects as Objective-C, like gofmt does.
#!/usr/bin/env ruby
require 'tempfile'
def main
if needs_uncrustify?
puts "Could not find `uncrustify` on the path. Try `brew install uncrustify`."
exit 1
end
(main)> "test".tainted?
=> false
(main)> y = ENV["HOME"]
=> "/Users/jonathan/Library/Application Support/iPhone Simulator/6.1/Applications/B44BDE1C-A9FC-430F-B318-4093FD6BC65B"
(main)> y.tainted?
=> true
@jonathanpenn
jonathanpenn / hidpi.txt
Created January 28, 2013 02:39 — forked from simX/hidpi.txt
sudo defaults write /Library/Preferences/com.apple.windowserver DisplayResolutionEnabled -bool YES;
sudo defaults delete /Library/Preferences/com.apple.windowserver DisplayResolutionDisabled;
// by the way, you need to logout and log back in for this to take effect. Or at least that's what
// Quartz Debug says. Who knows, maybe it's lying?
// P.S. Go to [Apple menu --> System Preferences --> Displays --> Display --> Scaled] after logging
// back in, and you'll see a bunch of "HiDPI" resolutions in the list to choose from.
@jonathanpenn
jonathanpenn / gist:4612637
Last active December 11, 2015 14:09
Here's how I'm generating a set of 1,000 random strings with between 4 and 14 random lowercase characters. Is there a better way?
@implementation SomeGenerater
- (NSArray *)generateAThousandRandomStrings
{
NSMutableArray *strings = [[NSMutableArray alloc] initWithCapacity:1000];
for (int count = 0; count < 1000; count++) {
int length = arc4random_uniform(10) + 4;
unichar buf[length];
@jonathanpenn
jonathanpenn / toggle_uiautomation_views.scpt
Created November 6, 2012 17:35 — forked from wearhere/toggle_uiautomation_views.scpt
Toggle Between Script and Editor Log Views in UIAutomation Instrument
(*
Running this script will cause Instruments to become active
and switch from the Script view (where you edit your UIAutomation script)
to the Editor Log view (where you see the logs of executing those scripts)
or vice versa.
*)
-- JW: This block only needs to be executed once, and can then be removed.
-- I don't know if leaving it in might cause a performance hit;
#import "MPAppDelegate.h"
@interface MPAppDelegate()
@property (strong, nonatomic) UIView *wildView;
@property (strong, nonatomic) UIViewController *viewController;
@end
@jonathanpenn
jonathanpenn / gist:3792241
Created September 27, 2012 04:58
Using to-many predicates with UIAutomation
// Based on this discussion:
// https://twitter.com/listrophy/statuses/251074683594747904
// To setup:
// Create an application that has a tableView with a couple cells in it, one of
// which has the "coffee" in it's label
var target = UIATarget.localTarget();
var app = target.frontMostApp();
var window = app.mainWindow();
@jonathanpenn
jonathanpenn / Gemfile
Created July 16, 2012 17:27 — forked from lukeredpath/Gemfile
A parser for Twitter's tweet archive dump format
gem "mongo"
gem "bson_ext"
gem "mongoid"
@jonathanpenn
jonathanpenn / device_uuid.rb
Created May 15, 2012 03:37
Ruby script that fetches the UUID of the first iOS device plugged into your machine
#!/usr/bin/env ruby
ioreg = `ioreg -w 0 -rc IOUSBDevice -k SupportsIPhoneOS`
device_uuid = ioreg[/"USB Serial Number" = "([0-9a-z]+)"/] && $1
if device_uuid
puts device_uuid
else
puts "No device detected."
exit 1