Skip to content

Instantly share code, notes, and snippets.

View ophentis's full-sized avatar

Willy Tseng ophentis

View GitHub Profile
@ophentis
ophentis / gist:5489621
Created April 30, 2013 15:52
change encoding of html to html entities, this can fix issue when using php domdocument
$html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8')
@ophentis
ophentis / nginx.conf
Created April 30, 2013 05:58
nginx proxy setup
server {
listen 80;
server_name www.playwithproxy.tw;
location / {
proxy_pass http://10.0.0.201;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@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);});
@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: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: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: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: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: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: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');
}