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
netstat -vanp tcp | grep 3000 | |
sudo lsof -i tcp:3000 | |
kill -9 PID | |
kill $(lsof -t -i :YOUR_PORT_NUMBER) | |
echo 'free-port() { kill "$(lsof -t -i :$1)"; } | |
kill-port() { kill -kill "$(lsof -t -i :$1)"; }' \ | |
>> ~/.bashrc && source ~/.bashrc |
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)createClass | |
{ | |
Class MyClass = objc_allocateClassPair([NSObject class], "myclass", 0); | |
//添加一个NSString的变量,第四个参数是对其方式,第五个参数是参数类型 | |
if (class_addIvar(MyClass, "itest", sizeof(NSString *), 0, "@")) { | |
NSLog(@"add ivar success"); | |
} | |
//myclasstest是已经实现的函数,"v@:"这种写法见参数类型连接 | |
class_addMethod(MyClass, @selector(myclasstest:), (IMP)myclasstest, "v@:"); | |
//注册这个类到runtime系统中就可以使用他了 |
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
+ (NSDate *)beginningOfDay:(NSDate *)date; | |
{ | |
NSCalendar *cal = [NSCalendar currentCalendar]; | |
NSDateComponents *components = [cal components:( NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond ) fromDate:date]; | |
[components setHour:0]; | |
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)startTimer | |
{ | |
self.leftSecondsNum = 59; | |
self.fetchCodeBtn.enabled = NO; | |
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(refreshCountNum) userInfo:nil repeats:YES]; | |
[self.fetchCodeBtn setTitle:[NSString stringWithFormat:@"重新获取(%ld)", (long)self.leftSecondsNum] forState:UIControlStateDisabled]; | |
} | |
- (void)endupTimer | |
{ |
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)startTimer | |
{ | |
self.leftSecondsNum = 59; | |
self.fetchCodeBtn.enabled = NO; | |
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(refreshCountNum) userInfo:nil repeats:YES]; | |
[self.fetchCodeBtn setTitle:[NSString stringWithFormat:@"重新获取(%ld)", (long)self.leftSecondsNum] forState:UIControlStateDisabled]; | |
} | |
- (void)endupTimer | |
{ |
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)startTimer | |
{ | |
self.leftSecondsNum = 59; | |
self.fetchCodeBtn.enabled = NO; | |
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(refreshCountNum) userInfo:nil repeats:YES]; | |
[self.fetchCodeBtn setTitle:[NSString stringWithFormat:@"重新获取(%ld)", (long)self.leftSecondsNum] forState:UIControlStateDisabled]; | |
} | |
- (void)endupTimer | |
{ |
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)startTimer | |
{ | |
self.leftSecondsNum = 59; | |
self.fetchCodeBtn.enabled = NO; | |
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(refreshCountNum) userInfo:nil repeats:YES]; | |
[self.fetchCodeBtn setTitle:[NSString stringWithFormat:@"重新获取(%ld)", (long)self.leftSecondsNum] forState:UIControlStateDisabled]; | |
} | |
- (void)endupTimer | |
{ |
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
@implementation UIView (ScreenShot) | |
- (UIImage *)apo_screenshotImage | |
{ | |
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0); | |
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:NO]; | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return image; | |
} |
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
+ (NSUInteger)countLengthOfString:(NSString *)textString { | |
NSUInteger strlength = 0; | |
char *p = (char *)[textString cStringUsingEncoding:NSUnicodeStringEncoding]; | |
for (int i = 0; i < [textString lengthOfBytesUsingEncoding:NSUnicodeStringEncoding]; i++) { | |
if (*p) { | |
p++; | |
strlength++; |