This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
q = [] | |
def producer(): | |
while True: | |
item = random.randrange(100) | |
print 'produce', item | |
yield item |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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;", | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[UIView animateWithDuration:0.0f animations:^{ | |
[textView_ becomeFirstResponder]; | |
}]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (void)dismissKeyboard { | |
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) | |
to:nil | |
from:nil | |
forEvent:nil]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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 ] ; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface UIImageView (Touch) | |
@property(nonatomic, assign) id delegate; | |
@end | |
@protocol UIImageViewTouchDelegate <NSObject> | |
@optional | |
- (void)imageViewDidTouch:(UIImageView *)imageView withPoint:(CGPoint)point; | |
@end | |
@implementation UIImageView (Touch) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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', |