Skip to content

Instantly share code, notes, and snippets.

View dcb9's full-sized avatar

Du, Chengbin dcb9

View GitHub Profile
<?php
$model = Model::find()
->where(['count' => ['$gt' => $count]])
->one();
@dcb9
dcb9 / findSvnFileOriginal.py
Last active August 29, 2015 14:07
查找svn文件的最开始的创始人和创建时间
import os, re, sys
RE =re.compile(ur'r(\d+)\s\|\s(\S+)\s\|\s(\S+\s\S+)')
SVN_LOG="svn log"
def backtrack(file):
fh = os.popen("%s -q %s" % (SVN_LOG, file), "r")
for line in fh:
line = line.strip()
if line != "------------------------------------------------------------------------":
@dcb9
dcb9 / SortAlgorithm.php
Last active August 29, 2015 14:08
四种比较常见的排序算法:插入,快速,选择,冒泡 以及测试程序
<?php
/**
* 排序算法
* 插入排序、快速排序、选择排序、冒泡排序
*
*/
class SortAlgorithm{
/**
@dcb9
dcb9 / simulator_python__main__.php
Last active August 29, 2015 14:08
用php模拟python的 __name__ == '__main__' 功能,这样可以做一些测试,只有直接运行这个php的时候才执行,如果这个php是被包含的则不执行,并且还要是在终端下。
<?php
function ismain(){
$debug = debug_backtrace();
if(PHP_SAPI === 'cli' && count($debug)==1 && $debug[0]["function"]==__FUNCTION__){
return true;
}
return false;
}
安装zsh
brew install zsh
设置zsh为默认shell
mate /etc/shells
在文末增加:
/usr/local/bin/zsh
将zsh设置为默认的Shell:
@dcb9
dcb9 / solved-angularjs-chromedriver-could-not-find
Last active August 29, 2015 14:11
学习Angularjs的时候运行 e2e 的时候,无法找到chromedriver.exe 在Mac OS X 中的解决办法
[launcher] Error: Could not find chromedriver at /Users/bob/Documents/github/angular-phonecat/node_modules/protractor/selenium/chromedriver.exe
npm ERR! angular-phonecat@0.0.0 protractor: `protractor test/protractor-conf.js`
npm ERR! Exit status 1
# 本人是Mac OS X 的解决办法:
1. 首先去拿到 chromedriver 的下载URL:https://code.google.com/p/chromedriver/downloads/list
2. 打开txt 中的路径,下载最新的 chromedriver,并解压。
3. 把解压出来的 chromedriver 命令复制到相应目录下并重命名 chromedriver.exe
$ cp -a ~/Downloads/chromedriver ~/Documents/github/angular-phonecat/node_modules/protractor/selenium/chromedriver.exe
@dcb9
dcb9 / yii2-reset-password.php
Created December 31, 2014 04:22
yii2 给用户重新设置密码的步骤
use common\models\User;
$user = User::findOne($user_id);
$user->setPassword($your_password);
$user->generateAuthKey();
$user->save();
@dcb9
dcb9 / gist:72da5e8412dfd97cff99
Created January 8, 2015 03:25
查看与 GitHub 服务器连接的信息
 ~/ ssh -vT git@github.com
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/bob/.ssh/config
debug1: /Users/bob/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to github.com [192.30.252.129] port 22.
debug1: Connection established.
debug1: identity file /Users/bob/.ssh/id_rsa type 1
debug1: identity file /Users/bob/.ssh/id_rsa-cert type -1
@dcb9
dcb9 / use_Yii2_createObject.php
Created January 10, 2015 06:08
Yii2 独立使用是验证器
$news_id = 1;
$existValidator = Yii::createObject([
'class' => '\yii\validators\ExistValidator',
'targetClass' => '\common\models\News',
'targetAttribute' => 'id',
]);
if( ! $existValidator->validate($news_id, $error)){
var_dump($error);
<?php
# filepath src/
class MyArray
{
public static function sumCountByIdentity($items, $identityKey, $countKey){
$tmp = $newItems = [];
foreach($items as $row){