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 / 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 / .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 / 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) {
//: Playground - noun: a place where people can play
import UIKit
protocol Async: class, Task {
}
extension Waterfall: Async {
@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
func makeTestViewControllerTransitionCoordinator() -> UIViewControllerTransitionCoordinator {
class ViewControllerTransitionCoordinator: NSObject, UIViewControllerTransitionCoordinatorContext, UIViewControllerTransitionCoordinator {
public var isAnimated: Bool { return false }
public var presentationStyle: UIModalPresentationStyle { return .formSheet }
public var initiallyInteractive: Bool { return false }
@ollieatkinson
ollieatkinson / main.rs
Last active December 21, 2017 15:13
2017 Sky Christmas Competition - find `n` which produces the sum of divisors over `x` [Rust] - Sum of Divisors, Prime Factorisation, Highly Abundant Numbers
use std::time::Instant;
fn main() {
let start = Instant::now();
let input = env!("PRESENTS");
let (index, _sum) = find_sum_of_divisors_over(input.parse::<u32>().unwrap() / 10);
println!("{}", index);
@ollieatkinson
ollieatkinson / Waterfall.swift
Created March 22, 2017 22:37
WIP: Waterfall 'esc' Promises
//: Playground - noun: a place where people can play
import Foundation
import PlaygroundSupport
class Waterfall<T> {
typealias Execute = (@escaping (Result<T>) -> Void) throws -> Void
typealias Callback = (Result<T>) -> Void