Skip to content

Instantly share code, notes, and snippets.

View mathewsanders's full-sized avatar

Mathew Sanders mathewsanders

View GitHub Profile
import UIKit
protocol SegueHandlerType {
typealias SegueIdentifier: RawRepresentable
}
extension SegueHandlerType where
Self: UIViewController,
SegueIdentifier.RawValue == String
{
@austinzheng
austinzheng / CustomTextInputView.swift
Last active January 20, 2022 15:14
Simple UIKeyInput example
import UIKit
/// A very simple example view that can accept keyboard input and add or delete text from an enclosed label.
class CustomTextInputView : UIControl, UIKeyInput {
var label : UILabel?
override func canBecomeFirstResponder() -> Bool {
return true
}
//
// SimpleScrollingStack.swift
// A super-simple demo of a scrolling UIStackView in iOS 9
//
// Created by Paul Hudson on 10/06/2015.
// Learn Swift at www.hackingwithswift.com
// @twostraws
//
import UIKit
anonymous
anonymous / definitions.units
Created April 8, 2015 06:26
#
# This file is the units database for use with GNU units, a units conversion
# program by Adrian Mariano adrianm@gnu.org
#
# March 2014 Version 2.10
#
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006
# 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
# Free Software Foundation, Inc
#
@natecook1000
natecook1000 / NSScanner+Swift.swift
Created March 3, 2015 20:13
Swift-friendly NSScanner methods
// NSScanner+Swift.swift
// A set of Swift-idiomatic methods for NSScanner
//
// (c) 2015 Nate Cook, licensed under the MIT license
import Foundation
extension NSScanner {
// MARK: Strings
@cmoulton
cmoulton / UISwiftRestDemo
Last active September 9, 2021 21:01
Quick & dirty REST API calls with Swift 2.2. See http://grokswift.com/simple-rest-with-swift/
// MARK: Using NSURLSession
// Get first todo item
let todoEndpoint: String = "http://jsonplaceholder.typicode.com/todos/1"
guard let url = NSURL(string: todoEndpoint) else {
print("Error: cannot create URL")
return
}
let urlRequest = NSURLRequest(URL: url)
2015-01-26 18:02:31.223 Invaluable iOS[29323:1139622] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '{objective 0x7ff55b678f30: <251:-343, 250:915> + <250:5.96046e-08>*0x7ff55d81f580.marker{id: 7363} + <250:-2.98023e-08>*0x7ff55db73220.marker{id: 7364} + <250:2>*0x7ff55fa3e030.marker{id: 9313} + <250:2>*0x7ff55fd01060.negError{id: 9018} + <250:-2>*0x7ff55fd01060.posErrorMarker{id: 9017} + <250:-2>*0x7ff55fd018b0.marker{id: 9032}}: internal error. Setting empty vector for variable INVTriColumnPriceView:0x7ff55fe35160.minX{id: 8877}.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001085ddf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010546cbb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001085dde6d +[NSException raise:format:] + 205
3 Foundation 0x00000001060cf45e -[NSISObjectiveLinearExpression setPriorityVector:forKnownAbsentVariable:] + 76
@Revolucent
Revolucent / BitwiseOptions.swift
Last active September 22, 2018 12:46
BitwiseOptions implementation for Swift
//
// BitwiseOptions.swift
//
// Created by Gregory Higley on 11/24/14.
// Copyright (c) 2014 Prosumma LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@natecook1000
natecook1000 / VulgarFraction.swift
Created August 28, 2014 03:08
Vulgar Fractions
// (c) 2014 Nate Cook, licensed under the MIT License
/**
Returns a tuple with the closest compound fraction possible with Unicode's built-in "vulgar fractions".
See here: http://www.unicode.org/charts/PDF/U2150.pdf
:param: number The floating point number to convert.
:returns: A tuple (String, Double): the string representation of the closest possible vulgar fraction and the value of that string
@Tron5000
Tron5000 / gist:7bb51318db1da86a3a78
Last active January 7, 2020 07:45
Compressing/Decompressing UUID to 22 characters via base64
import Foundation
// Compressing and decompressing a UUID to 22 characters via base64.
// Works great as a Swift playground. These articles were helpful:
// http://blog.codinghorror.com/equipping-our-ascii-armor/
// http://69.195.124.60/~jasondoh/2013/08/14/creating-a-short-guid-in-objective-c/
let identifier = NSUUID().uuidString
let base64TailBuffer = "="
func compress(identifier: String) -> String? {