Skip to content

Instantly share code, notes, and snippets.

@landonf
landonf / HTTPObservable.scala
Last active August 29, 2015 13:55
HTTPObservable
/**
* Asynchronously fetch and return a remote HTTP resource.
*
* @param request An HTTP request.
* @param maxBytes The maximum number of bytes to be fetched.
* @return The fetched byte array on success, or a NetworkError on failure.
*/
def fetch (request: HttpRequestBase, maxBytes: Long) (implicit xc: ExecutionContext): AsyncResult[NetworkError, HTTPFetchedData] = {
import ByteObservable._
@landonf
landonf / darwinfetcht.xt
Created February 15, 2014 21:47
darwinfetch.txt
landonf@bluefish:Documents/Code/Plausible/darwinfetch> ./target/native/darwinfetch
Product: OS X
10.9
10.8
10.7
10.6
10.5
10.4
10.3
10.2
@landonf
landonf / Future.scala
Created February 16, 2014 20:08
Proposed Future API
/**
* A future is a possibly asynchronous, functional computation producing a value of type `T`, or a failure
* of type `E`.
*/
trait Future[+E, +T] {
def swap: Future[T, E]
def foreach[U] (f: T => U): Future[E, T]
def getOrElse[T1 >: T] (default: => T1): Future[E, T1]
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[NSWindow ex_patchInstanceSelector: @selector(sendEvent:) withReplacementBlock: ^(EXPatchIMP *patch, NSEvent *event) {
NSWindow *window = (__bridge NSWindow *) patch->self;
if (window != self.window && [event type] == NSLeftMouseUp && [window isKeyWindow]) {
/* The last view seen */
static NSView *lastView = nil;
NSPoint point = [window.contentView convertPoint: [event locationInWindow] fromView: nil];
NSView *hitView = [window.contentView hitTest: point];
@landonf
landonf / 1-sugared.scala
Last active August 29, 2015 13:56
Example of monadic error handling posted to Twitter
/**
* Fetch credentials from git's credential interface.
*
* @param scheme The URL scheme (eg, http, https).
* @param host The destination host.
* @param realm The authentication realm (eg, HTTP Basic realm).
* @param user The username if known; otherwise, the git credential interface will attempt to fill in this information.
* @return Returns credentials, or a string explaining why credentials could not be fetched.
*/
private def getGitCredentials (scheme: String, host: String, realm: String, user: Option[String]): Result[KeychainError, Credentials] = {
@landonf
landonf / nx.scala
Last active August 29, 2015 13:56
NX macro example
/**
* Private implementation of the nx macro; rather than triggering compilation errors,
* it simply returns the result of the validation.
*
* Example usage:
*
* {{{
* val unhandledExceptions: Set[Class[_ <: Throwable]] = NX.check {
* java.inet.InetAddress.getByName("some host")
* }
@landonf
landonf / fs.txt
Created March 12, 2014 15:21
HFS+, what doing? Case insensitivity can DIAF.
landonf@nautilus:folders/6g/dwk25mtn7hn5c_15rttttzpw0000gn/T> ls -al | grep '7238A134-1823-4871-B724-56BB7CB8BCC6-mktemp_combo_test.A'
landonf@nautilus:folders/6g/dwk25mtn7hn5c_15rttttzpw0000gn/T> ls -al 7238A134-1823-4871-B724-56BB7CB8BCC6-mktemp_combo_test.A
-rw------- 1 landonf staff 0 Mar 12 11:15 7238A134-1823-4871-B724-56BB7CB8BCC6-mktemp_combo_test.A
@landonf
landonf / library_quality.md
Created April 1, 2014 21:10
An addendum to issue #1852

Social + Tool Driven Quality Control

The follow-up I wrote for CocoaPods issue #1852 covers a lot of technical ground, but I also wanted to tackle the issue from a less crash reporting-focused perspective.

While I think the technical direction is interesting, and we're exploring some of these ideas in PLCrashReporter, it's easy to lose sight of the original goal -- ensuring that CocoaPod users can introduce library dependencies without concern that there are significant regressions in a given library or release.

In this area, I think that social and tool-driven hints are not only cheaper to implement, but would be just as powerful -- if not more so -- than a complex crash reporting system that can only find issues after they've already shipped.

If you look at automated build and dependency tooling on other platforms (in particular, I have Maven since that's what I'm familiar with, but these notions are hardly unique to the JVM language family),

@landonf
landonf / 1-loop.swift
Last active August 29, 2015 14:02
Swift vs Scala, FIGHT
// Example totally stolen from Mike Ash
1> func lameFor(count: Int, body: @auto_closure () -> ()) { for _ in 0..count { body() } }
2>
3> lameFor(3, println("I'm the greetest"))
I'm the greetest
I'm the greetest
I'm the greetest
@landonf
landonf / example.swift
Created June 3, 2014 15:02
Shorter Class Syntax
class SongEntry (let name: String)
class ExampleWithAdditionalConstructor (let name: String) {
func self () {
self("default name");
}
}