Skip to content

Instantly share code, notes, and snippets.

View devilelephant's full-sized avatar

George Coller devilelephant

  • Minneapolis, MN
  • 02:50 (UTC -05:00)
View GitHub Profile
@devilelephant
devilelephant / gist:92a90d31e92219feaba4
Created July 3, 2014 20:21
Format log output that is compatible with Intellij Idea <Click to see difference> diff viewer
// The example is in Groovy but this probably works for any kind of logging for an app/test running in IDEA
// The important part is the template: "ComparisonFailure\nexpected:<{?}> but was:<{?}>"
// This works for multi-line values for each '?', which is why being able to use in-ide diff is so nice
def expected = ...
def actual = ...
// do your custom comparison, then if fails throw:
String msg = "ComparisonFailure\nexpected:<{${expected}}> but was:<{${actual}}>"
@devilelephant
devilelephant / gist:6554811
Created September 13, 2013 19:12
An easy way to do Unix piping when executing Unix commands from Java or Groovy In unix you can issue a command like: sh -c 'ls -l | sort" which is calling the 'sh' shell with a command and returning the result. I wrote the example in groovy but the trick works with Runtime.exec(String[] cmd) as well.
def cmd = ['sh', '-c', 'ls -l | sort']
def p = cmd.execute()
println p.text
// Java would be something like
// String[] cmd = { "sh", "-c", "ls -l | sort" };
// Process p = Runtime.getRuntime().exec(cmd);
// ...
@devilelephant
devilelephant / gist:6554529
Created September 13, 2013 18:48
Groovy XML Markup Builder Tricks: CDATA, declaration, comments
def out = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(out)
// MarkupBuilder gives us an instance of MarkupBuilderHelper named 'mkp'
// MarkupBuilderHelper has several helpful methods
xml.mkp.xmlDeclaration(version: "1.0", encoding: "utf-8")
xml.example {
a {
b {
mkp.comment('a comment')