Skip to content

Instantly share code, notes, and snippets.

View ophentis's full-sized avatar

Willy Tseng ophentis

View GitHub Profile
@ophentis
ophentis / gist:3943464
Created October 24, 2012 03:12
javascript Date object produce mysql format output
Date.prototype.toMysqlFormat = function() {
function twoDigits(d) {
if(0 <= d && d < 10) return '0' + d.toString();
if(-10 < d && d < 0) return '-0' + (-1*d).toString();
return d.toString();
}
return this.getUTCFullYear() + "-" + twoDigits(1 + this.getUTCMonth()) + "-" + twoDigits(this.getUTCDate()) + " " + twoDigits(this.getUTCHours()) + ":" + twoDigits(this.getUTCMinutes()) + ":" + twoDigits(this.getUTCSeconds());
};
@ophentis
ophentis / gist:4158967
Created November 28, 2012 04:05
customized twitter share by javascript without twitter api
//@requires jQuery to find width and height of window and creating querystring
var href = 'http://twitter.com/share';
var option = {
url: 'your location',
text: 'your text'
};
var width = 575,
@ophentis
ophentis / gist:4215883
Created December 5, 2012 14:27
script to show all images @ 99manga
var template = '<img style="max-width:100%" src=""></img>';
var imgs = PicListUrl.split('|');
$('body').empty();
for(var i=0; i<imgs.length; i++) {
$(template).attr('src',ServerList[server-1]+imgs[i]).appendTo('body');
}
@ophentis
ophentis / gist:4215904
Created December 5, 2012 14:29
script to show all images @ 99comic
var template = '<img style="max-width:100%" src=""></img>';
var path = getSLUrl(cuD);
$('body').empty();
for(var i=0; i<arrFiles.length; i++) {
$(template).attr('src',path+arrFiles[i]).appendTo('body');
}
@ophentis
ophentis / gist:5071835
Created March 2, 2013 16:36
function to output bytes with greatest unit
var units = ' KMGTPEZYXWVU';
function toHumanSize(bytes) {
if (bytes <= 0) { return 0; }
var t2 = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), 12);
return (Math.round(bytes * 100 / Math.pow(1024, t2)) / 100) + units.charAt(t2).replace(' ', '') + 'B';
}
@ophentis
ophentis / gist:5194276
Created March 19, 2013 07:20
rec change owner and file mode
find . -exec sudo chown www-data.adm {} \;
find . -type d -exec sudo chmod 775 {} \;
find . -type f -exec sudo chmod 664 {} \;
@ophentis
ophentis / gist:5402883
Created April 17, 2013 09:05
javascript timeago function in chinese and some modification
function(time, local){
(!local) && (local = Date.now());
if (typeof time !== 'number' || typeof local !== 'number') return;
var offset = Math.abs((local/1000 - time)),
span = [],
MINUTE = 60,
HOUR = 3600,
@ophentis
ophentis / gist:5473449
Created April 27, 2013 15:16
setting multiple private key for ssh
1.
ssh-keygen -t rsa -f ~/.ssh/id_rsa.work -C "Key for Word stuff"
2.
touch ~/.ssh/config
chmod 600 ~/.ssh/config
echo "IdentityFile ~/.ssh/id_rsa.work" >> ~/.ssh/config
echo "IdentityFile ~/.ssh/id_rsa.misc" >> ~/.ssh/config
@ophentis
ophentis / gist:5477428
Created April 28, 2013 16:32
99manga: show all images in one page
PicListUrl.split('|').forEach(function(path) {
var img = new Image();
img.src = ServerList[server-1]+path;
document.body.appendChild(img);
});
@ophentis
ophentis / gist:5482743
Created April 29, 2013 16:25
uuid generator by javascript
//rfc 4122 4.4. Algorithms for Creating a UUID from Truly Random or Pseudo-Random Numbers
//@author broofa
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);});