Skip to content

Instantly share code, notes, and snippets.

View neilco's full-sized avatar
🤠

Neil Cowburn neilco

🤠
View GitHub Profile
@neilco
neilco / NCAdHocUtils.h
Created June 13, 2014 10:13
HOW-TO: Detect ad-hoc release builds at runtime
#import <Foundation/Foundation.h>
FOUNDATION_EXPORT BOOL NCIsAdHocReleaseBuild();
import Foundation
public let GCD_MAIN_QUEUE = dispatch_get_main_queue()
public let GCD_BACKGROUND_QUEUE = dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)
public let GCD_LOW_PRIORITY_QUEUE = dispatch_get_global_queue(QOS_CLASS_UTILITY, 0)
public let GCD_DEFAULT_QUEUE = dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)
public let GCD_HIGH_PRIORITY_QUEUE = dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0)
public func after(delay: NSTimeInterval, block: () -> ())
{
@neilco
neilco / gist:7579740
Created November 21, 2013 10:59
Universal library build script
LIB_TARGET_NAME="${PRODUCT_NAME}"
if [ "${ACTION}" = "clean" ]
then
echo "Cleaning Libraries..."
cd "${PROJECT_DIR}"
xcodebuild -target "$LIB_TARGET_NAME" -configuration ${CONFIGURATION} -sdk iphoneos clean
xcodebuild -target "$LIB_TARGET_NAME" -configuration ${CONFIGURATION} -sdk iphonesimulator clean
fi
@neilco
neilco / address.go
Created November 21, 2013 14:52
Go function to return the first IPv4 address of the named interface
package net
import (
"net"
"os"
)
func InterfaceIPv4Address(name string) net.IP {
intf, err := net.InterfaceByName(name)
if err != nil {
@neilco
neilco / log.go
Last active February 5, 2016 23:23 — forked from cespare/log.go
Golang apache logging
package main
import (
"fmt"
"io"
"net/http"
"strings"
"time"
)
@neilco
neilco / Example Output.png
Last active March 17, 2017 01:52
json_curl: Pretty-print colourised JSON output from cURL
Example Output.png
@neilco
neilco / 1.Promise.swift
Last active May 18, 2018 09:10
Coffee Break Hack - Ultra-simple Promises
public final class Promise<T> {
private var resolveClosure: (T -> Void)?
private var rejectClosure: (AnyObject? -> Void)?
public init() { }
public func then(resolve: (T -> Void), _ reject: (AnyObject? -> Void)? = nil) -> Promise<T> {
self.rejectClosure = reject
self.resolveClosure = resolve
@neilco
neilco / RSASHA1.swift
Created April 27, 2015 09:07
RSA-SHA1 signing with a PKCS#12 private key
//
// RSASHA1.swift
//
// Copyright (c) 2015 Neil Cowburn. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@neilco
neilco / UIColor+Brightness.swift
Created October 29, 2015 23:20
Adjust brightness of a UIColor instance
import UIKit
public extension UIColor {
public func colorWithBrightness(brightness: CGFloat) -> UIColor {
var H: CGFloat = 0, S: CGFloat = 0, B: CGFloat = 0, A: CGFloat = 0
if getHue(&H, saturation: &S, brightness: &B, alpha: &A) {
B += (brightness - 1.0)
B = max(min(B, 1.0), 0.0)