Skip to content

Instantly share code, notes, and snippets.

@flashspys
flashspys / MapTo.js
Last active August 24, 2020 14:07
MapTo
const handler = {
get: function(_, prop) {
return (obj) => {
return obj.map((entry) => entry[prop]);
}
}
};
const MapTo = new Proxy({}, handler);
ScrollView {
Group {
Rectangle().fill(Color(UIColor.systemRed)).frame(width: 100, height: 100)
Rectangle().fill(Color(UIColor.systemBackground)).frame(width: 100, height: 100)
Rectangle().fill(Color(UIColor.secondarySystemBackground)).frame(width: 100, height: 100)
Rectangle().fill(Color(UIColor.tertiarySystemBackground)).frame(width: 100, height: 100)
Rectangle().fill(Color(UIColor.systemFill)).frame(width: 100, height: 100)
Rectangle().fill(Color(UIColor.secondarySystemFill)).frame(width: 100, height: 100)
Rectangle().fill(Color(UIColor.tertiarySystemFill)).frame(width: 100, height: 100)
@flashspys
flashspys / String+NSRangeOfString.swift
Last active January 11, 2016 22:49
String.rangeofString to NSRange
extension String {
func NSRangeOfString(string: String) -> NSRange {
let range = self.rangeOfString(string)
if (range != nil) {
let first: Int = self.startIndex.distanceTo(range!.startIndex)
let length: Int = range!.startIndex.distanceTo(range!.endIndex)
return NSMakeRange(first, length)
}
return NSMakeRange(NSNotFound, 0)
}
import Darwin
public func arc4random <T: IntegerLiteralConvertible> (type: T.Type) -> T {
var r: T = 0
arc4random_buf(&r, UInt(sizeof(T)))
return r
}
public extension UInt {
public static func random(lower: UInt = min, upper: UInt = max) -> UInt {
@flashspys
flashspys / Random.swift
Created September 20, 2014 09:48
simple swift random class
import UIKit
class Random {
class func randomInt() -> Int {
return Int(arc4random());
}
class func randomIntFrom(from: Int) -> Int {