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
@Override | |
protected Response<T> parseNetworkResponse(NetworkResponse response) { | |
Utility.log("statuscode", response.statusCode); | |
try { | |
if(response.statusCode != 200) { | |
return Response.error(new VolleyError("Network Error")); | |
} else { | |
String data = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); | |
Utility.log("data", data); | |
T list = mGson.fromJson(data, new TypeToken<T>(){}.getType()); |
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
var path = require('path'); | |
var fs = require('fs'); | |
var mkdirs = function(dir, mode, callback) { | |
fs.exists(dir, function(exists) { | |
if(exists) { | |
callback(dir); | |
} else { | |
mkdirs(path.dirname(dir), mode, function() { | |
fs.mkdir(dir, mode, callback); |
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
public String reverse(String str) { | |
if(str == null) | |
throw new NullPointerException("null"); | |
if(str.length() <= 1) | |
return str; | |
return new StringBuffer(str).reverse().toString(); | |
} | |
public String reverseTwo(String str) { |
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
public class ApplicationCache { | |
//NO Lazy Initialization | |
private static final ApplicationCache INSTANCE = new ApplicationCache(); | |
//Check the INSTANCE to avoid the reflect call | |
private ApplicationCache() { | |
if(INSTANCE != null) | |
throw new IllegalStateException("Exist Already"); | |
} |
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
var app = function() { | |
//Private stuff | |
var instance; | |
//Init method just like a constructor | |
function init() { | |
//Return an empty object | |
reutn {}; | |
} | |
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
var fs = require('fs'); | |
setTimeout(function() { | |
console.log('first timer...'); | |
setTimeout(function() { | |
console.log('second timer...'); | |
}, 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
The event loop cycle is timers -> I/O -> immediates, rinse and repeat. But that when you | |
haven't entered the event loop, then timers come first-but only on the first tick. timers | |
are based on a time in the future, even if it's 0, while check immediate is always on the | |
next turn of the loop. So it's possible that the delay of the event loop is low enough for | |
the timer to fire after the immediate. | |
setTimeout(function() { | |
console.log('setTimeout'); | |
}, 0); | |
setImmediate(function() { |
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
The "diamond problem" (sometimes referred to as the "deadly diamond of death"[4]) is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C. If there is a method in A that B and/or C has overridden, and D does not override it, then which version of the method does D inherit: that of B, or that of C? |
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
Lazy initialization has two objectives: | |
1. delay an expensive operation until it's absolutely necessary | |
2. store the result of that expensive operation, such that you won't need to repeat it again. | |
To avoid a NullPointerException, a class must self-encapsulate fields that have lazy initialization. | |
That is, a class cannot refer directly to such fields, but must access them through a method. | |
The hashCode method of an immutable Model Object is a common candidate for lazy initialization. | |
public final class Lazyer { |
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
//One implementation that not consider the | |
//time and space complexity and use string | |
//as input | |
public final class LeftShift { | |
//brute-force algorithm | |
private String leftShiftOne(String s) { | |
if(s == null) | |
throw new NullPointerException("null"); | |
if(s.length() <= 1) |
OlderNewer