Skip to content

Instantly share code, notes, and snippets.

vjosullivan vjosullivan

Block or report user

Report or block vjosullivan

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
vjosullivan / CoalescingOperator.swift
Created Jan 2, 2017
??? - A custom optional -> string coalescing operator
View CoalescingOperator.swift
// Source:
infix operator ???: NilCoalescingPrecedence
/// Provides a String default value for an Optional of any type.
/// Overcomes the problem with the `??` operator whare the default value must be
/// of the same type as the left hand side.
public func ???<T>(optional: T?, defaultValue: @autoclosure () -> String) -> String {
switch optional {
case let value?: return String(describing: value)
vjosullivan / testData.swift
Created Aug 26, 2016
Swift 3. Creates an array of n integers with random values in the range 0..<max. As written below, the code will generates 10 integers in the range 0..<100.
View testData.swift
let testData = { (n: Int, max: UInt32) -> [Int] in
var array = [Int]()
for i in 0..<n {
return array
}(10, 100)
vjosullivan / SortingTemplate.swift
Last active Aug 26, 2016
A Swift 3.0 template for comparing sorting algorithms.
View SortingTemplate.swift
import Foundation
/// A template for comparing different sorting algorithms.
/// To use:
/// - Sublass `SortTemplate`.
/// - Override the function `algorithm to sort the internal var `array`.
/// - Initialise the new class with data to be sorted.
/// - Call the `sort()` function.
class SortTemplate<C: Comparable> {
vjosullivan / deviceDetails.swift
Created Apr 16, 2015
Some device details (requires iOS 8.0.0 or later).
View deviceDetails.swift
import Foundation
// Is the device's iOS version equal or later to the targeted version?
let targetOSVersion = NSOperatingSystemVersion(majorVersion:8, minorVersion:0, patchVersion:0)
if NSProcessInfo().isOperatingSystemAtLeastVersion(targetOSVersion) {
println("Running iOS version 8.0.0 or later.")
} else {
println("Running iOS version 7 or earlier.")
vjosullivan / PreferredFonts.swift
Last active Aug 29, 2015
Something learnt from reading another person's code...
View PreferredFonts.swift
titleLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline)
bodyLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody)
footnoteLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleFootnote)
View SwiftExample.swift
// TableViewController.swift
// ColouredRose2
// Created by Vincent O'Sullivan on 08/04/2015.
// Copyright (c) 2015 Vincent O'Sullivan. All rights reserved.
import UIKit
View NewCodeSample
func getDatedString(basicDictionary: NSMutableArray, selectedIndex: Int) -> String {
return basicDictionary.objectAtIndex(selectedIndex)
View getDateString Example
- (NSString *) getDatedString:(NSMutableArray *)basicDictionary forindex:(int)selectedIndex {
return ([basicDictionary objectAtIndex:selectedIndex]);
vjosullivan / 0_reuse_code.js
Last active Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
You can’t perform that action at this time.