Skip to content

Instantly share code, notes, and snippets.

View tsraveling's full-sized avatar

Tim Raveling tsraveling

View GitHub Profile
@tsraveling
tsraveling / FacebokHandler.swift
Last active April 25, 2017 18:47
Facebook Integration
import FacebookCore
@tsraveling
tsraveling / common-formats.swift
Last active September 9, 2017 22:03
Date Formats
let shortest_date = "M.d.yy" // 1.15.17
let short_date = "M.d.yyyy" // 1.15.2017
let full_date = "MMMM d, yyyy" // January 15, 2017
@tsraveling
tsraveling / String+Error.swift
Created April 21, 2017 05:42
Strings as errors
extension String: LocalizedError {
public var errorDescription: String? { return self }
}
@tsraveling
tsraveling / protocol.md
Created April 20, 2017 22:04
Init PyPEG 2

PyPeg2 Setup

1. Set up virtualenv

Using Terminal:

> cd project_root
virtualenv env
source env/bin/activate
@tsraveling
tsraveling / copy-to-clipboard.swift
Last active April 19, 2017 23:00
Copy to clipboard
let clipboard = UIPasteboard.general
clipboard.string = <#T##string#>
// Do this next part in the background
DispatchQueue.global(qos: .userInitiated).async {
// Do your time-costly work here
// Return to the main thread to update the UI
DispatchQueue.main.async {
// Perform UI updates here
}
var keyboardHeight : CGFloat = 0
func textFieldDidBeginEditing(_ textField: UITextField) {
let y = textField.frame.origin.y
let h = self.scrollView.frame.size.height
let margin = h - (keyboardHeight + textField.frame.size.height)
self.scrollView.setContentOffset(CGPoint(x: 0, y: y >= margin ? y - margin : 0), animated: true)
}
@tsraveling
tsraveling / menu-tableview-delegate.swift
Created April 18, 2017 23:57
Menu UITableView delegate
// MARK: - Menu UITableView Delegate and Datasource -
enum MenuItem : String {
case <#T##key#> = "<#T##Value#>"
static var items = [ <#T##all values#>]
}
func numberOfSections(in tableView: UITableView) -> Int {
@tsraveling
tsraveling / prepare-for-segue.swift
Created April 18, 2017 23:56
Prepare for segue
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
@tsraveling
tsraveling / print-fonts.swift
Created April 18, 2017 23:56
Print font names
let fontFamilyNames = UIFont.familyNames
for familyName in fontFamilyNames {
print("------------------------------")
print("Font Family Name = [\(familyName)]")
let names = UIFont.fontNames(forFamilyName: familyName )
print("Font Names = [\(names)]")
}