Skip to content

Instantly share code, notes, and snippets.

@imzhi
imzhi / review.php
Last active August 29, 2015 14:27
从V2EX上看到的一道PHP面试题,给定一个整数n,生成一个形如[1,[2,[3,[n,"$$$$..."]]]]的数组。例如:n=4,生成[1,[2,[3,[4,"$$$$"]]]],链接:https://v2ex.com/t/182966
<?php
/**
*
* @authors imzhi (yxz_blue@126.com)
* @date 2015-08-18 19:35:20
* @version $Id$
*/
function test($n = 0) {
$arr = [];
@imzhi
imzhi / create_uuid.php
Created February 15, 2016 02:45
生成uuid
<?php
// UUID百度百科<http://baike.baidu.com/view/1052579.htm>
// 8-4-4-4-12
function create_uuid()
{
$str = md5(uniqid('', true));
return preg_replace('/(\w{8})(\w{4})(\w{4})(\w{4})(\w{12})/', '$1-$2-$3-$4-$5', $str);
}
@imzhi
imzhi / heart.coffee
Created February 18, 2016 17:04 — forked from weakish/heart.coffee
Matrix digital rain http://jsbin.com/ORIpOxi/
# Preview: http://jsbin.com/bijag
c = document.getElementById('c')
ctx = c.getContext('2d')
# full screen
c.height = window.innerHeight
c.width = window.innerWidth
@imzhi
imzhi / app.js
Created March 2, 2016 09:50 — forked from yang-wei/app.js
React JS color slider
(function(exports) {
'use strict';
var Slider = React.createClass({
getDefaultProps: function() {
return {
redVal: '',
greenVal: '',
blueVal: ''
@imzhi
imzhi / React sortable
Created March 4, 2016 06:32 — forked from petehunt/React sortable
Here's an example of React + jQuery UI sortable. The key thing to note is that we have the render() method do absolutely nothing and use componentDidUpdate() + React.renderComponent() to proxy updates through to the children. This lets us manage the DOM manually but still be able to use all the React goodies you know and love.
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://fb.me/react-0.5.1.js"></script>
<script src="http://fb.me/JSXTransformer-0.5.1.js"></script>
</head>
@imzhi
imzhi / ajax.js
Created March 7, 2016 02:04
简单封装的ajax请求
function ajax(opts) {
var options = {
type: opts.type || 'get',
url: opts.url,
data: opts.data || '',
success: opts.success
};
if (!options.url) {
alert('报错');
@imzhi
imzhi / rand_str.sql
Last active March 14, 2016 03:07
生成随机字符串(SQL函数)(http://www.jb51.net/article/61362.htm)
DROP FUNCTION `test`.`rand_str`;
SET GLOBAL log_bin_trust_function_creators=TRUE;
DELIMITER $$
CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
FUNCTION `test`.`rand_str`(n INT UNSIGNED)
RETURNS VARCHAR(2000)
@imzhi
imzhi / pad_str.js
Created March 19, 2016 09:02
补齐0
var pad_str = (function(arr) { // 数组缓存补齐的0个数,空间换时间 <http://www.cnblogs.com/bluedream2009/archive/2009/09/08/1562910.html>
// num 要补0的数字 n 需补齐到多少位
return function(num, n) {
var pad_len = (n - ('' + num).length);
return pad_len > 0 ? (arr[pad_len] || ( arr[pad_len] = Array(pad_len+1).join('0') )) + num
: num;
};
})([]);
@imzhi
imzhi / nginx-location
Created April 7, 2016 02:20 — forked from luxixing/nginx-location
nginx location 匹配规则
1 普通匹配,遵循最长匹配规则,假设一个请求匹配到了两个普通规则,则选择匹配长度大的那个
例如:
location /{
[matches]
}
location /test{
[matches]
}
2 精确匹配
location = /{
@imzhi
imzhi / space.js
Created June 6, 2016 09:15
复制替换空格
// ==UserScript==
// @name 复制替换空格
// @namespace http://tampermonkey.net/
// @version 0.1.0
// @description Hello World!
// @author Xiaozhi
// @match http://*/*
// @grant none
// @require http://cdn.bootcss.com/jquery/2.2.3/jquery.js
// ==/UserScript==