Author: jpuyy

  • 运行docker容器

    运行一个 centos 容器
    The -i and -t flags can be passed to the exec command to keep an interactive shell open, and you can specify the shell you want to attach after the container ID.

    [root@localhost ~]# docker run  -i -t centos /bin/bash
    Unable to find image 'centos:latest' locally
    latest: Pulling from library/centos
    8d30e94188e7: Pull complete 
    Digest: sha256:2ae0d2c881c7123870114fb9cc7afabd1e31f9888dac8286884f6cf59373ed9b
    Status: Downloaded newer image for centos:latest
    

    运行 docker 以 daemon 方式运行,host 开放端口 5001,对应容器内端口 5000
    The -p means “publish ports”

    docker run -d -p 5001:5000 python-flask
    

    查看信息

    docker info
    Containers: 1
     Running: 0
     Paused: 0
     Stopped: 1
    Images: 1
    

    查看容器列表

    docker ps -a
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
    ebf5f9bf4bc9        centos              "/bin/bash"         16 minutes ago      Exited (0) 7 minutes ago                       furious_leakey
    

    查看 docker 运行的 log

    docker logs  furious_leakey

    探测 docker 更详尽信息,json 输出

    docker inspect furious_leakey

    退出后的容器是 stopped 状态,现在根据名字 furious_leakey 启动它

    docker start furious_leakey

    通过 shell 进入到容器中

    docker attach furious_leakey

    上面运行的容器是交互式容器

    docker工作目录在

    /var/lib/docker/

    容器存放在

    /var/lib/docker/containers

    删除所有 docker 容器

    docker rm `docker ps -a -q`

    进入到运行中的 docker

    docker exec -i -t 82d98bdf2d77046ce52a61f2bab27465db868a97faebe94a83581fc0322e4c26 /bin/bash

    docker ps 只显示容器名

    docker ps -a --format '{{ .Names }}'
    

    docker 及对应的所有 ip

    docker inspect --format='{{.Name}} - {{range .NetworkSettings.Networks}} {{.IPAddress}} {{end}}' $(docker ps -aq)
    
  • centos7 docker 安装

    在 centos7 下,安装

    curl -s https://get.docker.com/ | sh

    启动并设置开机启动

    systemctl start docker.service
    systemctl enable docker.service
    

    检查 docker 状态

    docker info
    systemctl status docker
  • 身份证号构成

    18位身份证号码

    第7、8、9、10位为出生年份(四位数)
    第11、第12位为出生月份
    第13、14位代表出生日期
    第17位代表性别,奇数为男,偶数为女。
  • nodejs

    node 04
    Modules
    Semantic Versioning
    version patch
        “connect”: “~2.2.1”,
        “underscore”: “~1.3.3”
    node 03
    streams
    curl –upload-file abc.jpg http://localhost:3000
    node 01
    fs.readFileSync
    fs.readFile(‘/etc/hosts’, function(){});
    setTimeout(function(){ console.log(“here we go”)}, 5000); // 等 5000ms 再运行 function
    non-blocking
    epxress 05
    route instances
    app.route()
    chaining function
    single application file is too long
    extracting routes to modules
    var router = express.Router();
    set router as a express module
    module.exports = router;
    var router = express.Router();
    router.route(‘/’);
    app.use(‘/cities’, router);
    router.route(‘/’)
      .get(function (request, response) {
        if(request.query.search){
          response.json(citySearch(request.query.search));
        }else{
          response.json(cities);
        }
      })
      .post(parseUrlencoded, function (request, response) {
        if(request.body.description.length > 4){
          var city = createCity(request.body.name, request.body.description);
          response.status(201).json(city);
        }else{
          response.status(400).json(‘Invalid City’);
        }
      });
    router.route(‘/:name’)
      .get(function (request, response) {
        var cityInfo = cities[request.cityName];
        if(cityInfo){
          response.json(cityInfo);
        }else{
          response.status(404).json(“City not found”);
        }
      })
      .delete(function (request, response) {
        if(cities[request.cityName]){
          delete cities[request.cityName];
          response.sendStatus(200);
        }else{
          response.sendStatus(404);
        }
      });
    What function would you call to match all HTTP verbs?
    app.all()
    express 04
    post & delete
    body-parser
    app.delete(‘/blocks/:name’, function(request, response){});
    response.sendStatus(200);
    express 03
    handle routes
    response.json();
    /blocks?limit=1
    use request.query to access query strings
    blocks.slice(1, 3)  from 1 , 3 items
    response.status(404).json(‘No description found for ‘ + request.params.name)
    maps placeholders to callback functions, and is commonly used for running pre-conditions on Dynamic Routes
    app.param(‘name’, function(request, response, next){
    });
    javascript
    array ->   blocks = [‘Fixed’, ‘Movable’, ‘Rotating’];
    object ->  blocks = {
        ‘Fixed’: ‘description 1’,
        ‘Movable’: ‘description 2’,
        ‘Rotating’: ‘description 3’
    }
    for object , use Object.keys(blocks) get all keys of objects.
    express 02
    response.sendFile(__dirname + ‘/public/index.html’);
    express 的 static middleware
    middleware 用于检验,认证,数据解析
    app.use(express.static(‘public’));
    当调用一个 middleware ,可以加一个 next 调用下一个 middleware
    app.use(function(request, response, next) {
        next();
    });
    到最后一个 middleware,没有 next 则响应一个 done
    app.use(function(request, response, next){
        response.send(‘done!’);
    });
    express 使用 ajax 返回
    express 01
    安装 node 并指定版本
    npm install [email protected]
    response.send();
    blocks = [“a”, “b”, “c”];
    response.send(blocks);
    curl 查看 header 会发现自动解析成 json
    等同于
    response.json(blocks);
    302跳转
    response.redirect(‘/parts’);
    301跳转
    response.redirect(301, ‘/parts’);
  • git notes

    level 6

    rebase

    git fetch只获取,并不合并

    本地与远端使用git rebase
    git rebase进行了三步操作

    把所有master的改变放到一个临时区域里面

    运行所有origin/master的提交

    运行在临时区域的commits

    本地两个分支间的rebase,master和  develop均有提交

    在develop分支下,

    git rebase master

    然后再git checkout master

    把develp合并过来

    git merge develop

    conflicts本地master和远端origin/master都修改了同一个文件,并在本地提交

    解决冲突

    在master上git fetch

    然后git rebase,这样保证在master上有最新的代码

    这里会提示有冲突

    当解决了问题,则用git rebase –continue

    level 7

    git log
    sha hash

    git config –global color.ui true

    git log –pretty=oneline

    git log –oneline –stat

    当前分支与 master 的区别

    git log --oneline  ...master
    

    git log -p 查看具体的改变

    git diff  == git diff HEAD
    git diff HEAD^

    git diff HEAD~5
    git diff HEAD^..HEAD

    git diff sha..sha
    git diff master develop

    对于单个文件一直以来的变化
    git blame index.html –date short
    git status 看到有不想提交的,则在 .git/info/exclude 把文件过滤掉

    .gitignore
    git 删除文件
    git rm README.txt
    在 system 中不会被删除,但在 git 中会删除
    git rm –cached development.log

    mac 指定 merge 工具

    git config --global merge.tool opendiff
    git config --global alias.st status 来设置 status 的别名
    

    level 4

    git push rejected
    

    首先git pull

    pull的动做细分

    git fetch到origin/master

    将origin/master合并到本地  master

    git merge origin/master

    现在再push

    conflict

    必须手动解决

    level 1

    查看staged文件做了哪些改动

    git diff –staged

    在提交的同时进行添加

    git commit -a -m “add index”

    将修改的文件恢复

    git checkout — cats.html index.html

    level 2

    undo上一次提交,并将改变放到 staging 中

    git reset --soft HEAD^

    只修改上一次的提交

    git commit --amend -m "New Message"
    

    undo 上一次的提交和修改,你的修改会丢失

    git reset --hard HEAD^

    undo 上两次的提交和修改

    git reset --hard HEAD^^

    git reset HEAD ostrich.html

    查看远端的 fetch 及 push地址
    git remote -v

    git remote add <name> <address>

    删除远端 repo
    git remote rm <name>

    git push -u origin master

    origin是远端 repo 的名字, master 是本地分支的名字

    设置 git config user

    git config --global --edit
    #全局配置在 ~/.gitconfig
    [user]
        name = myusername
        email = [email protected]
    
    当前项目配置在
    .git/config
    

    想要保存一个空目录时,一般添加一个空文件.gitkeep,比如

    secrets/.gitkeep

    macOS 自动保存到 keychain

    git config --global credential.helper osxkeychain
    
  • nginx 499 原因

    Content-Length field missed