Skip to content

Instantly share code, notes, and snippets.

Rob Napier rnapier

Block or report user

Report or block rnapier

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
rnapier / json.swift
Last active Nov 8, 2019
Generic JSON Decodable
View json.swift
import Foundation
enum JSON: Codable, CustomStringConvertible {
var description: String {
switch self {
case .string(let string): return "\"\(string)\""
case .number(let double):
if let int = Int(exactly: double) {
return "\(int)"
jessesquires / generics_playground.swift
Last active Jun 27, 2018
Swift optional generic parameters?
View generics_playground.swift
protocol FactoryAType {
typealias Product
protocol FactoryBType {
typealias Product
andymatuschak / gist:2b311461caf740f5726f
Created Dec 28, 2014
A pragmatic and intentionally non-abstract solution to JSON decoding / initialization that doesn't require learning about five new operators.
View gist:2b311461caf740f5726f
struct User {
let id: Int
let name: String
let email: String?
extension User: JSONDecodable {
static func create(id: Int, name: String, email: String?) -> User {
return User(id: id, name: name, email: email)
mattt / NSDecimalNumber.swift
Last active Jul 16, 2019
NSDecimalNumber Additions for Swift
View NSDecimalNumber.swift
import Foundation
// MARK: - Comparable
extension NSDecimalNumber: Comparable {}
public func ==(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool {
return == .OrderedSame
rnapier / result.swift
Last active Aug 29, 2015
The ever-important Result type (without methods)
View result.swift
enum Result<A> {
case Success(Box<A>)
case Failure(NSError)
// Due to current swift limitations, we have to include this Box in Result.
// Swift cannot handle an enum with multiple associated data (A, NSError) where one is of unknown size (A)
final class Box<T> {
let unbox: T
init(_ value: T) { self.unbox = value }
ShamylZakariya / debounce.swift
Created Sep 4, 2014
Simple Swift Debouncer
View debounce.swift
func debounce( delay:NSTimeInterval, #queue:dispatch_queue_t, action: (()->()) ) -> ()->() {
var lastFireTime:dispatch_time_t = 0
let dispatchDelay = Int64(delay * Double(NSEC_PER_SEC))
return {
lastFireTime = dispatch_time(DISPATCH_TIME_NOW,0)
rnapier / Curryinate.swift
Last active Aug 29, 2015
Curry and flip with ~~ postfixing. I wonder if this is a good idea…
View Curryinate.swift
// Based on
// Warning, this is insanely slow to compile in Beta6 (can take several minutes)
// Remove some of the |> lines to speed things up
// For more on |>, see
infix operator |> { precedence 50 associativity left }
// "x |> f" is equivalent to "f(x)"
public func |> <T,U>(lhs: T, rhs: T -> U) -> U {
return rhs(lhs)
h12w /
Last active Jul 21, 2019 does automatic checking on a Go package and its sub-packages.
# The script does automatic checking on a Go package and its sub-packages, including:
# 1. gofmt (
# 2. goimports (
# 3. golint (
# 4. go vet (
# 5. race detector (
# 6. test coverage (
set -e
View gist:9176925
static OSStatus
SSLVerifySignedServerKeyExchange(SSLContext *ctx, bool isRsa, SSLBuffer signedParams,
uint8_t *signature, UInt16 signatureLen)
OSStatus err;
SSLBuffer hashOut, hashCtx, clientRandom, serverRandom;
SSLBuffer signedHashes;
uint8_t *dataToSign;
size_t dataToSignLen;
You can’t perform that action at this time.