Skip to content

Instantly share code, notes, and snippets.

View njdehoog's full-sized avatar

Niels de Hoog njdehoog

View GitHub Profile
---
title: "BCU Covid-19 statistics"
output:
pdf_document: default
html_document: default
---
## Install dependencies
```{r}
@njdehoog
njdehoog / .swiftlint.yml
Last active March 22, 2017 10:02
Custom Swiftlint rule to display developer warning (like #warning in Objective-C)
custom_rules:
developer_warning:
included: ".*.swift"
name: "Developer Warning"
regex: "//\h*?(?i)warning" # matches '// WARNING' (case insensitive)
match_kinds: comment
message: "Fix before merging"
severity: warning
### Keybase proof
I hereby claim:
* I am njdehoog on github.
* I am nielsdehoog (https://keybase.io/nielsdehoog) on keybase.
* I have a public key ASCcwc48V8dVR844Z9Mgwyx4mn2j7clhigAIYKPFWj-vLgo
To claim this, I am signing this object:
class Foo: NSObject {
private let bar = Bar()
private var kvoContext = 0
override init() {
super.init()
bar.addObserver(self, forKeyPath: "string", options: .New, context: &kvoContext)
bar.string = "world"
}
class Person {
var name = Observable("John")
}
let person = Person()
person.name.subscribe() { oldValue, newValue in
println("name changed: \(oldValue) to \(newValue)")
}
person.name.value = "Jane"
struct Observable<T> {
typealias ValueType = T
typealias SubscriptionType = Subscription<T>
var value: ValueType {
didSet {
for subscription in subscriptions {
let event = ValueChangeEvent(oldValue, value)
subscription.notify(event)
}
@njdehoog
njdehoog / KeyValueObserver.swift
Last active November 9, 2015 21:24
KVO in Swift
class KeyValueObserver: NSObject {
typealias KeyValueObservingCallback = (change: [NSObject : AnyObject]) -> Void
private let object: NSObject
private let keyPath: String
private let callback: KeyValueObservingCallback
private var kvoContext = 0
init(object: NSObject, keyPath: String, options: NSKeyValueObservingOptions, callback: KeyValueObservingCallback) {
self.object = object
MKMapRect zoomRect = MKMapRectNull;
for (id <MKAnnotation> annotation in mapView.annotations) {
MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
if (MKMapRectIsNull(zoomRect)) {
zoomRect = pointRect;
} else {
zoomRect = MKMapRectUnion(zoomRect, pointRect);
}
}
//
// NSObject+BlockObservation.h
// Version 1.0
//
// Andy Matuschak
// [email protected]
// Public domain because I love you. Let me know how you use it.
//
#import <Cocoa/Cocoa.h>