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 / .zshrc-brewselect
Created April 20, 2023 18:50
.zshrc script for auto-selecting homebrew path based on system architecture
# The i386 version of homebrew installs to "/usr/local/bin"
# The arm64 version of homebew installs to "/opt/homebrew"
# By default, "/usr/local/bin" is the very first entry in PATH on macs (see "man path_helper" and "/etc/paths")
# Therefore, when not using Rosetta 2, prepend "/opt/homebrew" to PATH to ensure the arm64 version of homebrew is used
if [ "arm64" = `arch` ]; then
export PATH="/opt/homebrew/bin:$PATH"
fi
@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" }
//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)
{
"hello":"world"
}
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:]
/**
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
@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
@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 / 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 / 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/^.//'