Skip to content

Instantly share code, notes, and snippets.

View tuchangwei's full-sized avatar

Changwei tuchangwei

View GitHub Profile
@tuchangwei
tuchangwei / post-commit
Last active January 24, 2024 13:11
Upload git log to Clickup via git hooks
#!/usr/bin/env ruby
# how to use?
# 1, input your your_api_key
# 2, make the file executable first: chmod +x post-commit
# 3, put the file in your_project/.git/hooks/ folder
require "git"
require 'net/http'
require 'json'
echo sha, contributor, date, message > log.csv
git log --date=local --pretty=format:'%h, %an, %ad, "%s"' >> log.csv
fun calculateInSampleSize(options: BitmapFactory.Options, reqWidth: Int, reqHeight: Int): Int {
// Raw height and width of image
val (height: Int, width: Int) = options.run { outHeight to outWidth }
var inSampleSize = 1
if (height > reqHeight || width > reqWidth) {
val halfHeight: Int = height / 2
val halfWidth: Int = width / 2
1, 赖世雄英标,2周三遍。
2, ESL 3~4个月。学习方法:
例如,针对职场人士工作的需要,
使用商业类的那三本教材最佳。试 拿Interview Questions Answered举例说明 如何最大限度地优化自己的学习流程:
A.首先不要看教材文本,花上两三 天时间,仔细地把全本书的音频听完。 放心,Jeff博士讲课非常细心,生词都一 个个拼写出来,绝对不用担心听不懂。 如果不是因为生词原因而听不懂,听的 时候绝对不要做别的事情,要拿出笔记 本,做好笔记。
B.初步听完后,开始读教材,花个 3∼4天的时间,对照着笔记把教材文本 里面的生词短语之类的都搞定。
C.之后开始进行跟读的练习,每天 跟读多少的量、多长时间要自己安排, 以能接受为准。
跟读练习是我们这里的重头戏。我
建议大家最好对教材全文跟读,不管是
讲解还是单纯的课程录音,对形成你的
转自:https://www.zybuluo.com/MicroCai/note/64272
本文名为《GCD 实现同步锁》,内容不止于锁。文章试图通过 GCD 同步锁的问题,尽量往外延伸扩展,以讲解更多 GCD 同步机制的内容。
引语:线程安全问题
如果一段代码所在的进程中有多个线程在同时运行,那么这些线程就有可能会同时运行这段代码。假如多个线程每次运行结果和单线程运行的结果是一样的,而且其他的变量的值也和预期的是一样的,就是线程安全的。或者说:一个类或者程序所提供的接口对于线程来说是原子操作或者多个线程之间的切换不会导致该接口的执行结果存在二义性,也就是说我们不用考虑同步的问题。
由于可读写的全局变量及静态变量可以在不同线程修改,所以这两者也通常是引起线程安全问题的所在。在 Objective-C 中还包括属性和实例变量(实际上属性和实例变量本质上也可以看做类内的全局变量)。
Objective-C 同步锁
@tuchangwei
tuchangwei / introrx.md
Created November 7, 2016 08:42 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
~ 将光标下的字母改变大小写
3~ 将光标位置开始的3个字母改变其大小写
g~~ 改变当前行字母的大小写
U 将可视模式下选择的字母全改成大写字母
u 将可视模式下选择的字母全改成小写
In Terminal, run these commands:
cd [Project folder]
find . -name \*.m | xargs genstrings -o .
@tuchangwei
tuchangwei / TypeErasure.swift
Created March 3, 2016 02:10 — forked from gwengrid/TypeErasure.swift
Example of type erasure with Pokemon
class Thunder { }
class Fire { }
protocol Pokemon {
typealias PokemonType
func attack(move:PokemonType)
}
struct Pikachu: Pokemon {
typealias PokemonType = Thunder
@tuchangwei
tuchangwei / gist:d0e3186d123a63ac3b7e
Created December 29, 2015 04:15 — forked from iwasrobbed/gist:5528897
UICollectionView w/ NSFetchedResultsController & NSBlockOperation. Idea originated from Blake Watters (https://github.com/AshFurrow/UICollectionView-NSFetchedResultsController/issues/13)
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
self.shouldReloadCollectionView = NO;
self.blockOperation = [[NSBlockOperation alloc] init];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id<NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type
{
__weak UICollectionView *collectionView = self.collectionView;