Skip to content

Instantly share code, notes, and snippets.

View kousen's full-sized avatar

Ken Kousen kousen

View GitHub Profile
@kousen
kousen / build.gradle
Created June 8, 2022 21:48
Gradle build file for the book _Mockito Made Clear_, by Ken Kousen, available from Pragmatic Programmers
// Gradle build file for the book "Mockito Made Clear" by Ken Kousen
plugins {
id 'java'
}
// depedency versions are in versions.gradle
apply from: 'versions.gradle'
group 'com.kousenit'
version '1.0'
@kousen
kousen / Jumble.groovy
Last active June 14, 2020 18:50
Jumble solver in Groovy
import groovy.transform.CompileStatic
@CompileStatic
class Jumble {
// dictionary words avail on Mac (or any Un*x system based on BSD)
private List wordList =
new File('/usr/share/dict/words').readLines()
.findAll { it.size() == 5 || it.size() == 6 }
String solve(String clue) {
import groovy.json.*
String jsonTxt = 'http://api.open-notify.org/astros.json'.toURL().text
def json = new JsonSlurper().parseText(jsonTxt)
println "There are ${json.number} people in space"
@kousen
kousen / astronauts3.groovy
Created November 20, 2019 19:57
Validate the astronaut response
assert sql.rows('select * from ASTRONAUTS').size() == 6
 
sql.eachRow('select * from ASTRONAUTS') { row ->
println "${row.name.padRight(20)} aboard ${row.craft}"
}
@GrabConfig(systemClassLoader=true)
@Grab('com.h2database:h2:1.4.200')
Sql sql = Sql.newInstance(url: 'jdbc:h2:~/astro', driver: 'org.h2.Driver')
sql.execute '''
create table if not exists ASTRONAUTS(
id int auto_increment primary key,
  name varchar(50),
  craft varchar(50)
  )
@kousen
kousen / astronauts1.groovy
Last active January 11, 2020 21:47
Astronauts in space at the moment
import groovy.json.*
import groovy.transform.*
import com.google.gson.Gson
@Grab('com.google.code.gson:gson:2.8.6')
@Canonical
class Assignment { String name; String craft }
@Canonical
import java.time.LocalDate;
import java.time.Month;
import static java.time.temporal.ChronoUnit.DAYS;
import static java.time.temporal.ChronoUnit.MONTHS;
import static java.time.temporal.ChronoUnit.YEARS;
public class DaysToElection {
private static String pluralize(long num) {
return num == 1 ? "" : "s";
#!/usr/bin/env groovy
import java.time.LocalDate
import java.time.Month
import static java.time.temporal.ChronoUnit.*
LocalDate electionDay = LocalDate.of(2020, Month.NOVEMBER, 3)
LocalDate now = LocalDate.now()
@kousen
kousen / keybase.md
Created August 31, 2016 23:53
keybase proof

Keybase proof

I hereby claim:

  • I am kousen on github.
  • I am kenkousen (https://keybase.io/kenkousen) on keybase.
  • I have a public key whose fingerprint is 803D 8209 EE54 9E6B 716A D409 17B0 B54A 9BF8 18DD

To claim this, I am signing this object:

@kousen
kousen / build.gradle
Created February 14, 2015 21:22
Gradle build file for GPars samples (downloaded samples.zip from http://gpars.codehaus.org/Demos)
apply plugin: 'groovy'
apply plugin: 'idea'
sourceSets {
src {
main {
groovy {
srcDirs 'src'
}
}