Skip to content

Instantly share code, notes, and snippets.

View zhigang1992's full-sized avatar
:octocat:
Focusing

Kyle Fang zhigang1992

:octocat:
Focusing
View GitHub Profile
@zhigang1992
zhigang1992 / scroll.swift
Last active March 14, 2016 10:36
Different scroll paging
import XCPlayground
import UIKit
let collectionCellId = "CollectionCell"
func newCollectionView() -> UICollectionView {
let layout = UICollectionViewFlowLayout()
layout.itemSize = CGSize(width: 250, height: 300)
layout.scrollDirection = .Horizontal
let collectionView = UICollectionView(frame: CGRect(x: 0, y:0, width: 300, height: 500), collectionViewLayout: layout)
@zhigang1992
zhigang1992 / freer.swift
Last active March 22, 2016 14:03
Attemp on freer in swift
enum Freer<V, M, MV> {
case Pure(V)
case Impure(M, MV->Freer<V, M, MV>)
func flatMap<U>(f:V -> Freer<U, M, MV>) -> Freer<U, M, MV> {
switch self {
case .Pure(let v):
return f(v)
case .Impure(let v, let k):
return .Impure(v, { newV in
typealias Disposable = () -> Void
protocol StoreType {
associatedtype StateType
associatedtype ActionType
var state:StateType { get }
func dispatch(action:ActionType)
func subscribe(subscriber:(StateType)->Void) -> Disposable
}
// (State, Action) -> State
class Store<State, Action> {
typealias Reducer = (State, Action) -> State
typealias Subscriber = State -> Void
typealias Disposable = () -> Void
private(set) var state: State
private let reducer:Reducer
private var subscribers:[Subscriber?] = []
// originally from https://gist.github.com/cobbal/7562875ab5bfc6f0aed6
protocol Monad {
associatedtype V // Value Type
associatedtype U // Constraint Type
func bind<M : Monad where M.U == U>(f: V -> M) -> M
static func just(unit: V) -> Self
}
extension Monad {
import Foundation
let dictionary: NSDictionary = [
"env": [
"address": "Home"
],
"setting": [
"up": "Hello",
"spnining": false
func const<A, B>(value:A) -> B -> A {
return { _ in value }
}
func f<T: Equatable>(o: Optional<T> -> [T], i: T) -> Optional<T> -> [T] {
return { optional in
if optional == i {
return o(optional)
}
return o(i) + [i]
struct Async<T> {
let execution: (T->Void, ErrorType->Void) -> Void
static func unit(value:T) -> Async<T> {
return Async { $0.0(value) }
}
}
infix operator >>= { associativity left }
func >>=<A, B>(f: A->Async<B>, a:Async<A>) -> Async<B> {
@zhigang1992
zhigang1992 / load.json
Created May 17, 2016 13:58
React Native Workshop
[{
"name": "Hello, World"
}]
@zhigang1992
zhigang1992 / fixXcodePluginWarnings.sh
Last active June 5, 2016 14:03
fixXcodePluginWarnings
XCODEUUID=`defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID`
for f in ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/*; do defaults write "$f/Contents/Info" DVTPlugInCompatibilityUUIDs -array-add $XCODEUUID; done