Skip to content

Instantly share code, notes, and snippets.

Avatar

Richard Kolb rjdkolb

View GitHub Profile
View RuleEngine.groovy
if (isUsed(usersHouse.cookingElectricStovePlates) && (isUsed(usersHouse.cookingLPGstovePlates))){//yes the user uses an electric plates and LPG plates
addSuggestion("I see you are using LPG gas in combination with an electric stove")
}
else if (isUsed(usersHouse.cookingElectricStovePlates))//yes the user uses an electric plates but not LPG gas
def percent = percent(usersHouse.cookingElectricStovePlates , perfectHouse.cookingLPGstovePlates)
if (percent > 150){
addSuggestion("I see you are not using LPG gas, perhaps you should switch and you are using more than 150 % of the IES house")
}
else if (percent > 110){
addSuggestion("I see you are not using LPG gas, perhaps you should switch")
@rjdkolb
rjdkolb / AuctionItemExternalWorker.java
Last active Dec 24, 2015
# This example shows an example of a container managed object relational mapping (ORM - http://bit.ly/GKnZ04) exposed as a Enterprise Java Bean (EJB). ## The dependency AuctionItemService injected into AuctionItemExternalWorker is not a pure replacement for the new operator. i.e. An EJB is injected and not a simple class. ## When the method Auct…
View AuctionItemExternalWorker.java
@Stateless
public class AuctionItemExternalWorker {
@EJB
AuctionItemService service;
@EJB
AuditServiceAudit audit;
public void setMinBid(long bidId,long minBidCents) {
audit.auditSetMinBid(bidId,minBidCents);
service.setMinBid(bidId,minBidCents);
}
@rjdkolb
rjdkolb / gist:7301662
Created Nov 4, 2013
How to spin up a restful webserver with jersey 1.x
View gist:7301662
import java.io.IOException;
import com.sun.jersey.api.container.httpserver.HttpServerFactory;
import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.api.core.ResourceConfig;
import com.sun.net.httpserver.HttpServer;
public class RunRest {
static final String BASE_URI = "http://localhost:9999/rest/";
@rjdkolb
rjdkolb / ConsumeHeap.java
Last active Dec 30, 2015
Simple class to create thousands of classes and test the performance of JEP 149 - OpenJDK 8 against OpenJDK7
View ConsumeHeap.java
public class ConsumeHeap {
public static void main(String []args) throws IOException{
HashMap<Long,Integer> hugeMap = new HashMap<>();
Random rand = new Random(System.currentTimeMillis());
for (int count=0;count <5000000;count++){
long time = System.currentTimeMillis();
hugeMap.put(time, rand.nextInt());
}
System.out.println("Done");
@rjdkolb
rjdkolb / App.java
Last active Aug 29, 2015
Java P Byte Code
View App.java
public class App {
public void createPrimativeInteger(){
int x = 100000000;
}
public void createObjectIntegerNonAutoBoxing(){
int x = 200000000;
}
public void createObjectIntegerAutoBoxing(){
Integer x = 300000000;
View gist:4829208096c488ad4c3d
Java 8 Java 8 G1GC Java 9 Java 9 G1GC
DynamicLanguages.groovy 402.142 352.266 397.495 370.121
ExceptionsBenchMark.throwRuntimeException 885181.859 823326.931 910622.671 843228.203
GeneratePoiWorkBook.generatePoiXLSWorkBook 34205.392 28162.636 35129.546 28693.55
GeneratePoiWorkBook.generatePoiXLSXWorkBook 1125.074 980.061 1172.468 1012.47
GeneratePrimeNumbersWithForLoop.generatePrime 231035.868 230904.102 231405.021 230599.11
Jackson.jsonMashal 30019.081 22232.937 31908.426 24242.968
Jackson.jsonUnmashal 26942.264 20443.724 26736.986 22404.13
Jackson.xmlMashalJackson 22868.064 19657.647 23112.766 19947.204
Jackson.xmlMashalJacksonStatic 691051.644 441105.658 745753.342 487013.862
View JMHJackson.java
public static AtomicInteger counter = new AtomicInteger(1);
public static final String user1JsonStart = "{\n"
+ " \"name\" : { \"first\" : \"Joe\", \"last\" : \"Sixpack";
public static final String user1JsonEnd = "\" },\n"
+ " \"gender\" : \"MALE\",\n"
+ " \"verified\" : false,\n"
+ " \"userImage\" : \"Rm9vYmFyIQ==\"\n"
+ "}";
@rjdkolb
rjdkolb / POI.java
Last active Dec 8, 2015
Generate a 12 meg XLSX file 60000x85 columns
View POI.java
List<String> list = new ArrayList<>();
for (int count = 0; count < 60000; count++) {
list.add("T " + count);
}
SXSSFWorkbook workbook = new SXSSFWorkbook();
SXSSFSheet sheet = workbook.createSheet("FIELD OPERATIONS TRACKER");
for (int i = 0; i < list.size(); i++) {
SXSSFRow rowHeader = sheet.createRow(i);
for (int cellcount = 0; cellcount < 85; cellcount++) {
SXSSFCell cell = rowHeader.createCell(cellcount);
View log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" name="API" monitorInterval="30">
<Appenders>
<RollingRandomAccessFile name="CatchAll" fileName="logs/all.log" immediateFlush="false" append="true" FilePattern="logs/$${date:yyyy-MM}/all-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout>
<Pattern>%d %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
<SizeBasedTriggeringPolicy size="2 GB"/>
@rjdkolb
rjdkolb / DuplicateSumTest.java
Last active Jul 12, 2018
Java Cloud Conference (2018) Caffeine Challenge. More about Caffeine : https://youtu.be/Xl1XBJLfIDU
View DuplicateSumTest.java
public class DuplicateSumTest {
@Test
public void sumNonDuplicates() {
Assert.assertEquals("", 3, sumNonDuplicates(new int[]{1, 2}));
}
@Test
public void sumDuplicates() {
Assert.assertEquals("", 3, sumNonDuplicates(new int[]{2, 1, 2, 1}));
}