Skip to content

Instantly share code, notes, and snippets.

View armadsen's full-sized avatar

Andrew Madsen armadsen

View GitHub Profile
@armadsen
armadsen / Person.m
Created February 23, 2015 02:09
Person.m for DevMountain Lesson 13
// For .h:
@interface Person : NSObject
@property (nonatomic, strong) NSString *imageName;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *phoneNumber;
@property (nonatomic, strong) NSString *job;
- (id)initWithDictionary:(NSDictionary *)dictionary;
@armadsen
armadsen / SceneKitCheatSheet.m
Last active October 28, 2021 08:06
Cheat sheet for SceneKit learning app (Objective-C)
// Configure the Scene View
self.sceneView.backgroundColor = [UIColor darkGrayColor];
// Create the scene
SCNScene *scene = [SCNScene scene];
/* Written for answer to http://stackoverflow.com/questions/23700556/getting-a-date-from-string-objective-c/23700701
Compile and run like so:
$> clang DateFormatterExample.m -ObjC -std=c99 -fobjc-arc -framework Foundation
$> ./a.out
*/
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
@armadsen
armadsen / CGMutablePathRef_NSInvocation.m
Last active August 29, 2015 13:56
Simple test program demonstrating use of NSInvocation to get CGMutablePathRef property by name
/* Compile and run like so:
$> clang CGMutablePathRef_NSInvocation.m -ObjC -std=c99 -fobjc-arc -framework Foundation -framework CoreGraphics
$> ./a.out
*/
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
@interface TestClass : NSObject
@armadsen
armadsen / MultipleClassExtensions.m
Last active January 4, 2016 11:59
Demonstration of multiple class extensions in Objective-C. For http://stackoverflow.com/a/21343983/344733
#import <Foundation/Foundation.h>
@interface TestClass : NSObject
@end
@interface TestClass ()
@property NSString *name;
@armadsen
armadsen / SeparateNSLocks.m
Last active December 25, 2015 21:49
Demo of separate instances of NSLock in response to this Stack Overflow question: http://stackoverflow.com/q/19451510/344733
#import <Foundation/Foundation.h>
@interface Test : NSObject
- (void)enqueue:(id)object;
- (id)dequeue;
@end
@implementation Test
@armadsen
armadsen / Reusable.m
Created June 21, 2013 17:49
Example of how I would do https://code.stypi.com/clifton/Objective-C/reusable.m if I were going to do it essentially the same way. In response to https://twitter.com/cliftonite/status/348133150880317440
- (void)makeGraphPopup:(NSString *)popupName {
/*
I want to pass a string (popupName) into this method and use it dynamically
for object names just like popupName.to_sym in Ruby.
Below you can see where I've insert {popupName} and how it would append itself
to various object names which are IBOutlets
*/
@armadsen
armadsen / CategoryPropertyDemo.m
Created March 14, 2013 21:42
Quick and dirty illustration of @Property declared (but not synthesized) in a category.
#import <Foundation/Foundation.h>
@interface MyClass : NSObject
@end
@implementation MyClass
@end
@interface MyClass (Properties)
@armadsen
armadsen / ORSSerialPort+Attributes.m
Last active July 11, 2018 13:44
Example code to get USB device properties for a given instance of ORSSerialPort. Will only work for USB-to-serial adapters, not internal serial ports. Based on https://gist.github.com/rhwood/4124251.
#import <Foundation/Foundation.h>
#import <IOKit/usb/USBSpec.h>
#import "ORSSerialPort.h"
@interface ORSSerialPort (Attributes)
@property (nonatomic, readonly) NSDictionary *ioDeviceAttributes;
@property (nonatomic, readonly) NSNumber *vendorID;
@property (nonatomic, readonly) NSNumber *productID;
@armadsen
armadsen / LabelDimensions.csv
Created March 4, 2013 18:49
CSV file containing dimensions information for various Avery label sheets.
labelTypeName labelSheetWidth labelSheetHeight topMargin bottomMargin leftMargin rightMargin numberOfRows numberOfColumns horizontalGutter verticalGutter
Avery 2160 Bottom 8.5 11 5.5 0.5 0.81 0.81 4 1 0 0
Avery 2160 Top 8.5 11 0.5 5.5 0.81 0.81 4 1 0 0
Avery 2162 Bottom 8.5 11 5.5 0.5 0.125 0.125 3 1 0 0
Avery 2162 Top 8.5 11 0.5 5.5 0.125 0.125 3 1 0 0
Avery 2163 Bottom 8.5 11 5.5 0.5 0.125 0.125 2 1 0 0
Avery 2163 Top 8.5 11 0.5 5.5 0.125 0.125 2 1 0 0
Avery 2164 Bottom 8.5 11 5.844 0.844 0.125 0.125 1 1 0 0
Avery 2164 Top 8.5 11 0.844 5.844 0.125 0.125 1 1 0 0
Avery 5159 8.5 11 0.25 0.25 0.156 0.156 7 2 0.188 0