Skip to content

Instantly share code, notes, and snippets.

func fridaysThe13(forYear:Int) -> [Date]? {
var days = [Date]()
let calendar = Calendar.current
let dateComponentsStart = DateComponents(year: 2017)
let dateStart = calendar.date(from: dateComponentsStart)!
let dateEnd = calendar.date(byAdding: .year, value: 1, to: dateStart)
var comps = DateComponents(day: 13, weekday: 6)
class Ns:NSObject {
var title: String = "unset"
}
struct Me {
var me:[Ns] {
didSet {
print("set me")
}
}
(lldb) e let $pin = unsafeBitCast(0x7df67c50, MKPinAnnotationView.self)
(lldb) po $pin
@biku
biku / gist:bb7905fec0c4886f4d3f59112e15ad3e
Last active May 10, 2016 13:48
sizing UIImage view with sizeToFitIn - you can just paste it into a playground, but it needs to have horizontal.jpg & vertical.jpg images
import Foundation
import XCPlayground
import UIKit
extension CGSize {
static func aspectFit(aspectRatio : CGSize, newSizeSize: CGSize) -> CGSize {
let mW = newSizeSize.width / aspectRatio.width;
let mH = newSizeSize.height / aspectRatio.height;
var boundingSize = newSizeSize
@biku
biku / RewindableGenerator
Last active August 29, 2015 14:27
Generator that you initialize with a CollectionType(restricted) and can get previous or next. Returns nil past bounds and that case changes to previous position.
/// create a rewindable generator from a collection
/// than previous and next can return you proper Value/Object or nil if it goes past bounds
/// if you find a way to improve it, I'm all ears :-D
struct RewindableGenerator<S : CollectionType where S.Index : BidirectionalIndexType> : GeneratorType, SequenceType {
typealias Sequence = S
private var currentIndex: Sequence.Index
private let prestartIndex: Sequence.Index
private let seq: Sequence
@biku
biku / gist:9919a56dc74c9cfb5655
Created April 8, 2015 17:19
random extension to Int
public extension Int {
/**
Create a random num Int
:param: lower number Int
:param: upper number Int
:return: random number Int
*/
public static func random (#lower: Int , upper: Int) -> Int {
return lower + Int(arc4random_uniform(upper - lower + 1))
}
@biku
biku / gist:5221907
Last active December 15, 2015 07:18
xCode sql debug
In Xcode, go to the Product menu and choose Edit Scheme.
Select Debug on the left.
Select Arguments on the right.
Under Arguments Passed On Launch, click the add button.
Enter: -com.apple.CoreData.SQLDebug 1
Click OK.
source and more: http://www.cimgf.com/2013/01/03/nsfetchedresultscontroller-sectionnamekeypath-discussion/#more-1994