Skip to content

Instantly share code, notes, and snippets.

View kumo's full-sized avatar

Robert Clarke kumo

View GitHub Profile
@kumo
kumo / Roman Nums.swift
Last active June 16, 2016 08:02
Roman Nums in Swift
//: Playground - noun: a place where people can play
import UIKit
extension Int {
func toRoman() -> String? {
var number = self
guard number > 0 else {
return nil
@kumo
kumo / gist:148fdbaf2677e13eaed0
Created April 17, 2015 08:21
Text change snippet
var label = context.selection[0];
label.setStringValue("where time becomes a loop");
// If I uncomment the following it works
// var name = label.name()
// label.setName(newText)
// label.setName(name)
@kumo
kumo / ReplacingText
Last active August 29, 2015 14:19
Experimenting with replacing text in a Sketch document
var replaceValues = function(string, values) {
var newString = string;
for (var i=0; i < values.length; i++) {
var stringToken = "["+(i+1)+"]";
newString = newString.replace(stringToken, values[i]);
}
return newString;
}
extension String {
/** If the string represents an double that fits into an Double, returns the corresponding double. This accepts strings that match the regular expression "[+-]?(?:\d*[\.,])?\d+" only. **/
func toDouble() -> Double? {
let pattern = "^[+-]?(?:\\d*[\\.,])?\\d+$"
var error: NSError? = nil
if let regex = NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.DotMatchesLineSeparators, error: &error) {
// Playground - noun: a place where people can play
import UIKit
enum SubtitleType {
case SubRip, SubStationAlpha, LRC, SAMI, YouTube, SubViewer, MicroDVD, WebVTT, TTML, Unknown
func description() -> String {
switch self {
case .SubRip:
@kumo
kumo / Group Presentations.rb
Last active August 29, 2015 14:10
Ordering the IT Group Presentations
groups = ["LITERATURE AND FILMS", "LE SETTE MERAVIGLIE DEL MONDO", "NEW YEAR'S EVE",
"MUSIC", "THE MEANING OF THE COLOURS IN THE WORLD", "ENGLISH CURIOSITIES",
"COSPLAY", "DRUGS", "WOMEN FOR THE HUMAN RIGHTS"]
groups.sort!
groups.shuffle(random: Random.new(20141203))
# "LITERATURE AND FILMS", "COSPLAY", "LE SETTE MERAVIGLIE DEL MONDO", "ENGLISH CURIOSITIES",
# "WOMEN FOR THE HUMAN RIGHTS", "THE MEANING OF THE COLOURS IN THE WORLD", "DRUGS",

Keybase proof

I hereby claim:

  • I am kumo on github.
  • I am kumo (https://keybase.io/kumo) on keybase.
  • I have a public key whose fingerprint is 9B1A 8097 E9F5 381D 5205 0F51 F9B2 3CCB 9C00 45F7

To claim this, I am signing this object:

@kumo
kumo / ArabicTuples.swift
Last active July 17, 2020 10:22
Converting to Arabic numbers using tuples
import UIKit
func toArabic(romanNumerals: String) -> Int? {
let values = [("M", 1000), ("CM", 900), ("D", 500), ("CD", 400), ("C",100), ("XC", 90), ("L",50), ("XL",40), ("X",10), ("IX", 9), ("V",5),("IV",4), ("I",1)]
var romanNumerals = romanNumerals
var result = 0
for (romanChars, arabicValue) in values {
let range = romanChars.startIndex ..< romanChars.endIndex
@kumo
kumo / RomanTuples.swift
Last active April 8, 2016 17:32
Converting to Roman Numerals using an array of tuples
func toRomanNumerals(number: Int) -> String? {
guard number > 0 else {
return nil
}
var remainder = number
let values = [("M", 1000), ("CM", 900), ("D", 500), ("CD", 400), ("C",100), ("XC", 90), ("L",50), ("XL",40), ("X",10), ("IX", 9), ("V",5),("IV",4), ("I",1)]
var result = ""
@kumo
kumo / RomanNumerals.swift
Last active February 21, 2022 21:07
A simple roman numerals converter in Swift
// Playground - noun: a place where people can play
import Foundation
func toRoman(number: Int) -> String {
let romanValues = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]
let arabicValues = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
var romanValue = ""