Skip to content

Instantly share code, notes, and snippets.

- (NSString *)ppi
{
NSString *ppi = @"";
if ([self.deviceName isEqualToString:@"iPod1,1"] ||
[self.deviceName isEqualToString:@"iPod2,1"] ||
[self.deviceName isEqualToString:@"iPod3,1"] ||
[self.deviceName isEqualToString:@"iPhone1,1"] ||
[self.deviceName isEqualToString:@"iPhone1,2"] ||
[self.deviceName isEqualToString:@"iPhone2,1"]) {
@dopcn
dopcn / main.m
Created December 15, 2016 08:46
fishhook hook NSSetUncaughtExceptionHandler
#import "AppDelegate.h"
#import "fishhook.h"
#import <dlfcn.h>
static NSUncaughtExceptionHandler *g_vaildUncaughtExceptionHandler;
static void (*ori_NSSetUncaughtExceptionHandler)( NSUncaughtExceptionHandler * );
void my_NSSetUncaughtExceptionHandler( NSUncaughtExceptionHandler * handler)
{
g_vaildUncaughtExceptionHandler = NSGetUncaughtExceptionHandler();
@dopcn
dopcn / gist:0ec19a52d7ea5440caf5
Last active December 23, 2015 15:54
recursion
import Foundation
var title = "fibonacci sequence"
func fib1(n: Int) -> Int {
switch n {
case 0: return 0
case 1: return 1
default: return fib1(n-1) + fib1(n-2)
}
@dopcn
dopcn / gist:779480f128bae5389fe8
Created July 21, 2015 12:52
xcode plugin renew
find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist -maxdepth 3 | xargs -I{} defaults write {} DVTPlugInCompatibilityUUIDs -array-add `defaults read /Applications/Xcode.app/Contents/Info.plist DVTPlugInCompatibilityUUID`
@dopcn
dopcn / gist:d87ac4aaeb73d1309bde
Last active August 29, 2015 14:24
based on control vs based on data
//based on control
//===============================================================================================================
- (void)iPhoneHandleOpenURL:(NSURL *)url {
NSString *keyword = url.host;
if ([keyword isEqualToString:@"feed"]) {
//
} else if ([keyword isEqualToString:@"board"]) {
//
} else if ([keyword isEqualToString:@"threads"]) {
//
#import "NSAttributedString+DXYTrim.h"
@implementation NSAttributedString (DXYTrim)
- (NSAttributedString *)attrStringByTrimmingCharacterInSet:(NSCharacterSet *)set {
__block __weak NSAttributedString*(^weak_leadingTrim)(NSAttributedString*);
NSAttributedString*(^leadingTrim)(NSAttributedString*);
weak_leadingTrim = leadingTrim = ^NSAttributedString*(NSAttributedString *attrString) {
NSRange range = [attrString.string rangeOfCharacterFromSet:set];
if (range.location == 0) {
@dopcn
dopcn / .gitignore
Last active August 29, 2015 14:17 — forked from adamgit/.gitignore
#########################
# .gitignore file for Xcode4 and Xcode5 Source projects
#
# Apple bugs, waiting for Apple to fix/respond:
#
# 15564624 - what does the xccheckout file in Xcode5 do? Where's the documentation?
#
# Version 2.3
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
@dopcn
dopcn / gist:d62262b6ceec1dc783cd
Created March 16, 2015 10:14
NSLineBreakByWordWrapping
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
paragraphStyle.alignment = NSTextAlignmentCenter;
[str drawInRect:rect withAttributes: @{NSFontAttributeName: f1,
NSParagraphStyleAttributeName: paragraphStyle }];
@dopcn
dopcn / NSLog all headers
Created July 29, 2014 09:25
NSLog all headers
NSString *className = NSStringFromClass([UIView class]);
const char *cClassName = [className UTF8String];
id theClass = objc_getClass(cClassName);
unsigned int outCount;