Skip to content

Instantly share code, notes, and snippets.

View lycaste's full-sized avatar

yaohao lycaste

  • UJS
  • china, zhenjiang
View GitHub Profile
@lycaste
lycaste / deep-string.js
Created April 23, 2017 12:15 — forked from threepointone/deep-string.js
deep update of text in a react component
import React from 'react'
import { render } from 'react-dom'
// with fiber, we'll be able to write components that update text deep
// inside another string without wrapper dom, or rerendering the whole component
// before
class Lorem extends React.Component {
state = {
str: ''
function reducer(state, action) {
if (action.type === 'INCREMENT') {
return state + action.amount;
} else if (action.type === 'DECREMENT') {
return state - action.amount;
} else {
return state;
}
}
@lycaste
lycaste / first.js
Created December 24, 2016 08:02 — forked from sofish/first.js
面试的时候我会经常问,js 中如何获得 <ul> 下的第一个 <li>,你的答案是什么?
// 大家写在评论中吧,代码高亮可以这样写:
// ```js
// your code
// ```
// update: Fri Aug 31 08:39:21
// copyright: https://gist.github.com/3549352
// 加个性能测试:http://jsperf.com/get-dom-s-first-element
var util = {};
@lycaste
lycaste / SpinlockTestTests.swift
Created October 8, 2016 04:45 — forked from steipete/SpinlockTestTests.swift
Updated for Xcode 8, Swift 3; added os_unfair_lock
//
// SpinlockTestTests.swift
// SpinlockTestTests
//
// Created by Peter Steinberger on 04/10/2016.
// Copyright © 2016 PSPDFKit GmbH. All rights reserved.
//
import XCTest
@lycaste
lycaste / TypeErasure.swift
Created September 9, 2016 01:21 — forked from russbishop/TypeErasure.swift
Type erasure with multiple adopting types
// Paste me into a playground!
import Cocoa
//: # Basic Setup
protocol FancyProtocol {
associatedtype Thing
func holdPinkyUp(x: Thing)
}
@lycaste
lycaste / README.md
Created September 4, 2016 16:53 — forked from mariotaku/README.md
删除当前屏幕所有微博

删除所有微博

在Chrome Dev Tools中粘贴代码到Console,就可以删除当前屏幕所有微博。经过测试一万条微博大约需要10小时的半人工操作。

每批删除大概一分钟,最多50条。

如果遇到微博的Rate limit(提示操作过快),稍等三五分钟再试即可。

UnsafeRawPointer Migration

Notes

Swift 3 introduces an UnsafeRawPointer type and enforces type safety with respect to unsafe pointer conversions.

  • SE-0107

    An Unsafe[Mutable]RawPointer type has been introduced. It replaces Unsafe[Mutable]Pointer. Conversion from

@lycaste
lycaste / MemoryLayouts.swift
Created September 4, 2016 08:35 — forked from pyrtsa/MemoryLayouts.swift
Looking at the memory layout of Array and AnyIterator in Swift
import Foundation
struct P : CustomStringConvertible {
var p: OpaquePointer?
init(_ p: OpaquePointer?) {
self.p = p
}
var description: String {
@lycaste
lycaste / NSData+PSPDFFoundation.m
Created August 25, 2016 15:54 — forked from steipete/NSData+PSPDFFoundation.m
Haven't done much with dispatch_io yet so I'd appreciate a few more eyeballs on this. Am I closing things correctly in all error conditions? Are there other knobs I could change to make things even faster? (I know I've been lazy on the NSError's)
static NSData *PSPDFCalculateSHA256FromFileURL(NSURL *fileURL, CC_LONG dataLength, NSError **error) {
NSCParameterAssert(fileURL);
dispatch_queue_t shaQueue = dispatch_queue_create("com.pspdfkit.sha256-queue", DISPATCH_QUEUE_SERIAL);
__block dispatch_io_t readChannel;
void (^processIntError)(int intError) = ^(int intError) {
if (intError != 0) {
PSPDFLogWarning(@"Stream error: %d", intError);
if (error) *error = [NSError errorWithDomain:@"SHA256Error" code:100 userInfo:@{NSLocalizedDescriptionKey: @"failed to open file for calculating SHA256."}];
@lycaste
lycaste / UIBarButtonItem+PSCBlockSupport.m
Created August 25, 2016 15:51 — forked from steipete/UIBarButtonItem+PSCBlockSupport.m
Helper to call target/action from an UIBarButtonItem.
#define PSCCAssert(condition, description, ...) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wnullable-to-nonnull-conversion\"") \
NSCAssert(condition, description, ##__VA_ARGS__) \
_Pragma("clang diagnostic pop")
#define PSCWeakifyAs(object, weakName) typeof(object) __weak weakName = object
void (^psc_targetActionBlock(id target, SEL action))(id) {
// If there's no target, return an empty block.