Skip to content

Instantly share code, notes, and snippets.

Avatar

Sebastien Windal sebastienwindal

View GitHub Profile
View notificationpayloads.json
// test
{
"aps": {
"alert": {
"title": "hello",
"body": "this is a push notification"
},
"sound": "default"
}
}
View TaggedTest.swift
import Foundation
import Tagged
struct Product: Codable {
let id: ProductID
let descr: String
typealias ProductID = Tagged<Product, UUID>
}
@sebastienwindal
sebastienwindal / gitshortcuts.md
Last active Nov 25, 2019
git command line shortcuts
View gitshortcuts.md

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 Jan 17, 2019
Simple reactive MVVM with KVO
View Mvvmkvo.swift
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.
View easing.swift
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
View Array+Shuffle.swift
// 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]
View DictArray.swift
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 Jun 29, 2017
index path from cell or button inside a cell in prepareforsegue
View prepareforsegue.swift
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 Jun 26, 2017
NSFetchedResultsController swift 3
View 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)
@sebastienwindal
sebastienwindal / gist:ab02e7dffee942f016194cf08b39ec56
Created Feb 9, 2017
find biggest image assets in your iOS app...
View gist:ab02e7dffee942f016194cf08b39ec56
du -ah | egrep -v "AppStore|DerivedData|Pods|Frameworks" | egrep -i "PNG|jp(e?)g" | sort -n -r | more