Skip to content

Instantly share code, notes, and snippets.

View yantze's full-sized avatar
🤤
Out sick

zhi yantze

🤤
Out sick
View GitHub Profile
@yantze
yantze / get_vim_startuptime
Last active August 29, 2015 14:05
use awk and sed get the elapsed time of vim startuptim
"获取插件加载时间
vim filename --startuptime 'time.txt'
"统计加载插件总用时
awk '{print $2}' time.txt | sed 's/\([0-9].*\):/\1/g' | awk '{sum+=$1} END {print sum}'
@yantze
yantze / get_param_js
Created April 26, 2015 04:54
get URL parameter
// get URL parameter
function get_param(name)
{
if (location.href.indexOf("?") >= 0) {
var query=location.href.split("?")[1];
var params=query.split("&");
for (var i = 0; i < params.length; i ++) {
value_pair=params[i].split("=");
if (value_pair[0] == name)
return unescape(value_pair[1]);
@yantze
yantze / parse_param
Created June 30, 2015 10:22
解析类似URI query字符串,返回数组对象
/**
* 解析类似URI query字符串,返回数组对象
* @param uri 类似location.search
* @param key 数组的key name
* @returns {*}
*/
function parse_param(uri, key)
{
var regex = /[?&]([^=#]+)=([^&#]*)/g,
url = uri,
@yantze
yantze / like switch
Created July 18, 2015 07:17
use array_key_exists and ArrayHelper switch a subArray
/**
* @return array of type
*/
public static function itemsAilas($type){
$items = [
'occupation'=> [
self::OCCUPATION_DOCTOR => 'แพทย์',
self::OCCUPATION_NURSE => 'พยาบาล',
self::OCCUPATION_PHARMACY => 'เภสัชกร',
self::OCCUPATION_DENTIST => 'ทันตแพทย์',
@yantze
yantze / DynamicModel.php
Created July 21, 2015 02:49
dynamic model
$phoneset = '';
$content = '';
$type = 'uid';
$types = [
'uid' =>'使用uid',
'phone'=>'电话号码',
];
$model = DynamicModel::validateData(compact('phoneset', 'content', 'type', 'types'), [
['phoneset', 'string', 'min' => 11],
['content', 'string', 'max' => 340, 'min' => 2],
@yantze
yantze / emptiness_and_arrays.php
Last active September 16, 2015 07:22
NULL is equal ''
<?php
// http://www.phpwtf.org/
$a = array();
$a[''] = 'string index';
$a[NULL] = 'NULL index';
$a[] = 'add index';
var_dump($a);
// NULL is equal ''
@yantze
yantze / MysqlHelper.php
Last active November 10, 2015 14:01
MysqlHelper can get select fields full info with no result 获取 select 结果集的字段信息
<?php
/**
* Created by PhpStorm.
* User: yantze.yang
* Date: 2015/11/7
* Time: 18:05
*/
namespace app\helpers\db;
// user:password@host:port\database
function addScript( src,callback) {
var s = document.createElement( 'script' );
s.setAttribute( 'src', src );
s.onload=callback;
document.body.appendChild( s );
}
@yantze
yantze / ipurl.sh
Last active July 1, 2016 05:08
get pure ip from url
#!/bin/sh
# get pure ip from url
function ipurl() {
echo $1 |
sed -e 's/^.*:\/\/\(.*\)/\1/g' | # remove http(s)://
awk -F/ '{print $1}' | # remove /query/abc?a=b
xargs ping -c 1 -t 1 | # -c only send one package, -t timeout 1s
sed -n '1p' | # result: get first line
sed -e 's/^.*(\([0-9\.]\{7,\}\)).*/\1/g' # get ip in the first line
@yantze
yantze / post_pre_inc.php
Last active August 18, 2016 11:06
php 奇怪的自增和运算符执行顺序分析 some weird evaluation about post_inc and pre_inc
<?php
// author: yantze
// date: 2016-07-31
// desc: php 自增和运算符执行顺序分析
// #1
function test1(){
echo PHP_EOL.__function__ .":";
$a=1;
echo (++$a)+(++$a);