50个常见的认知偏差

马斯克点赞的50个常见的认知偏差,快来学习一下:

  1. 权威偏见
    典型表现:专家说可以这么做…
  2. 聚类错误
    典型表现:你看那朵云好像你家的猫。
  3. 偏见盲点
    典型表现:我没有偏见。
  4. 乐观偏见
    典型表现:水还有一半,一切都好好起来的。
  5. 潜隐记忆
    典型表现:Greg以为去过墓地是他的一个梦,其实他真的去过。
More...

设置ssh代理解决git pull慢的问题

最近Github特别慢,应该和网络关系比较大,查了一下,用设置代理方式搞定,具体步骤如下:

  1. 搭建代理服务器

  2. 安装ncat 使用以下命令

    1
    sudo apt-get install ncat
  3. 设置ssh代理,编辑ssh设置文件

    1
    vim ~/.ssh/config

    文件内容如下:

    1
    2
    3
    4
    5
    6
    7
    Host github.com
    User git
    Port 443
    Hostname ssh.github.com
    IdentityFile ~/.ssh/id_rsa
    TCPKeepAlive yes
    ProxyCommand /usr/local/bin/ncat --proxy 127.0.0.1:7890 --proxy-type socks5 %h %p
  4. 使用以下命令测试,如果返回成功则设置成功

    1
    ssh -T git@github.com

Taylor Swift 纽约大学演讲(节选)

背景

Taylor Swift(泰勒·斯威夫特),1989年12月13日出生于美国宾夕法尼亚州,美国女歌手、词曲作者、音乐制作人、演员、纽约大学荣誉博士。
2022年5月19日,泰勒于纽约大学2022届毕业典礼发表演讲并被授予 “艺术博士” 荣誉学位。

荣誉博士学位(Honorary Doctoral Degree),也叫名誉博士学位,是世界多数国家通行授予的一种名誉性学术称号。

演讲稿

You went to NYU during a global pandemic, being essentially locked into your dorms and having to do classes over Zoom. Everyone in college during normal times stresses of about test scores. But on top of that, you also had to pass like a thousand COVID tests. I imagine the idea of a normal college experience was all you wanted to. But in this case, you and I both learned that you don’t always get all the things in the bag that you selected from the menu in the delivery surface. That is life. You get what you get.
你们在全球大流行期间去了纽约大学,基本上被困在宿舍里,不得不通过Zoom上课。在正常时期上大学的人都会担心考试成绩,但除此之外,你们还必须通过数以千次的核酸检测。我可以想象,你们也渴望能够拥有正常的大学经历。但在这种情况下,你和我都学到了,很多时候你难以获得你所选择的。这就是生活。你得到的仅仅是你所能够得到的。

More...

VUE页面刷新实战

背景

在进行VUE开发时,往往会出现需要实现当前页面操作完毕后,返回一个列表页面,如果用 this.$router.go(-1) 的方法,页面不会刷新。如果是没有操作,问题不大,但如果我们执行的是删除或添加动作,希望的效果是重新刷新页面,显示操作后的列表页面,这时,用 this.$router.go(-1) 就不能满足需求了。

解决方案

研究了一下,有多种解决方案,我选择了下面的解决方案:

  1. 先定义一个空页面,接收需要跳转的目标页面
  2. 需要跳转到列表页面的函数,不要直接跳到列表页面,先用push方法跳到空页面,同时把目标页面作为参数传给空页面
  3. 这样利用VUE的路由跳转功能,可以让页面流转比较流畅,不会出现页面闪烁的情况。

代码

  1. 定义空页面

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    <template>
    <div class="Empty-form"></div>
    </template>

    <script>
    import { useRoute } from 'vue-router';
    var topath = "";

    export default({
    setup() {
    const route = useRoute();
    topath = route.params.topath;
    },

    created(){
    this.$router.replace({ path: topath });
    }
    });

    </script>
  2. 定义空页面路由

    1
    2
    3
    4
    5
    {
    path: '/empty/:topath',
    name: 'Empty',
    component: EmptyView,
    },

    此处注意:如果需要传参数,必须把参数定义在path里。

  3. 页面跳转,传递参数

    1
    this.$router.push({name:'Empty', params: { topath: '/questionlist' }})

    此处注意:带参数push,请用‘name’ 指定页面。

