Skip to content

Instantly share code, notes, and snippets.

View grgcombs's full-sized avatar

Greg Combs grgcombs

View GitHub Profile
@grgcombs
grgcombs / consumer_of_libextobjc.m
Last active May 31, 2016 21:06
Obj-C Preprocessor Collision Aversion
/**
* Taken from @jspahrsummers:
*
* To avoid preprocessor definition collisions when working with third-party frameworks
* try this...
*/
#define strongify myPrefix_strongify
#define weakify myPrefix_weakify
#define onExit myPrefix_onExit
@grgcombs
grgcombs / angleGradientImage.swift
Created November 30, 2015 18:45
angleGradientImage.swift
//: angleGradientImage - Ported to Swift from http://stackoverflow.com/a/33991838/136582
import UIKit
import CoreImage
public func angleGradientImage(size: CGSize, radius: Float?, scale: CGFloat?, colors: (start:UIColor, end:UIColor)?) -> UIImage? {
let gradientRadius = (radius != nil) ? radius! : Float(min(size.width,size.height) - 2)
let gradientScale = (scale != nil) ? scale! : UIScreen.mainScreen().scale
let startColor : CIColor
let endColor : CIColor
@jarsen
jarsen / JaSON.swift
Last active November 10, 2016 00:14
JSON Value Extraction in Swift. Blog post here http://jasonlarsen.me/2015/10/16/no-magic-json-pt3.html
import Foundation
//
// MARK: - JSONError Type
//
public enum JSONError: ErrorType, CustomStringConvertible {
case KeyNotFound(key: JSONKeyType)
case NullValue(key: JSONKeyType)
case TypeMismatch(expected: Any, actual: Any)
struct Regex {
let pattern: String
let options: NSRegularExpressionOptions!
private var matcher: NSRegularExpression {
return NSRegularExpression(pattern: self.pattern, options: self.options, error: nil)
}
init(pattern: String, options: NSRegularExpressionOptions = nil) {
self.pattern = pattern
protocol Calendar {
typealias Unit: BidirectionalIndexType
typealias Era: Unit
typealias Year: Unit
typealias Month: Unit
typealias Week: Unit
typealias Day: Unit
typealias Weekday: Unit
typealias Hour: Unit
struct URL {
var scheme: String?
var user: String?
var password: String?
var host: String?
var port: Int?
var path: String?
var query: String?
var fragment: String?
@mattt
mattt / NSDecimalNumber.swift
Last active April 1, 2023 00:06
NSDecimalNumber Additions for Swift
import Foundation
// MARK: - Comparable
extension NSDecimalNumber: Comparable {}
public func ==(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool {
return lhs.compare(rhs) == .OrderedSame
}
@jarsen
jarsen / regression.swift
Created October 10, 2014 20:24
Univariate Linear Regression
import Cocoa
class CSVDoubleSequence: SequenceType {
typealias GeneratorType = IndexingGenerator<Array<Double>>
let path: String
let values: [Double]
init(path: String) {
self.path = path
@xfreebird
xfreebird / customsshd
Last active May 31, 2022 07:32
A script which can be used to start a second SSHD daemon on OS X. This is an workaround for running tests using xcodebuild through ssh with Jenkins .
#!/bin/bash
INSTALL_PATH="$HOME/scripts"
SCRIPT_PATH="$INSTALL_PATH/customsshd"
LAUNCHCTL_PATH="$HOME/Library/LaunchAgents/com.my.customsshd.plist"
SSH_KEYS_INSTALL_PATH=$HOME/customkeys
SSH_HOST_KEY=$SSH_KEYS_INSTALL_PATH/ssh_host_key
SSH_HOST_RSA_KEY=$SSH_KEYS_INSTALL_PATH/ssh_host_rsa_key
SSH_HOST_DSA_KEY=$SSH_KEYS_INSTALL_PATH/ssh_host_dsa_key
SSHD_PORT=50111
@boredzo
boredzo / README.md
Last active August 29, 2015 14:03
indexheaders/findheader

indexheaders/findheader

Ever wish you could do something like view $(findheader signal.h)—and have it be fast? Now you can.

(open -h is one alternative, but that opens it in Xcode, rather than a terminal-based or other editor.)

Basically, it's like “Open Quickly” for the command line.

Installation