Skip to content

Instantly share code, notes, and snippets.

View HarrisHan's full-sized avatar
🎯
Focusing

Harris HarrisHan

🎯
Focusing
View GitHub Profile
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
- (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系统中就可以使用他了
@HarrisHan
HarrisHan / gist:a71b7584d10adf6478fb8c4749128574
Created January 11, 2017 08:11
beginningOfDay and endOfDay
+ (NSDate *)beginningOfDay:(NSDate *)date;
{
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:( NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond ) fromDate:date];
[components setHour:0];
@HarrisHan
HarrisHan / gist:4f1cb8b6e67fcf8c14c3cdce066059a0
Created December 1, 2016 08:13
count down using button and NSTimer
- (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
{
@HarrisHan
HarrisHan / gist:a4dbc4926e7365fe2588ec507aa50234
Created December 1, 2016 08:13
count down using button and NSTimer
- (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
{
@HarrisHan
HarrisHan / gist:8a3a257765f4bcd364a61280e3f9e9fd
Created December 1, 2016 08:13
count down using button and NSTimer
- (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
{
@HarrisHan
HarrisHan / gist:959da6de8fb05f72d5ec4e29696d9ea2
Created December 1, 2016 08:12
count down using button and NSTimer
- (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
{
@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;
}
@HarrisHan
HarrisHan / this is a category for NSString to calculate the lengh of a string
Last active August 20, 2016 05:46
limit textField textView input char length
+ (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++;