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 / Squence
Created January 24, 2020 05:03
Sequence unique 稳定版
extension Sequence where Element: Hashable {
func unique() -> [Element] {
var seen: Set<Element> = []
return filter { (element) -> Bool in
if (seen.contains(element)) {
return false
} else {
seen.insert(element)
return true
}
@tangyumeng
tangyumeng / SplitArray
Created January 24, 2020 02:56
已排序数组,以相同元素为组拆分数组
extension Array {
func split(where condation: (Element, Element) -> Bool) -> [[Element]] {
var result: [[Element]] = self.isEmpty ? [] : [[self[0]]]
for (previous, current) in zip(self, self.dropFirst()) {
if (condation(previous, current)) {
result.append([current])
} else {
result[result.endIndex - 1].append(current)
}
}
@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 / ReverseLinkedList.java
Created November 16, 2019 02:58
ReverseLinkedList
public class ReverseLinkedList {
public static void main(String[] args) {
ListNode head = new ListNode(2);
head.next = new ListNode(4);
head.next.next = new ListNode(6);
head.next.next.next = new ListNode(8);
head.next.next.next.next = new ListNode(10);
ListNode result = ReverseLinkedList.reverse2(head);
System.out.print("Nodes of the reversed LinkedList are: ");