Skip to content

Instantly share code, notes, and snippets.

View s4cha's full-sized avatar
🎯
Focusing

Sacha DSO s4cha

🎯
Focusing
View GitHub Profile
tableView.register(MyCell.self, forCellReuseIdentifier: MyCell.reuseIdentifier)
@s4cha
s4cha / AsyncExample.swift
Created May 12, 2017 14:57
AsyncExample.swift
// Say you're on the main thread
DispatchQueue.global(qos: DispatchQoS.QoSClass.background).async {
// Do something expensinve in background
var mySuperLongComputedResult = computeSuperLongStuff()
DispatchQueue.main.async {
// come back to the main thread to ping UI
label.text = mySuperLongComputedResult
}
}
public extension Optional where Wrapped == String {
var isEmptyOrNil: Bool { return (self ?? "").isEmpty }
}
@s4cha
s4cha / NativeDependencyInversion.swift
Created July 26, 2018 12:22
Native Swift Dependency Inversion
protocol <#Depencency#> {
func foo()
}
protocol Has<#Depencency#> {
func get<#Depencency#> () -> <#Depencency#>
}
// Implementation
@s4cha
s4cha / View.swift
Created July 31, 2018 19:18
Typical Stevia View
//
// View.swift
// heroandstevia
//
// Created by Sacha on 31/07/2018.
// Copyright © 2018 Onur Geneş. All rights reserved.
//
import UIKit
import Stevia
@s4cha
s4cha / ViewController.swift
Created July 31, 2018 19:19
Typical Stevia/ViewController use case
//
// ViewController.swift
// steviademo
//
// Created by Onur Geneş on 17.07.2018.
// Copyright © 2018 Onur Geneş. All rights reserved.
//
import UIKit
import Stevia
@s4cha
s4cha / DogchowBenefitView.kt
Last active September 5, 2018 13:54
Android Custom View Component
package com.octopepper.yummypets.component.dogchow
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.LinearLayout
import com.octopepper.yummypets.R
import kotlinx.android.synthetic.main.dogchow_benefit.view.*
class DogchowBenefitView(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) {
@s4cha
s4cha / ThreadSafe.swift
Created September 20, 2018 12:43
ThreadSafeArray & ThreadSafe<T>
//
// ThreadSafe.swift
// ThreadSafeArray
//
// Created by Sacha DSO on 20/09/2018.
// Copyright © 2018 freshOS. All rights reserved.
//
import Foundation
@s4cha
s4cha / Channel.swift
Last active September 20, 2018 13:21
Channel (pub sub ) in swift
public class Channel<Message: Equatable>: IsChannel {
private var subscriptions = ThreadSafeArray<Subscription>()
public func broadcast(_ message: Message) {
subscriptions.forEach { $0.trigger(message: message) }
}
public func subscribe(_ object: AnyObject,
for specificMessage: Message,
@s4cha
s4cha / dependencyInversion.go
Last active April 5, 2022 23:08
Dependency inversion in go
package main
func main() {
// Create our dependency.
lf := FileLinkFetcher{}
// lf := DatabaseLinkFetcher{}
// Here we "inject" the fileLinkFetcher in the App constructor.