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
// This would be hosted on the server but node does not support atob btoa. | |
function decode(toDecode){ // eslint-disable-line no-unused-vars | |
let salt = 'MySimpleSalt'; | |
let decoded = atob(toDecode); | |
if (toDecode === btoa(decoded)){ | |
return decoded.replace(salt,''); | |
} | |
throw new Error('Could not decode data'); | |
} |
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
function areMapsEqual(left: Map<number, string []>, right: Map<number, string []>): boolean { | |
if (left.size !== right.size) { return false } | |
const leftKeys = Array.from(left.keys()).sort() | |
const rightKeys = Array.from(right.keys()).sort() | |
if ( leftKeys !== rightKeys ) { return false } | |
for ( const key of leftKeys ) { | |
const leftValues = left.get(key) || [] | |
const rightValues = right.get(key) || [] | |
if ( leftValues.sort() !== rightValues.sort()) { return false } |
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 UIViewController { | |
var appDelegate:AppDelegate { | |
return UIApplication.shared.delegate as! AppDelegate | |
} | |
var isAlertShowingComputed:Bool { | |
guard let window = self.appDelegate.window else { return false } | |
return !window.subviews.filter{ | |
$0.isKind(of: UIAlertController.self)}.isEmpty | |
} |
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
// | |
// main.swift | |
// pggrep - updated 12/4/15 | |
// Created by Erica Sadun on 6/17/15. | |
// Copyright © 2015 Erica Sadun. All rights reserved. | |
// | |
import Foundation | |
extension String { |
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
protocol Trying{ | |
var uno:Int {get set} | |
var name:String{get set} | |
} | |
extension Trying{ | |
init(unit:Int){ | |
self.init() | |
self.name = "" |
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
let hey = [1,2,23,3,4,5,5,6,6,7,7,8] | |
let slice = hey[4...10] | |
for each in slice.indices{ | |
print(slice[each]) | |
} |
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
//Filter.swift | |
public mutating func next() -> Base.Element? { | |
var n: Base.Element? | |
for/*ever*/;; { | |
n = _base.next() | |
if n != nil ? _predicate(n!) : true { | |
return n | |
} | |
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 fileinput | |
file = 'Directory' | |
filein = file + '.swift' | |
fileout = file + 'Edit' + '.swift' | |
def to_camel_case(snake_str): | |
components = snake_str.split('_') | |
return components[0] + "".join(x.capitalize() for x in components[1:]) |
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
enum Allergies:UInt { | |
static func hasAllergy(value:UInt, testAgainst: Allergies) -> Bool { | |
return value & testAgainst.rawValue > 0 | |
} | |
case None = 0 | |
case eggs = 1 | |
case peanuts = 2 | |
case shellfish = 4 | |
case strawberries = 8 |
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
// http://stackoverflow.com/questions/24026510/how-do-i-shuffle-an-array-in-swift | |
extension CollectionType { | |
/// Return a copy of `self` with its elements shuffled | |
func shuffle() -> [Generator.Element] { | |
var list = Array(self) | |
list.shuffleInPlace() | |
return list | |
} | |
} |