Skip to content

Instantly share code, notes, and snippets.

View s4cha's full-sized avatar
🎯
Focusing

Sacha DSO s4cha

🎯
Focusing
View GitHub Profile
// MARK - Network Layer
// Repository implementation
// (here in an extension)
extension RestApi: OrganizationRepository {
public func fetchCurrent() -> AnyPublisher<Organization, Error> {
get("/organizations/current").map { (jsonOrganization: JSONOrganization) in
return jsonOrganization.toOrganization()
}
.eraseToAnyPublisher()
@s4cha
s4cha / record.txt
Created June 9, 2020 14:40
Record iOS Simulator video
xcrun simctl io booted recordVideo --codec=h264 screenRecording.mp4
@s4cha
s4cha / LiveReload.txt
Created June 9, 2020 14:04
Android live reload
while true; do adb shell am broadcast -a debug; sleep 0.5; done
{
"total": 622,
"countryVotes": [
{
"country": "AL",
"totalVotes": 12,
"votes": {
"CZ": 0,
"MT": 4,
"FI": 1,
@s4cha
s4cha / InjectionContainer.kt
Last active June 18, 2019 13:00
Single Injection Container in pure Kotlin
typealias ServiceBuilderBlock<T> = () -> T
class ServiceBuilderkWrapper<T>(val serviceBuilderBlock:ServiceBuilderBlock<T>, val serviceName: String)
object InjectionContainer {
var serviceBuilderkWrappers = mutableListOf<ServiceBuilderkWrapper<Any>>()
inline fun <reified T>registerService(noinline block: ServiceBuilderBlock<T>) {
val wrapper = ServiceBuilderkWrapper(block, T::class.simpleName ?: "noname") as ServiceBuilderkWrapper<Any>
@s4cha
s4cha / Notifier.kt
Last active June 20, 2019 14:58
EventBus in Kotlin under 50 lines \o/
import kotlinx.coroutines.*
typealias Callback<T> = (T) -> Unit
class CallbackWrapper<T>(val callback:Callback<T>, val eventName: String, val receiverHash: Int, val dispatcher: CoroutineDispatcher)
object Notifier: CoroutineScope {
private val supervisorJob = SupervisorJob()
@s4cha
s4cha / kotlinJSON.kt
Last active October 19, 2018 17:43
Kotlin JSON parsing \o/
// Usage
fun parse(json: JSONObject): Car {
val car = Car()
car.apply {
::id < json.key("id")
::numberOfDoors < json.key("nb_of_doors")
::driverName < json.key("driver_name")
}
return car
@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.
@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 / 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