Skip to content

Instantly share code, notes, and snippets.

@fitsyu
fitsyu / G29-mac.js
Created March 3, 2021 03:17
Make use of Logitech G29 steering wheel to press commonly used buttons on a Mac
const g29 = require('logitech-g29')
const robot = require('robotjs')
g29.on('shifter-gear', function(gear) {
switch (gear) {
case 0:
break;
case 1:
robot.keyTap('v', ['command']);
break;
@fitsyu
fitsyu / Protokol Kesehatan.swift
Created July 6, 2021 01:23
Protokol kesehatan menggunakan bahasa pemrograman Swift
protocol Kesehatan {
func memakaiMasker()
func mencuciTangan()
func menjagaJarak()
func menjauhiKerumunan()
func membatasiMobilisasi()
}
@fitsyu
fitsyu / prokes.swift
Last active December 24, 2020 08:28
Implementasi Protokol Kesehatan Menggunakan Swift
protocol Kesehatan {
func memakaiMasker()
func menjagaJarak()
func mencuciTangan()
}
class MauSehat: /* implements */ Kesehatan {
@fitsyu
fitsyu / CLGeocoder+Promises.swift
Last active August 2, 2019 10:33
Growing list of wrapped CLGeocoder with PromisesSwift
extension CLGeocoder {
func reverseGeocode(_ location: CLLocation) -> Promise<([CLPlacemark]?,Error?)> {
return wrap { self.reverseGeocodeLocation(location, completionHandler: $0) }
}
// add some more here later
}
@fitsyu
fitsyu / Singleton Snippet.swift
Created July 9, 2019 03:17
Quickly generate swift object singleton
// MARK: Singleton Instance
private init() {}
private static var instance: <#T#>!
static var shared: <#T#> {
if instance == nil {
instance = <#T#>()
}
return instance
}
@fitsyu
fitsyu / Promises Snippet.swift
Created July 6, 2019 06:13
Quickly generate Google Promises code
let promise = Promise<<#T#>> { fulfill, reject in
}
return promise
@fitsyu
fitsyu / OneSectioned UITableView Snippet.swift
Last active July 6, 2019 06:10
A snippet to easily create the boilerplate UITableView DataSource and Delegate
extension <#_#>: UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return <#models#>.count
}
@fitsyu
fitsyu / Useful.swift
Created June 26, 2019 06:20
Detect UIView out of screen
extension UIView {
func origin(in view: UIView) -> CGPoint {
return view.convert(CGPoint.zero, from: self)
}
func isVisible(in view: UIView) -> Bool {
return view.frame.contains(self.origin(in: view))
}
}
@fitsyu
fitsyu / SimpleTest5
Created October 19, 2018 03:43
Easy Easy Medium
import UIKit
var str1 = "Hi"
var str2 = "World"
func twoString(s1: String, s2: String) -> String {
let filtered = str1.filter { char in str2.contains(char) }
let out = filtered.isEmpty ? "NO" : "YES"