建立个人和组织的声望(转)

品牌 VS 声望

Brand as a deliberately crafted, sustained narrative that is actively known about you. You don’t have to research Google engineering to have an opinion about Google engineering. In your career and as an engineering leader, you will likely be given the advice that it’s very important to build a brand.
品牌是一个经过精心打造、持续传播的叙事,它是人们主动了解你的方式。你不必研究谷歌的工程技术,就能对谷歌的工程技术有所见解。在你的职业生涯中,作为一名工程领导者,你很有可能会被建议:建立自己的品牌非常重要。
If you participate frequently in social media, it’s easy to get sucked into its reality distortion field. When you spend a lot of time in a given online community, being well-known in that community feels equivalent to professional credibility. However, my experience is that few of the most successful folks I know are well-known online, and many of the most successful folks I know don’t create content online at all. Maybe they have an Instagram account, but it focuses on their family and non-professional interests.
如果你经常参与社交媒体,很容易陷入其现实扭曲力场。当你在一个特定的在线社区花费大量时间时,在那个社区中广为人知似乎等同于专业信誉。然而,根据我的经验,我认识的许多最成功的人在线并不广为人知,而我认识的许多最成功的人根本不在线上创作内容。也许他们有一个Instagram账号,但它关注的是他们的家庭和非职业兴趣。
Enough folks find this counter-intuitive that I’ll emphasize this theme a bit. The majority of successful executives I’ve worked with don’t write online. They won’t post on Twitter or Mastodon. They haven’t written a book. They don’t speak at conferences. They don’t have a YouTube channel. They don’t stream on Twitch. In your engineering leadership career, you will at times be immersed in the message that you need to be creating content to be successful, but there’s abundant evidence to the contrary. You absolutely don’t have to do this sort of thing.
足够多的人认为这一点与直觉相悖,因此我将强调这个主题。我与之合作过的大多数成功高管并不在网上写作。他们不会在Twitter或Mastodon上发帖。他们没有写过书。他们不会在会议上演讲。他们没有YouTube频道。他不在Twitch上直播。在你的工程领导生涯中,你有时会沉浸在这样一种信息中,即你需要创造内容才能成功,但有大量证据表明相反。你绝对不必做这种事情。
Similarly, most Engineering organizations spend little time developing their external brand, and are not externally well-known. For every Meta Engineering blog or Netflix Engineering blog, you’ll find hundreds of engineering organizations with limited public visibility around their work. Many of those silent organizations are doing very interesting work, they just don’t spend much time talking about it publicly. You can, without a doubt, be a successful engineering organization without ever doing any external communication to build your brand.
同样,大多数工程组织很少花时间发展他们的外部品牌,也不为外界所熟知。在每一个Meta工程博客或Netflix工程博客之后,你会发现数百个工程组织几乎没有公开可见性。许多这些低调的组织正在做非常有趣的工作,只是他们不花太多时间公开谈论。毫无疑问,你可以在不做任何外部沟通来建立品牌的情况下成为一家成功的工程组织。

More...

Docker迁移默认的/var/lib/docker 目录(避坑指南)

最近在做docker 数据文件的迁移,按指引创建,遇到了一些问题,把步骤和解决方案记录一下。

1. 停止docker服务

systemctl stop docker

2.创建docker新目录

mkdir -p /data/docker/lib

3.安装迁移软件包

yum install rsync -y

或者

sudo apt-get install rsync

4.开始迁移

rsync -avzP /var/lib/docker /data/docker/lib/

注:这个不是必须的,也可以用mv命令

5.修改docker配置文件

vim /lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock后添加--graph=/data/docker/lib

注意:这里有个坑,最新的docker版本(≥ version 23.0.0 ) 这个参数(–graph)要改为 --data-root ,也就是: --data-root=/data/docker/lib

6.重启docker

systemctl daemon-reload
systemctl restart docker

7.确认docker没有问题,删除原目录

rm -rf /var/lib/docker

Django -APIView的使用

1.APIView的使用:

1.1 在 user/urls.py 中添加路由

1
2
3
4
5
6
7
8
9
from django.contrib import admin
from django.urls import path
from bookapp.views import *

