Skip to content

Instantly share code, notes, and snippets.

@RobertFischer
RobertFischer / signIn.groovy
Created August 12, 2014 20:57
signIn method
String signUp(Map namedArgs = [:], String firstName = 'Test', String lastName = 'User') {
namedArgs = namedArgs ?: [:] // In case they passed null to be a stinker
email = 'webonise.farmserver@gmail.com'
bothPasswords = "password"
setFullName(firstName, lastName)
organisation = namedArgs.remove('organisation') ?: "Webonise Farm"
phoneNumber = namedArgs.remove('phoneNumber') ?: "8001234567"
optionalTextingNumber = namedArgs.remove('optionalTextingNumber') ?: null
address = namedArgs.remove('address') ?: "9001 Glenwood Ave"
apartment = namedArgs.remove('apartment') ?: "100"
@RobertFischer
RobertFischer / errors.js
Last active August 29, 2015 14:05
Error Examples
/*
Three functions:
One if the message is hard-coded.
One if the message is provided entirely by the user.
One if the message needs a suffix provided by the user.
You could also create a function that used JavaScript's sprintf
and the arguments object (cast to an object by _.toArray()) for
truly flexible error messaging. That is left as an exercise for
the team.
@RobertFischer
RobertFischer / SamplePage.groovy
Created August 25, 2014 16:50
Example of content implementation — Geb
class SamplePage {
static theResultDivImpl = { /* Your impl here */ }
static at = { /* Your basic test here */ && waitFor(theResultDivImpl) }
static content = {
theResultDiv(wait:true, theResultDivImpl)
}
@RobertFischer
RobertFischer / option_or_not.scala
Created September 30, 2014 15:47
When Option.get() isn't...
scala> var opt = Some("Foo")
opt: Some[String] = Some(Foo)
So far, so good. I want to get the value from my Some. Checking the API for Option, and there's a .get() to retrieve the value — http://www.scala-lang.org/api/current/index.html#scala.Option
scala> opt.get()
<console>:9: error: not enough arguments for method apply: (index: Int)Char in class StringOps.
Unspecified value parameter index.
opt.get()
^
@RobertFischer
RobertFischer / hoisting_fix_problem.js
Last active August 29, 2015 14:07
Bad Hoisting "Fix"
var foo;
_.each(bars, function(it) {
foo = it.someProperty;
...
});
// foo is never used again
@RobertFischer
RobertFischer / PlayFrameworkIntegrationTestWTF.scala
Created October 16, 2014 22:34
Why does one work but the other doesn't?
import org.specs2.mutable._
import org.specs2.runner._
import org.junit.runner._
import play.api.test._
import play.api.test.Helpers._
import org.openqa.selenium.WebDriver
// This compiles
@RunWith(classOf[JUnitRunner])
class IntegrationSpec extends Specification {
@RobertFischer
RobertFischer / point_line.js
Last active August 29, 2015 14:08
Finding the Best Line for a Point Problem
/*
Here's the approach that I would take. In the description that follows,
P denotes the point where the user clicked, which has coordinates (x_p, y_p).
Each of these steps will involve checking pairs of points against the point
where the user clicked, denoted as A and B, with coordinates (x_a, y_a)
and (x_b, y_b).
We will move forward in three steps:
first, we will identify those pairs of points that could possibly be our point;
second, we will calculate the distance from the point to the line defined by
@RobertFischer
RobertFischer / aliasing.java
Last active August 29, 2015 14:08
Java Type Aliasing
class Aliasing {
// Put your type alias right before the return value.
public static <L extends Long> String parseToHex(String str) {
return L.toHexString(L.parseLong(str));
}
// Use this for when you have some ugly type.
public static <MAP extends Map<String,Set<String>>> boolean addToKey(String key, String value) {
MAP x = service.getKeyMap();
@RobertFischer
RobertFischer / helper.haml
Created December 3, 2014 12:54
Tabbed Helper
-# Here are the assumptions.
-# 1. We have a consistent UI concept of 'tabbed pages', which have a consistent frame (at least in terms of Haml).
-# 2. Each component of the tabbed pages can be represented as a partial.
-#
-# Given that, I propose that we create a helper that you would call like this.
= tabs {:first => "First Tab!", :second => "2nd Tab", :third => "last tab"}
-# The argument to that function we will call "tab_hash"
-# It would then first load the tab UI component, roughly equivalent to something like this.
= partial "partials/tabs", {:locals => tab_hash}
@RobertFischer
RobertFischer / golf.js
Created December 22, 2014 15:35
That's some fine golf you got there...
{
toFixed: function(num) {
return num.toFixed(0).replace(/./g, function(c, i, a) {
return i > 0 && c !== "." && (a.length - i) % 3 === 0 ? "," + c : c;
});
}
}