Skip to content

Instantly share code, notes, and snippets.

View isoiphone's full-sized avatar

Jacob Schwartz isoiphone

View GitHub Profile
@isoiphone
isoiphone / policy.txt
Created January 4, 2016 00:50
Canada National Student Loans Service Centre (NSLSC) Password Policy (https://csnpe-nslsc.cibletudes-canlearn.ca/eng/Default.aspx)
"Your Password must be between 7 and 15 characters long. It must contain at least one upper case letter, one lower case letter, and one number. Your Password cannot contain spaces or special characters (like @, &, or _). It also cannot contain consecutively repeated characters (e.g. 11, 222, AAAA). Please select another Password."
func emptyImage() -> UIImage {
UIGraphicsBeginImageContext(CGSize(width: 1, height: 1))
let img = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return img
}
let img = emptyImage()
let dat = UIImagePNGRepresentation(img)
@isoiphone
isoiphone / nodeAtPoint.swift
Created November 25, 2015 09:31
Late night SpriteKit discovery
let node = nodeAtPoint(location)
assert(node.containsPoint(location)) // wtf? this assert does fail sometimes.
@isoiphone
isoiphone / gist:5370ca2e626d7b3457b3
Created October 13, 2015 17:54
singleton.swift
class FooSingleton {
private static let _sharedInstance = FooSingleton()
class var sharedInstance: FooSingleton {
return _sharedInstance
}
}
@isoiphone
isoiphone / lerptest.swift
Created September 30, 2015 23:35
Default parameter handling changed
import UIKit
/*
// In Swift 1.2 this definition gave us what we wanted
func lerp(a: Float, b: Float, t: Float) -> Float {
return (b-a)*t+a
}
*/
// now Swift 2.0 requires this
func lerp(a: Float, _ b: Float, _ t: Float) -> Float {
@isoiphone
isoiphone / Change.swift
Created September 29, 2015 22:48
Comparing two arrays for changes
enum Change {
case Insert(at: Int)
case Delete(at: Int)
case Move(from: Int, to: Int)
}
extension Change: Printable {
var description: String {
switch self {
case .Insert(let at):
@isoiphone
isoiphone / cat.c
Created September 3, 2015 01:03
AVR
static const uint8_t image_cat[] PROGMEM = {0x55,0x8b,0x55,0x23,0x55,0x88,0x55,0x23,0x55,0xe8,0x55,0xa2,0x55,0x88,0x55,0x2,0x55,0xaf,0x77,0xff,0xdd,0xff,0x75,0xff,0xd5,0xef,0x77,0xff,0xdd,0xff,0x57,0xff,0xdf,0xff,0x77,0xff,0x5d,0xff,0x55,0xb8,0x55,0xa8,0x55,0x20,0x55,0x88,0x55,0xf2,0x55,0xe8,0x55,0xb,0x55,0xbe,0x55,0x2b,0x55,0xf,0x55,0xb,0x15,0xb,0x15,0x3,0x11,0x0,0x1,0x0,0x11,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x11,0x0,0x4,0x0,0x11,0x0,0x55,0x3b,0x55,0xff,0x55,0xff,0xd5,0xff,0x55,0xff,0xfd,0xff,0x77,0xff,0xdd,0xfe,0x75,0xfa,0xd5,0xff,0x55,0xfb,0xd5,0xea,0x55,0xba,0x55,0xaa,0x55,0x23,0x55,0x8a,0x55,0x22,0x55,0x88,0x55,0x2a,0x55,0xff,0x75,0xff,0x5d,0xfe,0x55,0x2e,0x55,0x8e,0x55,0x2b,0x55,0xff,0x57,0xff,0xdd,0xff,0x77,0xff,0xdd,0xff,0x77,0xff,0xdf,0xff,0x55,0xbf,0x5d,0xaf,0x55,0x3b,0x55,0xae,0x55,0xfa,0xd5,0xbe,0x55,0x1b,0x55,0x2,0x55,0x0,0x15,0x0,0x5,0x0,0x11,0x0,0x0,0x0,0x11,0x0,0x0,0x0,0x1,0x0,0x40,0x0,0x11,0x0,0x44,0x0,0x11,0x0,0x44,0x0,0x11,0x0,0x0
@isoiphone
isoiphone / random_characters.swift
Last active August 29, 2015 14:27
Swift 2.0 strings-- I don't understand
private let ValidCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\n".utf8
private func RandomString() -> String {
var str = ""
// 1-140
let len = 1+(Int(rand())%140)
for _ in 0...len {
let offset = Int(rand())%Int(ValidCharacters.count)
let index = advance(ValidCharacters.startIndex, offset)
@isoiphone
isoiphone / fix.swift
Created August 4, 2015 21:22
wtf UITableViewCell
// vertically expand label so hanging letters such as 'g' don't get clipped
override func layoutSubviews() {
super.layoutSubviews()
if let textLabel = textLabel {
textLabel.frame = CGRectInset(textLabel.frame, 0, -10)
}
}
// ...
tableView.reloadData()
// ...
CATransaction.begin()
tableView.tableFooterView?.layer.removeAllAnimations()
CATransaction.commit()