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
Number.prototype.toAmount = function() { | |
var parts=(this+'').split('.'); | |
parts[0]=(parts[0]?parts[0]:'0'); | |
parts[1]=(parts[1]?parts[1].substring(0,2):'00'); | |
parts[1]+=(parts[1].length==1?'0':''); | |
return parts[0]+'.'+parts[1]; | |
} | |
var price=12.112; | |
console.log(price.toAmount()); // Outputs 12.11 |
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
#! /bin/sh | |
# Init | |
cd / | |
if [ "$1" != "Y" ]; then | |
echo "$0 1:sure(Y/N)" | |
else | |
while read orgid database | |
do |
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
// Chaining API for URIBuilder | |
var uri=new URLBuilder().parse('bad_url_format').addQueryParam('param','value').setPort('443').toString(); | |
// How to handle the bad url parse error ? | |
// Don't want to throw exception | |
// Can't return 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
// Chainable API for URIBuilder | |
var uri = new URLBuilder(logErrorHandler) | |
.parse('bad_url_format') | |
.addQueryParam('param','value') | |
.setPort('443') | |
.toString(); | |
function logErrorHandler(err, url_object){ | |
if('parse_error'===err.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
var str="<h2>Blahblah</h2><p>Blahblah Blahblah Blahblah.</p><h2>Blahblah</h2><p style=\"text-align: center;\"> <img alt=\"Blahblah\" src=\"http://www.example.com/images/blah.jpg\" /></p><p>BlahblahBlahblah Blahblah Blahblah.</p><h2>Blahblah</h2><p>Blahblah</p>"; | |
var regExp=new RegExp('<([^>]+)"([^>]*)>','mg'); | |
var pattern='<$1$2>'; | |
while(regExp.test(str)) | |
str = str.replace(regExp, pattern); | |
console.log(str); | |
// outputs | |
// <h2>Blahblah</h2><p>Blahblah Blahblah Blahblah.</p><h2>Blahblah</h2><p style=text-align: center;> <img alt="Blahblah" src=http://www.example.com/images/blah.jpg /></p><p>BlahblahBlahblah Blahblah Blahblah.</p><h2>Blahblah</h2><p>Blahblah</p> | |
// Notice the " in the img alt attribute |
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 () {}).apply(this,new Array(1000000)) | |
// RangeError: Maximum call stack size exceeded |
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
if(function test(a){console.log(a)}) { console.log(test('test')) } | |
// ReferenceError : test is not defined | |
var test; | |
if(test = (function(a){console.log(a)})) { console.log(test('test')) } | |
// test |
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
# Json | |
{ | |
"truc":"bidule", | |
"truc2":"bidule2", | |
"truc3":"bidule3" | |
"tab": | |
[ | |
"machin", | |
"bidule", | |
"truc" |
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
{ | |
"name" : "FranceJS" | |
, "version" : "0.0.1" | |
, "dependencies" : { | |
"jslovers" : "*", | |
"parisjs" : "*", | |
"toulousejs" : "*", | |
"lyonjs" : "*", | |
"lillejs" : "*" | |
} |
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 test = Object.create([].prototype); | |
test.[]=function(index) { | |
console.log("Reading index "+index); | |
return Array.[].call(this,index); | |
} |
OlderNewer