开发拾遗
python unicode字符串转成中文
s = 'u6d4bu8bd5u957fu5ea6'
s = s.replace('u', '\u')
print s.decode('unicode-escape')
php 二进制直接量
$bin = bindec('110011');
$bin = 0b110011;
php foreach list
$arr = [
[1, 2],
[3, 4],
];
foreach ($arr as list($a, $b)) {
echo $a.$b\n";
}
PHP ==和隐式转换
var_dump(md5('240610708') == md5('QNKCDZO'));// true 两个字符串恰好以0e 的科学记数法开头,字符串被隐式转换为浮点数,也就等效于0×10^0
var_dump(sha1('aaroZmOk') == sha1('aaK1STfY'));// true
var_dump('0x1234Ab' == '1193131');// true 0x1234Ab转为16进制,php7无此bug
var_dump( 0 == "a" );// true
var_dump( "0" == "a" );// true
== 、switch、in_array 的松比较
// 如果 $name 值为 0,那么它会满足任何一条 case
switch ($name) {// 使用switch (strval($name)) {
case "danny":
break;
case "eve":
break;
}
$needle = '1abc';
$haystack = array(1,2,3);
var_dump(in_array($needle, $haystack);// true
javascript Date对象的浏览器兼容性问题
// chrome同时支持'-'和'/'分割日期的时间字符串;safari不支持'-'分割日期的时间字符串
var arr = "2010-03-15 10:30:00".split(/[- / :]/),
date = new Date(arr[0], arr[1]-1, arr[2], arr[3], arr[4], arr[5]);
javascript 模拟Object.keys()
function keys(obj){
var a = [];
for(a[a.length] in obj);
return a;
}
javascript数组去重
function dedupe(array){
return Array.from(new Set(array));
}
dedupe([1,1,2,3]) //[1,2,3]
工具
// 命令行提示tldr npm install -g tldr
octotree 是一款可为 GitHub 和 GitLab 添加侧边栏文件导航的 Chrome 和 Opera 插件
python下载视频工具
Sublime Text3 汉化
// Package Control:Install Package,输入Chinese,选择ChineseLocalization
javascript reduce
arr = [1,2,3,4,5]
arr.reduce(function(a,b){
return a10+b;
});//12345
var result = [1, 2, 3, 4, 5].reduce(function(prev, curr, index, array){
debugger;
prev.push(curr 2);
return prev;
}, []);
console.log(result);//[2, 4, 6, 8, 10]
//求最大值
var max = arr.reduce(function(pre,cur,inde,arr){return pre>cur?pre:cur;});
var arr = [ {name: 'brick1'}, {name: 'brick2'}, {name: 'brick3'} ]
function carryBricks(arr){
return arr.reduce(function(prev, current, index, array){
if (index === 0){
return current.name;
}
else if (index === array.length - 1){
return prev + ' & ' + current.name;
}
else {
return prev + ', ' + current.name;
}
}, '');
}//brick11, brick12 & brick13
//去重
var arr = [1, 3, 1, 'x', 'zz', 'x', false, false];
var result = arr.reduce(function(prev, curr, i, array) {
var flag = prev.every(function(value) {
return value !== curr;
});
flag && prev.push(curr);
return prev;
}, []);
console.log(result);
jquery插件
输入提示自动完成插件tokeninput
tablesorter 表格排序
Date.js执行日期/时间的计算
图片裁剪
日期选择插件pickadate.js
javascript刻度条插件
0.1+0.2
Math.round( (.1+.2)*100)/100; //0.3
mysql分解联合查询
select * from teacher
join school on teacher.id = school.id
join course on teacher.id = course.id
where course.name= 'english'
分解后
select from course where name = 'english'
select from school where course_id = 1
select * from teacher where school_id in (1,2,3)
字符串中每个字母重复出现的次数
var temp = {};
'abcdaabc'.replace(/(\w{1})/g,function($1){
temp[$1] ? temp[$1]+=1 : temp[$1] = 1;
})
console.log(temp) // {a: 3, b: 2, c: 2, d: 1}
composer
PHP HTTP请求套件
实现 Laravel 模型的无限极分类
php一维数组 转 多维数组
$arr = ['a', 'b', 'c', 'd'];
$child = array();
$res = [];
while($v = array_pop($arr)) {
$res = [$v => $child];
$child = $res;
}
python中字符串的按位或
a = "1000111000"
b = "1000000001"
c = int(a, 2) | int(b, 2)
print('{0:b}'.format(c))# 1000111001
python生成斐波拉契数列
def fib(max):
n, a, b = 0, 0, 1
while n
php正则匹配
$str="{a:1,b:2,c:3}";
preg_match_all('/(\w+):(\d+)/', $str, $matches);
$arr = array_combine($matches[1], $matches[2]);# ['a'=>1,'b'=>2,'c'=>3]
php max/min
max(ceil(-0.5), 0) # -0.0
max(0, ceil(-0.5)) # 0
NaN
.isNaN = function(obj){
return .isNumber(obj) && obj !==+obj;
};
Mysql 用 一张表中的数据更新另一张表的数据
update tableA as ca inner join tableB as cb set ca.thumbs=cb.thumbs where cb.courseid=1;
24.php后期静态绑定
class A {
public static function get_self() {
return new self();
}
public static function get_static() {
return new static();
}
}
class B extends A {}
get_class(B::get_self());//A
get_class(B::get_static()) //B
get_class(A::get_static());//A
json_encode输出动态javascript
$images = array( 'myself.png' , 'friends.png' , 'colleagues.png' );
$js_code = 'var images = ' . json_encode($images);
echo $js_code; // var images = ["myself.png","friends.png","colleagues.png"]
String.fromCharCode
var regex_num_set = /&# (\d+);/g;
var str = "Here is some text: 每日一色|蓝白~"
str2 = str.replace(regex_numset, function(, $1) {
return String.fromCharCode($1);
});//"Here is some text: 每日一色|蓝白~"
https://segmentfault.com/a/1190000002784965
http://joebon.cc/date-cross-browser-safari-chrome
https://segmentfault.com/a/1190000005116655
https://segmentfault.com/q/1010000005070166
http://t.cn/RqgIMWa
http://t.cn/h4tDfg
http://www.w3cfuns.com/notes/17398/665aaba7dd0045950b750af582b61b64.html
关键字:php, Python, mysql, linux
版权声明
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处。如若内容有涉嫌抄袭侵权/违法违规/事实不符,请点击 举报 进行投诉反馈!