Skip to content

Instantly share code, notes, and snippets.

View Dispader's full-sized avatar
:electron:
Present Company Excluded, LLC

Jake Gage Dispader

:electron:
Present Company Excluded, LLC
View GitHub Profile
@Dispader
Dispader / output.txt
Created March 7, 2016 06:52
sample output from GrabCommand.groovy
groovy:000> :load https://git.io/v2N1I
===> true
groovy:000> :register GrabCommand
===> true
groovy:000> :grab 'com.google.guava:guava:19.0'
groovy:000> import com.google.common.collect.Bi
BiMap BinaryTreeTraverser
groovy:000> import com.google.common.collect.BiMap
===> com.google.common.collect.BiMap
groovy:000>
@Dispader
Dispader / RaindropsTest.groovy
Created March 1, 2016 10:02
attempt at a more idiomatic Groovy test
try {
new Raindrops().with {
assert convert(1) == '1'
assert convert(3) == 'Pling'
assert convert(5) == 'Plang'
assert convert(6) == 'Pling'
assert convert(7) == 'Plong'
assert convert(9) == 'Pling'
assert convert(10) == 'Plang'
assert convert(14) == 'Plong'
@Dispader
Dispader / awt_headless.sh
Last active February 29, 2016 04:25
shell startup fragment to disable AWT registration with the display on startup for JVM applications that initialize them
# "I have measured out my life with coffee spoons." —T.S. Eliot
#
export JAVA_OPTS="-Djava.awt.headless=true"
@Dispader
Dispader / greed.rb
Last active August 3, 2016 17:26
one proposed solution to the greed.rb problem, proposed in [Ian Whitney's Ruby Brown Bag](https://github.com/IanWhitney/ruby_brownbag}, for comment — please, please comment: I'm a Ruby tyro, and could use the help. (And many thanks to Ian for his great session, and Chris Crosby-Schmidt for inspiring the approach!)
class Greed
def self.score(dice)
# initialize a score
score = 0
# create a hash of the roll (face values) and the number of times rolled
rolls = dice.inject(Hash.new(0)) {|hash, roll| hash[roll] += 1; hash }
@Dispader
Dispader / ocr-service-example.groovy
Created November 16, 2015 06:19
example of calling online OCR web service
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )
import groovy.io.FileType
import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.*
def standingsFile = new File('./src/test/resources/2015/fall/advsundiv.pdf')
def client = new RESTClient( 'http://beta.offenedaten.de:9998/tika' )
def response = client.put( requestContentType: BINARY, body: standingsFile.bytes )
println response.data.text
@Dispader
Dispader / groovysh-grab.sh
Created November 16, 2015 03:19
example call from the Groovy Shell to Grab `http-builder`
groovy.grape.Grape.grab(group:'org.codehaus.groovy.modules.http-builder', module:'http-builder', version:'0.7.1')
@Dispader
Dispader / successfulAssert.groovy
Created November 8, 2015 00:11
example, showing successful execution of the example in "Groovy Language Documentation" section "1.1.8. Arrays", when from a Groovy script
Integer[][] matrix2
matrix2 = [[1, 2], [3, 4]]
assert matrix2 instanceof Integer[][]
@Dispader
Dispader / failedAssert.sh
Last active November 8, 2015 00:10
example, showing error in the "Groovy Language Documentation" section "1.1.8. Arrays", when executed in the Groovy shell
(~){azazel}06:01P] groovysh
Groovy Shell (2.4.4, JVM: 1.8.0_60)
Type ':help' or ':h' for help.
----------------------------------------------------------------------------------------------------------------------------------------
groovy:000> Integer[][] matrix2
===> null
groovy:000> matrix2 = [[1, 2], [3, 4]]
===> [[1, 2], [3, 4]]
groovy:000> assert matrix2 instanceof Integer[][]
assert matrix2 instanceof Integer[][]
filename = './advsundiv.txt'
file = new File(filename)
expression = /(\d+?)\s(.*?)\s\d+.*/
file.findAll { (it=~expression).matches() }.collect { (it=~expression).collect { match, id, name ->
[ 'id': id, 'name': name ]
} }
@Dispader
Dispader / upl-regex.groovy
Last active October 29, 2015 22:41
UPL regex matcher
('72103 14 Balls & a Rack 412 3438 28 123' =~ /(\d+)\s(.*?)\s\d+.*/)
.collect { match, id, name -> [ 'id': id, 'name': name ] }