default: 27 items found.

Linux 命令:flock - 对打开的文件加锁或解锁

先来看看flock -h 的用法:

Usage:
 flock [options] <file|directory> <command> [command args]
 flock [options] <file|directory> -c <command>
 flock [options] <file descriptor number>

Options:
 -s  --shared             get a shared lock
 -x  --exclusive          get an exclusive lock (default)
 -u  --unlock             remove a lock
 -n  --nonblock           fail rather than wait
 -w  --timeout <secs>     wait for a limited amount of time
 -E  --conflict-exit-code <number>  exit code after conflict or timeout
 -o  --close              close file descriptor before running command
 -c  --command <command>  run a single command string through the shell

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see flock(1).
More ~

vue trigger button event

如下,button1 按下后想触发 button 2 的click事件,可以这样做:

<template>
    <button type="primary" @click="event2" ref="myBtn">
        button 2
    </button>
    <button type="primary" @click="event1">
        button 1
    </button>
</template>

<script>
export default {
    methods: {
        event1($event) {
            this.$refs.myBtn.$el.click()
        }
    }
}
</script>

这里注意是用this.$refs.myBtn.$el.click(),而不是this.$refs.myBtn.click()

More ~

树莓派用privoxy自动代理

首先说明下,本文是以树莓派作为客户端连接ss, 再用privoxy自动代理实现科学研究。
1 安装ss apt-get install shadowsocks-libev

2 禁用这个服务端服务 systemctl disable shadowsocks-libev

3 自动开启这个客户端连接服务 systemctl enable shadowsocks-libev-local@config

4 编辑ss的配置文件 vi /etc/shadowsocks-libev/config.json

More ~

就在刚刚,又被面试官的mysql联合索引问题问倒了

MySql经常用,但是通常就是ORM中间件来CRUD操作,很少关注索引问题,可能是我近些年很少用MySQL做大型的系统了。
现在一面试就遇到所有领域的问题来都来一个问一遍,MySQL的复合索引其实也就一知半解。

面试官的问类似于select语句里where a>100 and b=3 and c=1 能否命中创建的(a, b, c)这种索引,还有a>100能否命中这个复合索引。

我想当然就说,a>100 and b=3 and c=1 只能命令(a, b, c)这种索引, a>100不能命中。唉呀,人家笑了。我说我可能说的不对,我下来试试。好吧查资料,建表,亲自实操一把。

More ~

First start ansible on macos

I installed the ansible via pip install, and there are several issues here:

where is the config

Here you should create a file ~/.ansible.cfg

[defaults]
inventory =~/.ansible/hosts
sudo_user=root
remote_port=22
host_key_checking=False
remote_user=root
log_path=~/.ansible/log/ansible.log
module_name=command
private_key_file=~/.ssh/id_rsa
More ~

Python: 使用requests下载图片

来自最佳答案(推荐下面第一个):
You can either use the response.raw file object, or iterate over the response.

To use the response.raw file-like object will not, by default, decode compressed responses (with GZIP or deflate). You can force it to decompress for you anyway by setting the decode_content attribute to True (requests sets it to False to control decoding itself). You can then use shutil.copyfileobj() to have Python stream the data to a file object:

import requests
import shutil

r = requests.get(settings.STATICMAP_URL.format(**data), stream=True)
if r.status_code == 200:
    with open(path, 'wb') as f:
        r.raw.decode_content = True
        shutil.copyfileobj(r.raw, f)       

To iterate over the response use a loop; iterating like this ensures that data is decompressed by this stage:

r = requests.get(settings.STATICMAP_URL.format(**data), stream=True)
if r.status_code == 200:
    with open(path, 'wb') as f:
        for chunk in r:
            f.write(chunk)

This'll read the data in 128 byte chunks; if you feel another chunk size works better, use the Response.iter_content() method with a custom chunk size:

r = requests.get(settings.STATICMAP_URL.format(**data), stream=True)
if r.status_code == 200:
    with open(path, 'wb') as f:
        for chunk in r.iter_content(1024):
            f.write(chunk)

Note that you need to open the destination file in binary mode to ensure python doesn't try and translate newlines for you. We also set stream=True so that requests doesn't download the whole image into memory first.

More ~