Skip to content

Instantly share code, notes, and snippets.

View manajay's full-sized avatar
🎯
Focusing

manajay manajay

🎯
Focusing
View GitHub Profile
@manajay
manajay / oc-arc-memory-release.codesnippest
Last active March 8, 2020 04:52
研究OC在ARC下内存释放的问题代码
#import "ReleaseViewController.h"
void testStrongRelease0(void) ;
void testStrongRelease1(void) ;
void testStrongRelease2(void) ;
#define MNJSpaceLog() do { NSLog(@"\n\n");} while(0)
@interface MNJObject : NSObject
+ (instancetype)object;
@manajay
manajay / string-contains-in-strings-case-insensitive.codesnippest
Created August 29, 2019 15:47
比较字符串是否在数组中, 忽略大小写
// 比较字符串是否在数组中, 忽略大小写 参考 https://segmentfault.com/a/1190000000623005
NSPredicate *p = [NSPredicate predicateWithFormat:@"SELF ==[cd] %@",self];
NSArray *r = [strings filteredArrayUsingPredicate:p];
return r.count > 0;
/<(?:.|\s)*?>/g
/**
example
'<span class='at-member'>@manajay</span> hello world!'.replace(/<(?:.|\s)*?>/g, '')
==> '@manajay hello world!'
*/
@manajay
manajay / codesnippest
Created June 18, 2019 07:52
url-match-pattern
@"((http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)|(www.[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)";
@manajay
manajay / loadBundleImage.codesnippest
Created February 11, 2019 12:52
custom pod loadBundleImage
//
// LSBundleUtil.m
// Pods
//
// Created by ljtwan on 2018/10/9.
//
#import "LSBundleUtil.h"
@implementation LSBundleUtil
@manajay
manajay / unzip_ipa2app.codesnippest
Created December 8, 2018 08:26
解压 ipa 包为 App 文件
# -*- coding: UTF-8 -*-
#!/usr/bin/python
import sys, getopt
# gz: 即gzip。通常仅仅能压缩一个文件。与tar结合起来就能够实现先打包,再压缩。
#
# tar: linux系统下的打包工具。仅仅打包。不压缩
#
# tgz:即tar.gz。先用tar打包,然后再用gz压缩得到的文件
@manajay
manajay / oc_calculate_label_text_in_single_line.codesnippest
Created December 6, 2018 08:58
oc_calculate_label_text_in_single_line.codesnippest
//
// UILabel+LSFrame.m
// iLawSchool
//
// Created by ljtwan on 2018/8/30.
// Copyright © 2018 iCourt. All rights reserved.
//
#import "UILabel+LSFrame.h"
#import <CoreText/CoreText.h>
@manajay
manajay / oc_draw_CornerimageMaskMask.codesnippest
Created November 10, 2018 11:46
创建圆角的图片遮罩, insertSubview 到底部
- (UIImage *)createRoundedCornerImageWithRadius:(CGFloat)radius outerSize:(CGSize)outerSize innerSize:(CGSize)innerSize fillColor:(UIColor *)fillColor {
UIGraphicsBeginImageContextWithOptions(outerSize, false, [UIScreen mainScreen].scale);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
UIBezierPath *bezierPath = [[UIBezierPath alloc] init];
CGFloat xOffset = (outerSize.width - innerSize.width) / 2;
CGFloat yOffset = (outerSize.height - innerSize.height) / 2;
@manajay
manajay / oc_draw_image_corner.codesnippest
Created November 10, 2018 09:00
oc 高效绘制圆角
- (UIImage*)lj_imageAddCornerWithRadius:(CGFloat)radius byRoundingCorners:(UIRectCorner)corners borderWidth:(CGFloat)borderWidth borderColor:(UIColor *)borderColor imageSize:(CGSize)size {
// 1. 创建一个画布
CGRect rect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
// 2. 获取图形上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
// 3. 计算 path 圆角
UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)];
CGContextAddPath(ctx,path.CGPath);
@manajay
manajay / method-swizzling-oc
Created August 20, 2018 11:59
method-swizzling-oc
+ (void)ls_methodSwizzlingWithOriginalSelector:(SEL)originalSelector swizzledSelector:(SEL)swizzledSelector {
Class class = [self class];
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
// When swizzling a class method, use the following:
// Class class = object_getClass((id)self);
// ...
// Method originalMethod = class_getClassMethod(class, originalSelector);