Skip to content

Instantly share code, notes, and snippets.

@seivan
seivan / lesscode.swift
Last active April 19, 2017 11:13
live indicator
//Weak reference to layout attribute on controller level.
var currentTimeIndicatorAttribute:UICollectionViewLayoutAttributes? {
guard self._currentTimeIndicatorAttribute == nil else { return self._currentTimeIndicatorAttribute }
self._currentTimeIndicatorAttribute = self.layout.layoutAttributesForDecorationView(ofKind: EPGCollectionViewElementKind.Decoration.currentTimeIndicatorOverTimeline.rawValue, at: IndexPath(item: 0, section: 0))
print("adding again")
return self._currentTimeIndicatorAttribute
}
private weak var _currentTimeIndicatorAttribute:UICollectionViewLayoutAttributes?
//First
if let superview = backgroundImageView.superview {
backgroundImageView.topAnchor.constraint(equalTo: superview.topAnchor).isActive = true
backgroundImageView.leftAnchor.constraint(equalTo: superview.leftAnchor).isActive = true
backgroundImageView.rightAnchor.constraint(equalTo: superview.rightAnchor).isActive = true
backgroundImageView.bottomAnchor.constraint(equalTo: superview.bottomAnchor).isActive = true
}
//Second
let superView = backgroundImageView.superview
func slowAsyncCall() -> Observable<Int> {
return Observable.create { obs -> Disposable in
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(5)) {
obs.onNext(5)
obs.onCompleted()
}
return Disposables.create()
}
@seivan
seivan / sample.yml
Last active March 9, 2017 13:38
Theme ideas
#Component
- <SettingsCollectionViewCell:
- .view:
- background-color: "#fa0046"
- .name-label:
- text-color : white
- font-name : AmericanTypewriter-Bold
- font-size : 32
@seivan
seivan / bottom-border.swift
Created January 24, 2017 13:17
bottom-border
// Can use - border-bottom : "purple,3"
// Can use - border-bottom : "#444, 3"
// etc
conf.interpreter.map(UILabel.self, forAttributeKey: "border-bottom", withType:Borderized.self) {
let key = $0.key.appending("C-")
let layer = $0.component.layer.sublayers?.lazy.filter { $0.name == key }.first ?? CALayer()
layer.frame = $0.component.frame
//
// EitherProtocol+Error.swift
// CaoCaoKit
//
// Created by Seivan Heidari on 16/08/29.
//
//
import Foundation
@seivan
seivan / bb.js
Created December 26, 2016 01:43 — forked from stephantabor/bb.js
Bluebird .each vs .mapSeries vs .map
var Promise = require('bluebird');
var funcs = Promise.resolve([500, 100, 400, 200].map((n) => makeWait(n)));
funcs
.each(iterator) // logs: 500, 100, 400, 200
.then(console.log) // logs: [ [Function], [Function], [Function], [Function] ]
funcs
.mapSeries(iterator) // logs: 500, 100, 400, 200
/*:
## Phone Words
Generate a collection of words that can be represented by a given phone number. If a phone number contains the digits `1` or `0` then split up the phone number and find the words for each of the substrings as long as each substring has more than one digit. Non-keypad characters can be ignored. Optionally, filter out words so that only dictionary words are present in the result.
╔═════╦═════╦═════╗
║ 1 ║ 2 ║ 3 ║
║ ║ abc ║ def ║
╠═════╬═════╬═════╣
║ 4 ║ 5 ║ 6 ║
@seivan
seivan / A_Promise.swift
Created September 25, 2016 18:28 — forked from ChristianKienle/A_Promise.swift
simplest Promise framework possible?
public struct Promise<T> {
typealias Fulfiller = (T) -> (Void)
typealias Rejecter = (Void) -> (Void)
typealias Resolver = (_ fulfill: @escaping Fulfiller, _ reject: @escaping Rejecter) -> (Void)
let resolver: Resolver
init(_ resolver: @escaping Resolver){
self.resolver = resolver
}
func then<U>(_ execute: @escaping ((T) -> U)) -> Promise<U> {
return Promise<U>({(fulfill, reject) in
@seivan
seivan / dependency.swift
Created September 14, 2016 22:05
Closing the loop of dependencies with the properties.
//////public struct ConfuciusKeyValueMapResultList<C, V> : ArrayLiteralConvertible {
//////
////// public typealias ComponentType = C.Type
////// public typealias ValueType = V.Type
////// public typealias Element = ConfuciusKeyValueMapResult<C, V>
//////
////// private let results:Set<ConfuciusKeyValueMapResult<C, V>>
//////
////// public subscript(key:String) -> V? { return self.value(forKey: key) }
//////