Skip to content

Instantly share code, notes, and snippets.

enum UnitType: String {
case milligrams = "mg"
case grams = "g"
case kilograms = "kg"
case count = "count"
case pounds = "lb"
case ounces = "oz"
case milliliters = "ml"
case liters = "L"
case cups = "cup"
@aranasaurus
aranasaurus / DictionaryConvertable.swift
Created September 25, 2015 15:57 — forked from IanKeen/DictionaryConvertable.swift
_Very_ basic protocol to handle conversions between Model objects and Dictionaries. Model -> Dictionary has a default implementation provided for simple 1:1 non-nested Models - Will likely adapt this into a lib at some point
protocol DictionaryConvertable {
static func fromDictionary(dictionary: [String: Any]) throws -> Self
func toDictionary() -> [String: Any]
}
extension DictionaryConvertable {
func toDictionary() -> [String: Any] {
let mirror = Mirror(reflecting: self)
return mirror.children.reduce([:]) { result, child in
guard let key = child.label else { return result }
@aranasaurus
aranasaurus / KeyValueStorable.swift
Created September 25, 2015 03:03 — forked from IanKeen/KeyValueStorable.swift
A protocol I like to use in my apps anywhere something like NSUserDefaults or KeyChain is normally used... allows for easy swapping of implementation. Also provided is StringDictionary() which can be used when testing
protocol KeyValueStorable {
subscript (key: String) -> AnyObject? { get set }
mutating func removeAll() -> Void
}
extension NSUserDefaults: KeyValueStorable {
subscript (key: String) -> AnyObject? {
get { return self.objectForKey(key) }
set { self.setObject(newValue, forKey: key) }
- (BOOL)isEqual:(id)object;
{
if ( object == self ) {
return YES;
}
if ( object == nil || ![object isKindOfClass:[self class]] ) {
return NO;
}
@aranasaurus
aranasaurus / q1.py
Created July 29, 2011 19:51
First Level Question Answer
import sys
def main(num1, out1, num2, out2, start, end):
for val in range(start, end):
is1 = val % num1 == 0
is2 = val % num2 == 0
out = ''
if is1:
out += out1
if is2: