Skip to content

Instantly share code, notes, and snippets.

@klone1127
klone1127 / 获取当前线程ID
Created June 17, 2020 03:40
获取当前线程ID
__uint64_t ttt = 0;
pthread_t pt = pthread_self();
pthread_threadid_np(pt, &ttt);
NSLog(@"pid +++++:%llu", ttt);
参考:
https://stackoverflow.com/a/21206357/4626482
https://opensource.apple.com/source/Libc/Libc-583/pthreads/pthread.c
@klone1127
klone1127 / 根据FILE获取文件绝对路径
Last active June 14, 2020 08:42
根据 FILE 获取文件路径
NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
NSString *file = [path stringByAppendingFormat:@"/test.txt"];
const char *filePath = [[NSFileManager defaultManager] fileSystemRepresentationWithPath:file];
FILE *fd = fopen(filePath, "a+");
char *obj_file;
obj_file = malloc(PATH_MAX);
char buf[1024] = {'\0'};
/** 在 iOS/MacOS 上测试拿不到绝对路径,https://stackoverflow.com/a/13544447/4626482
@klone1127
klone1127 / 执行 self 中的 sel
Last active May 6, 2020 02:13
iOS 执行方法
SEL sel = NSSelectorFromString(@"adViewDismiss");
static void(*action)(id, SEL) = (void(*)(id, SEL))objc_msgSend;
action(self, sel);
@klone1127
klone1127 / 更改Xcode项目名称
Last active December 1, 2021 09:41
更改项目名称脚本
oldName="$1"
newName="$2"
oldNameAll=""$oldName"*"
brew install rename ack
rm podfile.lock
rm -rf Pods
rm *.xcworkspace
@klone1127
klone1127 / 显示 tag 中的签名信息
Last active April 24, 2019 06:34
显示 tag 中的签名信息
添加tag:
git tag -a 版本号 -m "要添加的签名信息"
获取最新 tag 对应的签名信息
git cat-file -p $(git rev-parse $(git tag -l | tail -n1)) | tail -n +6
获取指定 tag 对应的签名信息
@klone1127
klone1127 / 获取远端json并使版本号自增
Created March 26, 2019 08:44
获取远端json并使版本号自增
versionURL="https://xxx.json"
versionNum=`curl $versionURL | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["version"]' | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}'`
// 获取对应的版本号
python -c 'import json,sys;obj=json.load(sys.stdin);print obj["version"]'
// 版本号自增,如: 1.0.1 -> 1.0.2
awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}'
@klone1127
klone1127 / 树莓派安装seafile
Created March 26, 2019 01:24
树莓派安装seafile问题记录
OS: Ubuntu 18
树莓派 3B
服务端安装包下载地址: https://github.com/haiwen/seafile-rpi/releases
安装教程使用的英文版: https://manual.seafile.com/deploy/using_sqlite.html
以下操作均在 root 用户下完成
问题1:
执行 setup-seafile.sh 脚本时提示:
@klone1127
klone1127 / windows server 上安装openSSH 服务
Last active March 21, 2019 07:00
windows server 上安装openSSH 服务
安装服务
@klone1127
klone1127 / 私有库Cocoapods
Last active January 21, 2019 10:05
创建私有库(pods)
We couldn’t find that file to show.
@klone1127
klone1127 / universal-framework.sh
Created April 11, 2018 00:48 — forked from cromandini/universal-framework.sh
This run script will build the iphoneos and iphonesimulator schemes and then combine them into a single framework using the lipo tool (including all the Swift module architectures).
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build