Skip to content

Instantly share code, notes, and snippets.

View phucledien's full-sized avatar
🇻🇳
Xin chào

Le Dien Phuc phucledien

🇻🇳
Xin chào
View GitHub Profile
extension Sequence {
func reduce<A>(_ initial: A, combine: (inout A, Iterator.Element) -> ()) -> A {
var result = initial
for element in self {
combine(&result, element)
}
return result
}
}
// Original article here: https://www.fivestars.blog/code/redacted-custom-effects.html
import SwiftUI
// MARK: Step 1: Create RedactionReason
public enum RedactionReason {
case placeholder
case confidential
@phucledien
phucledien / value_types.md
Created July 31, 2020 06:20 — forked from rbobbins/value_types.md
Build Better Apps with Value Types in Swift

Build Better Apps with Value Types in Swift

Agenda

  • Reference semantics
  • Immutability
  • Value semantics
  • Value types in practice
  • Mixing value types and reference types

Reference semantics

@phucledien
phucledien / TaskConcurrencyManifesto.md
Created July 30, 2020 15:44 — forked from lattner/TaskConcurrencyManifesto.md
Swift Concurrency Manifesto
struct ContentView: View {
var body: some View {
VStack{
Label("Hello Label", systemImage: "sun.min")
.font(.system(.title, design: .rounded))
Label("Title only label", systemImage: "sun.min")
.font(.system(.title, design: .rounded))
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))

Keybase proof

I hereby claim:

  • I am phucledien on github.
  • I am phucld (https://keybase.io/phucld) on keybase.
  • I have a public key ASBiatEcxVZQ9aCLuqHPeKcmWtPgFsgs6GG9kkSCD70I5Qo

To claim this, I am signing this object:

/// Every view interacting with a `SayHelloViewModel` instance can conform to this.
protocol SayHelloViewModelBindable {
var disposeBag: DisposeBag? { get }
func bind(to viewModel: SayHelloViewModel)
}
/// TableViewCells
final class TextFieldCell: UITableViewCell, SayHelloViewModelBindable {
@IBOutlet weak var nameTextField: UITextField!
var disposeBag: DisposeBag?
@phucledien
phucledien / tmux-cheatsheet.markdown
Created October 20, 2018 13:39 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@phucledien
phucledien / The Rules.md
Created October 20, 2018 08:08 — forked from sebmarkbage/The Rules.md
The Rules of React

The Rules of React

All libraries have subtle rules that you have to follow for them to work well. Often these are implied and undocumented rules that you have to learn as you go. This is an attempt to document the rules of React renders. Ideally a type system could enforce it.

What Functions Are "Pure"?

A number of methods in React are assumed to be "pure".

On classes that's the constructor, getDerivedStateFromProps, shouldComponentUpdate and render.