Skip to content

Instantly share code, notes, and snippets.

View koingdev's full-sized avatar
🤖
Stay focus

Saingkoing SEA koingdev

🤖
Stay focus
  • Tokyo, Japan
View GitHub Profile
@koingdev
koingdev / query-local-secondary-index.vtl
Created July 22, 2019 09:25
Sample AppSync Resolver for Query Local Secondary Index
## REQUEST MAPPING
{
"version" : "2017-02-28",
"operation" : "Query",
"index": "shopID-vendorID-index",
"query" : {
"expression": "shopID = :shopID AND vendorID = :vendorID",
"expressionValues" : {
":shopID" : $util.dynamodb.toDynamoDBJson($ctx.args.shopID),
":vendorID" : $util.dynamodb.toDynamoDBJson($ctx.args.vendorID)
@koingdev
koingdev / FlattenNestedDictionary.swift
Created June 5, 2019 13:46
Make nested dictionary flat again
/*
BEFORE = ["id": 1, "sergio": ["yume": ["ssk": 999]], "product": ["name": "AAA", "description": ["banana": "yellow"]]]
AFTER = ["sergio/yume/ssk": 999, "id": 1, "product/name": "AAA", "product/description/banana": "yellow"]
*/
typealias JSON = [String : Any]
let nested: JSON = ["id": 1, "product": ["name": "AAA", "description": ["banana": "yellow"]], "sergio": ["yume": ["ssk": 999]]]
extension JSON where Key: ExpressibleByStringLiteral, Value: Any {
@koingdev
koingdev / ExportOptions.plist
Last active October 15, 2024 09:22
Script to automatically upload iOS App to AppStore and TestFlight (including versioning)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>destination</key>
<string>upload</string>
<key>method</key>
<string>app-store</string>
<key>provisioningProfiles</key>
<dict>
@koingdev
koingdev / OptionalX.swift
Created May 1, 2019 15:07
Optional extension
extension Optional where Wrapped == String {
var orEmpty: Wrapped {
return self ?? ""
}
var isNullOrEmpty: Bool {
return self?.isEmpty ?? true
}
@koingdev
koingdev / UIAlertControllerX.swift
Last active October 27, 2022 06:46
Easy way to show UIAlertController with Builder Pattern
extension UIAlertController {
// MARK: - Typealias
typealias Alert = UIAlertController
typealias Action = UIAlertAction
typealias Block = ((Alert) -> Void)?
// MARK: - Static function
@koingdev
koingdev / NetworkListener.swift
Created May 1, 2019 14:46
Network Listener (Detect network status changed and check Internet connection)
import Reachability
final class NetworkListener {
private let notification = Notification.Name("NetworkListenerStatusDidChanged")
private let reachability: Reachability!
/// Return true if connected to Internet
private(set) var isConnected: Bool!
init() {
@koingdev
koingdev / Log.swift
Created May 1, 2019 14:42
Simple Swift Logger
func dPrint(_ item: Any) {
#if DEBUG
Swift.print(item)
#endif
}
final class Log {
private enum LogType: String {
case error = "[⛔️]"
@koingdev
koingdev / AutoLayoutBuilder.swift
Created May 1, 2019 14:41
Swift Builder Pattern way to write AutoLayout code
/**
Builder Pattern way to write AutoLayout code
Example:
```swift
AutoLayoutBuilder(button)
.bottomTo(view.layoutMarginsGuide.bottomAnchor)
.centerXTo(view.centerXAnchor)
.width(value: button.width)
.height(value: button.height)
@koingdev
koingdev / Debounce.swift
Created May 1, 2019 14:39
Swift Debouncer
/// Return a new function that will be called only once after `delay` time passed between invocation
func debounce(delay: TimeInterval, queue: DispatchQueue = .main, function: @escaping () -> Void) -> () -> Void {
var currentWorkItem: DispatchWorkItem?
return {
currentWorkItem?.cancel()
currentWorkItem = DispatchWorkItem { function() }
queue.asyncAfter(deadline: .now() + delay, execute: currentWorkItem!)
}
}
@koingdev
koingdev / UIComponentStyler.swift
Created May 1, 2019 14:35
Flexible and faster way to style your View
/**
Flexible and faster way to style your View
Example:
```swift
let label = UILabel()
label.styling(UIColor.blue.style, UIFont.boldSystemFont(ofSize: 18).style)
```
*/
protocol UIComponentStyler: AnyObject {