Skip to content

Instantly share code, notes, and snippets.

View wenzhixin's full-sized avatar

文翼 wenzhixin

View GitHub Profile
function pad(len, num) {
return (new Array(len + 1).join('0') + num).slice(-len);
}
pad(2, 1); // 01
pad(2, 11); // 11
pad(10, 12345); // 0000012345
pad(10, 12345678); // 0012345678
pad(10, 1234567890); // 1234567890
<style>
.ribbon {
overflow: hidden;
white-space: nowrap;
position: absolute;
right: 0;
top: 0;
width: 100px;
height: 100px;
}
@wenzhixin
wenzhixin / validate_share
Created December 11, 2014 09:38
/usr/local/bin/validate_share
#!/bin/bash
DATA_DIR=/home/share/sdk*
case "$SSH_ORIGINAL_COMMAND" in
rsync\ --server*)
TARGET=`echo "$SSH_ORIGINAL_COMMAND" | awk '{ print $NF }'`
if [[ "$TARGET" == $DATA_DIR ]]; then
$SSH_ORIGINAL_COMMAND
else
// a.js
var A = function () {
};
A.prototype.a = function (a) {
return a;
};
@wenzhixin
wenzhixin / nginx-puma-redmine-sub-uri
Created May 8, 2015 03:44
running nginx, puma & redmine from sub-uri
####### NGINX
nginx config for running redmine under /redmine
(assuming working nginx config)
+++ add
upstream redmine-puma {
server unix:/<<redminepath>>/tmp/sockets/redmine.sock fail_timeout=0;
}
@wenzhixin
wenzhixin / timer.js
Created June 20, 2013 03:37
定时器
function timer(func, start, interval, end) {
start = start || 0;
if (arguments.length <= 2) {
setTimeout(func, start);
} else {
var repeat = function() {
var i = setInterval(func, interval);
end && setTimeout(function() {
clearInterval(i);
}, end);
@wenzhixin
wenzhixin / url.js
Last active December 18, 2015 17:48
/**
* var u = url('http://wenzhixin.net.cn:12345/test?name=wenzhixin#about');
* console.log(u.protocol); // http:
* console.log(u.hostname); // wenzhixin.net.cn
* console.log(u.port); // 12345
* console.log(u.pathname); // /test
* console.log(u.search); // ?name=wenzhixin
* console.log(u.hash); // #about
*/
function url(href) {
function parse(search) {
var query = {},
params = search.substring(1).split('&');
for (var i = 0, l = params.length; i < l; i++) {
var p = params[i].split('=');
query[p[0]] = p[1] || '';
}
return query;
}
@wenzhixin
wenzhixin / size.js
Created July 23, 2013 02:37
单位转换
function getSize(value) {
var b1 = Math.pow(2, 10), //KB
b2 = Math.pow(2, 20), //MB
b3 = Math.pow(2, 30), //GB
b4 = Math.pow(2, 40), //TB
value = value.toLowerCase(),
size = parseFloat(value);
if (!size) {
return 0;
@wenzhixin
wenzhixin / mac_install_nginx_php_fpm.md
Last active June 6, 2016 18:38
MAC install nginx + php-fpm

nginx

brew install nginx

config

vi /usr/local/etc/nginx/