Skip to content

Instantly share code, notes, and snippets.

@nvh
nvh / build-libevent-tvOS.sh
Created November 30, 2015 09:00
A build script for building a tvOS version for libevent
#!/bin/bash
# Builds libevent for tvOS targets:
# AppleTVSimulator-x86_64, AppleTVOS-arm64.
#
# Copyright 2015 Niels van Hoorn <[email protected]>
#
# Based on work by Mike Tigas
# Copyright 2012 Mike Tigas <[email protected]>
#
# Based on work by Felix Schulze on 16.12.10.
@nvh
nvh / optionals.swift
Last active August 29, 2015 14:19
Test for optionals
extension Dictionary {
func test() {
for (key,value) in self {
//Works
if value is Int {
println("int")
}
//Throws compiler error: cannot downcast from 'Value' to a more optional type 'Int?'
if value is Int? {
println("optional int")
@nvh
nvh / log.crash
Created March 12, 2015 07:31
TransIP iOS crashlog
{"app_name":"TransIP","app_version":"","bundleID":"nl.transip.TransIP","adam_id":325181784,"os_version":"iPhone OS 8.1.3 (12B466)","slice_uuid":"0d9c547d-3c8d-3eb0-b948-c1b5b26f47de","share_with_app_devs":true,"build_version":"2.2.1","is_first_party":false,"bug_type":"109","name":"TransIP"}
Incident Identifier: 1688A02F-A828-4E9D-80E4-D2825E4AA86E
CrashReporter Key: a80feeff082bd894f4b469f6e473ccaa67072c82
Hardware Model: iPhone7,1
Process: TransIP [7660]
Path: /private/var/mobile/Containers/Bundle/Application/685D85BB-B84F-4BD7-ACC1-EE1245308744/TransIP.app/TransIP
Identifier: nl.transip.TransIP
Version: 2.2.1
Code Type: ARM (Native)
Parent Process: launchd [1]
@nvh
nvh / DataSourceState.swift
Last active October 28, 2017 21:58
Data loading state machine enum
enum DataSourceState<D,E> {
case Empty
case Loading(Box<D?>)
case Ready(Box<D>)
case Error(Box<E>,Box<D?>)
func toLoading() -> DataSourceState {
switch self {
case .Ready(let oldData):
let value: D? = oldData.value
@nvh
nvh / Examples.swift
Last active August 29, 2015 14:07
Functional JSON Parsing in Swift
//MARK: examples
extension JSONValue {
static func url(value: JSONType) -> JSONResult<NSURL> {
return cast(value).map({NSURL(string: $0)})
}
}
extension JSONValue {
@nvh
nvh / example_root.js.coffee
Created February 17, 2012 10:26
Spine Substack
class App.Root extends Spine.Stack
controllers:
resources: App.Resources
users: App.Users
routes:
'/resources' : 'resources'
'/users' : 'users'
default: 'users'