Skip to content

Instantly share code, notes, and snippets.

View hborders's full-sized avatar

Heath Borders hborders

View GitHub Profile
@hborders
hborders / gist:7701826
Last active March 17, 2017 13:56
How to safely work with unicode strings in Java: Inspired by http://mortoray.com/2013/11/27/the-string-type-is-broken/
import java.text.BreakIterator;
public class UnicodeTest {
public static void main(String[] args) {
String noel = "noe\u0308l";
System.out.println("noel=" + noel);
System.out.println("Broken (java.lang.String methods):");
System.out.println("noel.length=" + noel.length());
System.out.println("noel.substring(0,3)=" + noel.substring(0, 3));
@hborders
hborders / Fixed895ShadowLooper
Last active January 2, 2016 09:49
A new ShadowLooper to workaround https://github.com/robolectric/robolectric/pull/895 Include it in your unit tests along with a top-level configuration file named: org.robolectric.Config.properties with the following contents: shadows=org.github.gist.hborders.Fixed895ShadowLooper
package org.github.gist.hborders;
/**
To automatically configure this Shadow for all tests, create a top-level configuration file named: org.robolectric.Config.properties with the following contents:
shadows=org.github.gist.hborders.Fixed895ShadowLooper
*/
@SuppressWarnings({"UnusedDeclaration"})
@Implements(Looper.class)
@hborders
hborders / gist:8560409
Created January 22, 2014 15:14
Class<?> varargs example from https://twitter.com/natesbrain/status/425720792760856576 compiles file for me.
class A {
}
class B extends A {
}
class C extends A {
@hborders
hborders / gist:8612342
Created January 25, 2014 05:42
ARC block release-only block crash
- (AFHTTPRequestOperation *)operationForEmptyResponseRequest:(NSURLRequest*) request onComplete:(void(^)(void)) completeBlock onError:(void (^)(NSError *)) errorBlock {
void (^nilObjectCompleteBlock)(id);
if (complete) {
void (^heapCompleteBlock)(void) = [completeBlock copy];
// INTERESTING BITS:
// iOS7: this crashes in weird ways if we don't copy the block we assign to nilObjectComplete here.
// it is supposed to be safe to pass a block down into another block, but maybe not.
nilObjectCompleteBlock = [^(id nilObject) {
heapCompleteBlock();
} copy];
@hborders
hborders / google-io-todo
Created March 22, 2014 19:55
A list of Google IO videos I need to watch.
https://developers.google.com/events/io/sessions/326148829
https://developers.google.com/events/io/2012/sessions/gooio2012/106/
https://developers.google.com/events/io/2012/sessions/gooio2012/131/
https://developers.google.com/events/io/2012/sessions/gooio2012/114/
https://developers.google.com/events/io/2012/sessions/gooio2012/122/
https://developers.google.com/events/io/2012/sessions/gooio2012/103/
https://developers.google.com/events/io/2012/sessions/gooio2012/107/
https://developers.google.com/events/io/2012/sessions/gooio2012/102/
https://developers.google.com/events/io/sessions/326425499
https://sites.google.com/site/io/dalvik-vm-internals
#!/bin/bash -e
# Argument = -h -v -i groupId:artifactId:version -c classifier -p packaging
#shopt -o -s xtrace
# Define Nexus Configuration
NEXUS_BASE=http://repository.example.com:8081/nexus #this URL shouldn't end in a /
REST_PATH=/service/local
ART_REDIR=/artifact/maven/redirect
#!/bin/bash
# Argument = -h -v -i groupId:artifactId:version -c classifier -p packaging -r repository
#shopt -o -s xtrace
# Define Nexus Configuration
NEXUS_BASE=http://repository.example.com:8081/nexus
REST_PATH=/service/local
ART_REDIR=/artifact/maven/redirect
@hborders
hborders / Better way to return failure?
Created February 20, 2015 15:09
Is there a better way to handle the failure case?
class Box<A> {
public let value: A
init(_ value: A) { self.value = value }
}
enum Result<A> {
case Success(Box<A>)
case Failure(NSError)
}
private class Poller<ResultType, ErrorType: JiveError, ErrorCodeType where ErrorType.CodeType == ErrorCodeType> {
private let retryInterval: NSTimeInterval
private let timeoutErrorCode: ErrorCodeType
private let expectation: XCTestExpectation
private var state: PollerState<ResultType, ErrorType>
init(
createJiveFuture: () -> JiveFuture<ResultType, ErrorType>,
acceptJiveResult: (JiveResult<ResultType, ErrorType>) -> JiveResult<ResultType, ErrorType>?,
retryInterval: NSTimeInterval,
@hborders
hborders / gist:316123ce2e506b9f11bc
Last active August 29, 2015 14:21
Swift enums with labels
enum Foo {
// enums can have many values, and they can be labeled
case Bar(
barString: String,
barInt: Int)
// or unlabeled
case Baz(
String,
Int)
}