Skip to content

Instantly share code, notes, and snippets.

View miguelfermin's full-sized avatar

Miguel Fermin miguelfermin

View GitHub Profile
@miguelfermin
miguelfermin / MultiListeners.kt
Created April 3, 2020 01:24
Model with multi-listeners.
interface OnModelChangeListener {
fun onModelChangeName(model: Model, name: String)
}
class Model {
var name = ""
set(value) {
field = value
publishChangedName(value)
}
class Node {
var left, right: Node?
var data: Int
init(data: Int, left: Node? = nil, right: Node? = nil) {
self.data = data
self.left = left
self.right = right
}
@miguelfermin
miguelfermin / addSubView.swift
Created December 10, 2018 11:16
Simple function that adds a child view and its constraints
func addChildView(_ childView: UIView, to containerView: UIView) {
containerView.addSubview(childView)
childView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint(item: childView,
attribute: .leading,
relatedBy: .equal,
toItem: containerView,
attribute: .leading,
multiplier: 1.0,
@miguelfermin
miguelfermin / goserver.go
Last active October 10, 2018 23:24
go service snippet
router := httprouter.New()
router.POST("/api/login", httpHandler(login))
func httpHandler(fn httpRouterFunc) httpRouterFunc {
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
fn(w, r, ps)
}
}
func login(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
@miguelfermin
miguelfermin / Future.swift
Created September 17, 2018 10:15
Simple Swift implementation of the Future design pattern.
enum Result<T> {
case value(T)
case error(Error)
}
final class Future<T> {
private let queue: DispatchQueue
private var callbacks: [(Result<T>) -> ()] = []
private var result: Result<T>?
@miguelfermin
miguelfermin / Networker.swift
Last active January 25, 2019 18:04
Simple Networking Protocol Extension
//
// Networker.swift
// SES Admin
//
// Created by Miguel Fermin on 8/03/18.
// Updated by Miguel Fermin on 8/22/18.
// Copyright © 2018 MAF Software LLC. All rights reserved.
//
import Foundation
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>0 0 0 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>Hack-Bold - 13.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>0 0 0 1</string>
@miguelfermin
miguelfermin / Darcula.xccolortheme
Created April 23, 2018 10:05
Xcode Darcula Color Theme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>0.901961 0.901961 0.901961 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>SFMono-Regular - 10.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>0.901961 0.901961 0.901961 1</string>
@miguelfermin
miguelfermin / unscrambleable.go
Created April 1, 2018 14:03
The unscramble-able algorithm written in go
package main
import (
"fmt"
)
func main() {
r := unscrambleable("hello", "llohe")
fmt.Println("is unscrambleable? ", r)
}
@miguelfermin
miguelfermin / wiki.go
Last active January 24, 2018 11:20
The "Writing Web Applications" exercise described here https://golang.org/doc/articles/wiki/
// Writing Web Applications:
//
// - Creating a data structure with load and save methods
// - Using the net/http package to build web applications
// - Using the html/template package to process HTML templates
// - Using the regexp package to validate user input
// - Using closures
//
// - Link: https://golang.org/doc/articles/wiki/