Skip to content

Instantly share code, notes, and snippets.

View justin's full-sized avatar

Justin Williams justin

View GitHub Profile
@justin
justin / sim.zsh
Last active January 18, 2023 20:21
Convenience wrapper around the simctl command to perform operations related to iOS simulators.
#!/usr/bin/env zsh
#
# Convenience wrapper around the simctl command to perform operations related to iOS simulators.
# Author: Justin Williams (@justin)
#
# Usage: sim <options> <subcommand>
#
# This script is designed to work with ZSH. ymmv with other shells.
set -e
@justin
justin / NSTimer+Blocks
Created September 9, 2011 15:40
NSTimer+Blocks
typedef void (^SGBlock)();
@interface NSTimer (Blocks)
+ (id)scheduledTimerWithTimeInterval:(NSTimeInterval)interval repeats:(BOOL)shouldRepeat block:(SGBlock)block;
+ (id)timerWithTimeInterval:(NSTimeInterval)interval repeats:(BOOL)shouldRepeat block:(SGBlock)block;
@end
@justin
justin / xcode_switch
Last active July 4, 2019 01:02
Check for the existence of an .xcoderc file in the root of a directory and attempt to switch to that Xcode version + update Carthage
#!/bin/zsh
#
# Check for the existence of an .xcoderc in the root of a project and update the DEVELOPER_DIR
# to point to that specific version of Xcode. Update Carthage dependencies as well.
#
# This is useful for all the switching between Xcode 10.x and 11.x as I am doing presently.
#
# Usage:
# xcode_switch [--no-bootstrap] [version_number]
#
@justin
justin / gist:2354923
Created April 10, 2012 22:01
NSObject+FancyDescription
#import <Foundation/Foundation.h>
@interface NSObject (FancyDescription)
//
// Output the values of all the properties associated with a given class.
// Iterates all the way down the chain until we hit NSObject.
//
- (NSString *)sg_description;

Keybase proof

I hereby claim:

  • I am justin on github.
  • I am justinwme (https://keybase.io/justinwme) on keybase.
  • I have a public key ASDBnz525aVsN7y7rHcRDjMt2ZOyhPTwUniM0mSxrtJpzwo

To claim this, I am signing this object:

@justin
justin / gist:1586076
Created January 10, 2012 00:54
UIAccessibilityElement Example
NSUInteger numberOfSegments = [self numberOfSegments];
CGFloat segmentWidth = CGRectGetWidth(self.bounds) / numberOfSegments;
CGFloat segmentHeight = CGRectGetHeight(self.bounds);
UIAccessibilityElement *element = [[UIAccessibilityElement alloc] initWithAccessibilityContainer:self];
element.isAccessibilityElement = YES;
CGRect segmentFrame = CGRectMake(i * segmentWidth, 0, segmentWidth, segmentHeight);
element.accessibilityFrame = [self.window convertRect:segmentFrame fromView:self];
UIAccessibilityTraits traits = UIAccessibilityTraitAllowsDirectInteraction;
if (i == [self selectedSegmentIndex])
{
@justin
justin / UIImageView+ImageFrame.h
Created February 18, 2013 19:27
Category to get the frame of an image that's inside a UIImageView. Since I use aspect fit on some stuff, I sometimes need to account for the top and bottom borders.
#import <UIKit/UIKit.h>
@interface UIImageView (SGExtensions)
- (CGRect)sg_imageFrame;
@end
@justin
justin / gist:1586083
Created January 10, 2012 00:56
UIAccessibilityTraits Example
- (UIAccessibilityTraits)accessibilityTraits
{
UIAccessibilityTraits traits = UIAccessibilityTraitButton | UIAccessibilityTraitAllowsDirectInteraction | UIAccessibilityTraitStaticText;
if (self.disabled == YES)
{
traits = traits | UIAccessibilityTraitNotEnabled;
}
return traits;
@justin
justin / 0_reuse_code.js
Created January 20, 2014 15:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@justin
justin / gist:5545529
Created May 9, 2013 04:16
Generate a shit load of random geocoordinates around a given distance.
#define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI))
#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
#define ARC4RANDOM_MAX 0x100000000
double startingLatitude = DEGREES_TO_RADIANS(39.753638);
double startingLongitude = DEGREES_TO_RADIANS(-105.007375);
double earthRadius = 3960.056052;
double maxdist = 50.0f;