Skip to content

Instantly share code, notes, and snippets.

View goldfish0506's full-sized avatar
💪
Bloody Battles & Unyielding Struggles

yu Jin goldfish0506

💪
Bloody Battles & Unyielding Struggles
View GitHub Profile
@goldfish0506
goldfish0506 / rx.md
Last active August 31, 2018 10:21
rx 101

函数式编程

wikipedia 定义:

Functional Programming is a programming paradigm

  • treats computation as the evaluation of mathematical functions.
  • avoids changing-state and mutable data

函数式编程是一种编程范式,它将计算机运算视为数学上的函数计算,并且避免使用程序状态以及易变对象

@goldfish0506
goldfish0506 / DumpObjcMethods.m
Last active August 27, 2018 07:37
DumpObjcMethods
void DumpObjcMethods(Class clz) {
unsigned int methodCount = 0;
unsigned int propertyCount = 0;
Method *methods = class_copyMethodList(clz, &methodCount);
objc_property_t *properties = class_copyPropertyList(clz, &propertyCount);
printf("Found %d methods on '%s'\n", methodCount, class_getName(clz));
+ (BOOL)isFund:(NSString *)symbol
{
for (NSString *fundSymbol in [self funds]) {
if ([symbol hasPrefix:fundSymbol]) {
return YES;
}
}
return NO;
}
@goldfish0506
goldfish0506 / json_from_bundle.m
Created November 11, 2015 09:08
Xcode snippets
NSString *path = [[NSBundle mainBundle] pathForResource:@"ad" ofType:@"json"];
NSData *jsonData = [NSData dataWithContentsOfFile:path];
jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
@goldfish0506
goldfish0506 / .clang-format
Created August 29, 2015 11:46
.clang-format base on LLVM
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: 0
AlignAfterOpenBracket: true
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
@goldfish0506
goldfish0506 / RoundImageView.m
Created July 25, 2015 11:38
Render a white inverted circle on top of square thumbnail asset
#import "RoundImageView.h"
@implementation RoundImageView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.clipsToBounds = YES;
self.contentMode = UIViewContentModeScaleAspectFill;
@goldfish0506
goldfish0506 / constrain.m
Last active August 29, 2015 14:02
给View添加 constrain
- (NSArray *)constrainSubview:(UIView *)subview toMatchWithSuperview:(UIView *)superview
{
subview.translatesAutoresizingMaskIntoConstraints = NO;
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(subview);
NSArray *constraints = [NSLayoutConstraint
constraintsWithVisualFormat:@"H:|[subview]|"
options:0
metrics:nil
views:viewsDictionary];
#import "UIImageView+Util.h"
@implementation UIImageView (Util)
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder animation:(BOOL)animation
{
__weak typeof (self) weakSelf = self;
[self setImageWithURL:url
placeholderImage:placeholder
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
typedef NS_ENUM(NSInteger, JYImageType) {
JYImageTypeJPEG,
JYImageTypePNG,
JYImageTypeUnknown,
};
static inline JYImageType JYImageTypeFromData(NSData *imageData) {
if (imageData.length > 4) {
const unsigned char * bytes = [imageData bytes];
NSString * JYKeyPathForSelectors(SEL selector, ...);
inline NSString * JYKeyPathForSelectors(SEL selector, ...) {
if (!selector) {
return nil;
}
NSMutableArray *selectors = [NSMutableArray array];
va_list args;
va_start(args, selector);