Skip to content

Instantly share code, notes, and snippets.

Avatar

Caleb Davenport calebd

View GitHub Profile
@calebd
calebd / ActionSheetPresentationController.swift
Created Jul 18, 2017
Action Sheet Presentation Controller
View ActionSheetPresentationController.swift
// Created by Caleb Davenport on 7/14/17.
import UIKit
final class ActionSheetPresentationController: UIPresentationController {
// MARK: - Properties
private var dimmingView: UIView!
@calebd
calebd / AsynchronousOperation.swift
Last active Aug 23, 2021
Concurrent NSOperation in Swift
View AsynchronousOperation.swift
import Foundation
/// An abstract class that makes building simple asynchronous operations easy.
/// Subclasses must implement `execute()` to perform any work and call
/// `finish()` when they are done. All `NSOperation` work will be handled
/// automatically.
open class AsynchronousOperation: Operation {
// MARK: - Properties
@calebd
calebd / README.md
Created Jun 7, 2012
Simple UITableView implementation using only HTML and CSS
View ArrayHelpers.swift
extension Array {
func first() -> Element? {
if isEmpty {
return nil
}
return self[0]
}
func last() -> Element? {
@calebd
calebd / Readme.markdown
Last active Nov 14, 2020
Run Loop Source
View Readme.markdown

CFRunLoopSource is cool. It lets you build behavior similar to the mechanisms that drive setNeedsLayout and setNeedsDisplay in UIKit.

I found myself in need of something like this a couple of times. It's great to know that no matter how many times I say I need to update something, I will get a single callback at the end of the run loop that gives me a chance to perform my work.

Here is a little Swift wrapper that makes the API easier to deal with.

View weird.markdown

The URL http://pancake.apple.com/bags/hls?version=4.12 contains a plist, and inside that is coded another plist. Together, they make references to Apple IP addresses, ports, web services, Netflix, and Apple TV. What is this?

Edit: It looks like AVPlayer encounters an eror in the simulator that points to this URL as seen here: http://stackoverflow.com/questions/22569013/rtcreporting-pancake-apple-com-errors. Thanks to @mwhuss for sharing this with me.

Outer property list:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
View Question.swift
import UIKit
class MyView: UIView {
// I could define this as UIPanGestureRecognizer! but that feels like the wrong solution
let panGestureRecognizer: UIPanGestureRecognizer
init(frame: CGRect) {
// Can't do this here because self is not initialized yet
View Brewfile
update
upgrade
install 'rbenv'
install 'ruby-build'
install 'redis'
install 'postgres'
install 'heroku'
install 'zsh-completions'
install 'pianobar'
@calebd
calebd / review-times.coffee
Created Jan 9, 2014
HuBot script for checking the latest average iOS and Mac App Store review times.
View review-times.coffee
# Description:
# Fetch iOS and Mac App Store average review times.
#
# Commands:
# bot review times
# bot review time
module.exports = (robot) ->
robot.respond /review times?/i, (msg) ->
msg.http("http://reviewtimes.shinydevelopment.com/sb_trend30.json")
@calebd
calebd / Readme.markdown
Last active Dec 20, 2015
Rdio table view scrolling
View Readme.markdown

Step 1: Configure the table view.

  • Set a view as the table footer
  • Set the background color to clear.

Step 2: Set the default table view values when your view loads. The values and variables seen here are explained below.

- (void)viewDidLoad {
    [super viewDidLoad];