Skip to content

Instantly share code, notes, and snippets.

View digoreis's full-sized avatar
🙃

Rodrigo Reis digoreis

🙃
  • Lisbon
View GitHub Profile
@digoreis
digoreis / cacheLRU.swift
Created June 27, 2018 21:26
A sample about cache LRU and used LinkedList for more performance in remove and include items.
import Cocoa
class Node<T,I: Hashable> {
let value: T
let index: I
var next: Node?
init(value: T,index: I) {
self.value = value
self.index = index
@digoreis
digoreis / PalindromeAndPermutation.swift
Created June 27, 2018 12:43
Function check if it is a permutation of a palindrome.
import Cocoa
struct CounterPalindrome {
var countOdd = 0
var isPermutationAndPalindrome: Bool {
return countOdd <= 1
}
var table = Dictionary<Character,Int>()
mutating func count(_ char: Character) {
table[char] = (table[char] ?? 0) + 1
@digoreis
digoreis / checkPermutation.swift
Created June 25, 2018 14:31
Given two strings, a method to decide if one is permutation of the other.
import Cocoa
struct Counter {
var table = Dictionary<Character,Int>()
mutating func add(_ key: Character) {
let value = table[key] ?? 0
table[key] = value + 1
}
@digoreis
digoreis / uniqueChar.swift
Created June 25, 2018 14:02
Implement an algorithm to determine if a string has all unique characters.
import Cocoa
struct Counter {
var table = Dictionary<String,Int>()
mutating func insertUnique(_ word: String) -> Bool {
let value = table[word] ?? 0
guard value == 0 else { return false }
table[word] = value + 1
return true
//: Playground - noun: a place where people can play
import Foundation
import PlaygroundSupport
struct Post {
let id: Int
let body: String
let username: String
let name: String
@digoreis
digoreis / Restkit.swift
Last active July 7, 2018 13:41
Simple DSL in Swift to Networking
import Cocoa
public typealias RestKitSuccess = (HTTPURLResponse, Data?) -> Void
public typealias RestKitFailure = (HTTPURLResponse, RestKitError) -> Void
public protocol RestKitProcess {
func process(_ request: URLRequest) -> URLRequest
}
public enum RestKitError: Error {
@digoreis
digoreis / service.swift
Created February 21, 2018 21:36
Sample service
import Dispatch
import Foundation
public protocol Service {
static func run()
}
class ServiceApplication {
@digoreis
digoreis / script-stackoverflow-database.gif
Last active March 9, 2022 19:03
Sample of parse Posts.xml of Stackoverflow
script-stackoverflow-database.gif
@digoreis
digoreis / pysyft-first-step.md
Created September 13, 2017 20:14
First Steps

PySyft - First Step

This a simple tutorial to explain about first steps.

Commands :

git clone https://github.com/OpenMined/PySyft.git
cd PySyft
docker build -f Development-Dockerfile -t "pysyft:local" .
make custom docker=pysyft:local
@digoreis
digoreis / local-branch-last-commit.sh
Created August 8, 2017 13:21
Command to list all last commit in all local branches
git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:red)%(objectname:short)%(color:reset);%(color:yellow)%(refname:short)%(color:reset);(%(color:green)%(committerdate:relative) - %(committerdate:local)%(color:reset));%(authorname);%(contents:subject)' | column -t -s ';'