Skip to content

Instantly share code, notes, and snippets.

@bgerstle
bgerstle / exhaustive_enum.rb
Last active April 25, 2019 17:03
Proof of concept for an exhaustive enum micro-lib in Ruby
module ExhaustiveEnum
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def switch(value, &block)
matcher = ExhaustiveMatcher.new(self)
matcher.match(value, &block)
end
Gen(unGen: { r, n in
let splitGen: () -> StdGen = {
var g: StdGen = r.split.0
return {
g = g.split.0
return g
}
}()
let Foo = Foo()
@bgerstle
bgerstle / not-so-horrible.js
Created April 2, 2016 18:19
Somewhat functional & elegant JS
// a bunch of requires & tiny helper fns...
function directoriesAtPath(path) {
return fs.readdir(dir)
.then(fp.map(appendToParentDir))
.then(zipPathsWithStats)
.then(mapWithoutNil(pathIfTupleIsDirectory));
};
@bgerstle
bgerstle / location.swift
Created February 29, 2016 17:38
TIL: Locations don't pass NSCoding round trip (location != itself when written/read from disk)
import Foundation
import CoreLocation
let l = CLLocation(latitude: 0, longitude: 0)
let data = NSKeyedArchiver.archivedDataWithRootObject(l)
let lprime = NSKeyedUnarchiver.unarchiveObjectWithData(data) as! CLLocation
l == lprime
// $R0: Bool = false
l.description
// $R2: String = "<+0.00000000,+0.00000000> +/- 0.00m (speed -1.00 mps / course -1.00) @ 2/29/16, 12:34:25 PM Eastern Standard Time"
lprime.description
@bgerstle
bgerstle / App Thinning Report.txt
Created February 26, 2016 14:49
App Thinning Report for Wikipedia iOS app when exported for iPhone 6
App Thinning Size Report for All Variants of Wikipedia
Variant: Wikipedia-iPhone 6.ipa
Supported devices: iPhone 6
App + On Demand Resources size: 7 MB compressed, 18.1 MB uncompressed
App size: 7 MB compressed, 18.1 MB uncompressed
On Demand Resources size: Zero KB compressed, Zero KB uncompressed
@bgerstle
bgerstle / DeadlockTest.swift
Last active February 23, 2016 20:11
Test for reproducing a deadlock between "cancel" and "connectionDidFinishLoading"
func testSDWebImageDownloaderOperationThreadSafety() {
NSURLProtocol.registerClass(WMFHTTPHangingProtocol)
defer {
NSURLProtocol.unregisterClass(WMFHTTPHangingProtocol)
}
[0...1000].forEach { _ in
let downloadOperation = SDWebImageDownloaderOperation(
request: NSURLRequest(URL: NSURL(string: "https://test.org/foo")!),
options: [],
@bgerstle
bgerstle / if_else_return.m
Created January 28, 2016 19:51
If statement examples in ObjC
- (int)exampleA {
if (foo) {
return 1;
}
// no man's land for side effects
if (bar) {
return 2;
}
@bgerstle
bgerstle / ViewControllerProtocolExtensionExample.swift
Created November 12, 2015 16:41
Demonstrating protocol extensions on UIViewController.
import UIKit
public protocol CellContainer {
var visibleCells: [NSIndexPath] { get }
}
public protocol CollectionViewContainer {
var collectionView: UICollectionView? { get }
}
@bgerstle
bgerstle / recent_swipe_delete_trace
Created October 13, 2015 22:22
Crash when deleted a recent article by swiping.
2015-10-13 18:20:28.865 Wikipedia Debug[976:36527763] *** Assertion failure in -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3505.16/UICollectionView.m:3936
2015-10-13 18:20:28.879 Wikipedia Debug[976:36527763] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete and reload the same index path (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0})'
*** First throw call stack:
(
0 CoreFoundation 0x000000010b694f65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010b10edeb objc_exception_throw + 48
2 CoreFoundation 0x000000010b694dca +[NSException raise:format:arguments:] + 106
3 Foundation 0x0000000108851ae2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
4 UIKit 0x0000
@bgerstle
bgerstle / example_ignore
Last active September 19, 2015 21:05
Wikipedia-iOS ignored file patterns setting in CodeCov
# Generic
Pods/.*
Applications/Xcode.app/.*
vendor/.*
Carthage/.*
build/.*
.*Tests.m
.*Tests.swift
# Wikipedia-specific test folders
# We filter the entire folder to exclude coverage of test utility code