Skip to content

Instantly share code, notes, and snippets.

View lzl124631x's full-sized avatar
💻
Learning

Richard Liu lzl124631x

💻
Learning
View GitHub Profile
String.prototype.toUnicode = function(){
var result = "";
for(var i = 0; i < this.length; i++){
result += "\\u" + ("000" + this[i].charCodeAt(0).toString(16)).substr(-4);
}
return result;
};
"みどりいろ".toUnicode(); //"\u307f\u3069\u308a\u3044\u308d"
"Mi Do Ri I Ro".toUnicode(); //"\u004d\u0069\u0020\u0044\u006f\u0020\u0052\u0069\u0020\u0049\u0020\u0052\u006f"
@lzl124631x
lzl124631x / js
Created May 25, 2016 06:26
get parameter in query string by name
function getParameterByName (name) {
var undefined;
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? undefined : decodeURIComponent(results[1].replace(/\+/g, " "));
};
@lzl124631x
lzl124631x / js
Created May 25, 2016 05:28
Test if an object is in DOM
function isInDom(obj) {
var root = obj.parents('html')[0]
return !!(root && root === document.documentElement);
}
//if(isInDom(myElement)) {
// ...
//}
@lzl124631x
lzl124631x / gulpfile.js
Created May 13, 2016 13:10
inject cdn domain and version number into js/css files
gulp.task('postprocess', function () {
// Get Cdn Domain
var xml = fs.readFileSync('Web.ProductionDeploy.config', 'utf8');
var xmlDoc = libxmljs.parseXml(xml);
var cdnDomain = xmlDoc.get("//add[@key='cdn-domain']/@value").value();
console.log('cdn-domain: \'' + cdnDomain + '\'');
// Get App Version
var appVersion = require('./package.json').version;
console.log('version: \'' + appVersion + '\'');
@lzl124631x
lzl124631x / reorg.sh
Last active September 17, 2016 16:04
organize jpg, png and mov files into different folders according to their create date
#!/bin/bash
for x in *.{JPG,PNG,MOV,MP4}; do
d=$(date -r "$x" +%Y-%m-%d)
mkdir -p "$d"
mv -- "$x" "$d/"
done