邢栋博客
邢栋博客,Action博客,记录工作和生活中的点点滴滴
golang 数组删除元素
package main import "fmt" func main(){ a := []int{0,1,2,3,4,5,6,7,8,9} //a = a[1:]//删除开头的第一个元素 unset 0 //a = a[3:] //删除开头的前3个元素 unset 0 1 2 //a = append(a[:0],a[1:]...) //删除开头的第一个元素,不移动数据指针,将后面的数据向开头移动 //a = append(a[:0],a[3:]...) //删除开头的前3个元素,不移动数据指针,将后面的数据向开头移动 //使用copy //a = a[:copy(a,a[1:])] //删除开头第一个元素 //a = a[:copy(a,a[3:])] //删除开头前3个元素 //从中间位置删除 //a = append(a[:3],a[4:]...)//删除索引为3的数据 unset[3] //a = append(a[:3],a[5:]...)//删除索引大于等于3且小于5的数据 unset[3 4] //从尾部删除 //a = a[:len(a)-1] //删除最后一个元素 9 //a = a[:len(a)-3] //删除最后的3个元素 9 8 7 fmt.Println(a) }
[golang]map的value赋值和遍历赋值
1、=========map的value赋值=========
package main import "fmt" type Student struct { Name string } var list map[string] Student //map的Value赋值 func main() { list = make(map[string] Student) student := Student{"action"} list["student"] = student //list["student"].Name = "xd" //错误 cannot assign to struct field list["student"].Name in map tempStudent := list["student"] tempStudent.Name = "xd" list["student"] = tempStudent fmt.Println(list["student"]) }
2、=========map的遍历赋值=========
package main import "fmt" type People struct { Name string Age int } //map的遍历赋值 func main() { //定义map list := make(map[string] *People) //定义student数组 peoples := []People{ {Name: "zhou", Age: 24}, {Name: "li", Age: 23}, {Name: "xing", Age: 22}, } //遍历结构体数组,依次赋值给map for i:=0;i<len(peoples);i++{ list[peoples[i].Name] = &peoples[i] } //打印map for k,v := range list{ fmt.Println(k,"=>",v.Name) } }
抢红包之二倍均值法
/** * 二倍均值法 * * @param $nums //分配人数 * @param $money //分配金额 * @return array */ function assignRedBag($nums,$money){ $result = [];//分配结果 $surplusMoney = $money;//剩余金额 for ($i=0;$i<$nums;$i++){ //最后一次分配,直接返回剩余金额 if($i+1 == $nums){ $result[] = $surplusMoney; break; } //每次分配的最大值,剩余金额 / 剩余分配人数 * 2倍 $max = intval($surplusMoney / ($nums - $i) * 2); //随机分配 $nowMoney = mt_rand(1,$max); //存入分配结果 $result[] = $nowMoney; //计算剩余money $surplusMoney = $surplusMoney - $nowMoney; } return $result; } echo '<pre>'; print_r(assignRedBag1(10,100));
Mac下使用clion调试php源码
=====第一大步安装php=====
1、安装libiconv依赖
brew install libiconv
2、安装php
wget https://www.php.net/distributions/php-7.4.22.tar.gz
tar -zxvf php-7.4.22.tar.gz
cd php-7.4.23
./configure --prefix=/Users/action/soft/php7 --with-config-file-path=/Users/action/soft/php7/etc --with-iconv =/usr/local/opt/libiconv --enable-debug
make
make install
ps:: 安装路径自己指定就好,iconv的路径写安装路径
如果再编译过程中报错且和iconv相关,查看文章末尾pkg-config相关内容,否则直接忽略
=====第二大步使用clion=====
1.==导入项目==
New CMake Project from Sources -> import as a new CMake project
2.==编辑CMakeLists.txt==
内容如下 (根据自己的路径来)
set(PHP_SOURCE /Users/action/code/source_code/php-7.4.22)
include_directories(${PHP_SOURCE}/ext/bcmath) include_directories(${PHP_SOURCE}/ext/bcmath/libbcmath/src)
......
include_directories(${PHP_SOURCE}/Zend) include_directories(${PHP_SOURCE}) add_custom_target(makefile COMMAND make && make install WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
这个时候 软件左上角会出现如下标识
3、==点击 Edit Configurations,配置如下:(配置文件路径根据自己的需要来)==
4、==然后在cli模式文件下 打个断点 sapi/cli/php_cli.c==
5、==点击右上角的debug按钮就可以进行操作了==
===================分割线=======================
====pkg-config相关====
==查看==
pkg-config --list-all
==brew安装的东西都可以直接出现在pkg-config列表里面==
export PKG_CONFIG_PATH=$(find /usr/local/Cellar -name 'pkgconfig' -type d | grep lib/pkgconfig | tr '\n' ':' | sed s/.$//)
==安装pkg-config==
wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz (下载就复制链接去手动下载)
tar -xf pkg-config-0.28.tar.gz
cd pkg-config-0.28
./configure --with-internal-glib
make
sudo make install
====php生命周期====
[docker-es]-None of the configured nodes are available
问题:
springboot连接我用docker启动的es服务时报错,None of the configured nodes are available
解决方案:
1、先通过http://localhost:9200/查看参数cluster_name 和 springboot里配置的参数cluster_name是否一致,如果不一致,要修改成一致
2、如果通过修改cluster_name参数仍然无法解决,这时候就要看下Spring Data Elasticsearch 依赖 和 Elasticsearch的版本对应关系了
Spring Data Elasticsearch |
Elasticsearch |
3.2.x |
6.7.2 |
3.1.x |
6.2.2 |
3.0.x |
5.5.0 |
2.1.x |
2.4.0 |
2.0.x |
2.2.0 |
1.3.x |
1.5.2 |
[java]SpingBoot修改启动文字图标
1、进入 src/main/resources 目录下,新建banner.txt 文件
2、进入字母转字符串,字母转字符串 ,制作一个你想要的,然后复制到banner.txt文件中即可,再次启动就可以看到了
[java]SpringBoot启动失败(Reason: Failed to determine a suitable driver class)
原因:启动时不需要数据源加载,但加载了数据源,数据源获取失败,异常报错,启动失败。
在启动类的@SpringBootApplication加上以下代码
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) public class SpringbootEsApplication { public static void main(String[] args) { SpringApplication.run(SpringbootEsApplication.class, args); } }
[php]PHP 两个有序数组合并成一个有序数组
<?php $a = [1,3,5,7,9,11]; $b = [2,4,6,8,10]; function test_sort($a,$b){ $c = []; $aCount = count($a); $bCount = count($b); $i = $j = 0; while($i < $aCount && $j < $bCount){ if($a[$i] > $b[$j]){ $c[] = $b[$j]; $j++; }elseif($a[$i] < $b[$j]){ $c[] = $a[$i]; $i++; }else{ $c[] = $a[$i]; $c[] = $b[$j]; $i++; $j++; } } while($i < $aCount){ $c[] = $a[$i]; $i++; } while($j < $bCount){ $c[] = $a[$j]; $j++; } return $c; } function test_sort2($a,$b){ $c = []; $aCount = count($a); $bCount = count($b); $i = $j = 0; while($i < $aCount || $j < $bCount){ if($i < $aCount && $j < $bCount){ if($a[$i] > $b[$j]){ $c[] = $b[$j]; $j++; }elseif($a[$i] < $b[$j]){ $c[] = $a[$i]; $i++; }else{ $c[] = $a[$i]; $c[] = $b[$j]; $i++; $j++; } }elseif($i < $aCount && $j >= $bCount){ $c[] = $a[$i]; $i++; }elseif($i >= $aCount && $j < $bCount){ $c[] = $b[$j]; $j++; } } return $c; } $res = test_sort2($a,$b); print_r($res);