Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am kylebshr on github.
  • I am kylebshr (https://keybase.io/kylebshr) on keybase.
  • I have a public key whose fingerprint is 7173 EFFF E1BC 0A21 D6A7 805B 0FF1 3C75 3800 1164

To claim this, I am signing this object:

@kylebshr
kylebshr / volhacks-process.py
Last active September 14, 2016 15:12
Volhacks Attendee Processing
import csv
import sys
import subprocess
NON_UTK_TICKET = 'Student Registration for non-UTK Students'
UTK_TICKET = 'Student Registration for UTK Students'
MENTOR_TICKET = 'Mentor Registration'
ORGANIZER_TICKET = 'Organizer'
PERCENT_NON_UTK = 0.45
@kylebshr
kylebshr / GenericSubclass.swift
Created March 6, 2017 05:40
Weird Generic Default Argument Thing
//: Playground - noun: a place where people can play
import UIKit
class Foo<T> {
init(first: T, second: Int = 10) {}
}
class Bar: Foo<Int> {
static func makeBar() -> Bar {
extension UIView {
/// Sets `isHidden` but only if the new value is different from the existing one.
/// Fixes http://stackoverflow.com/questions/33240635/hidden-property-cannot-be-changed-within-an-animation-block
var safeIsHidden: Bool {
get {
return isHidden
}
set {
if newValue != isHidden {
isHidden = newValue
class PopoverTableViewController: UITableViewController {
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.preferredContentSize = CGSize(width: 320, height: self.tableView.contentSize.height)
}
}
@kylebshr
kylebshr / SnappingSidePanel.swift
Created January 29, 2019 19:02
Playing around with getting a scroll view to snap a side panel open or closed. `decelerationRate` is really cool!
import UIKit
class ViewController: UIViewController, UIScrollViewDelegate {
private let blueView = UIView()
private let redView = UIView()
private let scrollView = UIScrollView()
override func viewDidLoad() {
super.viewDidLoad()
@kylebshr
kylebshr / CodableProperties.swift
Last active January 31, 2019 19:06
(Weird?) behavior with Codable and properties
// Decoding a `Bar` gives you the same UUID that it was encoded with
struct Bar: Codable {
let id: UUID
init() {
self.id = UUID()
}
}
// Decoding a `Foo` gives you a new UUID
@kylebshr
kylebshr / ScrollTriggeredControl.swift
Last active December 18, 2023 02:33
When added to a scroll view, this control listens to the content offset and will trigger if it's pulled past a threshold then released. Inspired by Things 3.
import UIKit
class ScrollTriggeredControl: UIControl {
private let dragThreshold: CGFloat = 80
private var previousFraction: CGFloat = 0
private var shouldTrigger = false
private var offsetObservation: NSKeyValueObservation?
private let imageView = UIImageView()
@kylebshr
kylebshr / ScrollTriggeredControl.swift
Created February 5, 2019 18:29
When added to a scroll view, this control listens to the content offset and will trigger if it's pulled past a threshold then released. Inspired by Things 3.
import UIKit
class ScrollTriggeredControl: UIControl {
private let dragThreshold: CGFloat = 80
private var previousFraction: CGFloat = 0
private var shouldTrigger = false
private var offsetObservation: NSKeyValueObservation?
private let imageView = UIImageView()
@kylebshr
kylebshr / ViewController.swift
Created November 11, 2019 16:36
Attempts at rendering a view's layer with light/dark interface style
//
// ViewController.swift
// Rendering
//
// Created by Kyle Bashour on 11/11/19.
// Copyright © 2019 Kyle Bashour. All rights reserved.
//
import UIKit