Skip to content

Instantly share code, notes, and snippets.

View tangyumeng's full-sized avatar

tangyumeng tangyumeng

View GitHub Profile
@tangyumeng
tangyumeng / libdispatch-efficiency-tips.md
Created May 26, 2023 14:21 — forked from tclementdev/libdispatch-efficiency-tips.md
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

@tangyumeng
tangyumeng / a.c
Created January 3, 2022 12:54 — forked from wiggin15/a.c
vm_region_recurse_64 / proc_regionfilename
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <libproc.h>
#include <mach/mach.h>
#include <CoreFoundation/CoreFoundation.h>
int main(void)
{
@tangyumeng
tangyumeng / find-unused-images.sh
Created February 5, 2020 03:19 — forked from danielctull/find-unused-images.sh
A script to find images that are not used in an iOS project. Originally from http://stackoverflow.com/questions/6113243/how-to-find-unused-images-in-an-xcode-project
#!/bin/sh
PROJ=`find . -name '*.xib' -o -name '*.[mh]'`
for png in `find . -name '*.png'`
do
name=`basename $png`
if ! grep -q $name $PROJ; then
echo "$png is not referenced"
fi
done
@tangyumeng
tangyumeng / AsynchronousOperation.swift
Created January 10, 2020 11:23 — forked from Sorix/AsynchronousOperation.swift
Subclass of NSOperation (Operation) to make it asynchronous in Swift 3, 4, 5
// Created by Vasily Ulianov on 09.02.17, updated in 2019.
// License: MIT
import Foundation
/// Subclass of `Operation` that adds support of asynchronous operations.
/// 1. Call `super.main()` when override `main` method.
/// 2. When operation is finished or cancelled set `state = .finished` or `finish()`
open class AsynchronousOperation: Operation {
public override var isAsynchronous: Bool {
@tangyumeng
tangyumeng / AsynchronousOperation.swift
Created January 10, 2020 11:23 — forked from Sorix/AsynchronousOperation.swift
Subclass of NSOperation (Operation) to make it asynchronous in Swift 3, 4, 5
// Created by Vasily Ulianov on 09.02.17, updated in 2019.
// License: MIT
import Foundation
/// Subclass of `Operation` that adds support of asynchronous operations.
/// 1. Call `super.main()` when override `main` method.
/// 2. When operation is finished or cancelled set `state = .finished` or `finish()`
open class AsynchronousOperation: Operation {
public override var isAsynchronous: Bool {
@tangyumeng
tangyumeng / Calculate
Created July 11, 2018 08:13 — forked from AnYuan/Calculate
TextKit calculate text height
+ (CGSize)rectForAttributedString:(NSAttributedString *)string
size:(CGSize)theSize {
if (!string || CGSizeEqualToSize(theSize, CGSizeZero)) {
return CGSizeZero;
}
// setup TextKit stack
NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:theSize];
NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:string];
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
@tangyumeng
tangyumeng / DeepCopy.h
Created April 5, 2018 10:00 — forked from tommybananas/DeepCopy.h
ARC iOS Category for a NSArray and NSDictionary deep copy implementations
//
// DeepCopy.h
//
//
#import <Foundation/Foundation.h>
// Deep -copy and -mutableCopy methods for NSArray and NSDictionary
@interface NSArray (DeepCopy)
As of iOS 11/macOS High Sierra, and only including ones in Foundation and CoreFoundation
Strings:
_NSCFString - a CFStringRef or CFMutableStringRef. This is the most common type of string object currently.
- May have 8 bit (ASCII) or 16 bit (UTF-16) backing store
_NSCFConstantString - a compile time constant CFStringRef, like you'd get with @"foo"
- May also be generated by dynamic string creation if matches a string in a pre-baked table of common strings called the StringROM
NSBigMutableString - an NSString backed by a CFStorage (https://github.com/opensource-apple/CF/blob/master/CFStorage.h) for faster handling of very large strings
NSCheapMutableString - a very limited NSMutableString that allows for zero-copy initialization. Used in NSFileManager for temporarily wrapping stack buffers.
@tangyumeng
tangyumeng / iOS 技能图谱.md
Created January 21, 2018 14:56 — forked from tangqiaoboy/iOS 技能图谱.md
iOS 技能图谱

编程语言

  • Swift
  • Objective-C
  • C++/C
  • JavaScript

操作系统

  • Mac OSX
  • iOS