This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func print(address o: UnsafeRawPointer ) { | |
print(String(format: "%p", Int(bitPattern: o))) | |
} | |
var array1: [Int] = [0, 1, 2, 3] | |
var array2 = array1 | |
//Print with just assign |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class Ref<T> { | |
var val : T | |
init(_ v : T) {val = v} | |
} | |
struct Box<T> { | |
var ref : Ref<T> | |
init(_ x : T) { ref = Ref(x) } | |
var value: T { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Example of a runtime check stubbing | |
class User { | |
} | |
enum ResultType<T> { | |
case success(T) | |
case error(Error) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class User { | |
} | |
enum ResultType<T> { | |
case success(T) | |
case error(Error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <limits.h> | |
int main(void) | |
{ | |
int x = INT_MAX; | |
x += 1; // Integer overflow here | |
printf("x = %i\n", x); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct CPFValidator { | |
var cpf: String | |
// Based on: | |
// https://pt.stackoverflow.com/questions/187106/valida%C3%A7%C3%A3o-cpf-e-cnpj | |
func validate() -> Bool { | |
let numbers = cpf.compactMap { (char) -> Int? in | |
return Int(char) | |
} | |
guard numbers.count == 11 && Set(numbers).count != 1 else { return false } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: CustomStringConvertible { | |
var tagged: Bool | |
var name: String = "" | |
var subnodes: [Node] = [] | |
init(tagged: Bool, name: String = "") { | |
self.tagged = tagged | |
self.name = name | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Event { | |
var count: Int = 0 | |
let lock = NSLock() | |
func start() { | |
lock.lock() | |
count += 1 | |
lock.unlock() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct Node { | |
var childs: [String] = [] | |
var lock = NSRecursiveLock() | |
init() {} | |
mutating func clearChilds() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct Node { | |
var childs: [String] = [] | |
init() {} | |
mutating func clearChilds() { | |
if childs.isEmpty { | |
childs.removeAll() |
OlderNewer