Skip to content

Instantly share code, notes, and snippets.

@kaiix
kaiix / cuckoo.scptd
Last active November 26, 2015 09:42
notify time
on cuckoo()
set dateStr to time string of (current date)
set meow to POSIX path of (path to resource "meow.mp3")
display notification dateStr with title "Meow"
do shell script ("afplay " & meow)
end cuckoo
script main
cuckoo()
end script
@kaiix
kaiix / mongodb.logrotate
Last active December 30, 2020 03:55
logrotate mongodb log
/var/log/mongodb/mongod.log {
hourly
missingok
rotate 5
compress
delaycompress
notifempty
create 0640 mongodb mongodb
sharedscripts
postrotate
# 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 / 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)
@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 / 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:4223248
Created December 6, 2012 09:33
control keyboard animation speed
[UIView animateWithDuration:0.0f animations:^{
[textView_ becomeFirstResponder];
}];
@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: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: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)