Skip to content

Instantly share code, notes, and snippets.

View lzl124631x's full-sized avatar
💻
Learning

Richard Liu lzl124631x

💻
Learning
View GitHub Profile
@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
@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 / 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 / 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, " "));
};
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 / html
Last active June 5, 2016 07:25
Html Meta: App Mode -- Not Scallable
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
@lzl124631x
lzl124631x / js
Last active August 11, 2016 15:39
keep element's ratio
// http://codepen.io/lzl124631x/pen/xOmJGE
$.fn.keepRatio = function(ratio) {
var self = this,
$p = this.parent(),
keep = function() {
var w = $p.width(),
h = $p.height();
if (w / h > ratio) {
self.height(h);
self.width(h * ratio);
@lzl124631x
lzl124631x / js
Created August 14, 2016 01:43
get percentage css value from element
$.fn.pureCss = function (css) {
var $dummy = this.parent().clone().appendTo('body').hide();
var ret = $dummy.find(this.selector).css(css);
$dummy.remove();
return ret;
};
@lzl124631x
lzl124631x / droplet.css
Created August 14, 2016 02:38
CSS 3 Water Droplet
.droplet {
width: 1em;
height: 1em;
border-radius: 80% 0 55% 50% / 55% 0 80% 50%;
background-color: #07C;
transform: rotate(-45deg);
}
use admin
files = ls();
files.forEach((file) => {
regex=/\.\/(.*)\.md/g
parts=regex.exec(file)
if (parts == null) return
title=parts[1]
print(title)
content=cat(file)
print(content)