Skip to content

Instantly share code, notes, and snippets.

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

Kyle zhigang1992

:octocat:
Focusing
View GitHub Profile
@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
@zhigang1992
zhigang1992 / git commit command.sh
Last active July 28, 2024 01:52
Git Previous and Next Commit
function n() {
git reset --hard HEAD
git log --reverse --pretty=%H master | grep -A 1 $(git rev-parse HEAD) | tail -n1 | xargs git checkout
}
function p() {
git reset --hard HEAD
git checkout HEAD^1
}
@zhigang1992
zhigang1992 / Slides.swift
Last active June 5, 2016 14:04
Slide in Playground
import UIKit
infix operator |> { associativity left precedence 90 }
func |> <A, B> (l: A, r: A -> B) -> B {
return r(l)
}
infix operator <+> { associativity left precedence 110 }
func <+><A>(l: A->A, r: A->A) -> A->A {
return { v in
r(l(v))
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> {
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]
import Foundation
let dictionary: NSDictionary = [
"env": [
"address": "Home"
],
"setting": [
"up": "Hello",
"spnining": false
// 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 {
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?] = []
@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