Skip to content

Instantly share code, notes, and snippets.

View mateuszszklarek's full-sized avatar
🗝️

Mateusz Szklarek mateuszszklarek

🗝️
View GitHub Profile

Setup multiple git identities & git user informations

/!\ Be very carrefull in your setup : any misconfiguration make all the git config to fail silently ! Go trought this guide step by step and it should be fine 😉

Setup multiple git ssh identities for git

  • Generate your SSH keys as per your git provider documentation.
  • Add each public SSH keys to your git providers acounts.
  • In your ~/.ssh/config, set each ssh key for each repository as in this exemple:
#!/usr/bin/swift
class Node {
var children: [Node] = []
var depth: Int = 0 {
didSet {
for child in children {
child.depth = depth + 1
protocol MyView: UIView { /*…*/ }
protocol MyView where Self: UIView { /*…*/ }
func forceCast<U>(_ value: Any?, to type: U.Type) -> U {
 return value as! U 
}
let value: Any? = 42
print(forceCast(value, to: Any.self))
// Prints "Optional(42)"
// (Prior to Swift 5, this would print "42".)
print(value as! Any)
// Prints "Optional(42)"
func foo(_ fn: @autoclosure () -> Int) {}
func bar(_ fn: @autoclosure () -> Int) {
foo(fn) // Incorrect, `fn` can't be forwarded and has to be called.
foo(fn()) // OK
}
#!/usr/bin/swift
import Foundation
func measure(_ title: String, operation: () -> Void) {
let closedRange = 0...4
let averageTimeInSeconds = closedRange
.map { _ -> CFAbsoluteTime in
let startTime = CFAbsoluteTimeGetCurrent()
operation()
struct Q: ExpressibleByStringLiteral {
typealias StringLiteralType = String
var question: String
init?(_ possibleQuestion: StringLiteralType) {
return nil
}
init(stringLiteral str: StringLiteralType) {
class CustomObject {
func value() throws -> Int {
return 5
}
func optionalValue() throws -> Int? {
return nil
}
class CustomObject {
func value() -> Int {
return 5
}
func optionalValue() -> Int? {
return nil
}
func value() -> Any {
return 1
}
func optionalValue() -> Any? {
return 2
}
let x = value() as? Int
let y = optionalValue() as? Int