Skip to content

Instantly share code, notes, and snippets.

Adam Preble preble

Block or report user

Report or block preble

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@preble
preble / autostart
Created Aug 15, 2018
Autostart JMRI PanelPro on a Raspberry Pi -- without launching two instances.
View autostart
# Full path: /home/pi/.config/lxsession/LXDE-pi/autostart
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xset s off
@xset -dpms
@xset s noblank
@/home/pi/jmri-runner.sh
View AVAssetImageGenerator-Error-from-HLS.md

Was getting the following errors when calling AVAssetImageGenerator generateCGImagesAsynchronously. The stream in question was an HLS stream. When I switched to using the AVURLAsset of an MP4, the error disappeared.

With Apple-supplied HLS stream:

Error Domain=AVFoundationErrorDomain Code=-11819 "Cannot Complete Action" UserInfo={NSLocalizedRecoverySuggestion=Try again later., NSLocalizedDescription=Cannot Complete Action, NSUnderlyingError=0x1c0057850 {Error Domain=NSOSStatusErrorDomain Code=-12178 "(null)"}}

With another HLS stream generated by a video hosting provider:

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12436), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x1c4a57e20 {Error Domain=NSOSStatusErrorDomain Code=-12436 "(null)"}}

View ProtocolExtensions.swift
protocol Protocol {
func methodInProtocol() -> String
}
extension Protocol {
func methodInProtocol() -> String {
return "Protocol"
}
func methodOnExtension() -> String {
@preble
preble / Mutated.swift
Created Apr 11, 2016
Need to mutate a value type but don't want to create a var in your scope?
View Mutated.swift
protocol Mutatable {}
extension Mutatable {
func mutated(f: (inout Self) -> Void) -> Self {
var copy = self
f(&copy)
return copy
}
}
@preble
preble / NSTextStorageSubclass.swift
Created Feb 9, 2016
Base subclass of NSTextStorage in Swift
View NSTextStorageSubclass.swift
import Cocoa
@objc
class SomeTextStorage: NSTextStorage {
private var storage: NSMutableAttributedString
override init() {
storage = NSMutableAttributedString(string: "", attributes: nil)
super.init()
@preble
preble / Completion.swift
Created Jan 20, 2016
A cancellable completion for Swift.
View Completion.swift
final class Completion<R> {
private let closure: (R) -> Void
private var cancelled = false
/// `closure` is called upon completion, if not cancelled.
init(closure: (R) -> Void) {
self.closure = closure
}
@preble
preble / PivotalTrackerMarkdownLink.js
Created Jan 20, 2016
Want an OS X Service to convert a Pivotal Tracker story id or URL into a Markdown link? Create a new Service in Automator and enter the following in a Run JavaScript step. Save, give it a name, and you'll be able to select it from the Services menu.
View PivotalTrackerMarkdownLink.js
View KeyValueObserver.swift
import Foundation
/// Helper object for more Swift-like KVO. To create, call NSObject.addObserverForKeyPath(_:handler:).
class KeyValueObserver: NSObject {
private weak var observing: NSObject?
private var keyPath: String
private var handler: () -> Void
private init(observing: NSObject, keyPath: String, handler: () -> Void) {
@preble
preble / ErrorType+LocalizedDescription.swift
Created Dec 16, 2015
Adds a sort of localizedDescription to ErrorType.
View ErrorType+LocalizedDescription.swift
extension ErrorType {
var myLocalizedDescription: String {
if self.dynamicType == NSError.self {
return ((self as Any) as! NSError).localizedDescription
}
else {
return "\(self)"
}
}
@preble
preble / DispatchSyncThrows.swift
Created Jun 27, 2015
An overload of dispatch_sync that throws any error thrown by the closure. (Swift 2)
View DispatchSyncThrows.swift
import Foundation
/// Call a throwing block synchronously.
func dispatch_sync(queue: dispatch_queue_t, block: () throws -> ()) throws {
var error: ErrorType?
dispatch_sync(queue) {
do {
try block()
} catch let caughtError {
error = caughtError
You can’t perform that action at this time.