Skip to content

Instantly share code, notes, and snippets.

View cyndibaby905's full-sized avatar

Fred Chen cyndibaby905

  • ByteDance
  • Beijing, China
View GitHub Profile
//
// KSDIdlingWindow.h
//
// Created by Brian King on 4/13/10.
// Copyright 2010 King Software Designs. All rights reserved.
//
// Based off:
// http://stackoverflow.com/questions/273450/iphone-detecting-user-inactivity-idle-time-since-last-screen-touch
//
@cyndibaby905
cyndibaby905 / gist:7781375
Created December 4, 2013 02:34
Animation issues
CABasicAnimation *positionAnimation;
positionAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
positionAnimation.fromValue = [NSValue valueWithCGPoint:fromPosition];
positionAnimation.toValue = [NSValue valueWithCGPoint:toPosition];
CABasicAnimation *alphaAnimation;
alphaAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
alphaAnimation.fromValue = [NSNumber numberWithFloat:fromAlpha];
alphaAnimation.toValue = [NSNumber numberWithFloat:toAlpha];
@cyndibaby905
cyndibaby905 / gist:8003205
Created December 17, 2013 11:00
Draw circle with two colors
CGFloat borderWidth = 3.f;
CGFloat circleRadius = self.bounds.size.width / 2 - borderWidth;
CGPoint circleCenter = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [[UIColor colorWithRed:255.0/255.0 green:210.0/255.0 blue:60.0/255.0 alpha:1] CGColor]);
UIBezierPath *firstHalf = [UIBezierPath bezierPath];
@cyndibaby905
cyndibaby905 / gist:8005951
Created December 17, 2013 14:43
Convert all frames of a gif pic to pngs
convert -coalesce googlechrome.gif target.png
@cyndibaby905
cyndibaby905 / UIImage+WebP.h
Created January 6, 2014 10:27
WebP extension
@interface UIImage(WebP)
- (id)initWithWebPData:(NSData *)data;
@end
@cyndibaby905
cyndibaby905 / curl.md
Created January 10, 2014 16:34 — forked from btoone/curl.md

Introduction

An introduction to curl using GitHub's API

The Basics

Makes a basic GET request to the specifed URI

curl https://api.github.com/users/caspyin
@cyndibaby905
cyndibaby905 / modalview.m
Last active January 3, 2016 10:59
How to write a modal view
UIViewController* avc = [[UIViewController alloc] init];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50,50,100,100)];
view.backgroundColor = [UIColor redColor];
[avc.view addSubview:view];
UIWindow* ow = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];
ow.windowLevel = UIWindowLevelAlert;
ow.backgroundColor = [UIColor clearColor];
ow.rootViewController = avc;
[ow makeKeyAndVisible];
@cyndibaby905
cyndibaby905 / PlayingInfo.m
Created January 20, 2014 09:11
Get iPod's current playing info. Do not use `MPNowPlayingInfoCenter`, since it works only for your current application.
MPMusicPlayerController* player = [MPMusicPlayerController iPodMusicPlayer];
//get now playing item
if (player.playbackState == MPMusicPlaybackStatePlaying) {
MPMediaItem*item = [player nowPlayingItem];
NSLog(@"playing %@",[item valueForProperty:MPMediaItemPropertyTitle]);
}
@cyndibaby905
cyndibaby905 / NSNUll+ InternalNullExtention.m
Created March 28, 2014 09:23
NSNUll+ InternalNullExtention.m
#define NSNullObjects @[@"",@0,@{},@[]]
@interface NSNull (InternalNullExtention)
@end
@implementation NSNull (InternalNullExtention)
@cyndibaby905
cyndibaby905 / orientation.m
Created April 23, 2014 02:05
Get device orientation using Accelerometer
CMMotionManager *_motionManager = [[CMMotionManager alloc] init];
_motionManager.accelerometerUpdateInterval = 0.1;
__block UIDeviceOrientation orientationLast = UIDeviceOrientationPortrait;
[_motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
UIDeviceOrientation orientationNew;
if (accelerometerData.acceleration.x >= 0.75) {
orientationNew = UIDeviceOrientationLandscapeRight;
}
else if (accelerometerData.acceleration.x <= -0.75) {
orientationNew = UIDeviceOrientationLandscapeLeft;