Skip to content

Instantly share code, notes, and snippets.

View sebastienwindal's full-sized avatar

Sebastien Windal sebastienwindal

View GitHub Profile
// 1.
override func viewDidLoad() {
super.viewDidLoad()
dataSource = CardListDataSource(
tableView: tableView,
onPlusTapped: { self in
self.launchCardIssue()
})
}
// test
{
"aps": {
"alert": {
"title": "hello",
"body": "this is a push notification"
},
"sound": "default"
}
}
import Foundation
import Tagged
struct Product: Codable {
let id: ProductID
let descr: String
typealias ProductID = Tagged<Product, UUID>
}
@sebastienwindal
sebastienwindal / gitshortcuts.md
Last active November 25, 2019 17:53
git command line shortcuts

br

echo -e "> \033[1;92m git branch\033[0m"
git branch | nl

co

BRANCHINDEX=`echo $1 | xargs`
BRANCHNAME=`git branch | sed -n "$BRANCHINDEX p" | sed "s/\*//g"`
@sebastienwindal
sebastienwindal / Mvvmkvo.swift
Created January 17, 2019 15:55
Simple reactive MVVM with KVO
import UIKit
//
// ViewModel, all KVO compliant to ViewController can observe changes in a decouple way.
//
class MyViewModel: NSObject {
@objc dynamic var firstName:String = ""
@objc dynamic var lastName: String = ""
// Fullname, concatenation of first and last.
enum Easing {
// Linear interpolation (no easing)
case linear
// Quadratic easing; p^2
case quadraticIn
case quadraticOut
case quadraticInOut
// Cubic easing; p^3
case cubicIn
case cubicOut
// Fisher–Yates Array shuffle
extension Array {
func shuffledArray() -> Array {
var arr = self
for i in 0..<count {
print(count - i)
let j = i + Int(arc4random_uniform(UInt32(count - i)))
let tmp = arr[i]
arr[i] = arr[j]
public struct DictArray<Key: Hashable, Value> : CustomDebugStringConvertible {
private typealias Bucket = [Value]
private var buckets: [ Key: Bucket ]
init() {
buckets = [:]
}
public mutating func add(value:Value, key:Key) {
var bucket:Bucket
@sebastienwindal
sebastienwindal / prepareforsegue.swift
Created June 29, 2017 07:27
index path from cell or button inside a cell in prepareforsegue
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
var indexPath:IndexPath? = nil
if let cell = sender as? UITableViewCell {
indexPath = tableView.indexPath(for: cell)
}
if let button = sender as? UIButton {
let buttonFrame = button.convert(button.bounds, to:tableView)
indexPath = tableView.indexPathForRow(at: buttonFrame.origin)
@sebastienwindal
sebastienwindal / NSFetchedResultsController swift 3
Last active June 26, 2017 23:40
NSFetchedResultsController swift 3
func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
tableView.beginUpdates()
}
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) {
switch type {
case .insert:
tableView.insertSections(IndexSet(integer: sectionIndex), with: .fade)
case .delete:
tableView.deleteSections(IndexSet(integer: sectionIndex), with: .fade)