编程以外的编程知识——The Missing Semester of Your CS Education

Posted on 2022年6月13日周一 技术
💡

学习完这门课程后,我也有了自己的 dotfile repo:

知道的前提是知道自己不知道什么。

The Missing Semester of Your CS Education

Classes teach you all about advanced topics within CS, from operating systems to machine learning, but there's one critical subject that's rarely covered, and is instead left to students to figure out on their own: proficiency with their tools.

Shell

Special Characters

What makes a character special? If it has a meaning beyond its literal meaning, a meta-meaning, then we refer to it as a special character. Along with commands and keywords, special characters are building blocks of Bash scripts. Special Characters Found In Scripts and Elsewhere # Comments.

GitHub - koalaman/shellcheck: ShellCheck, a static analysis tool for shell scripts

ShellCheck is a GPLv3 tool that gives warnings and suggestions for bash/sh shell scripts: The goals of ShellCheck are To point out and clarify typical beginner's syntax issues that cause a shell to give cryptic error messages. To point out and clarify typical intermediate level semantic problems that cause a shell to behave strangely and counter-intuitively.

Tools

GNU coreutils via Homebrew

Job Control

Aliases

Note that there is no space around the equal sign =, because alias  is a shell command that takes a single argument.

Dotfiles

GitHub does dotfiles - dotfiles.github.io

If you're just starting out, before you go symlinking everything in ~/*, you might want to check out some tutorials that discuss how you can organize your dotfiles. Next, you could look through the general-purpose dotfiles utilities to find a system you can use to manage your dotfiles.

Use Git to manage secret content via creating bash functions to encrypt / decrypt secret content into / from Git.

Portability

if [[ "$(uname)" == "Linux" ]]; then {do_something}; fi

# Check before using shell-specific features
if [[ "$SHELL" == "zsh" ]]; then {do_something}; fi

# You can also make it machine-specific
if [[ "$(hostname)" == "myServer" ]]; then {do_something}; fi

# Test if ~/.aliases exists and source it
if [ -f ~/.aliases ]; then
    source ~/.aliases
fi

gitconfig supports including configurations from local files.

[include]
    path = ~/.gitconfig_local

SSH Configuration

Connecting to GitHub with SSH - GitHub Docs

You can connect to GitHub using the Secure Shell Protocol (SSH), which provides a secure channel over an unsecured network.

What's ssh port forwarding and what's the difference between ssh local and remote port forwarding

local: -L Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side. ssh -L sourcePort:forwardToHost:onPort connectToHost means: connect with ssh to connectToHost, and forward all connection attempts to the local sourcePort to port onPort on the machine called forwardToHost, which can be reached from the connectToHost machine.

~/.ssh/config

Host vm
    User foobar
    HostName 172.16.174.141
    Port 2222
    IdentityFile ~/.ssh/id_ed25519
    LocalForward 9999 localhost:8888

# Configs can also take wildcards
Host *.mit.edu
    User foobaz

Key based authentication

cat .ssh/id_ed25519.pub | ssh foobar@remote 'cat >> ~/.ssh/authorized_keys'

# Or
ssh-copy-id -i .ssh/id_ed25519 foobar@remote

Copying files over SSH

rsync

ZSH

为什么不使用fish?

因为我对shell不够了解,fish不支持Posix标准,我觉得有很多我不知道的坑。

Editors (Vim)

Know keyboard shortcuts about your most recently used editor!d

The big list of Vim-like software

Keyboard remapping

Karabiner-Elements

Karabiner-Elements A powerful and stable keyboard customizer for macOS.

GitHub - koekeishiya/skhd: Simple hotkey daemon for macOS

skhd is a simple hotkey daemon for macOS that focuses on responsiveness and performance. Hotkeys are defined in a text file through a simple DSL. skhd is able to hotload its config file, meaning that hotkeys can be edited and updated live while skhd is running.

folivora.ai - Great Tools for your Mac!

Daemon & Automation

systemd

# /etc/systemd/system/myapp.service
[Unit]
Description=My Custom App
After=network.target

[Service]
User=foo
Group=foo
WorkingDirectory=/home/foo/projects/mydaemon
ExecStart=/usr/bin/local/python3.7 app.py
Restart=on-failure

[Install]
WantedBy=multi-user.target

cron

Hammerspoon

This is a tool for powerful automation of macOS. At its core, Hammerspoon is just a bridge between the operating system and a Lua scripting engine. What gives Hammerspoon its power is a set of extensions that expose specific pieces of system functionality, to the user.

FUSE

filesystem in user space,对文件系统的中间抽象,用来加上远程、分布式、加密等功能。

Backups

Filesystem Hierarchy Standard