Skip to content

Instantly share code, notes, and snippets.

View muizidn's full-sized avatar
👨‍🚀
Working between Tiangong and Mir

Former Not Wannabe Lord Paramount of the Wkwkland muizidn

👨‍🚀
Working between Tiangong and Mir
  • Indian Ocean
View GitHub Profile
@muizidn
muizidn / cmd_color.rb
Created February 18, 2019 07:56
String extension for CommandLine output coloring
# Source https://github.com/PaulTaykalo/swift-scripts/blob/master/unused.rb
class String
def black; "\e[30m#{self}\e[0m" end
def red; "\e[31m#{self}\e[0m" end
def green; "\e[32m#{self}\e[0m" end
def yellow; "\e[33m#{self}\e[0m" end
def blue; "\e[34m#{self}\e[0m" end
def magenta; "\e[35m#{self}\e[0m" end
def cyan; "\e[36m#{self}\e[0m" end
def gray; "\e[37m#{self}\e[0m" end
// MuslimApp AppLaucherViewController.swift
// DidSelectCellForRowAt indexPath: IndexPath
let subApp = items[indexPath.row]
let vc = subApp.starter
navigationController.pushViewController(vc, animated: true)
// MuslimApp Application.swift
import MuslimNote
let subApplication: [SubApplication] = [
MuslimNote.Application()
]
// MuslimNote
// Application.swift
import SubApplication
public class Application: SubApplication {
let name = "Muslim Note"
let thumbnail = UIImage(named: "muslim_note_thumnail")
let starter: UIViewController
init() {
let vc = HomeController(
nibName: "HomeController"
public protocol SubApplication {
var name: String { get }
var thumbnail: UIImage? { get }
var starter: UIViewController { get }
}
/// MuslimApp
// AppLaucherViewController.swift
import SubApplication
class AppLaucherViewController: UITableViewController {
private var items: [SubApplication] = []
convenience init(items: [SubApplication]) {
self.init()
class WhateverUseCase {
...
let store: Store // I don't need specify any type
func performOperation() {
/// Car
store.fetch(Car.self, with: [.color(.red), .year(Date())])
.success { cars in
// Do logic
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<style>
.main-button {
background-color: white;
color: black;
border: 2px solid #4CAF50;
@muizidn
muizidn / ErrorRxSwift.swift
Created February 19, 2018 02:36
RxSwift: Error handling without disposing subscription or Resubscribe after disposed
// Setelah print "Fetch Error ..." maka subscription -> onCompleted -> isDisposed (dan tidak bisa fetchProduct lagi)
Network.fetchProduct() // Return Observable<[Product]>
.subscribe(onNext: { value in
print("Product is \(value)")
}, onError: { error in
print("Fetch Error \(error)")
})
.diposed(by: bag)
@muizidn
muizidn / withLatestFromRxSwift.swift
Created February 5, 2018 06:09
Usage of withLatestFrom in RxSwift to tackle cyclic Observable sequence
let user: PublishSubject<User>()
let cart = user.startWith( ... ) // I provide a starter value for sequence
.flatMapLatest { user -> Observable<Cart> in
return Observable.just(user.cart)
}
.map {
... // Do some logic here
}
// Updating user for other observer