Skip to content

Instantly share code, notes, and snippets.

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

ChildhoodAndy dabing1022

👨‍💻
Focusing
View GitHub Profile
// Code by Francois Guibert
// Contact: www.frozax.com - http://twitter.com/frozax - www.facebook.com/frozax
#include "CCShake.h"
#include "cocos2d.h"
USING_NS_CC;
// not really useful, but I like clean default constructors
CCShake::CCShake() : m_strength_x(0), m_strength_y(0), m_initial_x(0), m_initial_y(0)
@dabing1022
dabing1022 / UIKitBox2dView.h
Last active August 29, 2015 14:01
UIKitBox2dView
#import <UIKit/UIKit.h>
#import <Box2D/Box2D.h>
@interface ViewController : UIViewController <UIAccelerometerDelegate> {
b2World* world;
NSTimer *tickTimer;
b2Vec2 gravity;
}
@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
@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 / 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();
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 / 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];
@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 / .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
#
- (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;
}