Skip to content

Instantly share code, notes, and snippets.

@webdeveloper987
webdeveloper987 / start_testing_java8_today.asciidoc
Created March 8, 2018 00:50 — forked from aslakknutsen/start_testing_java8_today.asciidoc
Example of how to use both JDK 7 and JDK 8 in one build.

JDK 8 Released

Most of us won’t be able to use/deploy JDK 8 in production for a looong time. But that shouldn’t stop us from using it, right?

It should be possible to sneak in JDK 8 in the back way, the same way we snuck in Groovy and other libraries we wanted to use.

The Test Suite to the rescue

The Maven compiler plugin run in two separate lifecycles, compile and testCompile. Those can be configured separately.

@webdeveloper987
webdeveloper987 / latency.txt
Created January 29, 2018 01:13 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@webdeveloper987
webdeveloper987 / volley-POST-example.java
Created January 14, 2018 20:28 — forked from mombrea/volley-POST-example.java
Example of performing a POST request using Google Volley for Android
public static void postNewComment(Context context,final UserAccount userAccount,final String comment,final int blogId,final int postId){
mPostCommentResponse.requestStarted();
RequestQueue queue = Volley.newRequestQueue(context);
StringRequest sr = new StringRequest(Request.Method.POST,"http://api.someservice.com/post/comment", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
mPostCommentResponse.requestCompleted();
}
}, new Response.ErrorListener() {
@Override
@webdeveloper987
webdeveloper987 / FileUpload
Created July 18, 2013 23:28
FileUpload_servlet (only part)
// Validate file.
Object fileObject = request.getAttribute("file");
if (fileObject == null) {
// No file uploaded.
myForm.setError("file", "Please select file to upload.");
}
private void processFileField(FileItem fileField, HttpServletRequest request)
@webdeveloper987
webdeveloper987 / HashMap_iterate
Created July 18, 2013 23:27
Java - iterate over HashMap
Map<String, Object> map = ...;
for (String key : map.keySet())
{
// ...
}
//If you only need the values, use values():
for (Object value : map.values())