Skip to content

Instantly share code, notes, and snippets.

View dclelland's full-sized avatar

Daniel Clelland dclelland

  • Wellington, New Zealand
View GitHub Profile
@dclelland
dclelland / UIImage+Extensions.swift
Created September 17, 2017 11:48
Testing out the new UIGraphicsImageRenderer class on iOS 11
import UIKit
extension UIImage {
convenience init?(color: UIColor, size: CGSize = CGSize(width: 1.0, height: 1.0)) {
let image = UIGraphicsImageRenderer(size: size).image { context in
color.setFill()
context.fill(CGRect(origin: .zero, size: size))
}
public func zip<A>(_ arrays: [[A]]) -> ZipArrayCollection<A> {
return ZipArrayCollection(arrays)
}
public struct ZipArrayCollection<A>: Collection {
private let arrays: [[A]]
public let startIndex: Int
@dclelland
dclelland / hoonsay.sed
Last active January 18, 2016 10:23
hoonsay: convert Hoon code to a phonetic representation
## hoonsay.sed - Daniel Clelland 2016
## List of regular expressions for converting Hoon to a phonetic representation
##
## Recommended usage:
##
## sed -E -f hoonsay.sed file.hoon > file.txt # Saves contents of hoon.hoon into hoon.txt
## cat hoon.txt | say -o hoon.aiff # Renders hoon.txt using the OS X speech to text engine
##
## Sample output, the add function from chapter 2a in hoon.hoon:
##
@dclelland
dclelland / renderability.m
Last active August 29, 2015 14:04
Check whether a character is renderable on iOS
/* The character we are going to check*/
NSString *character = @"字";
/* Turn it into a character set ahead of our comparison */
NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:character];
/* Fetch the system fallback font, as [UIFont familyNames] won't include it */
UIFontDescriptor *fallbackFontDescriptor = [UIFont fontWithName:@".PhoneFallBack" size:12.0f].fontDescriptor;
/* Start with the fallback font's character set */
@dclelland
dclelland / .bash_profile
Last active December 17, 2015 05:46
.bash_profile
######################
# ENVIRONMENT CONFIG #
######################
# Custom prompt
GIT_PS1_SHOWDIRTYSTATE=1
PS1='\[\e[00;34m\]\u:\[\e[00m\] \[\e[00;33m\]\w \$\[\e[00m\]$(__git_ps1 " \[\e[00;35m\](%s)\[\e[00m\]")\[\033[00m\] '
PS2='\[\e[00;33m\]> \[\e[00m\]'