Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Refactoring

Koze Koze

:octocat:
Refactoring
View GitHub Profile
@Koze
Koze / WriteToPlist.js
Last active August 26, 2015 19:16
Write plist file with JavaScript for Automation and Objective-C Bridge.
View WriteToPlist.js
// use Foundation.framework
ObjC.import('Foundation');
// get applicaiton
app = Application.currentApplication();
// use StandardAdditions
app.includeStandardAdditions = true;
array = [1, 2, 3];
array.push(['a', 'b', 'c']);
@Koze
Koze / SampleTable.tsv
Last active August 27, 2015 10:26
sample data
View SampleTable.tsv
name inch scale colors
iPhone 3.5 1.0 black
iPhone 3G 3.5 1.0 black,white
iPhone 4 3.5 2.0 black,white
iPhone 5 4 2.0 black,white
iPhone 6 4.7 2.0 space gray,gold,silver
iPhone 6 Plus 5.5 3.0 space gray,gold,silver
@Koze
Koze / gist:b50d187fed615772b974
Last active August 29, 2015 14:16
JavaScript for Automation Objective-C bridge Sample
View gist:b50d187fed615772b974
ObjC.import('Cocoa')
//var array = $.NSArray.arrayWithObjects($('jp'), $('us'), $('es'), $('ru'));
var array = $(['jp', 'us', 'es', 'ru']);
for (var i=0; i<array.count; i++) {
var string = array.objectAtIndex(i);
var URLString = $.NSString.stringWithFormat('http://store.apple.com/%@/product/MB110CH/B/', string);
var URL = $.NSURL.URLWithString(URLString)
$.NSWorkspace.sharedWorkspace.openURL(URL)
}
@Koze
Koze / Assert.m
Last active August 29, 2015 14:18
NSAssert, NSCAssert
View Assert.m
// NSAssert can be used in method
- (void)method
{
NSAssert(false, @"message");
}
// NSCAssert can be used in function
void func()
{
NSCAssert(false, @"message");
@Koze
Koze / PrintClassHierarchy.m
Created April 4, 2015 16:30
Print Class Hierarchy
View PrintClassHierarchy.m
#import <objc/runtime.h>
void PrintClassHierarchy(Class cls) {
printf("// Class Hierarchy of %s\n", class_getName(cls));
Class superClass = cls;
while (superClass) {
printf("%s", class_getName(superClass));
superClass = class_getSuperclass(superClass);
if (superClass) {
printf(" : ");
@Koze
Koze / UIGestureRecognizerTarget.h
Last active August 29, 2015 14:18
UIGestureRecognizerTarget
View UIGestureRecognizerTarget.h
@interface UIGestureRecognizerTarget : NSObject {
id _target;
SEL _action;
}
- (NSString *)description;
@end
@Koze
Koze / MethodExhange1.m
Created April 8, 2015 15:01
Example for method_exchangeImplementations
View MethodExhange1.m
#import "ViewController.h"
#import <objc/runtime.h>
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
Class cls = self.class;
Method m1 = class_getInstanceMethod(cls, @selector(methodA));
@Koze
Koze / HookAddGestureRecognizer.m
Last active August 29, 2015 14:18
Hook addGestureRecognizer:
View HookAddGestureRecognizer.m
#import "ViewController.h"
#import <objc/runtime.h>
static NSMutableDictionary *_stack;
NSString *LogGesture(UIGestureRecognizer *gestureRecognizer);
@interface UIView (LogGesture)
- (void)exchangedAddGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer;
@end
@Koze
Koze / test1.m
Last active August 29, 2015 14:19
Invisible Characters in Xcode
View test1.m
- (NSString *)test
{
NSString *string = @"whitespace is invisible";
return string;
}
@Koze
Koze / Basic.xccolortheme.plist
Last active August 29, 2015 14:19
/Applications/Xcode.app/Contents/OtherFrameworks/XcodeEdit.framework/Resources/Basic.xccolortheme
View Basic.xccolortheme.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Colors</key>
<dict>
<key>Background</key>
<string>1.000 1.000 1.000</string>
<key>InsertionPoint</key>
<string>0.000 0.000 0.000</string>