诚实的小猴子

Hey man, just code it!!!


  • 首页

  • 归档

  • 标签

  • 关于
诚实的小猴子

Doctrine数据类型映射关系

发表于 2016-11-21
  • string: Type that maps a SQL VARCHAR to a PHP string.

  • integer: Type that maps a SQL INT to a PHP integer.

  • smallint: Type that maps a database SMALLINT to a PHP integer.

  • bigint: Type that maps a database BIGINT to a PHP string.

  • boolean: Type that maps a SQL boolean or equivalent (TINYINT) to a PHP boolean.

  • decimal: Type that maps a SQL DECIMAL to a PHP string.

  • date: Type that maps a SQL DATETIME to a PHP DateTime object.

  • time: Type that maps a SQL TIME to a PHP DateTime object.

  • datetime: Type that maps a SQL DATETIME/TIMESTAMP to a PHP DateTime object.

  • datetimetz: Type that maps a SQL DATETIME/TIMESTAMP to a PHP DateTime object with timezone.

  • text: Type that maps a SQL CLOB to a PHP string.

  • object: Type that maps a SQL CLOB to a PHP object using serialize() and unserialize()

  • array: Type that maps a SQL CLOB to a PHP array using serialize() and unserialize()

  • simple_array: Type that maps a SQL CLOB to a PHP array using implode() and explode(), with a comma as delimiter. IMPORTANT Only use this type if you are sure that your values cannot contain a ”,”.

  • json_array: Type that maps a SQL CLOB to a PHP array using json_encode() and json_decode()

  • float: Type that maps a SQL Float (Double Precision) to a PHP double. IMPORTANT: Works only with locale settings that use decimal points as separator.

  • guid: Type that maps a database GUID/UUID to a PHP string. Defaults to varchar but uses a specific type if the platform supports it.

  • blob: Type that maps a SQL BLOB to a PHP resource stream

诚实的小猴子

常用正则表达式

发表于 2016-11-21
  • 匹配汉字 /^[\x{4e00}-\x{9fa5}].+$/u

  • 用户名 /^[a-z0-9_-]{3,16}$/

  • 密码 /^[a-z0-9_-]{6,18}$/

诚实的小猴子

Git中的AutoCRLF与SafeCRLF

发表于 2016-11-21

一、AutoCRLF

提交时转换为LF,检出时转换为CRLF

1
git config --global core.autocrlf true

提交时转换为LF,检出时不转换

1
git config --global core.autocrlf input

提交检出均不转换

1
git config --global core.autocrlf false

二、SafeCRLF

拒绝提交包含混合换行符的文件

1
2
3
4
5
6
git config --global core.safecrlf true   
```

允许提交包含混合换行符的文件
```bash
git config --global core.safecrlf false

提交包含混合换行符的文件时给出警告

1
git config --global core.safecrlf warn

诚实的小猴子

避免重复Ajax提交

发表于 2016-11-21

之前在做网站的时候,采用如下代码进行ajax提交,在访客点击的时候请求如果没有及时得到服务器的响应,会尝试反复点击造成重复提交

1
2
3
4
5
6
7
8
9
10
11
12
$(function(){
$('selector').bind('click', function(){
$.ajax({
type : 'POST',
url : 'requestURL',
dataType : 'json',
success : function(res) {

}
});
})
});

为了避免重复提交,将代码改成如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$(function(){
$('selector').bind('eventType', function(){
var thisFunc = arguments.callee,
self = $(this);
self.unbind('click', thisFunc); //一次请求解绑事件监听函数
$.ajax({
type : 'POST',
url : 'requestURL',
dataType : 'json',
success : function(res) {
self.bind('click',thisFunc); //请求完成再次绑定事件监听函数
}
});
})
});
诚实的小猴子

几个面试题

发表于 2016-11-21

1、编写一个函数将1,2,3,4,5,6随机放到一个数组,3不能在第三的位置,5和6不能挨着。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
function sort_test($array)
{
while (true) {
shuffle($array);
$temp = array_flip($array);
if ($array[2] != 3 && 1 != abs($temp[5] - $temp[6])) {
return $array;
}
}
}

$array = array(1, 2, 3, 4, 5, 6);
print_r(sort_test($array));

2、编写一个函数实现 将字符串$str=”asdfasflasdfopafdsa”, 中第一个之出现过一次的字母。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
function get_target_letter($str)
{
$i = 0;
$array = array();
while (isset($str[$i])) {
$array[$str[$i]] = isset($array[$str[$i]]) ? $array[$str[$i]] + 1 : 1;
$i++;
}
foreach ($array as $key => $val) {
if ($val == 1) {
return $key;
}
}
return false;
}

echo get_target_letter('asdfastflasdfopafdsa');

3、有两个表,请编写一条sql语句查询出t1-t2时间段间的产品名、销售量总数并按照销售量总数由高到低排序。

1
2
3
4
5
6
7
8
9
CREATE TABLE products (
product_id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
product_name VARCHAR(64) NOT NULL
);
CREATE TABLE orders (
product_id INT UNSIGNED NOT NULL ,
create_at INT UNSIGNED NOT NULL,
num INT UNSIGNED NOT NULL
);

我的解法:

1
2
3
4
5
6
7
8
9
10
SELECT
products.product_name,
number.num
FROM ((SELECT
product_id,
sum(num) AS num
FROM orders
WHERE orders.create_at BETWEEN {$t1} AND {$t2}
GROUP BY product_id) AS number) INNER JOIN products ON products.product_id = number.product_id
ORDER BY number.num DESC;
1…678
诚实的小猴子

诚实的小猴子

36 日志
31 标签
© 2019 诚实的小猴子
由 Hexo 强力驱动
主题 - NexT.Mist