Skip to content

Instantly share code, notes, and snippets.

View hannesoid's full-sized avatar

Hannes Oud hannesoid

View GitHub Profile
@hannesoid
hannesoid / Swift4JSONValue.swift
Created June 26, 2017 13:47
Decodes an unknown JSON structure using Swift 4 Decoding
import XCTest
// Requires a recent Swift 4 snapshot toolchain (Xcode 9 beta 2 not new enough)
public indirect enum JSONValue: Decodable {
case double(Double)
case string(String)
case bool(Bool)
case dictionary([String: JSONValue])
case array([JSONValue])
@hannesoid
hannesoid / AutoEquatable.stencil
Created June 1, 2017 12:06
AutoEquatable.stencil for Sourcery with softness for Doubles and Dates
// Based on https://github.com/krzysztofzablocki/Sourcery/blob/master/Templates/Templates/AutoEquatable.stencil
// 1. Uses =~= for Dates and Double comparison by default
// 2. Supports custom operators specified by annotation above property like // sourcery equalityOperator="=~="
// Currently not supporting enum associated types
// swiftlint:disable file_length
fileprivate func compareOptionals<T>(lhs: T?, rhs: T?, compare: (_ lhs: T, _ rhs: T) -> Bool) -> Bool {
switch (lhs, rhs) {
case let (lValue?, rValue?):
return compare(lValue, rValue)
@hannesoid
hannesoid / xcode_show_build_duration.sh
Created December 7, 2016 10:52
Make Xcode show total build duration
defaults write com.apple.dt.Xcode ShowBuildOperationDuration YES
//
// EurekaWhitespaceWorkaround.swift
//
// Created by Hannes Oud on 23.11.16.
// Use this however you want.
import Eureka
/// Configures right-aligned text rows to make spaces visible on edit,
/// by temporary replacing them with non-breaking spaces. Call `EurekaWhitespaceWorkaround.configureTextCells()`.
/// - Note: this will set the `TextRow.defaultCellSetup`
@hannesoid
hannesoid / swift-compile-times.md
Created November 16, 2016 13:39
Measure Swift Compile Times

List swift functions by slowest compile time (minimum 2-digit milliseconds):

$ xcodebuild -workspace MyProject.xcworkspace -scheme "MyProject" clean build OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-function-bodies" | grep '^[0-9][0-9][0-9]*\.[0-9]*ms' | sort -n

If you want to see the compile times in Xcode build report add to build settings "other swift flags": -Xfrontend -debug-time-function-bodies

Sources

@hannesoid
hannesoid / OpenTokObjC+Silencer.m
Created August 17, 2015 13:51
Resolve crash on jenkins due to combination of KIWI class loading and OpenTok 2.4.1 Audio initializiation
//
// OpenTokObjC+Silencer.m
//
// Created by Hannes Oud on 17.08.15.
//
#if TEST
extern void otk_console_set_logger(void(*)(const char*));
@hannesoid
hannesoid / demo.html
Created February 12, 2013 22:35
This is a simple example of an HTML with a javascript timer, which continues to be executed within a UIWebView after the container-app goes to background.
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
var counter = 0;
function increaseCounter() {
counter++;
document.getElementById("count").innerHTML = "" + counter;
}