Skip to content

Instantly share code, notes, and snippets.

View koromiko's full-sized avatar

Shih Ting Huang (Neo) koromiko

View GitHub Profile
@koromiko
koromiko / example.js
Created September 18, 2013 02:45
Welcome to your first Gist! Gists are simple code reminders. Whenever you come across a piece of code you think might be useful later on, save it as a Gist. With GistBox, you can also tag the Gist with a label. This is especially useful for keeping them organized by language, project or purpose. For more info about GistBox, visit: http://www.gi…
// log an object to the browser console
console.log({ text: "foobar" });
@koromiko
koromiko / new_gist_file
Created October 11, 2013 05:34
spin animation
- (void) runSpinAnimationOnView:(UIView*)view duration:(CGFloat)duration rotations:(CGFloat)rotations repeat:(float)repeat;
{
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];
rotationAnimation.duration = duration;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = repeat;
[view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
@koromiko
koromiko / new_gist_file
Created October 11, 2013 06:09
dissolve image transition
self.imgeView.image = xxxx;
CATransition *transition = [CATransition animation];
transition.duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.imageView.layer addAnimation:transition forKey:nil];
@koromiko
koromiko / MBProgressHUD
Created December 11, 2013 03:53
MBProgressHUD
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[MBProgressHUD hideHUDForView:self.view animated:YES];
@koromiko
koromiko / singleton
Created December 11, 2013 09:38
singleton defination
+ (SSNetworkDataSource*)sharedDataSource{
static dispatch_once_t pred;
static SSNetworkDataSource *obj = nil;
dispatch_once(&pred, ^{
obj = [[SSNetworkDataSource alloc]init];
});
return obj;
}
@koromiko
koromiko / block
Created December 12, 2013 03:46
block define
- (void)requestForSomethingWithComplete:(void (^)(void))completeBlock fail:(void (^)(NSError* error))failBlock;
@koromiko
koromiko / device_bound
Created January 2, 2014 08:25
bound frame size for ipad or landscape view
CGRect windowBounds;
if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
windowBounds = CGRectMake( 0.0f, 0.0f, [[UIScreen mainScreen]bounds].size.height, [UIScreen mainScreen].bounds.size.width );
}else{
windowBounds = CGRectMake( 0.0f, 0.0f, [[UIScreen mainScreen]bounds].size.width, [UIScreen mainScreen].bounds.size.height );
}
@koromiko
koromiko / touch event in view
Created January 2, 2014 10:20
detect touch event
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
/* if touch point inside the konogram image */
if(CGRectContainsPoint(self.magCoverImageView.frame, touchPoint)){
if(self.delegate!=nil && [self.delegate respondsToSelector:@selector(didClickOnImageForNewIssueCell:)]){
class HttpClient {
typealias completeClosure = ( _ data: Data?, _ error: Error?)->Void
func get( url: URL, callback: @escaping completeClosure ) {
let request = NSMutableURLRequest(url: url)
request.httpMethod = "GET"
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
callback(data, error)
}
task.resume()
}
HttpClient().get(url: url) { (success, response) in // Return data }