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
// Classic Module Pattern | |
// See e.g: https://javascriptweblog.wordpress.com/2010/12/07/namespacing-in-javascript/ | |
// http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html | |
var V0 = (function() { | |
'use strict'; | |
var self = this, | |
i = 0, | |
privateFunction = 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
// See e.g: http://www.sitepoint.com/creating-accurate-timers-in-javascript/ | |
// http://stackoverflow.com/questions/3969475/javascript-pause-settimeout | |
Timer = function(duration, resolution, delegates) { | |
'use strict'; | |
duration || (duration = 1000); | |
resolution || (resolution = 20); | |
delegates || (delegates = {}); | |
delegates.onStart || (delegates.onStart = 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
// Throttling is a means by which we can limit the number of times a function can be called in a given period. | |
// Throttling is good for reducing mousemove events to a lesser, manageable rate, for instance. | |
// See e.g: https://remysharp.com/2010/07/21/throttling-function-calls | |
function throttle(fn, delay, options) { | |
'use strict'; | |
delay || (delay = 250); | |
options || (options = {}); | |
var timeout, |
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
// Debounce limits the rate at which a function can fire. | |
// Debouncing ensures that exactly one signal is sent for an event that may be happening several times | |
// See e.g: http://unscriptable.com/2009/03/20/debouncing-javascript-methods/ | |
// http://davidwalsh.name/javascript-debounce-function | |
function debounce(fn, treshold, options) { | |
'use strict'; | |
treshold || (treshold = 250); | |
options || (options = {}); |
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
package com.github.leifoolsen.reflection; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import java.lang.reflect.Constructor; | |
import java.lang.reflect.Type; | |
import java.util.ArrayList; | |
import java.util.Iterator; |
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
['Undefined', 'Null', 'Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Array', 'Object'].forEach( | |
function(name) { | |
var is = 'is' + name; | |
if(!window.is) | |
window[is] = function(obj) { | |
return ({}).toString.call(obj) === '[object ' + name + ']'; | |
}; | |
}); | |
(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
/* | |
* Author : leif.o.olsen | |
* Description : Extensions to the standard javascript String object | |
*/ | |
(function () { | |
var methods = { | |
/** | |
* Check if a string contains a newline character | |
* @return {boolean} true if a newline character ocurs in the string |
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
// Function in javascript that can be called only once | |
// See e.g : http://davidwalsh.name/javascript-once | |
// http://stackoverflow.com/questions/12713564/function-in-javascript-that-can-be-called-only-once | |
function once(fn, context) { | |
var result; | |
return function() { | |
if(fn) { | |
result = fn.apply(context || this, arguments); | |
fn = null; |
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
@GET | |
public Response allBooks() { | |
UriBuilder uriBuilder = uriInfo.getAbsolutePathBuilder().clone(); | |
// Given a list of books | |
List<Book> books = Lists.newArrayList(new Book("1234567890"), new Book("0123456789")); | |
// Convert to GenericEntity and return in response | |
GenericEntity<List<Book>> entities = new GenericEntity<List<Book>>(books){}; |
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
String s1 = http://localhost:8080/api; | |
String s2 = http://localhost:8080/api/books/search/any?offset=5&limit=5; | |
// Remove identical part from s2 | |
List<String> l = Lists.newArrayList(Splitter.on(s1).omitEmptyStrings().trimResults().split(s2)); | |
String s3 = l.get(0); // => /books/search/any?offset=5&limit=5 | |
// Split query string into name value | |
URI uri = URI.create(s3); |
OlderNewer