Skip to content

Instantly share code, notes, and snippets.

View cruinh's full-sized avatar

Matt Hayes cruinh

  • uShip, Inc.
  • Austin, TX
View GitHub Profile
@cruinh
cruinh / vidsnaps.rb
Last active December 10, 2015 21:09
ruby script for generating contact sheet images for video files.
# ruby script for generating contact sheet images for video files.
# can be configured via an ini file which is expected to be in the current working directory.
# Requirements:
# - VLC (http://videolan.org) must be installed and available in the system PATH.
# - gem iniparse.
#
# vidsnaps will open the given video in VLC and save a screenshot at predetermined time intervals.
# By default it will save 20 images 500 seconds apart starting at the very beginning of the video.
# If these settings take it beyond the end of the video, a number of black screens will be generated, which can be ignored/deleted
# images are saved as png files using the format "##h##m##s.png".
@cruinh
cruinh / AppleDevPortalStatus.sh
Last active December 20, 2015 05:09
lists just the apple developer portal services that are online right now. Meant to be used with Geektool (http://projects.tynsoe.org/en/geektool/)
echo "Apple Developer Services Online\n"; curl -s https://developer.apple.com/support/system-status/ | grep "online-icon.*href" | grep -o '<a href[[:print:]]*</a>' | grep -o '>.*<' | sed -e 's/.$//' -e 's/^.//'
@cruinh
cruinh / gist:6186568
Created August 8, 2013 17:09
example of using apple's method_exchangeImplementations from objective-c runtime
- (void)atest1
{
NSLog(@"this is test 1");
}
- (void)atest2
{
NSLog(@"this is test 2");
[self atest2];
}
@cruinh
cruinh / swift.sublime-build
Created December 8, 2015 17:01
Sublime Text 3 Build System for Swift 2.2 on Linux
{
"name" : "swift-oss",
"selector" : "source.swift",
"cmd": ["swift","build"],
"working_dir": "$project_path"
}
@cruinh
cruinh / GlowFilter.swift
Last active July 21, 2022 01:08
GlowFilter for CoreImage in Swift
//
// GlowFilter.swift
// based on ENHGlowFilter from http://stackoverflow.com/a/21586439/114409
//
// Created by Matthew Hayes on 12/27/15.
//
import Foundation
import UIKit
import CoreImage
/**
Compatible with the iOS 10 Beta 1 Swift Playgrounds app
The code below talks to NASA's "Astronomy Picture of the Day" API endpoint to download the latest picture. After running the code, the picture is viewable by tapping the image literal that appears in the right-hand margin as indicated by a comment.
note: Must replace "YOUR API KEY" on the first line of code, with a your personally-generated NASA api key. See the following link to get your API key: https://api.nasa.gov/index.html#apply-for-an-api-key
*/
import Foundation
import UIKit
Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x187e1259c __exceptionPreprocess
1 libobjc.A.dylib 0x198a6c0e4 objc_exception_throw
2 CoreFoundation 0x187e124dc -[NSException initWithCoder:]
3 UIKit 0x18c5c7d50 -[UIView(Internal) _addSubview:positioned:relativeTo:]
4 UIKit 0x18c7ab4b0 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke
5 UIKit 0x18c5cece8 +[UIView(Animation) performWithoutAnimation:]
6 UIKit 0x18c7aad3c -[_UINavigationParallaxTransition animateTransition:]
7 UIKit 0x18c764704 -[UINavigationController _startCustomTransition:]
8 UIKit 0x18c675630 -[UINavigationController _startDeferredTransitionIfNeeded:]
{
"hello":"world"
}
//Add this to a view controller
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 75, height: 20))
var bbItem : UIBarButtonItem!
extension SettingsViewController : UIPopoverPresentationControllerDelegate {
fileprivate func _setupPopoverTest() {
bbItem = UIBarButtonItem(customView: button)
button.setTitle("Popover", for: .normal)
@cruinh
cruinh / CodableDecoder.swift
Last active October 12, 2017 16:19
Generic Codable Parsing
func parseResponse(data: Data?, response:URLResponse?, completion:(_ decodedResponse: Codable)->() ) {
//Handle the first matching response
if let decodedResponse = Decoder<User>.decode(data, response) { completion(decodedResponse) ; return }
if let decodedResponse = Decoder<Place>.decode(data, response) { completion(decodedResponse) ; return }
if let decodedResponse = Decoder<Thing>.decode(data, response) { completion(decodedResponse) ; return }
}
struct User: Codable, EndpointData {
static var endpoint : String { return "/user" }