This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// these 9 characters represent our days: 2 days of rain ('R') and 7 days of dryness ('D') | |
def days = 'RRDDDDDDD' as List | |
// number of trials to run; the bigger the number, the more accurate the probability | |
int trials = 10000 | |
// counter for the number of consecutive rainy days we see | |
int consecutiveRainyDays = 0 | |
// run the trials |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group='org.apache.pdfbox', module='pdfbox', version='2.0.21') | |
import org.apache.pdfbox.multipdf.PDFMergerUtility | |
import org.apache.pdfbox.io.MemoryUsageSetting | |
def dir = new File('C:\\Users\\Joe\\Documents\\pdfs') | |
def merger = new PDFMergerUtility(); | |
(1..3).each { merger.addSource(new File(dir, "document_page${it}.pdf")) } | |
merger.destinationFileName = new File(dir, "document.pdf").absolutePath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When concrete classes are preferrable to interfaces | |
String vs. CharSequence | |
- better relays immutability? | |
- so widespread that it can be an inconvenience to accept a CharSequence and have to do something with it, like pass to another 3rd party library method | |
Exception vs. Throwable | |
- error details object in REST application, don't want people to attempt to create these if there's an Error | |
LocalDate vs. ChronoLocalDate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.temporal.*; | |
import static java.time.Month.OCTOBER; | |
import static java.time.temporal.ChronoField.MONTH_OF_YEAR; | |
import static java.time.temporal.ChronoField.YEAR; | |
/** | |
* Temporal fields that are commonly used within the Federal government. | |
* | |
* More fields may be added in the future (e.g. Leave Year, Bi-Weekly Pay Period) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.DayOfWeek; | |
import java.time.LocalDate; | |
import java.time.Month; | |
import java.time.MonthDay; | |
import java.time.temporal.TemporalAdjusters; | |
import java.util.*; | |
import java.util.function.Function; | |
import java.util.function.Supplier; | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group='org.springframework.security', module='spring-security-core', version='3.2.5.RELEASE') | |
@Grab(group='org.springframework.security', module='spring-security-ldap', version='3.2.5.RELEASE') | |
import groovy.transform.* | |
import javax.naming.NamingException | |
import javax.naming.directory.Attribute | |
import javax.naming.directory.Attributes | |
import org.springframework.ldap.core.* | |
import org.springframework.security.ldap.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
println groovy.json.JsonOutput.prettyPrint(new File(args[0]).text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.transform.* | |
import java.nio.* | |
import java.nio.charset.* | |
@Field CharsetDecoder cs = Charset.forName('UTF-8').newDecoder() | |
InputStream.metaClass.eachChunk << { int preferredChunkSize, Closure closure -> | |
delegate.eachByte(preferredChunkSize) { buffer, bytesRead -> | |
if (bytesRead == preferredChunkSize) { | |
closure(buffer) | |
} else if (bytesRead > 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*def imewi = Iterable.metaClass.eachWithIndex | |
def lmewi = List.metaClass.eachWithIndex | |
println imewi | |
println lmewi | |
def iewi = Iterable.&eachWithIndex | |
def lewi = List.&eachWithIndex | |
*/ | |
def eachWithLast = { Closure c -> | |
int size = delegate.size() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gov.uspto.iqs; | |
import java.time.DayOfWeek; | |
import java.util.Arrays; | |
public class SadCompiler { | |
int sadInstanceOf(Object o) { | |
if (o instanceof List) { | |
return ((List) o).size(); |
NewerOlder