Skip to content

Instantly share code, notes, and snippets.

View blakemerryman's full-sized avatar

Blake Merryman blakemerryman

View GitHub Profile
@blakemerryman
blakemerryman / String.length
Created October 12, 2014 19:23
Adds .length to Swift Strings
public extension String {
var length : Int { return countElements(self) }
}
@blakemerryman
blakemerryman / NSMutableData.insertBytes(bytes: withLength: atIndex: )
Last active August 29, 2015 14:07
Adds .insertBytes(...) to NSMutableData in Swift
public extension NSMutableData {
func insertBytes(bytes: UnsafePointer<Void>, withLength length: Int, atIndex index: Int) -> NSMutableData {
if index > self.length {
return NSMutableData()
}
var data = self // Holds self for modification
@blakemerryman
blakemerryman / NSData.packetCount
Last active August 29, 2015 14:07
Adds property to NSData (in Swift) that calculates number of Core Bluetooth packets data will be split up into
public extension NSData {
// Calculates the number of packets it should be broken down into based on Core Bluetooth spec of 20 Bytes/Packet
var packetCount : Int { return Int( ceil( Double(self.length) / 20.0 ) ) }
}
@blakemerryman
blakemerryman / DailyProgrammerChallenge193
Created December 21, 2014 06:04
My Swift solution to the /r/DailyProgrammer Challenge # 193
#!/usr/bin/env xcrun swift
/*
/r/DailyProgrammer Challenge # 193
Reddit" : "http://www.reddit.com/r/dailyprogrammer/
Blake Merryman
Github" : "https://github.com/blakemerryman
Notes:
@blakemerryman
blakemerryman / gist:a45416b6d751fa5b9f68
Created December 22, 2014 19:40
DailyProgrammer-Challenge193_ContainerDimensions
#!/usr/bin/env xcrun swift
/*
/r/DailyProgrammer Challenge # 193
Reddit - http://www.reddit.com/r/dailyprogrammer/
Blake Merryman
Github - https://github.com/blakemerryman
Challenge Description:
An international shipping company is trying to figure out how to manufacture various types of containers. Given a volume they want to figure out the dimensions of various shapes that would all hold the same volume.
Input:
@blakemerryman
blakemerryman / StringLengthTests
Created February 12, 2015 15:57
A test to determine performance difference between two String.length implementation
// A test to determine performance difference between two String.length implementations in Swift.
import Foundation
// String with 1,000 characters
var testString = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
@blakemerryman
blakemerryman / Glob.swift
Last active January 31, 2019 22:20 — forked from listrophy/Glob.swift
Wrap glob(3) in Swift
//
// Glob.swift
//
// Created by Brad Grzesiak on 6/25/15.
// Copyright © 2015 Bendyworks Inc.
// Released under the Apache v2 License.
//
import Darwin
@blakemerryman
blakemerryman / SwiftInST3.md
Last active June 18, 2018 20:41 — forked from Star-Lord-XIII/SwiftInST3.md
Running Swift scripts from Sublime Text 3 in MacOSX10.11

Adding Swift Build System

  • Open Sublime Text 3
  • Go To Preferences > Browse Packages...
  • Add a file named Swift.sublime-build inside Packages directory.
  • Copy the following script in Swift.sublime-build file.
{
 "shell_cmd": "xcrun swift \"$file\"",
git config --global alias.trim '!f() { git branch | grep -v "\*" | xargs -n 1 git branch -D; }; f'
@blakemerryman
blakemerryman / DateFormatter+iso8601Full.swift
Created April 27, 2018 21:26
A fully ISO 8601 compliant date formatter
extension DateFormatter {
static let iso8601Full: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
formatter.calendar = Calendar(identifier: .iso8601)
formatter.timeZone = TimeZone(secondsFromGMT: 0)
formatter.locale = Locale(identifier: "en_US_POSIX")
return formatter
}()