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 validator = { | |
// all available checks | |
types: {}, | |
// error messages in the current | |
// validation session | |
messages: [], | |
// current validation config | |
// name: validation type |
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
// decorator pattern with prototypal inheritance. | |
function Sale(price) { | |
this.price = price || 100; | |
} | |
Sale.prototype.getPrice = function() { | |
return this.price; | |
}; | |
Sale.decorators = {}; |
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 FactorySample() {} | |
FactorySample.prototype.action = function() { | |
return "the id of this instance is " + this.id; | |
}; | |
FactorySample.factory = function(type) { | |
var newInstance; | |
// check whether constructor type exist |
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
// Constructor way | |
function SingletonKlass() { | |
var instance; | |
SingletonKlass = function SingletonKlass() { | |
return instance; | |
} | |
SingletonKlass.prototype = this; | |
instance = new SingletonKlass(); |
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
def tstamp = new Date().format('yyyy-MM-dd_HH-mm-ss') | |
def buildLogDir = "${rootDir}/build/logs" | |
mkdir("${buildLogDir}") | |
def buildLog = new File("${buildLogDir}/${tstamp}_buildLog.log") | |
import org.gradle.logging.internal.* | |
System.setProperty('org.gradle.color.error', 'RED') | |
gradle.services.get(LoggingOutputInternal).addStandardOutputListener (new StandardOutputListener () { | |
void onOutput(CharSequence output) { |
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
/*! | |
* Pub/Sub implementation | |
* http://addyosmani.com/ | |
* Licensed under the GPL | |
* http://jsfiddle.net/LxPrq/ | |
*/ | |
;(function ( window, doc, undef ) { |
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
private void enableHTML5AppCache() { | |
webView.getSettings().setDomStorageEnabled(true); | |
// Set cache size to 8 mb by default. should be more than enough | |
webView.getSettings().setAppCacheMaxSize(1024*1024*8); | |
// This next one is crazy. It's the DEFAULT location for your app's cache | |
// But it didn't work for me without this line | |
webView.getSettings().setAppCachePath("/data/data/"+ getPackageName() +"/cache"); |
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
// trim with regular expression | |
String.prototype.trim = function () { | |
return this.replace(/^\s*([\s\S]*\S)?\s*$/, "$1"); | |
}; | |
// trim with string methods | |
String.prototype.trim = function () { | |
var start = 0, | |
end = this.length - 1, | |
ws = " \n\r\t\f\x0b\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u202f\u205f\u3000\ufeff"; |
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
//customized mem function for factorial, with very good performance. | |
function memfactorial(n) { | |
if (!memfactorial.cache) { | |
memfactorial.cache = { | |
"0": 1, | |
"1": 1 | |
}; | |
} | |
if (!memfactorial.cache.hasOwnProperty(n)) { | |
memfactorial.cache[n] = n * memfactorial(n - 1); |
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 bubblesort() { | |
var numElements = this.dataStore.length; | |
var temp; | |
for (var outer = numElements; outer >= 2; --outer) { | |
for (var inner = 0; inner <= outer - 1; ++inner) { | |
if (this.dataStore[inner] > this.dataStore[inner + 1]) { | |
temp = this.dataStore[inner]; | |
this.dataStore[inner] = this.dataStore[inner + 1]; | |
this.dataStore[inner + 1] = temp; | |
} |