class MyClass {
private $data;
private function __construct($data) {
$this->data = $data;
}
public static function run($data) {
return (new static($data))->callfun();
}
private function callfun() {
return $this->lookup($this->data);
}
private function lookup($data) {
return $data;
}
}
用 collection 重构代码
安装
composer require illuminate/support
Laravel 框架已经自带此组件
引用
require 'vendor/autoload.php';
map
$array = [];
$collection = collect($array)->map(function($item) {
return $item;
});
linux 中安装 nodejs
安装 nvm
需要有
curl
程序支持,请先安装。
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.4/install.sh | bash
# 安装全后要重新打开新会话
arch/manjaro 安装 nvm
yay -S nvm
echo "source /usr/share/nvm/init-nvm.sh" >> ~/.bashrc
echo "source /usr/share/nvm/init-nvm.sh" >> ~/.zshrc
使用 nvm 安装 node
# 安装最新版
nvm install node
# 安装 v16
nvm install v16
# 查看所有可安装版本
nvm ls-remote
# 查看已安装版本
nvm ls
继续阅读 composer 安装 laravel 和 lumen
laravel 6.0
- PHP >= 7.2.0
- BCMath PHP 拓展
- Ctype PHP 拓展
- JSON PHP 拓展
- Mbstring PHP 拓展
- OpenSSL PHP 拓展
- PDO PHP 拓展
- Tokenizer PHP 拓展
- XML PHP 拓展
composer global require "laravel/installer"
// 创建新项目,blog是项目名(文件夹名)
composer create-project --prefer-dist laravel/laravel blog "6.0.*"
lumen
composer global require "laravel/lumen-installer"
lumen new blog
或
composer create-project --prefer-dist laravel/lumen blog
oh-my-zsh 安装和配置方法
安装 zsh
$ sudo apt install zsh
安装 oh-my-zsh
$ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
禁用 history 共享
让每个窗口的 history 相互隔离,方便用光标键选择。
打开 ~/.oh-my-zsh/lib/history.zsh
,注释掉这一行: setopt share_history
继续阅读官网: http://ohmyz.sh/
ubuntu 终端利用 proxychains 实现科学上网
安装proxychains
sudo apt install proxychains
配置proxychains
编辑 /etc/proxychains.conf
,最下面有一行 socks4 127.0.0.1 9050
,把这一行注释掉,添加一行 socks5 127.0.0.1 1080
。
Js 数组——filter()、map()、some()、every()、forEach()、lastIndexOf()、indexOf()
filter()
语法:
参数说明:
callback: 要对每个数组元素执行的回调函数。
thisObject : 在执行回调函数时定义的this对象。
//过滤掉小于 10 的数组元素:
//代码:
function isBigEnough(element, index, array) {
return (element >= 10);
}
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);
// 12, 130, 44
//结果:[12, 5, 8, 130, 44].filter(isBigEnough) : 12, 130, 44
功能说明:
对数组中的每个元素都执行一次指定的函数(callback),并且创建一个新的数组,该数组元素是所有回调函数执行时返回值为 true 的原数组元素。它只对数组中的非空元素执行指定的函数,没有赋值或者已经删除的元素将被忽略,同时,新创建的数组也不会包含这些元素。
回调函数可以有三个参数:当前元素,当前元素的索引和当前的数组对象。
如参数** thisObject** 被传递进来,它将被当做回调函数(callback)内部的 this 对象,如果没有传递或者为null,那么将会使用全局对象。
filter 不会改变原有数组,记住:只有在回调函数执行前传入的数组元素才有效,在回调函数开始执行后才添加的元素将被忽略,而在回调函数开始执行到最后一个元素这一期间,数组元素被删除或者被更改的,将以回调函数访问到该元素的时间为准,被删除的元素将被忽略。
linux 下更新字体缓存
fc-cache -fv
ubuntu中创建程序为自启动
#!/bin/bash
### BEGIN INIT INFO
# Provides: appname
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: appinfo
# Description: appinfo
### END INIT INFO
bin="/home/user/app"
start(){
ps -ef | grep $bin | grep -v grep > /dev/null
if [ $? -eq 0 ]; then
echo "The Service has started."
else
echo -n "Starting..."
$bin 1>/dev/null 2>/dev/null &
echo "Done!"
fi
}
stop(){
ps -ef | grep $bin | grep -v grep > /dev/null
if [ $? -eq 0 ]; then
echo -n "Stoping..."
killall $bin
echo "Done!"
else
echo "The service did not start."
fi
}
case $1 in
start)
start
;;
stop)
stop
;;
status)
ps -ef | grep $bin | grep -v grep > /dev/null
if [ $? -eq 0 ]; then
echo "The service is running."
else
echo "The service is not running."
fi
;;
*)
echo "Usage: $0 {start|stop|status}"
;;
esac
脚本放在 /etc/init.d/
目录下,添加 执行 权限。
# 添加到服务
sudo systemctl enable app # app 是服务文件名
# 启动服务
sudo service app start
ubuntu 安装 gnome3
安装之前先添加库并更新,已保证后面的安装顺利。
建议在服务器版安装。utility版可以不安装gdm。
sudo add-apt-repository ppa:gnome3-team/gnome3
sudo add-apt-repository ppa:gnome3-team/gnome3-staging
sudo apt-get update
sudo apt-get dist-upgrade -y
sudo apt-get install gdm gnome-shell gnome-shell-extensions gnome-tweak-tool ubuntu-gnome-desktop