Skip to content

Instantly share code, notes, and snippets.

View avh4's full-sized avatar

Aaron VonderHaar avh4

View GitHub Profile
@avh4
avh4 / TestBus.java
Created February 2, 2014 17:04
Helper for testing the Otto EventBus
package net.avh4.test.otto;
import com.squareup.otto.ThreadEnforcer;
import java.util.ArrayList;
import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertThat;
public class TestBus extends com.squareup.otto.Bus {
@avh4
avh4 / gist:9560454
Created March 15, 2014 01:24
Stable testing with fluentlenium + angularjs
public class IntegrationTestBase extends FluentTest {
private static final String ngAppElement = "html";
private static final String markerClass = "angularReady";
public void waitForAngular() {
executeScript(
"angular.element(document.querySelector('body')).removeClass('" + markerClass + "');" +
"angular.element(document.querySelector('" + ngAppElement + "'))" +
" .injector().get('$browser').notifyWhenNoOutstandingRequests("+
" function() {" +
var playerData = {
"U123": { name: "RockMAN", score: 150, wins: 1, losses: 200, currentGame: false, position: {} },
"U888": { name: "Jenny", score: 2, wins: 1, losses: 0, currentGame: "G1", position: {} },
"U007": { name: "Johnny", score: 0, wins: 0, losses: 0, currentGame: "G2", position: {} }
};
var activeGames = {
"G1": { players: ["U555", "U888"], found: true, results: {"U555": "U555", "U888": "U555"} },
"G2": { players: ["U123", "U007"], found: false, results: {} }
@avh4
avh4 / ARCUtil.h
Last active August 29, 2015 14:03
ARC release/retain/retainCount
// You shouldn't normally want these, but if you are debugging or working on dark magic,
// here is how you can call retain/release/retainCount in ARC
// From http://stackoverflow.com/a/15707096
#define ARCRetain(...) { void *retainedThing = (__bridge_retained void *)__VA_ARGS__; retainedThing = retainedThing; }
#define ARCRelease(...) { void *retainedThing = (__bridge void *) __VA_ARGS__; id unretainedThing = (__bridge_transfer id)retainedThing; unretainedThing = nil; }
// From http://stackoverflow.com/a/8963645
#define ARCRetainCount(obj) CFGetRetainCount((__bridge CFTypeRef)NSApp)

Keybase proof

I hereby claim:

  • I am avh4 on github.
  • I am avh4 (https://keybase.io/avh4) on keybase.
  • I have a public key whose fingerprint is 77C4 B904 349C F1E5 5BBD 8FE4 79AC 6B2F 3F6C CA93

To claim this, I am signing this object:

@avh4
avh4 / gist:8997ef6a74c9da5a6e23
Created November 13, 2014 03:50
Detect the row under the mouse
import Color
import Mouse
e (col,text) = plainText text |> color col |> width 400
type Model = [(Color, String)]
model : Model
model =
[ (Color.red, "short")
@avh4
avh4 / gist:a5adab664c19f60be992
Created January 11, 2015 19:21
Outline Zipper example
-- -- -- type definitions
type Outline = Outline
{ title : String
, description: String
, inbox : List Outline
, children : List Outline
}
type OutlineCrumb
-- Only works with Elm 0.15
import Html
import Task
import Port
import Debug
import Dict
import Time
-- MODEL
@avh4
avh4 / gist:15e5a9be3e6cff0cef01
Created June 10, 2015 20:21
parsing onClick location in Elm
import Json.Decode as Decode
decodeClickLocation : Decode.Decoder (Int,Int)
decodeClickLocation =
Decode.object2 (,)
(Decode.object2 (-)
(Decode.at ["pageX"] Decode.int)
(Decode.at ["target", "offsetLeft"] Decode.int)
)
(Decode.object2 (-)
@avh4
avh4 / 00 Original.java
Last active August 29, 2015 14:23
Cohesion example 1
class Game {
int ballX = 0;
int ballY = 0;
public void update() {
ballX = ballX + 5;
ballY = ballY + 5;
}
}