Skip to content

Instantly share code, notes, and snippets.

View pgherveou's full-sized avatar

PG Herveou pgherveou

View GitHub Profile
@pgherveou
pgherveou / pull-stream.swift
Created August 31, 2016 23:34
pull stream playground in swift
// https://github.com/dominictarr/pull-stream-examples/blob/master/pull.js
import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
/// Pull stream events
enum Event<T> {
case next(T)
case error(Error)
import RxSwift
// MARK: globals
private var noOp: () -> Void = { _ in }
// MARK: Pager
public class Pager<T> {
public typealias PagingFunction = ([T]) -> Observable<[T]>
@pgherveou
pgherveou / bst.js
Created January 14, 2016 06:00
es6 binary search tree
import { inspect } from 'util'
const Tree = Object.create({
init(value) {
this.value = value
this.height = 0
return this
},
@pgherveou
pgherveou / filter-pull-request.js
Last active November 30, 2015 17:35
filter file in pull request
$('.file-header')
.filter(function() {
const path = $(this).data('path')
return !path.endsWith("swift")
})
.each(function() {
$(this).parent().remove()
})
@pgherveou
pgherveou / firebaseArray.swift
Last active November 15, 2015 23:47
First attempt at porting FirebaseArray to swift - https://github.com/firebase/FirebaseUI-iOS
import XCPlayground
import Firebase
import PromiseKit
// MARK: FirebaseArrayDelegate
protocol FirebaseArrayDelegate: class {
func childNotFound(key: String)
func childAdded(snapshot: FDataSnapshot, atIndex index: Int)
func childChanged(snapshot: FDataSnapshot, atIndex index: Int)
@pgherveou
pgherveou / base-ui-classes.swift
Last active November 13, 2015 20:39
label, uiimage, uibutton subclasses to use with circle or rounded rect shapes
// MARK: CircleComponent protocol
protocol CircleComponent {
var circleSize: CGFloat { get }
var borderColor: UIColor { get }
var borderWidth: CGFloat { get }
var hasCircleMaskLayer: Bool { get }
var hasRingLayer: Bool { get }
import Foundation
// global singleton instance
let tweaks = FBTweakStore.sharedInstance()
/**
* ## Usage
*
* class MyClass {
* struct statics {
@pgherveou
pgherveou / viewcontroller-tpl.swift
Created April 20, 2015 13:35
View Controller code style template
import Foundation
import UIKit
class <#name#>: UIViewController {
// MARK: static properties
struct statics {
static let someValue = 1
static let someOtherValue = "foo"
/// custom unique identifier
/// @see https://www.firebase.com/blog/2015-02-11-firebase-unique-identifiers.html
private let ASC_CHARS = Array("-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz")
private let DESC_CHARS = ASC_CHARS.reverse()
private var lastPushTime: UInt64 = 0
private var lastRandChars = Array<Int>(count: 12, repeatedValue: 0)
func generatePushID(ascending: Bool = true) -> String {
let PUSH_CHARS = ascending ? ASC_CHARS: DESC_CHARS
var timeStampChars = Array<Character>(count: 8, repeatedValue: PUSH_CHARS.first!)
@pgherveou
pgherveou / emitter.swift
Last active August 29, 2015 14:17
event emitter in swift
private var autoId: Int = 1
// MARK: Subscription Protocol
protocol Subscription {
func remove()
}
// MARK: AbstractSubscription<T>