Skip to content

Instantly share code, notes, and snippets.

@wanyakun
wanyakun / 0_reuse_code.js
Created September 14, 2016 06:47
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@wanyakun
wanyakun / NSObject+Swizzle.h
Created October 24, 2016 07:41
NSObject+Swizzle
//
// NSObject+Swizzle.h
// CrashDemo
//
// Created by wanyakun on 16/7/5.
// Copyright © 2016年 com.ucaiyuan. All rights reserved.
//
#import <Foundation/Foundation.h>
@wanyakun
wanyakun / GCD中的串行,并行,同步,异步.md
Last active October 26, 2016 09:07
GCD中的串行,并行,同步,异步

首先,串行并行针对的是队列,同步异步针对的是任务;如果觉得队列和任务不太好理解咱们可以打个比方,假设一个应用程序是一个工厂,那队列就是里面的流水线以及线上的工人,而流水线上的工人所要处理的产品就是所谓的任务。

串行,并行

系统会给每个应用自动分配两个队列:

  1. dispatch_get_main_queue() 串行队列 处理UI,也可以叫串行主队列,这个队列会排在主线程中。

  2. dispatch_get_global_queue(优先级, 扩展)并行队列。

@wanyakun
wanyakun / DoubleLink.c
Created October 27, 2016 09:31
数组、单向链表和双向链表
@wanyakun
wanyakun / 如何理解C++中的关键字static, const, 以及#define的区别.md
Created October 28, 2016 03:13
如何理解C++中的关键字static, const, 以及#define的区别

如何理解C++中的关键字static, const, 以及#define的区别

[TOC]

1. define

define和那两个都不一样,它属于宏,是预处理器的一部分。预处理是在编译之前的一道,简单地进行字符串替换。它不按照语言的语法,而是直观自己的语法。你#define里面写的东西会被简单粗暴地塞进去。

2. const

Linux内核中双向链表的经典实现

1. Linux中的两个经典宏定义

offsetof

定义:offsetof在linux内核的include/linux/stddef.h中定义

#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
@wanyakun
wanyakun / MyObject.h
Created November 1, 2016 03:18
Block块代码示例,以及Clang编译后的解释,以及将Clang编译后的代码贴到block之上,并进行注释
//
// MyObject.h
// BlockDemo
//
// Created by wanyakun on 16/8/1.
// Copyright © 2016年 com.ucaiyuan. All rights reserved.
//
#import <Foundation/Foundation.h>
@wanyakun
wanyakun / UCYDeviceModel.m
Created November 7, 2016 02:46
根据设备platform获取设备型号
#include <sys/sysctl.h>
+ (NSString *) platform {
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine);
return platform;
@wanyakun
wanyakun / LLDB Debugger commands.txt
Created November 8, 2016 03:03
LLDB Debugger commands
Debugger commands:
apropos -- List debugger commands related to a word or subject.
breakpoint -- Commands for operating on breakpoints (see 'help b' for
shorthand.)
bugreport -- Commands for creating domain-specific bug reports.
command -- Commands for managing custom LLDB commands.
disassemble -- Disassemble specified instructions in the current
target. Defaults to the current function for the
current thread and stack frame.
@wanyakun
wanyakun / BuildFramework.sh
Created May 8, 2017 06:29
iOS build dynamic framework for cocoapods development. please put this shell file into library root path. Then run the BuildFramework.sh in terminal.
#当前目录
current_path=$(pwd)
#workspace绝对路径
workspace_path=$(pwd)/Example
#workspace
build_workspace=$(echo $(basename $workspace_path/*.xcworkspace))
#target 和workspace同名