Skip to content

Instantly share code, notes, and snippets.

@abargh
abargh / delete-git-recursively.sh
Created June 28, 2019 08:07 — forked from facelordgists/delete-git-recursively.sh
Recursively remove .git folders
( find . -type d -name ".git" && find . -name ".gitignore" && find . -name ".gitmodules" ) | xargs rm -rf
@abargh
abargh / AppDevelopment.gitignore
Last active September 26, 2018 11:11
An amalgamation of the macOS, Swift and Xcode .gitignore files from https://github.com/github/gitignore/
# An amalgamation of .gitignore files from: https://github.com/github/gitignore/
# ====
# macOS: gitignore/Global/macOS.gitignore
# ====
# General
.DS_Store
.AppleDouble
.LSOverride
@abargh
abargh / CLLocationCoordinate2D+Extensions.swift
Last active September 11, 2018 08:01
Extension adding Equatable conformance to CLLocationCoordiate2D
import CoreLocation
extension CLLocationCoordinate2D: Equatable {
public static func ==(lhs: CLLocationCoordinate2D, rhs: CLLocationCoordinate2D) -> Bool {
return lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude
}
}
@abargh
abargh / DateFormatter+Extensions.swift
Created September 11, 2018 07:58
Swift iso8601 Date formatter
import Foundation
extension DateFormatter {
static let iso8601: DateFormatter = {
let formatter = DateFormatter()
formatter.calendar = Calendar(identifier: .iso8601)
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.timeZone = TimeZone(secondsFromGMT: 0)
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
@abargh
abargh / create_gitkeep_files.sh
Last active August 24, 2018 06:54
Script to create .gitkeep files in all empty directories within an initialised Git project
#!/bin/bash
# Recursively create .gitkeep files
# Git tracks files, and not directories. This means any empty directories in your source project will be
# omitted whenever the source code is cloned via Git. Sometimes though you want to keep these directories
# (a typical example being when you want to a directory to hold log files or some other runtime artefacts).
# To preserve empty directories within a Git project, users typically create a hidden `.gitkeep` file and commit
# that file to source control for each empty directory they wish to keep. Creating these by hand can be a bit of
extension String {
func hashtags() -> [String] {
guard let regex = try? NSRegularExpression(pattern: "#[a-z0-9]+", options: .caseInsensitive) else {
return []
}
let string = self as NSString
return regex.matches(in: self, options: [], range: NSRange(location: 0, length: string.length)).map {
string.substring(with: $0.range).replacingOccurrences(of: "#", with: "").lowercased()
@abargh
abargh / test_stub.swift
Created March 2, 2018 07:56
Xcode snippet to help stub tests:
func test<#name#>() {
XCTFail("Test isn't implemented yet")
}
@abargh
abargh / todo_comments_to_xcode_warnings.sh
Last active February 23, 2018 18:11
Map TODO: / FIXME: / WARNING: / ERROR: Code Comments to Xcode Compiler Warnings / Errors
# Courtesy of https://medium.com/ios-os-x-development/highlight-warnings-in-xcode-521125121a75
TAGS="TODO:|FIXME:|WARNING:"
ERRORTAG="ERROR:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"| perl -p -e "s/($ERRORTAG)/ error: \$1/"
@abargh
abargh / MeasurePerf.swift
Created December 2, 2016 19:30 — forked from fpillet/MeasurePerf.swift
A tool to measure code performance in Swift
//
// Created by Florent Pillet on 14/11/16.
// Copyright (c) 2016 Florent Pillet. All rights reserved.
//
import Foundation
/*
* A utility struct that helps mesure the performance of sections of code. Only uses Foundation
* (we could also use QuartzCore's CACurrentMediaTime() for similar precision)