Skip to content

Instantly share code, notes, and snippets.

View ddrccw's full-sized avatar

ddrccw ddrccw

  • alibaba
  • Shanghai China
View GitHub Profile
@lexrus
lexrus / LTLog.h
Last active February 21, 2016 19:56
My DDLog config
//
// LTLog.h
//
// Created by Lex on 6/29/14.
// Copyright (c) 2014 LexTang.com. All rights reserved.
// https://gist.github.com/lexrus/8c6414e7c0177e9e66ea
//
#import <Foundation/Foundation.h>
@steipete
steipete / PSPDFBlockAssert.m
Created January 12, 2016 21:56
Check if object is a block - nice for assertions.
PSPDF_EXTERN BOOL PSPDFIsBlock(id _Nullable block) {
static Class blockClass;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
blockClass = [^{} class];
while ([blockClass superclass] != NSObject.class) {
blockClass = [blockClass superclass];
}
});
@n-b
n-b / NBResponderChainUtilities.h
Last active August 3, 2021 10:08
Chain Responder Debugging Methods
//
// NBResponderChainUtilities.h
//
// Created by Nicolas @ bou.io on 19/04/13.
//
#import <UIKit/UIKit.h>
@interface UIView (NBResponderChainUtilities)
- (UIView*) nb_firstResponder; // Recurse into subviews to find one that responds YES to -isFirstResponder
@krin-san
krin-san / #1. Simple retry
Last active October 22, 2021 00:24
ReactiveCocoa. Optional retry on error
// Taken from http://www.slideshare.net/manuelmaly/reactivecocoa-goodness-part-i-of-ii
// Exact presentation slide: http://image.slidesharecdn.com/presentation-141009165841-conversion-gate01/95/reactivecocoa-goodness-part-i-of-ii-37-638.jpg?cb=1412892113
// Try to repeat signal 3 times
static NSUInteger const retryAttempts = 2;
static NSTimeInterval const retrydelay = 1.;
RACSignal *signal = ...;
RACSignal *result = [[signal catch:^RACSignal *(NSError *error) {
return [[[RACSignal empty] delay:retrydelay]
@unak
unak / history.txt
Last active November 29, 2021 01:40
The History of Ruby
* Only the releases of the stable versions are listed in principle. The releases of the unstable versions especially considered to be important are indicated as "not stable."
* The branches used as the source of each releases are specified, and the branching timing of them are also shown. BTW, before subversionizing of the repository, the term called "trunk" was not used, but this list uses it in order to avoid confusion.
* In order to show a historical backdrop, big conferences (RubyKaigi, RubyConf and Euruko) are also listed. About the venues of such conferences, general English notations are adopted, in my hope.
* ruby_1_8_7 branch was recut from v1_8_7 tag after the 1.8.7 release because of an accident.
* 1.2.1 release was canceled once, and the 2nd release called "repack" was performed. Although there were other examples similar to this, since the re-releases were performed during the same day, it does not write clearly in particular.
* Since 1.0 was released with the date in large quantities, the mi
/**
* Several macros simplifying use of weak references to self inside blocks
* which goal is to reduce risk of retain cycles.
*
* Example:
* @code
@interface Example : NSObject{
int _i;
}
@nicklockwood
nicklockwood / Deprecated.md
Last active March 28, 2022 08:16
Writing Objective-C framework code that works on multiple OS versions AND can be compiled using multiple SDK versions without warnings can be a PITA. Here's my approach:

Suppose we want to add support for a new iOS 8 API in our framework that replaces an older iOS 7 API. There are a few problems we might face:

  1. The new API will crash if we call it on iOS 7
  2. The new API won't compile if we build it using the iOS 7 SDK
  3. The old API will raise a deprecation warning if built with a deployment target of iOS 8 and up

These three problems require three different technical solutions:

  1. We can avoid calling the new API on an old OS version by using runtime detection (e.g. respondsToSelector:)
  2. We can avoid compiling new APIs on old SDKs using the __IPHONE_OS_VERSION_MAX_ALLOWED macro
// Note that this checker is always running, even when the app is in the background (where it doesn't matter if the main thread is blocked)
// You'll have to add more code if you don't want the checker to run while the app is in the background
final class ANRChecker {
private let ANRThreshold: CFTimeInterval = 5
// This variable may be accessed from multiple threads at the same time. It won't cause issues, but if you want prevent the thread sanitizer from complaining, you can add locking around it or w/e
private lazy var lastResponseTime: CFTimeInterval = CACurrentMediaTime()
func beginChecking() {
updateLastResponseTime()
@wangchauyan
wangchauyan / yuv2rgb
Created May 18, 2016 04:46
Convert YUV to RGB
const char fragmentShader_yuv420p[] =
{
"precision mediump float;\n"
"uniform sampler2D Ytex;\n"
"uniform sampler2D Utex,Vtex;\n"
"varying vec2 vTextureCoord;\n"
"void main(void) {\n"
" float nx,ny,r,g,b,y,u,v;\n"
" mediump vec4 txl,ux,vx;"
" nx=vTextureCoord[0];\n"
'''
Break on Objective-C 's method using its address'
'''
import shlex
import lldb
import re
def breakonmethod(debugger, command, exe_ctx,result, internal_dict):
args=shlex.split(command)
Class=args[0]
Method=args[1]