Skip to content

Instantly share code, notes, and snippets.

View Alexander-Ignition's full-sized avatar
:atom:

Alexander Ignition Alexander-Ignition

:atom:
View GitHub Profile

Server Side Swift with Vapor:

PostgreSQL

  • ะฃัั‚ะฐะฝะพะฒะบะฐ
    • ะžะฑะฝะพะฒะธั‚ัŒ Homebrew $ brew update
    • ะฃัั‚ะฐะฝะพะฒะธั‚ัŒ PostgreSQL $ brew install postgres
  • ะะฐัั‚ั€ะพะนะบะฐ
  • ะ—ะฐะฟัƒัั‚ะธั‚ัŒ ัะตั€ะฒะตั€ ะฑะฐะทั‹ ะดะฐะฝะฝั‹ั… $ postgres -D /usr/local/var/postgres
extension Optional where Wrapped == String {
var isEmpty: Bool { return map { $0.isEmpty } ?? true }
}
extension Optional where Wrapped == Collection {
var isEmpty: Bool { return map { $0.isEmpty } ?? true }
}
@Alexander-Ignition
Alexander-Ignition / sendMessage.sh
Created June 13, 2017 07:27
send message from terminal
osascript -e 'tell application "Messages" to send "Hello World" to buddy "+1234567890" of (1st service whose service type = iMessage)'
#!/usr/bin/env bash
cd "$(dirname "$0")"
source ml-env/bin/activate
jupyter notebook
@Alexander-Ignition
Alexander-Ignition / URLRequest+Property.swift
Created June 20, 2018 09:34
Set additional property to URLRequest
extension URLRequest {
func property(forKey key: String) -> Any? {
return URLProtocol.property(forKey: key, in: self)
}
mutating func setProperty(_ value: Any, forKey key: String) {
mutate { URLProtocol.setProperty(value, forKey: key, in: $0) }
}
@Alexander-Ignition
Alexander-Ignition / KeyPathAnimation.swift
Created July 28, 2018 13:41
Smart key path using with CABasicAnimation
class KeyPathAnimation<View, Value> {
let basicAnimation: CABasicAnimation
let keyPath: KeyPath<View, Value>
init(keyPath: KeyPath<View, Value>) {
self.keyPath = keyPath
// https://github.com/apple/swift/blob/2844583d7f9d51ce5c4da7776e19f0aab6f2e3f6/stdlib/public/core/KeyPath.swift#L107
basicAnimation = CABasicAnimation(keyPath: keyPath._kvcKeyPathString)
}
@Alexander-Ignition
Alexander-Ignition / measure.swift
Created September 17, 2018 06:40
Measure on Darwin Match
func measure(_ name: String, _ block: () -> Void) {
let machToSeconds: Double = {
var timebase: mach_timebase_info_data_t = mach_timebase_info_data_t()
mach_timebase_info(&timebase)
return Double(timebase.numer) / Double(timebase.denom) * 1e-9
}()
let startTime = mach_absolute_time()
block()
let endTime = mach_absolute_time()
extension Locale {
static func locale(forCurrencyCode currencyCode: String) -> Locale? {
return availableIdentifiers.lazy
.map { Locale(identifier: $0) }
.first { $0.currencyCode == currencyCode }
}
static func currencySymbol(forCurrencyCode currencyCode: String) -> String? {
return locale(forCurrencyCode: currencyCode).flatMap { $0.currencySymbol }
}
@Alexander-Ignition
Alexander-Ignition / uifont_system.md
Last active October 21, 2018 10:26
UIFont system font size

UIFont system font size (iOS 12)

UIInterface.h

UIFont Size
labelFontSize 17.0
buttonFontSize 18.0
smallSystemFontSize 12.0
systemFontSize 14.0

Swift Asserts

Function name Condition In playgrounds and -Onone builds (the default for Xcode's Debug configuration) In -O builds (the default for Xcode's Release configuration) In -Ounchecked builds
assert ๐Ÿ”˜ ๐Ÿ”˜ โšช โšช
assertionFailure โšช ๐Ÿ”˜ โšช โšช
precondition ๐Ÿ”˜ ๐Ÿ”˜ ๐Ÿ”˜ โšช
preconditionFailure โšช ๐Ÿ”˜ ๐Ÿ”˜ โšช
fatalError โšช ๐Ÿ”˜ ๐Ÿ”˜ ๐Ÿ”˜
dispatchPrecondition ๐Ÿ”˜ ๐Ÿ”˜ ๐Ÿ”˜ โšช