Skip to content

Instantly share code, notes, and snippets.

View ollieatkinson's full-sized avatar

Oliver Atkinson ollieatkinson

View GitHub Profile
import UIKit
extension UIColor {
static func colorWithHex(hex RGBAHex: String) -> UIColor? {
if !RGBAHex.hasPrefix("#") {
return nil
}
@ollieatkinson
ollieatkinson / .bashrc
Last active January 22, 2016 22:46
PS1 - git dirty branch using a ruby script
export PS1="\w \[\e[0;33m\]\`ruby ~/.theme/git.rb\` \[\e[0m\]\\$ "
@ollieatkinson
ollieatkinson / .bashrc
Last active December 12, 2016 11:35
PS1 for git repositories
function branch_status {
branch=`branch`
[ -n "$branch" ] && echo "[$branch`dirty_status`] " || echo
}
function branch {
git branch | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
function dirty_status {
@ollieatkinson
ollieatkinson / JSONDecoding.swift
Last active September 17, 2022 12:13
JSONDecoding
//: Playground - noun: a place where people can play
import Foundation
/// A type describing a JSON object.
public typealias JSONObject = Any
/// Provides information about an error which occured when trying to decode the JSON object.
public enum DecodingError: Error {
@ollieatkinson
ollieatkinson / functions.swift
Created November 26, 2016 15:08
Swift - Functions Playground
//: Playground - noun: a place where people can play
import UIKit
func helloWorld() -> Void {
print("hello, world!")
}
helloWorld()
@ollieatkinson
ollieatkinson / Example.swift
Created December 12, 2016 11:28
Swift extension with a default parameter - 🐛 bug
protocol Foo {
func foo(_ int: Int)
}
extension Foo {
func foo(_ int: Int = 1) { print("foo") }
func bar() { print("bar") }
}
func testFoo(foo: Foo) {
@ollieatkinson
ollieatkinson / HTTPStatusCode.swift
Last active April 15, 2024 18:34
HTTP status codes as a Swift enum.
/// This is a list of Hypertext Transfer Protocol (HTTP) response status codes.
/// It includes codes from IETF internet standards, other IETF RFCs, other specifications, and some additional commonly used codes.
/// The first digit of the status code specifies one of five classes of response; an HTTP client must recognise these five classes at a minimum.
enum HTTPStatusCode: Int, Error {
/// The response class representation of status codes, these get grouped by their first digit.
enum ResponseType {
/// - informational: This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line.
case informational
//: Playground - noun: a place where people can play
import UIKit
protocol Async: class, Task {
}
extension Waterfall: Async {
@ollieatkinson
ollieatkinson / URLRequest+cURLCommand.swift
Last active September 17, 2020 14:53
Generate cURL command's from URLRequest's
//: Playground - noun: a place where people can play
import Foundation
extension URLRequest {
/// The cURL representation of the URLRequest, useful for debugging and executing requests outside of the app.
public var cURLCommand: String {
var command = "curl"
@ollieatkinson
ollieatkinson / String+HTML.swift
Last active March 3, 2017 04:39
Unescape HTML entities in Swift 3 == £ -> £
extension String {
func unescapeHTMLEntities() throws -> String {
guard contains("&#") else {
return self
}
guard let data = data(using: .utf8) else {
return self