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 StateMachine(private val initialState: State) { | |
interface Event | |
interface State | |
class Edge(private val triggerEvent: Event, private val targetState: State) { | |
private val actionList = mutableListOf<(Edge) -> Unit>() | |
fun action(action: (Edge) -> Unit) { | |
actionList.add(action) | |
} |
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
require 'xcodeproj' | |
require 'find' | |
require 'yaml' | |
require 'set' | |
class XCodeProject | |
def initialize(path) | |
unless File.exists?(path) | |
raise Errno::ENOENT, "#{path} does not exist." |
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
allprojects { project -> | |
afterEvaluate { | |
if((project.plugins.hasPlugin('android') || project.plugins.hasPlugin('android-library'))) { | |
android { | |
compileSdkVersion myCompileSdkVersion as Integer | |
buildToolsVersion myBuildToolsVersion | |
} | |
} | |
} | |
} |
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
extension Array { | |
func properDescribe(indent: Int = 0) { | |
var indentString: String = "" | |
for _ in 0...indent { | |
indentString += "\t" | |
} | |
for value in self { | |
switch value { | |
case let x as NSManagedObject: |
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 | |
import CoreData | |
var dictA: [String : Any] = ["key1": "value1", "key3": "value3", "key4": "notModified", | |
"key5" : 1, "key6" : 1.0, | |
"key7": ["a", "b"], "key8": ["a"], "key9": ["a", "b"]] | |
var dictB: [String : Any] = ["key2": "value2", "key3": "modified", "key4": "notModified", | |
"key5" : 2, "key6" : 2.0, | |
"key7": ["a", "c"], "key8": ["a", "b"], "key9": ["a"]] |
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
func calculatePercentageDistribution(ofValues inputValues: [Double]) -> [Double] { | |
let totalValue = inputValues.reduce(0.0) { $0.0 + $0.1 } | |
guard totalValue > 0 else { | |
return Array<Double>(repeating: 0.0, count: inputValues.count) | |
} | |
var fractionSum: Double = 0.0 | |
var percentArray = inputValues.map { value -> Double in | |
let value = (value * 100.0) / totalValue |
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
public class FontsUtility { | |
/** | |
Call this at the app startup to register custom fonts and use them in the app. | |
*/ | |
public static func registerFonts() { | |
let bundle = Bundle(for: FontsUtility.self) | |
guard let path = bundle.path(forResource: "Info", ofType: "plist") else { | |
print("[RegisterFonts] Failed to find Info.plist") | |
return | |
} |
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
func isChineseNewYear() -> Bool { | |
let today = Date() | |
let chineseCalendar = Calendar(identifier: Calendar.Identifier.chinese) | |
var components = chineseCalendar.dateComponents([.year, .timeZone], from: today) | |
guard let chineseDate = chineseCalendar.date(from: components) else { return false } | |
let chineseYear = Calendar.current.component(.year, from: chineseDate) | |
let currentYear = Calendar.current.component(.year, from: today) | |
guard let year = components.year else { return false } | |
components.year = year + (currentYear - chineseYear) |
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
//: Playground - noun: a place where people can play | |
import UIKit | |
class Step { | |
let x: Int | |
let y: Int | |
init?(_ x: Int, _ y: Int) { | |
guard x >= 0 && x < Step.maze.count else { return nil } |
NewerOlder