Skip to content

Instantly share code, notes, and snippets.

View hanfengs's full-sized avatar

hanfengs

  • Beijing China
View GitHub Profile
@hanfengs
hanfengs / fangzhou.md
Created August 7, 2019 01:44
[方舟编译器]

早上地铁的时间就看了这一篇文章《方舟编译器的荣光和使命》,总结一下:

安卓的四大问题

1;java虚拟机+编译器+解释器,应用安装或者空闲编译,在手机上生成二进制的机器码

2;额外的JNI开销,用于和C/C++代码交互,

3;代码优化空间有限,为了防止生态过于碎片化,为第三方开放了简单的优化

@hanfengs
hanfengs / btn.m
Created August 14, 2019 10:54
[UIButton文字和图片间距随意调整]
UIButton category
-----------------------------------------.h
// 定义一个枚举(包含了四种类型的button)
typedef NS_ENUM(NSUInteger, GLButtonEdgeInsetsStyle) {
GLButtonEdgeInsetsStyleTop, // image在上,label在下
GLButtonEdgeInsetsStyleLeft, // image在左,label在右
GLButtonEdgeInsetsStyleBottom, // image在下,label在上
GLButtonEdgeInsetsStyleRight // image在右,label在左
};
@hanfengs
hanfengs / auth.m
Last active August 30, 2019 09:57
[鉴权说明]
#import <CommonCrypto/CommonDigest.h>
#import <CommonCrypto/CommonHMAC.h>
#import "NSString+Hash.h"
NSString *username = @"quxueabc";
NSString *accessKey = @"k3on19kusewub1swa2u";
NSString *secretKey = @"3z1nhvcngrdk8xlrnor";
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.locale = [NSLocale localeWithLocaleIdentifier:@"en-us"];
@hanfengs
hanfengs / op.m
Created August 20, 2019 09:23
[多选项(4或者更多),自动布局]
UIImageView *lastIV = nil;
self.ivArrM = [NSMutableArray array];
for (NSInteger i = 0; i < 4; i++) {
UIImageView *iv = [[UIImageView alloc] init];
[self addSubview:iv];
[iv mas_makeConstraints:^(MASConstraintMaker *make) {
if (isPad) {
make.width.mas_equalTo(163);
}else{
make.width.equalTo(self).multipliedBy(0.5).offset(-IVMragin16 * 1.5);
@hanfengs
hanfengs / array.m
Created August 26, 2019 02:28
[数组去重]
//1.开辟新的内存空间
NSArray *originalArr = @[@1, @2, @3, @1, @3];
NSMutableArray *resultArrM = [NSMutableArray array];
for (NSString *item in originalArr) {
if (![resultArrM containsObject:item]) {
[resultArrM addObject:item];
}
}
@hanfengs
hanfengs / file.m
Created September 7, 2019 06:11
[沙盒数据追加,不是覆盖]
+(void)writefile:(NSString *)string fileName:(NSString *)fileName{
NSLog(@"fileName==%@",fileName);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *homePath = [paths objectAtIndex:0];
NSString *filePath = [homePath stringByAppendingPathComponent:fileName];
NSFileManager *fileManager = [NSFileManager defaultManager];
//如果不存在
if(![fileManager fileExistsAtPath:filePath]){
@hanfengs
hanfengs / ws.m
Last active September 17, 2019 10:14
[webSocket发送text and binary message]
- (void)SRWebSocketDidOpen {
NSLog(@"开启成功");
//在成功后需要做的操作。。。
NSDictionary *dict = @{
@"ref_text": @"sunny",
@"audio_format": @{
@"type": @"WAV",
@"audio_channel": @(1),
@"sample_rate": @(16000)
@hanfengs
hanfengs / image.m
Last active September 17, 2019 10:20
[二进制文件头,判断文件格式]
https://ioscaff.com/articles/262?order_by=created_at&
//WebImage 框架为 NSData 实现了个分类来判断二进制文件图片格式
+ (SDImageFormat)sd_imageFormatForImageData:(nullable NSData *)data {
if (!data) {
return SDImageFormatUndefined;
}
// File signatures table: http://www.garykessler.net/library/file_sigs.html
@hanfengs
hanfengs / cache.m
Last active September 18, 2019 09:49
[暂存]
TSStemLabel *stem = [[TSStemLabel alloc] init];
stem.numberOfLines = 0;
stem.text = @" $$CCTV$$ reported that every year Chinese people throw away a lot of food. Luckily, a number of people have realized the importance of saving food. {Last November}, Li Hong, a waitress in a restaurant in $$Nanjing$$, lost her job because she took some leftover food home for her son. Many people stood by her side.@What should we do in our daily life to waste less food? Here are two tips:@1. Don’t order too much food. If you can’t eat all the food you order, take the rest of it home.@2. Don’t keep too much food at home, especially for {vegetables} and fruit.In my opinion, everybody must save food.";
CGFloat height = stem.stemHeight;
[self addSubview:stem];
[stem mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(LRMragin);
make.right.equalTo(self).offset(-LRMragin);
make.height.mas_equalTo(height);
make.top.equalTo(self).offset(35);
@hanfengs
hanfengs / copy.m
Created November 5, 2019 06:11
[自定义对象深拷贝]
.h文件中
@interface DemoModel : NSObject<NSCopying,NSMutableCopying>
@property (nonatomic,assign) NSInteger age;
@property (nonatomic,  copy) NSString * name;
.m文件中 实现copyWithZone mutableCopyWithZone 方法