Skip to content

Instantly share code, notes, and snippets.

@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
@kaiix
kaiix / echoserv.py
Last active August 29, 2015 14:10
coroutine rocks
import socket
from pyos import Scheduler
from pyos import NewTask
from pyos import Accept, Send, Receive
def handle_client(client, addr):
print "Connection from", addr
while True:
data = yield Receive(client, 65536)
# http://blog.hakril.net/articles/0-understanding-python-by-breaking-it.html
def get_ref(obj):
""" returns a c_size_t, which is the refcount of obj """
return ctypes.c_size_t.from_address(id(obj))
@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: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];
}];