Skip to content

Instantly share code, notes, and snippets.

View jeffbowman's full-sized avatar

Jeff Bowman jeffbowman

  • Appnovation Technologies
  • Oklahoma City, OK
View GitHub Profile
@jeffbowman
jeffbowman / PredicateExample1.java
Last active August 29, 2015 14:01
ConfluexBlogPredicateExample1
Predicate<String> notNullNorEmpty = s -> s != null && !s.isEmpty();
Predicate<String> isFull = s -> s.matches("\\S+");
Predicate<String> isIntegral = s -> s.matches("\\d+");
Predicate<String> isDecimal = s -> s.matches("\\d+\\.\\d+");
Predicate<String> isNumeric = isIntegral.or(isDecimal);
Predicate<String> notNullNumeric = notNullNorEmpty.and(isNumeric);
@jeffbowman
jeffbowman / FunctionalExample1.java
Last active August 29, 2015 14:01
ConfluexBlogFunctionExample1
Function<String, Integer> only3PositiveDigits = s -> {
if (!s.matches("\\d{3}") {
return -1;
}
return new Integer(s);
};
@jeffbowman
jeffbowman / FunctionExample2.java
Created May 20, 2014 15:32
ConfluexBlogFunctionExample2
Function<String , Integer> only3PositiveDigits = s -> s.matches("\\d{3}") ? new Integer(s) : -1;
@jeffbowman
jeffbowman / SupplierExample1.java
Created May 20, 2014 15:35
ConfluexBlogSupplierExample1
Supplier<Integer> alwaysOne = () -> 1;
alwaysOne.get(); // --> 1
alwaysOne.get(); // --> 1, again
alwaysOne.get(); // --> still 1
@jeffbowman
jeffbowman / SupplierExample2.java
Last active August 29, 2015 14:01
ConfluexBlogSupplierExample2
class MyIndex implements Supplier<Integer> {
private int index = 0;
@Override
public Integer get() {
return index++;
}
}
MyIndex i = new MyIndex();
i.get(); // --> 0
i.get(); // --> 1
@jeffbowman
jeffbowman / ConsumerExample1.java
Last active August 29, 2015 14:01
ConfluexBlogConsumerExample1
Consumer<String> log = s -> Logger.getGlobal().info(s);
Consumer<String> toss = s -> {
throw new IllegalArgumentException(s);
}
Consumer<String> logAndToss = log.andThen(toss);
@jeffbowman
jeffbowman / wipe.rkt
Created February 25, 2016 21:57
Overwrite a file with random bits for secure file deletion
#lang racket/base
(require racket/list
racket/sequence)
(define MAX-OVERWRITE 8)
(define overwrite-range (range MAX-OVERWRITE))
(define (get-random-bytes count)
(with-input-from-file "/dev/urandom"
(λ () (read-bytes count))))
@jeffbowman
jeffbowman / LotParser.fs
Last active August 2, 2016 16:56
G+ response to some F# code
open System.Text.RegularExpressions
open FsUnit
open NUnit.Framework
let parseLot lot =
match lot with
| x when Regex.Match(x, @"^\d+$").Success -> [ x |> int ]
| x when Regex.Match(x, @"^\d+-\d+$").Success ->
let parts = x.Split('-')
[ parts.[0] |> int..parts.[1] |> int ]
@jeffbowman
jeffbowman / input.xml
Last active August 22, 2018 15:57
DW Rudimentary unit testing example
<words>
<word>123</word>
<word>mom</word>
<word>12321</word>
<word>madam im adam</word>
<word>Mom</word>
<word>Madam I'm Adam</word>
<word>FooBar</word>
<word>Eva, Can I Stab Bats In A Cave?</word>
</words>
@jeffbowman
jeffbowman / console.log
Created May 16, 2017 21:41
Mule lambda expressions returned in DW
mvn clean test -Dmunit.test="lambda-test-suite.xml" :(
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Mule dataweave Application 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://nexusprod:8080/nexus/content/repositories/releases/org/apache/maven/plugins/maven-install-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/snapshots/org/apache/maven/plugins/maven-install-plugin/maven-metadata.xml
Downloading: http://repository.mulesoft.org/releases/org/apache/maven/plugins/maven-install-plugin/maven-metadata.xml
Downloading: http://nexusprod:8080/nexus/content/repositories/thirdparty/org/apache/maven/plugins/mav