Skip to content

Instantly share code, notes, and snippets.

@YauzZ
YauzZ / .c
Created January 21, 2019 07:03
直接在C代码中造成野指针错误的代码
// 直接崩溃
int *volatile nptr = 0;
int c = *nptr;
printf("%d", c);
@YauzZ
YauzZ / obj.m
Created February 28, 2018 09:11
表单上传示例
NSDictionary *dict = @{@"modelId":11};
NSString *url = @"http://xxx/api/file/upload";
[manager POST:url parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
[formData appendPartWithFileData:imageData name:@"modelObjUrl" fileName:@"mesh.obj" mimeType:@"application/octet-stream"];
[formData appendPartWithFileData:imageData name:@"modelMtlUrl" fileName:@"mesh.obj.mtl" mimeType:@"application/octet-stream"];
[formData appendPartWithFileData:imageData name:@"modelImageUrl" fileName:@"mesh.png" mimeType:@"application/octet-stream"];
[formData appendPartWithFileData:imageData name:@"modelCropImageUrl" fileName:@"crop.png" mimeType:@"application/octet-stream"];
} progress:^(NSProgress * _Nonnull uploadProgress) {
@YauzZ
YauzZ / obj.m
Created January 11, 2018 10:15
单例代码例子
+ (instancetype)shareInstance
{
static id instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc] init];
});
return instance;
}
@YauzZ
YauzZ / mnist.py
Created December 27, 2017 10:30
基于 Softmax 的 Mnist 识别训练代码
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data",one_hot=True)
print(mnist.train.images.shape,mnist.train.labels.shape)
print(mnist.test.images.shape,mnist.test.labels.shape)
print(mnist.validation.images.shape,mnist.validation.labels.shape)
import tensorflow as tf
sess = tf.InteractiveSession()
Advanced Animations with UIKit
video: https://devstreaming-cdn.apple.com/videos/wwdc/2017/230lc4n1loob9/230/230_hd_advanced_animations_with_uikit.mp4?dl=1
pdf: https://devstreaming-cdn.apple.com/videos/wwdc/2017/230lc4n1loob9/230/230_advanced_animations_with_uikit.pdf
Advanced Touch Bar
video: https://devstreaming-cdn.apple.com/videos/wwdc/2017/222ijxk2akkrebmr/222/222_hd_advanced_touch_bar.mp4?dl=1
pdf: https://devstreaming-cdn.apple.com/videos/wwdc/2017/222ijxk2akkrebmr/222/222_advanced_touch_bar.pdf
Advances in TVMLKit
video: https://devstreaming-cdn.apple.com/videos/wwdc/2017/202ximbb9e2dq222/202/202_hd_advances_in_tvmlkit.mp4?dl=1
@YauzZ
YauzZ / YYDuckObj.h
Created August 13, 2017 15:32
鸭子对象例子
//
// YYDuckObj.h
// YYDuckObj
//
// Created by yauzz on 17/8/13.
// Copyright © 2017年 yauzz. All rights reserved.
//
#import <Foundation/Foundation.h>
OVERVIEW: LLVM 'Clang' Compiler: http://clang.llvm.org
USAGE: clang -cc1 [options] <inputs>
OPTIONS:
-### Print the commands to run for this compilation
--analyze Run the static analyzer
--migrate Run the migrator
--relocatable-pch Build a relocatable precompiled header
--serialize-diagnostics <value>
@YauzZ
YauzZ / ASDK_Layer.mm
Last active August 24, 2016 09:31
YYLayer中,异步渲染的核心逻辑代码
- (void)displayAsyncLayer:(_ASDisplayLayer *)asyncLayer asynchronously:(BOOL)asynchronously
{
ASDisplayNodeAssertMainThread();
ASDN::MutexLocker l(__instanceLock__);
if (_hierarchyState & ASHierarchyStateRasterized) {
return;
}
@YauzZ
YauzZ / runloop.m
Created August 24, 2016 02:55
注册 RunLoop 观察者代码示例,from YYKit
// 注册Runloop观察者,from YYKit
static void YYRunLoopObserverCallBack(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info) {
if (transactionSet.count == 0) return;
NSSet *currentSet = transactionSet;
transactionSet = [NSMutableSet new];
[currentSet enumerateObjectsUsingBlock:^(YYTransaction *transaction, BOOL *stop) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[transaction.target performSelector:transaction.selector];
@YauzZ
YauzZ / gist:a0004327d857ef86612570c6e8696ce7
Last active August 24, 2016 03:19
使用 NSProxy 来解除引用循环
/**
A proxy used to hold a weak object.
It can be used to avoid retain cycles, such as the target in NSTimer or CADisplayLink.
sample code:
@implementation MyView {
NSTimer *_timer;
}