Skip to content

Instantly share code, notes, and snippets.

View digoreis's full-sized avatar
🙃

Rodrigo Reis digoreis

🙃
  • Lisbon
View GitHub Profile
import Cocoa
@propertyWrapper
struct Clapping<Value: Comparable> {
var value: Value
let range: ClosedRange<Value>
init(wrappedValue: Value, _ range: ClosedRange<Value>) {
precondition(range.contains(wrappedValue))
@digoreis
digoreis / xcresult.rb
Created June 23, 2019 10:55
xcresult.rb - a simple parse for XCResult
require 'plist'
require 'ostruct'
require 'base64'
require 'json'
fixedPath = "Test-NewDangerSnapshotting-2019.06.15_19-52-13-+0100.xcresult"
class XCResult
attr_reader :reference, :tests
@digoreis
digoreis / patience.swift
Created May 21, 2019 23:23
Patience Implementation in Swift
import UIKit
struct DiffLine: CustomDebugStringConvertible {
enum DiffLineType {
case equal
case remove
case add
case replace
}
func create<T: UIView>(usingAutoLayout: Bool = true, configure: (T) -> Void) -> T {
let object = T()
object.translatesAutoresizingMaskIntoConstraints = !usingAutoLayout
configure(object)
return object
}
@digoreis
digoreis / url.swift
Created April 23, 2019 11:07
Small abstraction for url scheme
import Foundation
enum LinkType: FormatterUrl {
case product(String)
case look(String)
func formatter(prefix: String) -> String {
switch self {
case .product(let id): return prefix.appending("://products/\(id)")
case .look(let id): return prefix.appending("://looks?order=1&collections=\(id)")
@digoreis
digoreis / kadaneSumMaxSubArray.swift
Created July 4, 2018 22:10
Algorithm for Maximun Sum of a SubArray in Swift
import Cocoa
func kadaneSumMaxSubArray(_ values: [Int]) -> Int {
guard let firstValue = values.first else { return 0}
var current = firstValue
var global = firstValue
for value in values[1 ..< values.count] {
current = (current + value) < current ? 0 : current
current = max(current, (current + value))
global = max(global, current)
@digoreis
digoreis / CompressString.swift
Created July 2, 2018 16:18
Algorithm for compress string
import Cocoa
let str = "aabbaaccccdaeeeebb"
func compressString(_ value: String) -> String {
var resultStr = ""
var currentChar: Character?
var currentCount: Int = 0
for c in value {
guard let char = currentChar else {
@digoreis
digoreis / BinaryTree-BFS.swift
Created June 30, 2018 13:23
Sample of BinaryTree with BFS navigation
import Cocoa
indirect enum BinaryTree<T> {
case node(BinaryTree, T, BinaryTree)
case empty
}
extension BinaryTree {
static func leaf(_ value: T) -> BinaryTree {
return .node(.empty,value,.empty)
import Cocoa
struct CircularQueueIterator<T>: IteratorProtocol {
let queue: [T]
private var position = 0
init(queue: [T]) {
self.queue = queue
}
@digoreis
digoreis / BinaryTree.swift
Created June 29, 2018 14:07
A sample for BinaryTree with Enum.
import Cocoa
indirect enum BinaryTree<T> {
case node(BinaryTree, T, BinaryTree)
case empty
}
extension BinaryTree {
static func leaf(_ value: T) -> BinaryTree {