Skip to content

Instantly share code, notes, and snippets.

@kaiix
kaiix / GlossGradientButton.h
Created May 28, 2012 11:55
Gloss gradients button for ios
//
// GlossGradientButton.h
// iOS version of gloss gradients button
// original version for Mac OSX http://cocoawithlove.com/2008/09/drawing-gloss-gradients-in-coregraphics.html
//
#import <UIKit/UIKit.h>
@interface GlossGradientButton : UIButton {
UIColor *buttonColor_;
@kaiix
kaiix / gist:2928980
Created June 14, 2012 08:21
Django logging config
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'formatters': {
@kaiix
kaiix / gist:4070333
Created November 14, 2012 04:56
interesting_repos_plist
#!/bin/env python
fixtures = [{'forks': u'159', 'lang': u'Objective-C', 'name': u'nu', 'stars': u'1,671'},
{'forks': u'299',
'lang': u'JavaScript',
'name': u'prototype',
'stars': u'2,504'},
{'forks': u'197', 'lang': u'C++', 'name': u'passenger', 'stars': u'1,413'},
{'forks': u'464',
'lang': u'JavaScript',
@kaiix
kaiix / gist:4070967
Created November 14, 2012 08:20
Add dotted/dashed border to a UITableViewCell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
@kaiix
kaiix / gist:4212431
Created December 5, 2012 05:02
UIImageView+Touch
@interface UIImageView (Touch)
@property(nonatomic, assign) id delegate;
@end
@protocol UIImageViewTouchDelegate <NSObject>
@optional
- (void)imageViewDidTouch:(UIImageView *)imageView withPoint:(CGPoint)point;
@end
@implementation UIImageView (Touch)
@kaiix
kaiix / gist:4212439
Created December 5, 2012 05:03
UIView shake animation
- (void)shake {
CAKeyframeAnimation * anim = [ CAKeyframeAnimation animationWithKeyPath:@"transform" ] ;
anim.values = @[
[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(-5.0f, 0.0f, 0.0f) ],
[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(5.0f, 0.0f, 0.0f)]];
anim.autoreverses = YES ;
anim.repeatCount = 2.0f ;
anim.duration = 0.07f ;
[self.layer addAnimation:anim forKey:nil ] ;
}
@kaiix
kaiix / gist:4223242
Created December 6, 2012 09:32
dismiss keyboard
+ (void)dismissKeyboard {
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder)
to:nil
from:nil
forEvent:nil];
}
@kaiix
kaiix / gist:4223248
Created December 6, 2012 09:33
control keyboard animation speed
[UIView animateWithDuration:0.0f animations:^{
[textView_ becomeFirstResponder];
}];
@kaiix
kaiix / gist:11165467
Created April 22, 2014 04:37
netease cloud music
# coding: utf-8
import requests
MAX_COUNT = 10
DOWNLOAD_DIR = "/Users/kaiix/Music/Songs/"
common_headers = {
"User-Agent": "网易云音乐 1.7.1 (iPhone; iPhone OS 7.1; en_US)",
"Cookie": "os=iPhone OS; osver=7.1; appver=1.7.1;",
}
@kaiix
kaiix / gist:b9f0e2b32f2380d52458
Created November 25, 2014 04:31
generator based coroutine
import random
q = []
def producer():
while True:
item = random.randrange(100)
print 'produce', item
yield item