This file contains hidden or 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
Server server = new Server(config.getPort()); | |
final ContextHandlerCollection contexts = new ContextHandlerCollection(); | |
server.setHandler(contexts); | |
ServletHolder jaxrs = new ServletHolder(ServletContainer.class); | |
jaxrs.setInitParameter("javax.ws.rs.Application", applicationClassName); | |
final ServletContextHandler mainHandler = new ServletContextHandler(contexts, "/", true, false); | |
mainHandler.addServlet(jaxrs, "/*"); |
This file contains hidden or 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 twitterprocessor; | |
import java.util.List; | |
import java.util.Spliterator; | |
import java.util.concurrent.ArrayBlockingQueue; | |
import java.util.concurrent.CopyOnWriteArrayList; | |
import java.util.concurrent.ForkJoinPool; | |
import java.util.concurrent.atomic.AtomicInteger; | |
import java.util.function.Consumer; | |
import java.util.stream.Stream; |
This file contains hidden or 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
class User { | |
String username; | |
long createdAt; | |
} |
This file contains hidden or 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
public void testFunctions2() { | |
Map<String, Object> scopes = new HashMap<String, Object>(); | |
scopes.put("map", new HashMap<String, String>(){{put("key", "value");}}); | |
final Function<String, String> upperFunction = new Function<String, String>() | |
{ | |
@Override | |
public String apply(String aInput) | |
{ | |
return aInput.toUpperCase(); |
This file contains hidden or 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 twitterprocessor; | |
import com.amazonaws.auth.BasicAWSCredentials; | |
import com.amazonaws.services.s3.AmazonS3Client; | |
import com.amazonaws.services.s3.model.GetObjectRequest; | |
import com.amazonaws.services.s3.model.S3Object; | |
import com.fasterxml.jackson.databind.JsonNode; | |
import com.fasterxml.jackson.databind.MappingJsonFactory; | |
import com.sampullara.cli.Args; | |
import com.sampullara.cli.Argument; |
This file contains hidden or 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
MappingJsonFactory jf = new MappingJsonFactory(); | |
AtomicInteger lines = new AtomicInteger(0); | |
for (int i = 0; i < 10; i++) { | |
long start = System.currentTimeMillis(); | |
Stream<String> br = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(args[0])), "UTF-8")).lines(); | |
if (i % 2 == 0) { | |
System.out.print("parallel: "); | |
br = br.parallel(); | |
} else { | |
System.out.print("serial: "); |
This file contains hidden or 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
{ | |
"vehicle": { | |
"color": null, | |
"display_name": null, | |
"id": XXXXXXXXX, | |
"option_codes": "MS01,RENA,TM00,DRLH,PF01,BT85,PMTG,RFPO,WTSP,IZMB,IDCF,TR01,SU01,SC01,TP01,AU01,CH00,HP00,PA01,PS00,AD02,X024,X019,X001,X003,X007,X011,X013", | |
"user_id": XXXXXXXXX, | |
"vehicle_id": XXXXXXXXX, | |
"vin": "XXXXXXXXX", | |
"tokens": [ |
This file contains hidden or 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
@Test | |
public void testPivotTable() { | |
List<Row> rows = new ArrayList<>(); | |
rows.add(new Row("East", "Boy", "Tee", 10, 12.00)); | |
rows.add(new Row("East", "Boy", "Golf", 15, 20.00)); | |
rows.add(new Row("East", "Girl", "Tee", 8, 14.00)); | |
rows.add(new Row("East", "Girl", "Golf", 20, 24.00)); | |
rows.add(new Row("West", "Boy", "Tee", 5, 12.00)); | |
rows.add(new Row("West", "Boy", "Golf", 12, 20.00)); | |
rows.add(new Row("West", "Girl", "Tee", 15, 14.00)); |
This file contains hidden or 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
public class Rated { | |
public Rated(JsonNode node) { | |
starRating = node.get("rating").intValue(); | |
} | |
int starRating; | |
class Star { | |
boolean active; |
This file contains hidden or 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 webserver; | |
import org.webbitserver.WebServers; | |
public class App { | |
public static void main(String[] args) { | |
WebServers.createWebServer(8080).add((req, res, con) -> { | |
res.content("Hello, world!").end(); | |
}).start(); | |
} |