Skip to content

Instantly share code, notes, and snippets.

View rickytan's full-sized avatar
💭
I may be slow to respond.

Ricky Tan rickytan

💭
I may be slow to respond.
View GitHub Profile
@rickytan
rickytan / Lazy.ts
Last active April 17, 2024 16:24
TypeScript @ Lazy annotation
function Lazy<T>(target: Object, propertyKey: string | symbol, {
get:initializer,
enumerable,
configurable,
set:setter
}: TypedPropertyDescriptor<T> = {}): TypedPropertyDescriptor<T> {
const {constructor} = target;
if (setter) {
throw `@Lazy can't be annotated with get ${propertyKey.toString()}() existing a setter on ${constructor.name} class!`;
}
@rickytan
rickytan / NameWrapper.swift
Created December 8, 2023 16:00
Swift Namewrapper
public struct NameWrapper<Base> {
public let base: Base
public init(_ base: Base) {
self.base = base
}
}
public protocol NameWrapperCompatiable {
associatedtype Base
@rickytan
rickytan / iOS16KeyboardFixer.m
Created July 11, 2023 07:27
Fix iOS 16 crash on [UIKeyboardTaskQueue promoteDeferredTaskIfIdle]
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface UIDeferredTasksWrapper : NSProxy
- (instancetype)initWithArray:(NSMutableArray *)array;
@end
@implementation UIDeferredTasksWrapper
{
NSMutableArray <id> * _tasks;
+ [WKBrowsingContextController registerSchemeForCustomProtocol:]
@rickytan
rickytan / debug.m
Created October 20, 2022 10:14
NSObject debug info
[self _methodDescription];
[self _ivarDescription];
[self _propertyDescription];
@rickytan
rickytan / sample.caml
Created April 1, 2022 05:35
caml under CALayer
<?xml version="1.0" encoding="UTF-8"?>
<caml xmlns="http://www.apple.com/CoreAnimation/1.0">
<CALayer allowsEdgeAntialiasing="1" allowsGroupOpacity="1" bounds="0 0 18 18" contentsFormat="RGBA8" name="Root Layer" position="9 9" transform="">
<sublayers>
<CAShapeLayer id="#4" fillColor="1 1 1" path="0.26367188 0.7418073 m 5.57226563 6.83714 l 5.78320313 7.060576 6.1171875 7.060576 6.31933594 6.83714 c 11.62792968 0.7418073 l 11.90039068 0.4468719 11.73339848 0 11.32031248 0 c 0.57128907 0 l 0.16699219 0 0 0.4468719 0.26367188 0.7418073 c h" allowsEdgeAntialiasing="1" allowsGroupOpacity="1" bounds="0 0 11.90039068 7.060576" contentsFormat="RGBA8" name="triangle" position="8.99121096 4.030288">
<scriptComponents/>
</CAShapeLayer>
<CALayer allowsEdgeAntialiasing="1" allowsGroupOpacity="1" bounds="0 0 18 18" contentsFormat="RGBA8" name="rings" position="9 9">
<mask allowsEdgeAntialiasing="1" allowsGroupOpacity="1" backgroundColor="0 0 0" bounds="0 0 18 18" contentsFormat="RGBA8" name="mas
@rickytan
rickytan / grub.cfg
Created September 4, 2021 15:15
openwrt grub turn off text console monitor
menuentry "****" {
linux /xxxxx consoleblank=5
}
@rickytan
rickytan / REGEXP.h
Last active January 31, 2019 03:50
A Macro to generate regular expression
#ifndef REGEXP
# define _regexp_stringify(x) #x
# define _regexp_stringify2(x) _regexp_stringify(x)
# define _regexp(...) ({ const char *str = _regexp_stringify2(# __VA_ARGS__); const size_t length = strlen(str); [[NSString alloc] initWithBytes:str + 1 length:length - 2 encoding:NSUTF8StringEncoding]; })
# define REGEXP(...) [NSRegularExpression regularExpressionWithPattern:_regexp(__VA_ARGS__) options:0 error:NULL]
#endif
@rickytan
rickytan / NSString+RegExp.h
Created January 18, 2019 04:08
NSString regular expression replace
@interface NSString (RegExp)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wstrict-prototypes"
- (NSString *)reg_replace:(NSRegularExpression *)regexp withBlock:(NSString *(NS_NOESCAPE ^)())block;
- (NSString *)reg_replacePattern:(NSString *)pattern withBlock:(NSString *(NS_NOESCAPE ^)())block;
#pragma clang diagnostic pop
@end
@rickytan
rickytan / UIImage+Border.m
Created January 8, 2019 11:09
UIImage Category
+ (UIImage *)rt_borderImageWithBorderColor:(UIColor *)borderColor fillColor:(UIColor *)fillColor borderWidth:(CGFloat)width radius:(CGFloat)radius forCorner:(UIRectCorner)corner
{
const CGFloat length = MAX(3, 2 * MAX(radius, width / 2) + width + 1.f / [UIScreen mainScreen].scale);
UIGraphicsBeginImageContextWithOptions(CGSizeMake(length, length), NO, 0);
[borderColor ?: [UIColor clearColor] setStroke];
[fillColor ?: [UIColor clearColor] setFill];
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(width / 2, width / 2, length - width, length - width)
byRoundingCorners:corner
cornerRadii:CGSizeMake(radius, radius)];