Skip to content

Instantly share code, notes, and snippets.

View goldcoast's full-sized avatar
:atom:

Tait goldcoast

:atom:
  • Morningstar, Welab
  • shenzhen china
View GitHub Profile
//return an array of objects according to key, value, or key and value matching
function getObjects(obj, key, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(getObjects(obj[i], key, val));
} else
//if key matches and value matches or if key matches and value is not passed (eliminating the case where key matches but passed value does not)
if (i == key && obj[i] == val || i == key && val == '') { //
@goldcoast
goldcoast / gist:e320939d662d19e701f1
Created April 9, 2015 04:16
ios safari 上传图片变形bug
// answer get from: http://stackoverflow.com/questions/11929099/html5-canvas-drawimage-ratio-bug-ios
// usage example: drawImageIOSFix(context, img, 0, 0, file.width, file.height, 0,0, width, height);
/**
* Detecting vertical squash in loaded image.
* Fixes a bug which squash image vertically while drawing into canvas for some images.
* This is a bug in iOS6 devices. This function from https://github.com/stomita/ios-imagefile-megapixel
*
*/
function detectVerticalSquash(img) {
var iw = img.naturalWidth, ih = img.naturalHeight;
@goldcoast
goldcoast / gist:5dbaadaf308c8dcd33e8
Created March 23, 2015 01:37
手势密码后显示控制
- (void)applicationDidBecomeActive:(UIApplication *)application
{
NSDate* end = [NSDate date];
NSTimeInterval distanceBetweenDates = [self.current timeIntervalSinceDate:end];
//if time is more than LOCK_DISPLAY_TIME(30s)
if (fabs(distanceBetweenDates) > LOCK_DISPLAY_TIME)
{
UIViewController *root = [UIApplication sharedApplication].keyWindow.rootViewController;
while (root.presentedViewController)
{
@goldcoast
goldcoast / gist:90bba5d8a83be9f4ddd6
Created March 5, 2015 01:59
ios切换view controller
//http://stackoverflow.com/questions/12445190/dismissmodalviewcontrolleranimated-deprecated
[self presentViewController:xxViewController animated:NO completion:nil];
@goldcoast
goldcoast / gist:978ac14b2704d23cd24f
Last active August 29, 2015 14:16
viewController的两种初始化方法
// 1. init with storyboard
//@"xxViewController" 这个值需要在storyboard中indetity inspector的storyboard ID相同
//这种初始化可以带入storyboard的segue
xxViewController *xxViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"xxViewController"];
// 2. init directly
aaViewController *aaViewController = [[aaViewController alloc] init];
@goldcoast
goldcoast / example.code
Last active August 29, 2015 14:16
OC自定义构造方法,初始化私有变量
// human.h:
#import <Foundation/Foundation.h>
@interface Human : NSObject
{
int age;
NSString *name;
}
@goldcoast
goldcoast / gist:84e1fe8ccee56636b05d
Created February 15, 2015 09:29
setting title from within YourViewController:
//use other controller push to navigation controller
YourViewController *yourViewController = [[YourViewController alloc] init];
yourViewController.title = @"TestTitle";
[self.navigationController pushViewController:yourViewController animated:YES];
[yourViewController release];
// set current navigation title
self.navigationController.navigationBar.topItem.title = @"title 4 testing";