having-so-much-fun-enjoying-cmdline-emoji

命令行里加个小表情足以愉悦自己
当git工作区不是”working tree clean”状态时 放出小表情

实现方法:

1
2
3
4
5
6
7
8
# $HOME/.zshrc
# env: MacOS

ZSH_THEME="ys"
function parse_git_dirty {
command git rev-parse --is-inside-work-tree &> /dev/null && [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working tree clean" ]] && echo "🤣"
}
export PS1='%n@%m:%1~%$(__git_ps1 " (%s)")$(parse_git_dirty)$ ' # with git branch, 配合 iterm的(smart selection)

根基不稳

2022-05-15 15:50:10 updated

Ruby version < 2.7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Demo
def run
foo # 正常
self.foo # 报错: private method `foo' called for #<Demo:0x00007fd39e80c2e8>
end

private

def foo
puts __method__
end
end

Demo.new.run

今天遇到这个问题的时候, 我这才意识到我的OOP基础有多薄弱…

继续努力

遇到这个问题的原因是, 使用的ruby版本小于2.7, 这时候不能这么用

sso-using-ssh-agent

终于搞懂了 ssh-add ssh-agent ssh -A user@host 实现的SSO

  • keyword: SSH + SSO

https://www.ssh.com/academy/ssh/agent

1
2
3
4
5
6
7
8
eval `ssh-agent` && ssh-add # 启动 ssh-agent 并且把当前用户的 key加到agent里

ssh -A user@host_a # 如果sshconfig里没有 `ForwardAgent yes`
ssh user@host_a # 如果sshconfig里 有 `ForwardAgent yes`

ssh-add -l # 检查本机的key是否被带到了机器上

ssh user@host_b

假设 本机 可以ssh到 host_b
假设 host_a 不可以ssh到 host_b

使用上面的方法, 可以实现在 host_a 上, 直接ssh登录 host_b

假设 本机 有权限拉代码库A的代码
假设 host_a 没有权限拉代码库A的代码

使用上面的方法, 可以实现在 host_a 上, 拉代码库A的代码

My First TamperMonkey Userscripts

Youtube Tutorial

Tampermonkey

Tampermonkey 是一款 浏览器插件

需求来源

空余时间在B站学习C语言, 偶尔发现 某个接口可以获取到列表信息, 可以通过这个计算还剩多长时间能学完这个系列

结合大佬分享过的脚本工具 TamperMonkey

发现可以自动化这个过程… 真是太好了

脚本实现

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
// ==UserScript==
// @name bilibili
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author ljw532344863@sina.com
// @match https://www.bilibili.com/video/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==

window.addEventListener('load', function(){
(function() {
'use strict';

fetch("https://api.bilibili.com/x/player/pagelist?bvid=BV1bs41197KN&jsonp=jsonp")
.then(response => response.json())
.then(function(info){
let data = info.data;
let urlSearchParams = new URLSearchParams(window.location.search);
let params = Object.fromEntries(urlSearchParams.entries());
let currentPage = params.p;
let isCurrentPage = function(item){return (item.page==currentPage);};

let wanted = data.filter(isCurrentPage);
let pageIndex = data.findIndex(isCurrentPage);

let restPages = data.slice(pageIndex);
// duration 的单位是秒
let restTime = restPages.map(item => item.duration).reduce((a, b) => a + b) / 60;
alert(`当前正在观看第 ${currentPage} 节: "${wanted[0].part}"\n剩余时间: ${parseInt(restTime)} 分钟`);
})
.catch(err => {
console.log('caught it!',err);
});

})();
})

脚本调试方法

谷歌浏览器 -> F12 -> “Source” Tab -> “Snippets” -> “Net Snippets” -> write your script and enjoy debuging…

Have Fun automating !!!

https-config-guide

注: 这里主要记录怎么申请免费的SSL证书 在nginx上配置HTTPS

主要的参考文档: 阿里云.SSL证书服务

起因: 调试 小米小爱开放平台 里的 服务端口类型 需要https接口

前置要求

  • 一个阿里云账号
  • 一个已备案的域名
  • 一台ECS(Ubuntu)
  • 一个用nginx代理的http服务

申请SSL证书

  • 进入 阿里云SSL证书 控制台
  • SSL证书
  • 免费证书 (测试, 个人试用场景, 商用的不在这里讨论)
  • 立即购买
  • 填入必要信息即可
  • 状态 那里可以看到证书的签发进度
  • 签发后, 点击下载

上传 key和pem

1
scp yourdomain_nginx.zip youserver:/home/

检查 ECS的安全组

  • 进入 阿里云ECS控制台
  • 进入ECS实例控制台
  • 进入 安全组 tab, 进入安全组配置
  • 检查 安全组的入方向是否允许 443 端口的访问, 如果没有, 点击 快速添加, 选择https即可

检查 ECS的防火墙配置

1
2
3
4
5
sudo ufw status
sudo ufw allow https

# 本机测试端口是否已开放
telnet yourdomain 443

配置nginx

在Nginx(或Tengine)服务器上安装证书

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# http请求转为https请求
server {
listen 80;
server_name yourdomain;
rewrite ^(.*)$ https://${server_name}$1 permanent;
}

server {
listen 443;
ssl on;
server_name yourdomain;

ssl_certificate /etc/nginx/cert/6556112_yourdomain.pem; # 证书pem 所在的路径
ssl_certificate_key /etc/nginx/cert/6556112_yourdomain.key; # 证书key 所在的路径
ssl_session_timeout 5m;

...
}

配置后, 需要reload nginx服务

1
2
sudo nginx -t
sudo nginx -s reload

验证https生效

1
2
3
curl -I http://yourdomain  # 应该返回 `301 Moved Permanently`
curl -L http://yourdomain # 应该正常访问(200)
curl -I https://yourdomain # 应该正常访问(200)

You’re All Set !!!

Mistakes Junior Coders Make

分享看视频做的一些记录

Top 3 Mistakes Junior Coders Make
https://www.youtube.com/watch?v=4Bgeumjhf4w

  1. They believe everything they have build has to be scalable like Facebook or Instagram, they always look at “what happens if I have s millions users, what am I going to do…”. This is not gonna happen for 99.99999% of projects that you have work on, you do not have to worry about scale for the most part, for the vast majority apps you ever work on.

  2. Write time speed is far more important than runtime speed in development.

  3. Don’t be chasing after the bleeding edge tech, let the jobs and opportunities and job requirements determine what tech you choose, not what’s buzzing now on interwebs.

  4. Don’t try to write overly complex code. Don’t do it.

  5. Strive to write really easy to understand code and you will rise quickly as a favorite developer in the team or in the business, because they are going to say: “This person here write really good simple code.”

  6. Newbies tried to reinvent the wheels, they are reluctant to use libraries or frameworks

These tips are based on my 250 years as a developer, trust me, these are universal, doesn’t matter what language, doesn’t matter what framework, nothing matters really…