urlpatterns = [
path('admin/', admin.site.urls),
path('book/cate/', CateView.as_view()),

]

1.2创建user/serializers.py写序列化器

1
2
3
4
5
6
7
8
9
10
11
from rest_framework import serializers
from .models import *

class Cateser(serializers.ModelSerializer):
class Meta:
model = Cate #数据库表名
fields = "__all__" #序列化所有字段
#depth = 1 # 外键序列化 添加了这个关联的外键都会查询出来*class Bookser(serializers.ModelSerializer):
class Meta:
model = Book
fields = "__all__"

1.3 在 user/views.py 中添加视图函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from .models import *
from rest_framework.views import APIView
from rest_framework.response import Response
from .sers import *

class CateView(APIView):
# get是查询数据 post是添加数据
def get(self, request):
cate = Cate.objects.all() # 查询所有数据 他是一个查询集
ser = Cateser(cate, many=True) # 因为查询的是一个查询集 所以需要些many=True
return Response(ser.data)

def post(self, request):
ser = Cateser(data=request.data)
resp = {}
if ser.is_valid():
ser.save()
resp['code'] = 200
resp['code'] = ser.data
else:
print(ser.errors)
resp['code'] = 400
resp['code'] = ser.errors
return Response(resp)

def put(self, request): # put 修改数据 完全修改数据 patch 部分修改数据# 想要修改的话 需要知道要修改谁 还要知道最新的数据 data=xxx 传递的新的值
id = request.GET.get('id')
# first是从查询集中 获取一个model对象
cate = Cate.objects.filter(id=id).first()
# 传递 两个参数 参数1是要修改的数据 参数2是要赋予的新值
ser = Cateser(instance=cate, data=request.data)
resp = {}
if ser.is_valid():
ser.save()
resp['code'] = 200
else:
resp['code'] = 400
return Response(resp)

def delete(self, request):
# 需要知道删除谁
id = request.GET.get('id')
resp = {}
try:
Cate.objects.filter(id=id).delete()
resp['code'] = 200
except Exception as e:
print(e)
resp['code'] = 400
return Response(resp)

避免每次更新代码后Docker都重新安装依赖

背景

最简单的Dockerfile指令打包一个项目(以某python项目为例):

1
2
3
4
5
6
7
8
9
10
# 选择一个基础镜像
FROM python:3.6
# 设置虚拟机中的工作路径
WORKDIR /qqzone
# 将当前目录下所有文件拷贝到工作路径中
COPY . /qqzone
# 执行命令,安装依赖
RUN pip install -r requirements.txt
# 执行命令,启动服务
CMD python src/web/server.py

但是这样存在一个巨大的问题,每次更新代码后重新build镜像都会重新安装依赖,会浪费大量时间。

解决方案

有两种途径可以解决这个问题,一是将安装依赖后的环境打包为一个镜像,但是这样做显然有点麻烦,并且每次更新依赖后都得重新打包,因此推荐下面这种方式:使用缓存

先安装依赖再拷贝代码时就会显示Using cache

只需要更改上面的Dockerfile命令如下:

1
2
3
4
5
6
7
8
9
FROM python:3.6
WORKDIR /qqzone
# 先将依赖文件拷贝到项目中
COPY requirements.txt /qqzone
# 执行指令,安装依赖
RUN pip install -i -r requirements.txt
# 拷贝项目文件和代码
COPY . /qqzone
CMD python src/web/server.py

与之前代码不同的是,先单独拷贝依赖文件(requirements.txt)到docker中,再立即安装依赖。由于通常在更新代码之后,依赖文件并没有改变(改变的代码部分在下一步才会被拷贝到镜像中),因此docker在build中会显示“using cache”(调用缓存),从而避免了重新安装依赖。

问题解决 - Your configuration specifies to merge with the ref xxx

原因

在执行git pull的时候会报错:
Your configuration specifies to merge with the ref ‘refs/heads/master’ from the remote, but no such ref was fetched
原因是,现在默认分支已更名为 “main”,但本地git仍试图从 "master "中提取,因此出现了此消息。

解决方案:执行以下脚本:

1
2
3
4
git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a

请我喝杯咖啡吧~

支付宝
微信