Tradeoff Collection

I observed a lot of trade-offs.
I would call Trade Off some kind of Art.
Tradeoff collection therein.

Space | Time Tradeoff

A space–time Tradeoff or time–memory trade-off in computer science is a case where an algorithm or program trades increased space usage with decreased time.

Here, space refers to the data storage consumed in performing a given task (RAM, HDD, etc), and time refers to the time consumed in performing a given task (computation time or response time).

Code Changeability/Simplicity | Code Readability Tradeoff

hint from “99-bottles-of-oop”

  • abstraction -> changeability(hard to understand)
  • concrete -> easy to read(hard to change)

Security | Effiency Tradeoff

cryptography

  • The more complex the encryption algorithm is, the more secure it will be, while it’ll take more time to encrypt/dencrypt

even good (or trendy) solutions add complexity

Use sidekiq or use sidekiq with rails activejob

  • sidekiq: powerful/simple
  • activejob: more rails-favored features

ease of use | feature rich

  • beginners want programs/interface to be easy to use

  • advanced users want programs/interface to be more powerful

top -> down design | bottom -> up design

“the art of unix programming” ch4.3.1

接口复杂度 | 实现复杂度

“the art of unix programming” ch13.1.2

features/performance | price

“Fast and resilient web apps: Tools and techniques - Google I/O 2016”

Event-carried state transfer

  • more decoupling

  • more availablity

  • less data consistency(eventual consistency)

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 !!!