Skip to content

Instantly share code, notes, and snippets.

View dabing1022's full-sized avatar
👨‍💻
Focusing

ChildhoodAndy dabing1022

👨‍💻
Focusing
View GitHub Profile
// this code will cause a UIView to shake--good for "login error"
CAKeyframeAnimation * anim = [ CAKeyframeAnimation animationWithKeyPath:@"transform" ] ;
anim.values = [ NSArray arrayWithObjects:
[ NSValue valueWithCATransform3D:CATransform3DMakeTranslation(-5.0f, 0.0f, 0.0f) ],
[ NSValue valueWithCATransform3D:CATransform3DMakeTranslation(5.0f, 0.0f, 0.0f) ],
nil ] ;
anim.autoreverses = YES ;
anim.repeatCount = 2.0f ;
anim.duration = 0.07f ;
@dabing1022
dabing1022 / QuickKit.mm
Created July 8, 2015 03:25
常用方法片段
// 01. init method forbidden
- (id)init {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"-init is not a valid initializer for the class Foo"
userInfo:nil];
return nil;
}
- (NSArray *)matchUrlInString:(NSString *)string
{
NSError *error = NULL;
NSDataDetector *detectorLink = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:&error];
NSArray *urlMatchArr = [detectorLink matchesInString:string options:NSMatchingReportCompletion range:NSMakeRange(0, string.length)];
return urlMatchArr;
}
@dabing1022
dabing1022 / .gitignore
Last active August 29, 2015 14:16 — 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
#
@dabing1022
dabing1022 / LogClassMethods.m
Created January 30, 2015 08:13
LogClassMethods
- (void)logClassMethods:(Class)class
{
NSString* className = NSStringFromClass(class);
const char* cClassName = [className UTF8String];
id theClass = objc_getClass(cClassName);
unsigned int outCount;
Method* m = class_copyMethodList(theClass, &outCount);
NSLog(@"Class: %@, has methods: %d", className, outCount);
@dabing1022
dabing1022 / TextInput.m
Created October 8, 2014 03:20
Handling the keyboard notifications
// Call this method somewhere in your view controller setup code.
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
NSString *str = @"中国";
CFStringRef aCFString = (__bridge CFStringRef)str;
CFMutableStringRef string = CFStringCreateMutableCopy(NULL, 0, aCFString);
CFStringTransform(string, NULL, kCFStringTransformMandarinLatin, NO);
CFStringTransform(string, NULL, kCFStringTransformStripDiacritics, NO);
NSLog(@"中国 = %@", string);
@dabing1022
dabing1022 / CoreDataDemoSnippet.mm
Created July 15, 2014 02:28
CoreDataDemoSnippet
#pragma mark - CoreDataAbout
- (void)saveContext
{
NSError* error = nil;
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
if (managedObjectContext != nil) {
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
NSLog(@"Unresolved error :%@, %@", error, [error userInfo]);
abort();
@dabing1022
dabing1022 / GetDeviceInfo.mm
Last active May 22, 2022 06:57
IOS_GET_DEVICE_INFO
NSLog(@"HostName: %@", [[NSProcessInfo processInfo] hostName]);
//globallyUniqueString 唯一的标示符,每次调用都会不一样,可以用作一些临时缓存文件的名字
NSLog(@"GlobalUniqueString: %@", [[NSProcessInfo processInfo] globallyUniqueString]);
//操作系统名称
NSLog(@"OperatingSystemName: %@", [[NSProcessInfo processInfo] operatingSystemName]);
//操作系统版本
NSLog(@"OperatingSystemVersion: %@", [[NSProcessInfo processInfo] operatingSystemVersionString]);
//物理内存
NSLog(@"PhysicalMem: %llu", [[NSProcessInfo processInfo] physicalMemory]);
//进程名称
@dabing1022
dabing1022 / 0_reuse_code.js
Created July 3, 2014 07:11
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