Skip to content

Instantly share code, notes, and snippets.

@khamiltonuk
khamiltonuk / printLnAsLambda
Created November 29, 2015 10:40
Java 8 is coming
myList.forEach(System.out::println);
@khamiltonuk
khamiltonuk / lambdaSort.java
Last active November 29, 2015 22:07
Java 8 is coming
Arrays.sort(words,
(String w1, String w2) -> { w2.length() - w1.length() });
@khamiltonuk
khamiltonuk / annotationsChecker.java
Last active November 29, 2015 10:36
Java 8 is coming
// Type cast
mustExist = (@NotNull Integer) choice;
// Object creation
new @NoSQLInjection LittleBobbyTables(String input);
// Adding interfaces
class MySetWrapper<T> implements @Immutable Set<@Immutable T>
// Declaring exception
@khamiltonuk
khamiltonuk / Optional.java
Last active November 29, 2015 22:06
Java 8 is coming
Optional<String> opt = toBeOrNotToBe();
if(opt.isPresent())
return opt.get();
else
return "";
@khamiltonuk
khamiltonuk / local time function
Created November 29, 2015 10:26
Java 8 is coming
Clock.systemDefaultZone();
@khamiltonuk
khamiltonuk / local.java
Last active November 29, 2015 22:05
Java 8 is coming
LocalTime current = LocalTime.now();
LocalTime CoB = current.plus(9, HOURS);
@khamiltonuk
khamiltonuk / typicalLoop.js
Created November 29, 2015 08:49
Optimising JavaScript performances with asynchronous loops
for (var i = 0; i < collection.length; i++) { }
@khamiltonuk
khamiltonuk / simpleSplitLoop.js
Created November 29, 2015 08:48
Optimising JavaScript performances with asynchronous loops
splitLoop( $(".items").toArray(), function (item) {
$(item) .processItem();
}, this );
@khamiltonuk
khamiltonuk / splitLoop.js
Last active November 29, 2015 08:53
Optimising JavaScript performances with asynchronous loops
function splitLoop(items, process, context, callback) {
var todo = items.concat();
setTimeout(function () {
var start = +new Date();
do {
process.call(context, todo.shift());
} while (todo.length > 0);
if (todo.length > 0) {
@khamiltonuk
khamiltonuk / endOfTheCollectionCheck.js
Last active November 29, 2015 08:45
Optimising JavaScript performances with asynchronous loops
function todo(item) {
console.log(item);
};
function done() {
console.log('done');
}
var items = [];
for (var i = 0; i < 1000; i++)