Skip to content

Instantly share code, notes, and snippets.

View sword-jin's full-sized avatar
:atom:

Sword sword-jin

:atom:
View GitHub Profile
@sword-jin
sword-jin / readme.php
Last active September 14, 2015 11:35
PHP Cookbook Number
// 判断数字类型
is_numeric()
is_int() is_integer() is_long()
is_float() is_real() is_double()
// 求绝对值
abs()
// 进一,去整,四舍五入
float round ( float $val [, int $precision = 0 [, int $mode = PHP_ROUND_HALF_UP ]] )
@sword-jin
sword-jin / index.php
Last active September 14, 2015 14:47
PHP CookBook Array
// 让索引数组从0开始
$presidents = array(1 => 'Washington', 'Adams', 'Jefferson', 'Madison');
// 使用 while list each 遍历数组
while(list($key, $value) = each ($arrays)) {
//
}
// 删除数组元素
unset()
@sword-jin
sword-jin / index.php
Last active September 14, 2015 15:14
PHP Cookbook variable , function
// You don't want to accidentally assign values when comparing a variable to a constant.
Use:
if (12 == $a) {}
instead of:
if ($a == 12) {}
// You want to assign a default value to a variable that doesn't already have a value.
$cars = isset($_GET['cars']) ? $_GET['cars'] : $default_cars;
$cars = array_key_exists('cars', $_GET) ? $_GET['cars'] : $default_cars;
@sword-jin
sword-jin / see.php
Created September 27, 2015 02:41
see() 来源
protected function see($text, $element= 'body')
{
$crawler = $this->client->getCrawler();
$found = $crawler->filter("{$element}:contains('{$text}')");
$this->assertGreaterThan(0, count($found), "Excepted to see {$text} with view");
}
@sword-jin
sword-jin / setUp.php
Created September 27, 2015 04:39
测试IoC 使用Mockery
public function setUp()
{
parent::setUp();
$this->task = Mockery::mock('Acme\TaskReponsitoryInterface');
App::instance('Acme\TaskReponsitoryInterface', $this->task);
}
@sword-jin
sword-jin / create_object.js
Created October 2, 2015 09:37
js 的创建对象之一
var human = {
species: "human",
create: function(values) {
var instance = Object.create(this);
Object.keys(values).forEach(function(key) {
instance[key] = values[key];
});
return instance;
},
@sword-jin
sword-jin / speeds.js
Last active October 4, 2015 09:24
jQuery 自定义动画
// 自定义时间
jQuery.fx.speeds = {
slow: 600,
fast: 200,
// Default speed
_default: 400
};
// 修改时间
$.fx.speeds._default = 500;
@sword-jin
sword-jin / simple-template.html
Created October 5, 2015 07:18
jQuery 的简单模版
<body>
<script id="blogTemplate" type="app/template">
<h2> {{title}} </h2>
<img src="{{thumbnail}}" alt="{{title}}"/>
</script>
<script>
(function($) {
var content = [
@sword-jin
sword-jin / cf.css
Created October 7, 2015 17:21
清楚浮动
.cf:before,
.cf:after {
content: ' ';
display: table;
}
.cf:after {
clear: both;
}
@sword-jin
sword-jin / tree.php
Created October 15, 2015 04:12
write a tree mock.
<?php
function makeTree($arr) {
$result = '';
foreach ($arr as $key => $value) {
$result .= '<li>' . (is_array($value) ? ($key . makeTree($value)) : $value) . '</li>';
}