Skip to content

Instantly share code, notes, and snippets.

Heath Borders hborders

View GitHub Profile
@hborders
hborders / CompactDecimalFormatTest.java
Last active Mar 16, 2019
Demonstrates that CompactDecimalFormat#setMaximumFractionDigits and CompactDecimalFormat#setMaximumIntegerDigits don't work on Android API 24, but work on Android API 28.
View CompactDecimalFormatTest.java
import android.icu.text.CompactDecimalFormat;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Locale;
import static org.junit.Assert.assertEquals;
@RunWith(AndroidJUnit4.class)
public class CompactDecimalFormatTest {
@hborders
hborders / move-subscription-after.sql
Last active Mar 1, 2019
Moves a subscription row after a given reference subscription row
View move-subscription-after.sql
/*
Moves moving_id after reference_id by finding the next row after
reference_id and setting moving_id.sort to be the midpoint of
reference_id.sort and next_reference_id.sort
*/
UPDATE subscription
SET sort = (
CASE WHEN (
/*
Get the first sort value after the reference_id
@hborders
hborders / Heath-C-Java-Apple-Android.opml
Created Feb 3, 2019
An OPML of all the C, Java, Apple, and Android feeds I follow in Feedly.
View Heath-C-Java-Apple-Android.opml
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>Heath's C, Java, Apple, and Android feeds</title>
</head>
<body>
<outline text="C" title="C">
<outline type="rss" text="zeuxcg.org" title="zeuxcg.org" xmlUrl="http://zeuxcg.org/feed/" htmlUrl="http://zeuxcg.org"/>
<outline type="rss" text="Krister Walfridsson’s blog" title="Krister Walfridsson’s blog" xmlUrl="http://kristerw.blogspot.com/feeds/posts/default" htmlUrl="https://kristerw.blogspot.com/"/>
@hborders
hborders / KotlinExtensions.kt
Created Sep 27, 2018
Some confusion over Kotlin extension methods
View KotlinExtensions.kt
open class D {}
class D1: D() {}
fun D.foo() {
println("D.foo")
}
// this seems like an override, but isn't
// It's good that the compiler doesn't let
// me add `override`, but it's still not clear
@hborders
hborders / GenericIsKindOfClass.m
Created Oct 23, 2017
How to use Objective-C Generics with -isKindOfClass:
View GenericIsKindOfClass.m
#import "MyNonClusteredClass.h"
@interface GenericIsKindOfClass<ObjectType : MyNonClusteredClass *> : NSObject
+ (instancetype _Nonnull)new NS_UNAVAILABLE;
- (instancetype _Nonnull)init NS_UNAVAILABLE;
- (instancetype _Nonnull)initWithInstanceOfObjectType:(ObjectType _Nonnull)instanceOfObjectType NS_DESIGNATED_INITIALIZER;
- (ObjectType _Nullable)typeSafeDowncastOrNil:(NSObject * _Nonnull)object;
@hborders
hborders / BadUnpack.m
Created Mar 13, 2017
Trying to unpack the wrong distinct values from a sum type
View BadUnpack.m
static void badPrintExample(Example * _Nonnull example) {
[example switchFoo:^(ExampleBar * _Nonnull bar_) {
// ^
// error: incompatible block pointer types sending 'void (^)(ExampleBar * _Nonnull __strong)' to parameter of type 'void (^ _Nonnull)(ExampleFoo * _Nonnull __strong)'
NSLog(@"Bar: %@, %@", @(bar_.b), @(bar_.c));
}
bar:^(ExampleFoo * _Nonnull foo_) {
// ^
// error: incompatible block pointer types sending 'void (^)(ExampleFoo * _Nonnull __strong)' to parameter of type 'void (^ _Nonnull)(ExampleBar * _Nonnull __strong)'
NSLog(@"Foo: %@, %@", foo_.f, foo_.g);
@hborders
hborders / BadInstantiation.m
Created Mar 13, 2017
Trying to instantiate a distinct type of a sum type with the wrong parameters
View BadInstantiation.m
- (void)testWrongValues {
Example * _Nonnull fooExample = [[ExampleFoo alloc] initWithB:2 c:3];
// ^
// error: no visible @interface for 'ExampleFoo' declares the selector 'initWithB:c:'
Example * _Nonnull barExample = [[ExampleBar alloc] initWithF:@"foo" g:@"goo"];
// ^
// error: no visible @interface for 'ExampleBar' declares the selector 'initWithF:g:'
}
@hborders
hborders / MissingReturn.m
Last active May 14, 2018
An example of the compiler error when get when we miss a return that a block requires
View MissingReturn.m
#import "Example.h" // https://gist.github.com/hborders/2af9b39e27b62ef9e68c65085126fe4a
- (void)missingReturn {
Example * _Nonnull fooExample = [[ExampleFoo alloc] initWithF:@"foo"
g:@"goo"];
NSNumber * _Nonnull number =
[ExampleSwitcher<NSNumber *> nonnullExampleFrom:fooExample
switchFoo:^(ExampleFoo * _Nonnull foo_) {
return @(foo_.f.length + foo_.g.length);
}
@hborders
hborders / MissingAssignment.m
Created Mar 13, 2017
Only assigning to a __block variable in one of the blocks. I wish this was an error.
View MissingAssignment.m
#import "Example.h" // https://gist.github.com/hborders/2af9b39e27b62ef9e68c65085126fe4a
- (void)missingAssignment {
Example * _Nonnull fooExample = [[ExampleFoo alloc] initWithF:@"foo"
g:@"goo"];
NSNumber * _Nonnull __block number;
[fooExample switchFoo:^(ExampleFoo * _Nonnull foo_) {
number = @(foo_.f.length + foo_.g.length);
}
bar:^(ExampleBar * _Nonnull bar_) {
@hborders
hborders / ExampleTestsTestTransformExample.m
Created Mar 13, 2017
An Objective-C pattern for making sum types - ExampleTestsTestTransformExample.m
View ExampleTestsTestTransformExample.m
#import "Example.h" // https://gist.github.com/hborders/e00d7ff965ca8f8df8f7e762a2269efb
#import "ExampleSwitcher.h" // https://gist.github.com/hborders/f378b4e0d0f1d74ff7c8149cb04c6268
#import "ExampleFoo.h" // https://gist.github.com/hborders/094f05d932b3d7a1e389184ba525b0c3
#import "ExampleBar.h" // https://gist.github.com/hborders/f1c231a89de11157adf46ee85880733a
static NSNumber * _Nonnull transformExample(Example * _Nonnull example) {
return [ExampleSwitcher<NSNumber *> nonnullValueFrom:example
switchFoo:^NSNumber * _Nonnull (ExampleFoo * _Nonnull foo_) {
return @(foo_.f.length + foo_.g.length);
}
You can’t perform that action at this time.