profile配置

1
2
3
4
5
6
7
8
9
PS1='[\u@\H] \W \[\033[012;36m\]\$\[\033[00m\] '

export LS_OPTIONS='--color=auto' # 如果没有指定,则自动选择颜色
export CLICOLOR=1 #是否输出颜色
# export LSCOLORS='Exfxcxdxbxegedabagacad'
export LSCOLORS='dxfxcxdxgxegedabagacad'

alias ll='ls -l'
alias lal='ls -al'

MAC解压pkg文件

1
2
xar -xf Setup.pkg
cat ./Payload | cpio -i

cpio用法

cpio 指令可以将文件复制到 存档包(archives),也可以从存档包(archives)复制出文件。缺省情况下,cpio从标准输入读取输入数据,向标准输出写入输出数据。

阅读更多

docker笔记

docker操作

docker run

-i 标志保证容器中STDIN是开启的 -t创建的容器分配一个伪tty终端

docker run --name bob_the_container -i -t ubuntu /bin/bash

创建守护式容器

docker run --name daemon_dave -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done"

docker start | stop | restart | rm | rmi

批量删除镜像或者容器

删除全部标签为none的镜像

1
docker rmi `docker images -a | awk '/^<none>/ { print $3 }'`

删除除某个容器ID外的其他容器

1
docker rm `docker ps -a -q | awk '!/81df01422b69/'`

docker attach

重新回到了容器的Bash提示符

docker attach bob_the_container

阅读更多

MAC安装Pygame

  1. 安装pygame依赖包:brew install hg sdl sdl_image sdl_ttf,如果想启动更高级的功能,如在游戏中包含声音,可安装下面的两个额外的库:brew install sdl_mixer portmidi
  2. 安装Pygame:pip3 install --user hg+http://bitbucket.org/pygame/pygame,如果报错可以尝试:pip3 install pygame
  3. 验证 Pygame 是否安装成功,可以启动一个Python终端,输入:import pygame

MAC安装MongoDB

下载安装

  1. curl -O https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-4.0.5.tgz 或者 官网下载tar包
  2. 解压 tar -zxvf mongodb-osx-ssl-x86_64-4.0.5.tgz
  3. 重命名 mv ./mongodb-osx-ssl-x86_64-4.0.5.tgz ./mongodb
  4. 移动到合适位置 sudo mv ./mongodb /usr/local/opt/
  5. 在.bashrc文件添加 export PATH=/usr/local/opt/mongodb/bin:$PATH

brew安装

  • sudo brew install mongodb
  • sudo brew install mongodb --with-openssl // 要安装支持 TLS/SSL 命令
  • sudo brew install mongodb --devel // 安装最新开发版本

阅读更多

用vscode开发golang

首先配置GOPATH

GOPATH允许多个目录,当有多个目录时,请注意分隔符,多个目录的时候Windows是分号;,Linux系统是冒号:,当有多个GOPATH时默认将go get获取的包存放在第一个目录下,在开发的gopath中写代码,使用go工具(go install, go build) 会将二进制包安装到开发的gopath中

GOPATH目录约定有三个子目录

  • src存放源代码(比如:.go .c .h .s等)
  • pkg编译时生成的中间文件(比如:.a)
  • bin编译后生成的可执行文件(为了方便,可以把此目录加入到 $PATH 变量中,如果有多个gopath,那么使用${GOPATH//://bin:}/bin添加所有的bin目录)

阅读更多

postgres触发器

触发器的创建语法

1
2
3
4
5
6
7
8
CREATE [CONSTRAINT] TRIGGER name 
{ BEFORE | AFTER | INSTEAD OF } { event [ OR ...] }
ON table_name
[ FROM referenced_table_name ]
{[ NOT DEFERRABLE ][ DEFERRABLE ]{[ INITIALLY IMMEDIATE ][ INITIALLY DEFERRED]}}
[ FOR [ EACH ] { ROW | STATEMENT } ]
[ WHEN (condition) ]
EXECUTE PROCEDURE function_name ( arguments )

阅读更多

php设计模式

适配器模式

适配器设计模式只是将某个对象的接口适配为另外一个对象所期望的接口

当添加新功能时,功能要求采用不同的方式使用现有的对象,而不是采用远行设计的方式,可以采用适配器模式构建另一个对象的方案。

同时,适配器设计模式也是针对数据源改变的优秀解决方案,常见有改变数据库引擎第三方提供数据格式变化

关系说明

  1. MyObject类包含一个名为 methodA()的公共方法。OriginalConsumer类获取MyObject的一个实例,并且在执行其doSomthing()函数期间调用methodA()
  2. 引入NewConsumer类。这个类的doSomthing( )函数在执行期间期望调用MyObject实例的一个公共方法: methodB()
  3. 通过扩展MyObject类创建MyObjectAdapterForNewConsumer类。像NewConsumer期望的样,新创建的类会提供名为methodB()的公共方法。在这个简单的示例中,所有methodB()都会调用methodA()

阅读更多

markdown添加目录

基于GitHub项目:https://github.com/ekalinin/github-markdown-toc

  1. 安装执行文件
1
2
3
wget https://raw.githubusercontent.com/ekalinin/github-markdown-toc/master/gh-md-toc
// curl -O https://raw.githubusercontent.com/ekalinin/github-markdown-toc/master/gh-md-toc
chmod a+x gh-md-toc
  1. 生成目录输出到命令行
1
2
3
4
5
6
7
8
9
10
11
./gh-md-toc ~/README.md

Table of Contents
=================

* [Dockerfile.vim](#dockerfilevim)
* [Screenshot](#screenshot)
* [Installation](#installation)
* [OR using Pathogen:](#or-using-pathogen)
* [OR using Vundle:](#or-using-vundle)
* [License](#license)

mac下php版本切换

brew安装php-version

1
2
3
4
5
6
7
# brew install php56
# brew install php70
# brew install php-version
# source $(brew --prefix php-version)/php-version.sh

# php-version
# php-version 5.6.5

php开机启动

1
2
3
4
# mkdir -p ~/Library/LaunchAgents
# cp /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/
# launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
# launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

切换本机php版本

1
2
3
// 先确认phpinfo里面的php版本,先卸载5.6的plist,在加载7.1的plist
# launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
# launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist