一些记录 by neoctobers¶
Personal records.
Init a RPi3B+ (and boot from USB HDD)¶
records…
Hardware¶
- RPi3B+ x1
- TF 16G x1
- USB HDD 1T x1
- USB Keyboard x1
- USB Mouse x1
System Image¶
Switch to: Boot from USB HDD¶
- Write the image to TF card.
- Add
program_usb_boot_mode=1
to filecmdline.txt
- Insert the TF card, power on for about 60 seconds, power off, remove the TF
- Write the image to USB HDD
- Adjust partitions, by
DiskGenius
, on win10:- 0: keep the
boot
, do not edit it - 2: adjust
rootfs
to32GB
, and move it to the end, end, end - 1: create an
ext4
partition, with the rest all spaces, nameddata
- 0: keep the
Configurations¶
- Boot to
Raspbian desktop
, follow the guide, then reboot - Terminal:
- sudo apt update
- sudo apt upgrade
- Pi Configuration
- rename
- switch boot to CLI, will disable auto login at the same time
- enable SSH
- reboot
Mount partition #1¶
Append one line to /etc/fstab
, before it, make sure /dev/sda3
is correct:
/dev/sda3 /data ext4 defaults 1 1
Reboot
Change /data owner to pi¶
$ sudo chown pi /data
Don’t allow kworker eats CPU¶
System will check TF slot every 500ms(green led blinks), during it is blank, that will eat your CPU time.
ref: | https://github.com/raspberrypi/linux/issues/2567 |
---|
Check CPU usage:
$ top
top - 07:43:51 up 7:55, 1 user, load average: 0.33, 0.29, 0.28
Tasks: 100 total, 2 running, 57 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.1 us, 1.3 sy, 0.0 ni, 98.6 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1000180 total, 771736 free, 59604 used, 168840 buff/cache
KiB Swap: 102396 total, 102396 free, 0 used. 876512 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
29 root 20 0 0 0 0 R 8.9 0.0 44:15.23 kworker/0:1
1670 pi 20 0 8128 3288 2764 R 1.0 0.3 0:01.59 top
...
If kworker eats 8-13% CPU, append one line to /boot/config.txt
:
# With no TF card
dtoverlay=sdtweak,poll_once
Reboot, OKay.
hd-idle¶
To protect the HDD, suspend when idle.
ref: | http://www.mkitby.com/2016/05/15/raspberry-pi-nas-manage-hdd-power/ |
---|
Check support:
$ cat /proc/diskstats
1 0 ram0 0 0 0 0 0 0 0 0 0 0 0
1 1 ram1 0 0 0 0 0 0 0 0 0 0 0
1 2 ram2 0 0 0 0 0 0 0 0 0 0 0
1 3 ram3 0 0 0 0 0 0 0 0 0 0 0
1 4 ram4 0 0 0 0 0 0 0 0 0 0 0
1 5 ram5 0 0 0 0 0 0 0 0 0 0 0
1 6 ram6 0 0 0 0 0 0 0 0 0 0 0
1 7 ram7 0 0 0 0 0 0 0 0 0 0 0
1 8 ram8 0 0 0 0 0 0 0 0 0 0 0
1 9 ram9 0 0 0 0 0 0 0 0 0 0 0
1 10 ram10 0 0 0 0 0 0 0 0 0 0 0
1 11 ram11 0 0 0 0 0 0 0 0 0 0 0
1 12 ram12 0 0 0 0 0 0 0 0 0 0 0
1 13 ram13 0 0 0 0 0 0 0 0 0 0 0
1 14 ram14 0 0 0 0 0 0 0 0 0 0 0
1 15 ram15 0 0 0 0 0 0 0 0 0 0 0
7 0 loop0 0 0 0 0 0 0 0 0 0 0 0
7 1 loop1 0 0 0 0 0 0 0 0 0 0 0
7 2 loop2 0 0 0 0 0 0 0 0 0 0 0
7 3 loop3 0 0 0 0 0 0 0 0 0 0 0
7 4 loop4 0 0 0 0 0 0 0 0 0 0 0
7 5 loop5 0 0 0 0 0 0 0 0 0 0 0
7 6 loop6 0 0 0 0 0 0 0 0 0 0 0
7 7 loop7 0 0 0 0 0 0 0 0 0 0 0
8 0 sda 17021 1174 1520519 302550 51991 7860 10477700 1732050 0 237770 2034780
8 1 sda1 146 199 4589 1050 3 0 4 10 0 770 1060
8 2 sda2 16756 923 1507888 299660 5031 7169 344976 359560 0 79220 659400
8 3 sda3 95 52 6994 1660 45719 691 10132720 1371990 0 163900 1373650
Install dependencies:
$ sudo apt install build-essential fakeroot debhelper -y
Download:
$ wget http://sourceforge.net/projects/hd-idle/files/hd-idle-1.05.tgz
Unzip and cd in:
$ tar -xvf hd-idle-1.05.tgz && cd hd-idle
Install:
$ sudo dpkg-buildpackage -rfakeroot
$ sudo dpkg -i ../hd-idle_*.deb
Check for support:
$ sudo hd-idle -i 0 -a sda -i 300 -d
probing sda: reads: 1520519, writes: 10949452
^C
Ctrl + C
to break.
Edit conf:
$ sudo nano /etc/default/hd-idle
Modify:
START_HD_IDLE=true
Append for idle, after 600
seconds:
HD_IDLE_OPTS="-i 0 -a sda -i 600"
Restart the service:
$ sudo service hd-idle restart
Install Python3.7.2¶
Install Phthon3.7.2 and make symlink to /usr/bin/
.
Install dependence¶
$ sudo apt update
$ sudo apt install build-essential python-dev python-setuptools python-pip python-smbus build-essential libncursesw5-dev libgdbm-dev libc6-dev zlib1g-dev libsqlite3-dev tk-dev libssl-dev openssl libffi-dev
Download and install Python-3.7.2¶
$ wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
$ tar zxvf Python-3.7.2.tgz && cd Python-3.7.2
$ sudo ./configure --prefix=/usr/local/opt/python-3.7.2 --with-ssl
$ sudo make && sudo make install
注解
In the 3rd command, param --with--ssl
is important, don’t miss it!
Backup python3.5 and pip3 symlink¶
$ sudo cp /usr/bin/python3 /usr/bin/python3.5
cp: '/usr/bin/python3' and '/usr/bin/python3.5' are the same file
$ sudo cp /usr/bin/pip3 /usr/bin/pip3.5
Make Symlinks¶
$ sudo ln -s /usr/local/opt/python-3.7.2/bin/python3.7 /usr/bin/python3.7
$ sudo ln -s /usr/local/opt/python-3.7.2/bin/python3.7 /usr/bin/python3
$ sudo ln -s /usr/local/opt/python-3.7.2/bin/python3.7 /usr/bin/py
$ sudo ln -s /usr/local/opt/python-3.7.2/bin/pip3.7 /usr/bin/pip3.7
$ sudo ln -s /usr/local/opt/python-3.7.2/bin/pip3.7 /usr/bin/pip3
$ sudo ln -s /usr/local/opt/python-3.7.2/bin/pydoc3.7 /usr/bin/pydoc3.7
$ sudo ln -s /usr/local/opt/python-3.7.2/bin/python3.7m /usr/bin/python3.7m
$ sudo ln -s /usr/local/opt/python-3.7.2/bin/pyvenv-3.7 /usr/bin/pyvenv-3.7
Rename lsb_release if there is a error¶
Try:
$ $ pip3 list
Package Version
---------- -------
pip 10.0.1
setuptools 39.0.1
Traceback (most recent call last):
File "/usr/bin/pip3", line 11, in <module>
sys.exit(main())
File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/pip/_internal/__init__.py", line 246, in main
return command.main(cmd_args)
File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/pip/_internal/basecommand.py", line 264, in main
timeout=min(5, options.timeout)) as session:
File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/pip/_internal/basecommand.py", line 81, in _build_session
insecure_hosts=options.trusted_hosts,
File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/pip/_internal/download.py", line 338, in __init__
self.headers["User-Agent"] = user_agent()
File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/pip/_internal/download.py", line 101, in user_agent
zip(["name", "version", "id"], distro.linux_distribution()),
File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/pip/_vendor/distro.py", line 120, in linux_distribution
return _distro.linux_distribution(full_distribution_name)
File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/pip/_vendor/distro.py", line 634, in linux_distribution
self.version(),
File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/pip/_vendor/distro.py", line 688, in version
self.lsb_release_attr('release'),
File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/pip/_vendor/distro.py", line 836, in lsb_release_attr
return self._lsb_release_info.get(attribute, '')
File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/pip/_vendor/distro.py", line 522, in __get__
ret = obj.__dict__[self._fname] = self._f(obj)
File "/usr/local/opt/python-3.7.2/lib/python3.7/site-packages/pip/_vendor/distro.py", line 933, in _lsb_release_info
stdout = subprocess.check_output(cmd, stderr=devnull)
File "/usr/local/opt/python-3.7.2/lib/python3.7/subprocess.py", line 389, in check_output
**kwargs).stdout
File "/usr/local/opt/python-3.7.2/lib/python3.7/subprocess.py", line 481, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1.
Rename it safely:
$ sudo mv /usr/bin/lsb_release /usr/bin/lsb_release_back
Then, try again:
$ pip3 list
Package Version
---------- -------
pip 10.0.1
setuptools 39.0.1
You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Upgrade pip3¶
Do it:
$ pip3 install -U pip
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting pip
Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 43kB/s
Installing collected packages: pip
Found existing installation: pip 10.0.1
Uninstalling pip-10.0.1:
Successfully uninstalled pip-10.0.1
Successfully installed pip-18.1
Check it:
$ pip3 list
Package Version
---------- -------
pip 18.1
setuptools 39.0.1
$
May update setuptools:
$ sudo pip3 install -U setuptools
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting setuptools
Downloading https://files.pythonhosted.org/packages/37/06/754589caf971b0d2d48f151c2586f62902d93dc908e2fd9b9b9f6aa3c9dd/setuptools-40.6.3-py2.py3-none-any.whl (573kB)
100% |████████████████████████████████| 573kB 20kB/s
Installing collected packages: setuptools
Found existing installation: setuptools 39.0.1
Uninstalling setuptools-39.0.1:
Successfully uninstalled setuptools-39.0.1
Successfully installed setuptools-40.6.3
Python3 is ready now, well done!
Restore UART/ttyAMA0 over GPIO, by Disable BT¶
Release the serial port, GPIO:
GPIO | FUNC |
---|---|
6 | TXD0(UART) |
8 | RXD0(UART) |
Modify Boot Configuration¶
Edit /boot/config.txt
, append:
# Disable BT
dtoverlay=pi3-disable-bt
Reboot.
Check¶
$ ls -l /dev
...
lrwxrwxrwx 1 root root 7 Dec 21 21:10 serial0 -> ttyAMA0
lrwxrwxrwx 1 root root 5 Dec 21 21:10 serial1 -> ttyS0
...
Permit access for pi¶
$ sudo raspi-config
Select: Interfacing Options
- Serial
:
- Disable the login shell on the serial
- Enable the serial port hardware
- Reboot
ref: | https://www.raspberrypi.org/forums/viewtopic.php?t=180254 |
---|
Disable hciuart.service
¶
$ sudo systemctl disable hciuart
Removed /etc/systemd/system/multi-user.target.wants/hciuart.service.
Supervisor¶
Supervisor: A Process Control System
ref: | http://supervisord.org/index.html |
---|
Install¶
$ sudo apt install supervisor
sample.conf¶
ref: | http://supervisord.org/configuration.html#program-x-section-example |
---|
Under /etc/supervisor/conf.d/
, write a file sample.conf
like:
[program:sample]
directory=/path/to/dir/
command=/path/to/file --param
autostart=true
autorestart=true
startretries=5
redirect_stderr=true
stdout_logfile=/path/to/file.log
Commands¶
$ supervisorctl status
$ supervisorctl reload
$ supervisorctl restart all
$ supervisorctl stop sample
$ supervisorctl start sample
$ supervisorctl restart sample
$ supervisorctl update
Crontab -e¶
Create a cron task
ref: | https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/crontab.html |
---|
Restart cron service¶
$ sudo service cron reload
[ ok ] Reloading configuration files for periodic command scheduler: cron.
$ sudo service cron restart
ShadowsocksR Client¶
ShadowsocksR by Python
Install¶
$ git clone git@github.com:shadowsocksrr/shadowsocksr.git
Config¶
Make a config file in /path/to/config.json
{
"server": "123.123.123.123",
"server_port": 8388,
"method": "aes-256-cfb",
"password": "password",
"protocol": "origin",
"protocol_param": "",
"obfs": "plain",
"obfs_param": "",
"local_address": "127.0.0.1",
"local_port": 1080
}
They are:
- Server IP address or domain
- Server port
- Method
- Password
- Protocol
- Protocol params
- Obfs
- Obfs Params
- Listen IP
- Listen Port
Try to run¶
$ python /path/to/shadowsocksr/shadowsocks/local.py -c /path/to/config.json
Keep it running by supervisor¶
Write a supervisor /etc/supervisor/conf.d/ssr.conf
file:
[program:ssr]
user=root
command=/usr/bin/python3 /path/to/shadowsocksr/shadowsocks/local.py -c /path/to/config.json
autostart=true
autorestart=true
startretries=5
redirect_stderr=true
stdout_logfile=/path/to/ssr.log
Make sure all the path is already exist.
Proxychains-NG: Run commands behind a Socks5 proxy¶
Run a command behind a Socks5 proxy.
ref: | https://github.com/rofl0r/proxychains-ng |
---|
Installation¶
$ git clone git@github.com:rofl0r/proxychains-ng.git
$ cd proxychains-ng
$ sudo ./configure
$ sudo make && sudo make install
The full path to command is: /usr/local/bin/porxychains4
Configuration¶
Write config file /etc/proxychains.conf
as default:
strict_chain
proxy_dns
remote_dns_subnet 224
tcp_read_time_out 15000
tcp_connect_time_out 8000
[ProxyList]
socks5 127.0.0.1 1080
PS: Port 1080 is listened by a Shadowsocks or shadowsocksR.
注解
Original proxychains.conf
file: proxychains.conf on Github.com or in RAW format
Check and usage¶
$ porxychains4 curl https://api.myip.com/
Run Tor on RPi¶
Tor on RPi3B+
ref: | https://www.freebuf.com/geek/121780.html |
---|---|
ref: | http://shumeipai.nxez.com/2014/02/28/based-on-anonymous-proxy-raspberry-pi-and-tordajian.html |
Install tor¶
$ sudo apt install tor
Stop tor service and make a configuration file¶
$ sudo service tor stop
Make tor work for lan, modify configuration file /etc/tor/torrc
:
# VIA SS(R)
SOCKS5Proxy 127.0.0.1:1008
# SOCKS
SOCKSPort 9050
SocksListenAddress 0.0.0.0:9050
SocksPolicy accept 127.0.0.0/8
SocksPolicy accept 10.168.0.0/16
SocksPolicy accept 172.16.0.0/12
SocksPolicy accept 192.168.0.0/16
SocksPolicy reject *
# WOULD NOT BE A EXIT
ExitPolicy reject *:*
# LOG
Log notice file /var/log/tor/notices.log
ref: | https://github.com/torproject/tor/blob/master/src/config/torrc.sample.in |
---|
Restart tor service¶
$ sudo service tor restart
Cat log¶
$ cat /var/log/tor/notices.log
Dec 21 23:19:40.000 [notice] Tor 0.2.9.16 (git-9ef571339967c1e5) opening log file.
Dec 21 23:19:39.939 [warn] OpenSSL version from headers does not match the version we're running with. If you get weird crashes, that might be why. (Compiled with 1010006f: OpenSSL 1.1.0f 25 May 2017; running with 101000af: OpenSSL 1.1.0j 20 Nov 2018).
Dec 21 23:19:40.367 [notice] Tor 0.2.9.16 (git-9ef571339967c1e5) running on Linux with Libevent 2.0.21-stable, OpenSSL 1.1.0j and Zlib 1.2.8.
Dec 21 23:19:40.367 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
Dec 21 23:19:40.368 [notice] Read configuration file "/usr/share/tor/tor-service-defaults-torrc".
Dec 21 23:19:40.368 [notice] Read configuration file "/etc/tor/torrc".
Dec 21 23:19:40.378 [warn] The SocksListenAddress option is deprecated, and will most likely be removed in a future version of Tor. Use SocksPort instead. (If you think this is a mistake, please let us know!)
Dec 21 23:19:40.379 [warn] You specified a public address '0.0.0.0:9050' for SocksPort. Other people on the Internet might find your computer and use it as an open proxy. Please don't allow this unless you have a good reason.
Dec 21 23:19:40.381 [warn] You specified a public address '0.0.0.0:9050' for SocksPort. Other people on the Internet might find your computer and use it as an open proxy. Please don't allow this unless you have a good reason.
Dec 21 23:19:40.381 [notice] Opening Socks listener on 0.0.0.0:9050
Dec 21 23:19:40.000 [notice] Parsing GEOIP IPv4 file /usr/share/tor/geoip.
Dec 21 23:19:41.000 [notice] Parsing GEOIP IPv6 file /usr/share/tor/geoip6.
Dec 21 23:19:42.000 [notice] Bootstrapped 0%: Starting
Dec 21 23:19:43.000 [notice] Bootstrapped 80%: Connecting to the Tor network
Dec 21 23:19:43.000 [notice] Signaled readiness to systemd
Dec 21 23:19:43.000 [notice] Opening Control listener on /var/run/tor/control
Dec 21 23:19:44.000 [notice] Bootstrapped 85%: Finishing handshake with first hop
Dec 21 23:19:45.000 [notice] Bootstrapped 90%: Establishing a Tor circuit
Dec 21 23:19:47.000 [notice] Tor has successfully opened a circuit. Looks like client functionality is working.
Dec 21 23:19:47.000 [notice] Bootstrapped 100%: Done
That’s right.
Use tor via socks5¶
Can use tor via socks5 now…
Convert socks to http proxy thr privoxy¶
Privoxy
Installation¶
$ sudo apt install -y privoxy
Configuration¶
ref: | https://www.privoxy.org/faq/configuration.html |
---|
Modify or append lines of /etc/privoxy/config
:
# listen on 9051
listen-address :9051
# permit access from LOCAL
permit-access 127.0.0.0/8
# permit access from LAN
permit-access 10.168.0.0/16
permit-access 172.16.0.0/12
permit-access 192.168.0.0/16
# forward to TOR
forward-socks5 / 127.0.0.1:9050 .
so, the whole config text would be:
confdir /etc/privoxy
logdir /var/log/privoxy
actionsfile match-all.action # Actions that are applied to all sites and maybe overruled later on.
actionsfile default.action # Main actions file
actionsfile user.action # User customizations
filterfile default.filter
filterfile user.filter # User customizations
logfile logfile
# listen on 9051
listen-address :9051
# listen-address [::1]:8118
toggle 1
enable-remote-toggle 0
enable-remote-http-toggle 0
enable-edit-actions 0
enforce-blocks 0
# permit access from LOCAL
permit-access 127.0.0.0/8
# permit access from LAN
permit-access 10.168.0.0/16
permit-access 172.16.0.0/12
permit-access 192.168.0.0/16
buffer-limit 4096
enable-proxy-authentication-forwarding 0
forwarded-connect-retries 0
accept-intercepted-requests 0
allow-cgi-request-crunching 0
split-large-forms 0
keep-alive-timeout 5
tolerate-pipelining 1
socket-timeout 300
max-client-connections 128
# forward to TOR
forward-socks5 / 127.0.0.1:9050 .
注解
Make sure: don’t miss the .
at the end.
Google 开源项目风格指南¶
FRP 反向代理¶
服务端,以 ubuntu 为例¶
编辑 frps.ini
文件:
[common]
bind_port = 7000
vhost_https_port = 443
token = t0ken4c0nnect
创建 /etc/systemd/system/frps.service
文件:
[Unit]
Description=FRP Server
After=network.target
[Service]
ExecStart=/path/to/frps -c /path/to/frps.ini
Restart=on-abort
[Install]
WantedBy=multi-user.target
Enable the service:
$ systemctl enable frps
start / stop / restart / check status:
$ service frps start
$ service frps stop
$ service frps restart
$ service frps status
or run it in console:
$ ./frps -c ./frps.ini
Client-side, win10 for example¶
Edit the frpc.ini
:
[common]
server_addr = your-ip-address
server_port = 7000
token = t0ken4c0nnect
[your.domain.com:port]
type = https
local_port = 443
custom_domains = your.domain.com
Run:
$ ./frpc -c ./frpc.ini
Enjoy it!
Git 版本控制¶
配置¶
$ git config --global user.name "your-name"
$ git config --global user.email "your-name@domain.com"
$ ssh-keygen -t rsa -C "your-name@domain.com"
将已有文件夹推送到远程仓库¶
$ cd existing_folder
$ git init
$ git remote add origin ...
$ git add .
$ git commit -m "Initial commit"
$ git push -u origin master
撤销 git add .
操作¶
$ git reset --mixed
Git 多用户¶
在不同的代码仓库使用多用户配置
为不同的用户创建对应的 ssh-key¶
建议设置不同的密码,避免用混以及被黑客入侵拷走 id_rsa
文件
$ ssh-keygen -t rsa -C "name1@sample.domain"
$ ssh-keygen -t rsa -C "name2@sample.domain"
$ ssh-keygen -t rsa -C "name3@sample.domain"
Put them to ~/.ssh/
directory.
Edit or create ~/.ssh/config
file:
# name1
Host name1
HostName github.com
IdentityFile C:\\Users\\user\\.ssh\\id_rsa_name1
PreferredAuthentications publickey
User name1
# name2
Host name2
HostName github.com
IdentityFile C:\\Users\\user\\.ssh\\id_rsa_name2
PreferredAuthentications publickey
User user2
# name3
Host name3
HostName git.oschina.net
IdentityFile C:\\Users\\user\\.ssh\\id_rsa_name3
PreferredAuthentications publickey
User user3
# ...
Shorten a Github URL¶
run:
$ curl -i https://git.io -F "url=https://github.com/neoctobers" -F "code=neoctobers"
cmder¶
Run cmder as administrator, and run:
$ Cmder.exe /REGISTER ALL
ref: | https://www.jianshu.com/p/979db1a96f6d |
---|
cmder in hyper.js¶
ref: | https://hyper.is/ |
---|---|
ref: | https://github.com/cmderdev/cmder/wiki/Seamless-Hyper-integration |
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
updateChannel: 'stable',
// default font size in pixels for all tabs
fontSize: 12,
// font family with optional fallbacks
fontFamily: 'Menlo, "DejaVu Sans Mono", Consolas, "Lucida Console", monospace',
// default font weight: 'normal' or 'bold'
fontWeight: 'normal',
// font weight for bold characters: 'normal' or 'bold'
fontWeightBold: 'bold',
// line height as a relative unit
lineHeight: 1,
// letter spacing as a relative unit
letterSpacing: 0,
// terminal cursor background color and opacity (hex, rgb, hsl, hsv, hwb or cmyk)
cursorColor: 'rgba(248,28,229,0.8)',
// terminal text color under BLOCK cursor
cursorAccentColor: '#000',
// `'BEAM'` for |, `'UNDERLINE'` for _, `'BLOCK'` for █
cursorShape: 'BLOCK',
// set to `true` (without backticks and without quotes) for blinking cursor
cursorBlink: false,
// color of the text
foregroundColor: '#fff',
// terminal background color
// opacity is only supported on macOS
backgroundColor: '#000',
// terminal selection color
selectionColor: 'rgba(248,28,229,0.3)',
// border color (window, tabs)
borderColor: '#333',
// custom CSS to embed in the main window
css: '',
// custom CSS to embed in the terminal window
termCSS: '',
// if you're using a Linux setup which show native menus, set to false
// default: `true` on Linux, `true` on Windows, ignored on macOS
showHamburgerMenu: '',
// set to `false` (without backticks and without quotes) if you want to hide the minimize, maximize and close buttons
// additionally, set to `'left'` if you want them on the left, like in Ubuntu
// default: `true` (without backticks and without quotes) on Windows and Linux, ignored on macOS
showWindowControls: '',
// custom padding (CSS format, i.e.: `top right bottom left`)
padding: '12px 14px',
// the full list. if you're going to provide the full color palette,
// including the 6 x 6 color cubes and the grayscale map, just provide
// an array here instead of a color map object
colors: {
black: '#000000',
red: '#C51E14',
green: '#1DC121',
yellow: '#C7C329',
blue: '#0A2FC4',
magenta: '#C839C5',
cyan: '#20C5C6',
white: '#C7C7C7',
lightBlack: '#686868',
lightRed: '#FD6F6B',
lightGreen: '#67F86F',
lightYellow: '#FFFA72',
lightBlue: '#6A76FB',
lightMagenta: '#FD7CFC',
lightCyan: '#68FDFE',
lightWhite: '#FFFFFF',
},
// the shell to run when spawning a new session (i.e. /usr/local/bin/fish)
// if left empty, your system's login shell will be used by default
//
// Windows
// - Make sure to use a full path if the binary name doesn't work
// - Remove `--login` in shellArgs
//
// Bash on Windows
// - Example: `C:\\Windows\\System32\\bash.exe`
//
// PowerShell on Windows
// - Example: `C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`
shell: 'cmd.exe',
// for setting shell arguments (i.e. for using interactive shellArgs: `['-i']`)
// by default `['--login']` will be used
shellArgs: ['/k', 'D:\\G\\cmder_mini\\vendor\\init.bat'],
// for environment variables
env: { 'TERM':'cygwin' },
// set to `false` for no bell
bell: 'SOUND',
// if `true` (without backticks and without quotes), selected text will automatically be copied to the clipboard
copyOnSelect: false,
// if `true` (without backticks and without quotes), hyper will be set as the default protocol client for SSH
defaultSSHApp: true,
// if `true` (without backticks and without quotes), on right click selected text will be copied or pasted if no
// selection is present (`true` by default on Windows and disables the context menu feature)
// quickEdit: true,
// URL to custom bell
// bellSoundURL: 'http://example.com/bell.mp3',
// for advanced config flags please refer to https://hyper.is/#cfg
},
// a list of plugins to fetch and install from npm
// format: [@org/]project[#version]
// examples:
// `hyperpower`
// `@company/project`
// `project#1.0.1`
plugins: [
'hyperpower',
'hyper-tab-icons',
'hyper-statusline',
'hyper-material-theme',
'hyper-pane',
],
// in development, you can create a directory under
// `~/.hyper_plugins/local/` and include it here
// to load it and avoid it being `npm install`ed
localPlugins: [],
keymaps: {
// Example
// 'window:devtools': 'cmd+alt+o',
},
};
CMD behind a proxy¶
I am using the cmder, just run:
$ set http_proxy=http://127.0.0.1:1009
$ set https_proxy=http://127.0.0.1:1009
If u wanna know what ip address u are using:
$ curl https://api.myip.com/
Read the docs 撰写文档¶
Use sphinx to write a documentation, and host it on RTD, just like this page(site) you are reading.
使用 sphinx 初始化¶
通过 pip 安装 sphinx 然后使用 sphinx-quickstart
初始化。
$ pip install sphinx
$ cd /path/to/project
$ mkdir docs
$ cd docs
$ sphinx-quickstart
编辑 .rst
文件撰写内容。
在本地生成 html 预览,运行:
$ make html
Localization of Documentation¶
Create/Update translatable files:
$ make gettext
or:
$ sphinx-build -b gettext . _build/gettext
This command above will leave the generated files under _build/gettext
.
Generate .po
files from source language manually:
$ sphinx-intl update -p _build/gettext -l zh_CN
Do translate, edit the .po
files.
Then,
Build the documentation in target language, for preview locally:
$ sphinx-build -D language=zh_CN . _build/html/zh_CN
Multi-languages in RTD¶
Manually.
VS Code Settings Sync¶
Synchronize Settings, Snippets, Themes, File Icons, Launch, Keybindings, Workspaces and Extensions Across Multiple Machines Using GitHub Gist.
- Settings Sync on Visual Studio Marketplace All there.
Creating a self-signed certificate using OpenSSL¶
$ openssl req -newkey rsa:2048 -sha256 -nodes -keyout private.key -x509 -days 3650 -out cert.pem
The openssl
utility will ask you a few details. Make sure you enter the correct FQDN! If your server has a domain, enter the full domain name here (eg. sub.example.com
).
ref: | https://github.com/python-telegram-bot/python-telegram-bot/wiki/Webhooks |
---|
PostgreSQL: Grant all privileges on all xxx in schema public to user-name¶
For tables:
# GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO user-name;
ref: | https://poanchen.github.io/blog/2018/03/07/How-to-fix-permission-denied-for-relation-some_table_name-in-PostgreSQL |
---|
For sequence xx_id_seq
:
# GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO user-name;
ref: | https://stackoverflow.com/questions/9325017/error-permission-denied-for-sequence-cities-id-seq-using-postgres |
---|
reStructuredText¶
reStructuredText(reST) is the default plaintext markup language used by Sphinx.
http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
And, [Official] reStructuredText Markup Specification
Inline markup¶
- Italics: italics
- Bold: bold
- Code samples:
code samples
*italics*
**boldface**
``text``
Lists and Quote-like blocks¶
- This is a bulleted list.
- It has two items, the second item uses two lines.
- This is a numbered list.
- It has two items.
* This is a bulleted list.
* It has two items, the second
item uses two lines.
1. This is a numbered list.
2. It has two items.
and:
- This is a numbered list.
- It has two items too.
#. This is a numbered list.
#. It has two items too.
Nested lists¶
Nested lists are possible
- this is
- a list
- with a nested list
- and some subitems
- and here the parent list continues
* this is
* a list
* with a nested list
* and some subitems
* and here the parent list continues
but be aware that they must be separated from the parent list items by blank lines:
Definition Lists¶
- term (up to a line of text)
Definition of the term, which must be indented
and can even consist of multiple paragraphs
- next term
- Description.
term (up to a line of text)
Definition of the term, which must be indented
and can even consist of multiple paragraphs
next term
Description.
Note that the term cannot have more than one line of text.
Quoted paragraphs¶
John Doe wrote:
>> Great idea!
>
> Why didn't I think of that?
You just did! ;-)
John Doe wrote::
>> Great idea!
>
> Why didn't I think of that?
You just did! ;-)
Line Blocks¶
Take it away, Eric the Orchestra Leader!
A one, two, a one two three fourHalf a bee, philosophically,must, ipso facto, half not be.But half the bee has got to be,vis a vis its entity. D’you see?But can a bee be said to beor not to be an entire bee,when half the bee is not a bee,due to some ancient injury?Singing…
Take it away, Eric the Orchestra Leader!
| A one, two, a one two three four
|
| Half a bee, philosophically,
| must, *ipso facto*, half not be.
| But half the bee has got to be,
| *vis a vis* its entity. D'you see?
|
| But can a bee be said to be
| or not to be an entire bee,
| when half the bee is not a bee,
| due to some ancient injury?
|
| Singing...
Literal blocks¶
Literal code blocks are introduced by ending a paragraph with the special marker ::
.
The literal block must be indented (and, like all paragraphs, separated from the surrounding ones by blank lines):
This is a normal text paragraph. The next paragraph is a code sample::
It is not processed in any way, except
that the indentation is removed.
It can span multiple lines.
This is a normal text paragraph again.
The handling of the :: marker is smart:
- If it occurs as a paragraph of its own, that paragraph is completely left out of the document.
- If it is preceded by whitespace, the marker is removed.
- If it is preceded by non-whitespace, the marker is replaced by a single colon.
Doctest blocks¶
Doctest blocks are interactive Python sessions cut-and-pasted into docstrings. They do not require the literal blocks syntax. The doctest block must end with a blank line and should not end with with an unused prompt:
>>> 1 + 1
2
Tables¶
Grid tables:
Header row, column 1 (header rows optional) | Header 2 | Header 3 | Header 4 |
---|---|---|---|
body row 1, column 1 | column 2 | column 3 | column 4 |
body row 2 | … | … |
+------------------------+------------+----------+----------+
| Header row, column 1 | Header 2 | Header 3 | Header 4 |
| (header rows optional) | | | |
+========================+============+==========+==========+
| body row 1, column 1 | column 2 | column 3 | column 4 |
+------------------------+------------+----------+----------+
| body row 2 | ... | ... | |
+------------------------+------------+----------+----------+
Simple tables:
A | B | A and B |
---|---|---|
False | False | False |
True | False | False |
False | True | False |
True | True | True |
===== ===== =======
A B A and B
===== ===== =======
False False False
True False False
False True False
True True True
===== ===== =======
Hyperlinks¶
External links:
This is a paragraph that contains a Link text, inline:
This is a paragraph that contains a `Link text <https://neoctobers.readthedocs.io/>`_, inline:
You can also separate the link and the target definition (ref), like this:
This is a paragraph that contains a `Link text`_, inline:
.. _Link text: https://neoctobers.readthedocs.io/
Internal links:
Internal linking is done via a special reST role provided by Sphinx, see the section on specific markup, Cross-referencing arbitrary locations.
See: http://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#ref-role
Sections¶
Section headers are created by underlining (and optionally overlining) the section title with a punctuation character, at least as long as the text:
=================
This is a heading
=================
or:
This is a heading
-----------------
Normally, there are no heading levels assigned to certain characters as the structure is determined from the succession of headings. However, this convention is used in Python’s Style Guide for documenting which you may follow:
- # with overline, for parts
- * with overline, for chapters
- =, for sections
- -, for subsections
- ^, for subsubsections
- “, for paragraphs
For me, in this reST guide sample, I prefer -----------
.
Use keyword for footnote¶
Here is a [1] sample, and a same [1] here, and a link note also.
[1] | (1, 2) This is the footnote labeled “note”. |
Here is a [#note]_ sample, and a same [#note]_ here, and a link note_ also.
.. [#note] This is the footnote labeled "note".
Citations¶
Here is a citation reference: [CIT2002].
[CIT2002] | This is the citation. It’s just like a footnote, except the label is textual. |
Here is a citation reference: [CIT2002]_.
.. [CIT2002] This is the citation. It's just like a footnote,
except the label is textual.
Hyperlink Targets¶
Clicking on this internal hyperlink will take us to the target
The hyperlink target above points to this paragraph.
Clicking on this internal hyperlink will take us to the target_
.. _target:
The hyperlink target above points to this paragraph.
Substitution Definitions¶
The symbol must be used on containers used to dispose of medical waste.
The |biohazard| symbol must be used on containers used to
dispose of medical waste.
.. |biohazard| image:: https://avatars2.githubusercontent.com/u/6206827?s=40&v=4
TBC¶
To be continued…
Linux Tools Quick Tutorial¶
https://linuxtools-rst.readthedocs.io/ (zh_CN Only)
Set timezone on Ubuntu¶
Run and select Asia
, China
, Beijing time
:
$ tzselect
Copy the zoneinfo file to /etc
:
$ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
TCP Ping on Ubuntu¶
A TCP Ping tool.
Download¶
$ sudo apt install tcptraceroute
$ sudo wget http://www.vdberg.org/~richard/tcpping -O /usr/bin/tcping
$ sudo chmod 755 /usr/bin/tcping
Usage¶
$ tcping 127.0.0.1 22
seq 0: tcp response from localhost (127.0.0.1) [open] 0.031 ms
seq 1: tcp response from localhost (127.0.0.1) [open] 0.095 ms
seq 2: tcp response from localhost (127.0.0.1) [open] 0.032 ms
seq 3: tcp response from localhost (127.0.0.1) [open] 0.034 ms
seq 4: tcp response from localhost (127.0.0.1) [open] 0.111 ms
seq 5: tcp response from localhost (127.0.0.1) [open] 0.035 ms
^C
Linux Commands (for remark)¶
some commands here…
Update & upgrade¶
$ sudo apt update
$ sudo apt upgrade
or
$ sudo apt update && sudo apt upgrade
List listening ports¶
$ netstat -ntlp | grep LISTEN
.tar.gz¶
$ tar -zcvf filename.tar.gz source
unzip¶
$ tar xzf filename.tar.gz
Check tcp_bbr¶
$ lsmod | grep bbr
MySQL Connection support for Python3 on ubuntu¶
$ sudo apt install libmysqlclient-dev
$ pip3 install mysqlclient
Install libsodium¶
$ sudo apt install libsodium-dev
Python Cookbook 3rd Edition Documentation¶
https://python3-cookbook.readthedocs.io/ (zh_CN Only)
Update pip3 to 18.x on Ubuntu 18.04 LTS¶
Check for python3 version:
# python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Install pip3
:
# wget https://bootstrap.pypa.io/get-pip.py
# python3 get-pip.py
Check pip3
:
# pip3
-bash: /usr/bin/pip3: No such file or directory
but:
# pip -V
pip 18.1 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)
pip
=== pip3
??! Make a symblink for it:
# ln -s /usr/local/bin/pip /usr/bin/pip3
# pip3 -V
pip 18.1 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)
Django¶
useful commands:
django-admin startproject projectname
python manage.py startapp appname
python manage.py makemigrations appname
python manage.py makemigrations
python manage.py migrate
python manage.py runserver 8000
Use Django ORM¶
In a deeper directory, without the manage.py
# coding:utf-8
import os, sys
from django.core.wsgi import get_wsgi_application
# /path/to/django/project
PROJECT_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir))
sys.path.extend([PROJECT_DIR])
# load auto.settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'name.settings')
application = get_wsgi_application()
# only if run directly
if __name__ == "__main__":
pass
virtualenvwrapper-win¶
Install¶
pip3 install virtualenvwrapper-win
Enviroment Vars¶
set enviroment WORKON_HOME
as D:\path\to\envs
create venv¶
mkvirtualenv venv-name
enter venv¶
workon venv-name
exit venv¶
deactivate
PostgreSQL SSL connection for Django settings¶
Many many many many many many searches and tries….. Fxck…
psycopg2 package¶
pip3 install --upgrade psycopg2
configration file¶
PostgreSQL official: Database Connection Control Functions
https://www.postgresql.org/docs/current/libpq-connect.html
Edit the settings.py
file like this:
DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# },
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'HOST': 'server-ip',
'PORT': '5432',
'NAME': 'database-name',
'USER': 'username',
'PASSWORD': 'password',
'OPTIONS': {
'sslmode': 'require',
'sslcert': '/path/to/file',
'sslkey': '/path/to/file',
'sslrootcert': '/path/to/file',
},
},
}
Auto install packages from requirements.txt¶
$ pip3 install -r requirements.txt
PyPI¶
Installation¶
$ pip3 install --user --upgrade setuptools wheel twine
Configuration¶
~/.pypirc file:
[distutils]
index-servers=pypi
[pypi]
repository = https://upload.pypi.org/legacy/
username = <username>
password = <password>
Pack¶
$ py setup.py sdist bdist_wheel
Upload¶
$ twine upload dist/*
Github: scripts - Some useful scripts¶
https://github.com/neoctobers/scripts
Clone¶
$ git clone git@github.com:neoctobers/scripts.git
Windows¶
Add the absolute path to PATH
. Then you can easily use these commands everywhere.
Linux¶
+x
:
$ sudo chmod +x /path/to/scripts/linux/*
Create /etc/profile.d/add_to_path.sh
:
$ sudo nano /etc/profile.d/add_to_path.sh
Edit with one line:
export PATH=/path/to/scripts/linux:$PATH
Permit:
$ sudo chmod +x /etc/profile.d/add_to_path.sh
Add to sudo:
$ sudo visudo
Add /path/to/scripts/linux
in secure_path="..."
.
Reboot
PyPI: list-ext - 一个 Python 的 list 类型扩展功能包¶
一个 Python 的 list
类型扩展功能包
unique
strip
strip_and_unique
remove
strip_and_remove
remove_and_unique
sur
安装¶
$ pip3 install -U list-ext
使用¶
import list_ext
a = ['abc', ' abc ', 'a', 'b', 'c', 'a', 'b', '', '', 'd', None, 0, '', '1']
print(a)
print()
print(list_ext.unique(a))
print(list_ext.strip(a))
print(list_ext.remove(a))
print(list_ext.remove(a, 0))
print(list_ext.remove(a, ['', None, 0]))
print()
print(list_ext.strip_and_unique(a))
print(list_ext.strip_and_remove(a))
print(list_ext.remove_and_unique(a))
print()
print(list_ext.sur(a))
print(list_ext.sur(a, 0))
运行结果
['abc', ' abc ', 'a', 'b', 'c', 'a', 'b', '', '', 'd', None, 0, '', '1']
['abc', ' abc ', 'a', 'b', 'c', '', 'd', None, 0, '1']
['abc', 'abc', 'a', 'b', 'c', 'a', 'b', '', '', 'd', None, 0, '', '1']
['abc', ' abc ', 'a', 'b', 'c', 'a', 'b', 'd', 0, '1']
['abc', ' abc ', 'a', 'b', 'c', 'a', 'b', '', '', 'd', None, '', '1']
['abc', ' abc ', 'a', 'b', 'c', 'a', 'b', 'd', '1']
['abc', 'a', 'b', 'c', '', 'd', None, 0, '1']
['abc', 'abc', 'a', 'b', 'c', 'a', 'b', 'd', 0, '1']
['abc', ' abc ', 'a', 'b', 'c', 'd', 0, '1']
['abc', ' abc ', 'a', 'b', 'c', 'a', 'b', 'd', 0, '1']
['abc', ' abc ', 'a', 'b', 'c', 'a', 'b', '', '', 'd', None, '', '1']
PyPI: dict-ext - A Python dict extension¶
A Python list
extension.
…tbc
Installation¶
$ pip3 install -U dict-ext
PyPI: file-ext - A Python file extension¶
A Python file
extension, comment starts with #
is allowed:
read_to_list(path_to_file)
Installation¶
$ pip3 install -U file-ext
PyPI: ssr-utils - Shadowsocks(R) Utils¶
Shadowsocks(R) utils:
- Get SSR URLs by subscribe
- SSR URL encode/decode
- Generate plain text
- Generate
.json
config file - Check available (for linux only)
Installation¶
$ pip3 install ssr-utils
Usage¶
import ssr_utils
ssr = ssr_utils.SSR()
ssr.load(ssr_object)
# or
ssr.url = 'ssr://...' # 'ss://...' is accepted too
# or
ssr.set(server=server,
port=port,
method=method,
password=password,
protocol=protocol,
proto_param=proto_param,
obfs=obfs,
obfs_param=obfs_param,
remarks=remarks,
group=group,
)
# and you may:
ssr.remarks = '...'
ssr.group = '...'
# then...
print(ssr.url)
print(ssr.plain)
print(ssr.config)
# generage a config file, as .json
ssr.local_address = '127.0.0.1'
ssr.local_port = 1080
ssr.path_to_config = 'config.json'
print(ssr.json_string)
ssr.generate_config_file()
# even, healthy check, for linux only and need a .env file
if ssr.is_available:
print(ssr.ip)
print(ssr.country)
print(ssr.country_code)
Get SSR URLs by subscribe¶
import ssr_utils
urls = ssr_utils.get_ssr_urls_by_subscribe('https://...')
PyPI: ip-utils - IP utils¶
TBC.
PyPI: xpi - Some useful functions for Raspberry Pi3B+¶
https://github.com/neoctobers/xpi
Installation¶
$ pip3 install -U xpi
Usage¶
import xpi
ip = xpi.get_host_ip() # Get host IP address by UDP
ip = xpi.save_host_ip() # Force to save the IP address to a temporary file
ip = xpi.read_host_ip() # Read the IP address from a temporary file, or get and save it
Lavarel-Homestead on Win10¶
https://laravel.com/docs/5.7/homestead
VirtualBox and Vagrant¶
Download and install:
- VirtualBox: https://www.virtualbox.org/wiki/Downloads
- Vagrant: https://www.vagrantup.com/downloads.html
Clone Homestead¶
$ git clone https://github.com/laravel/homestead.git
Download Laravel Homestead Box file¶
Index page: https://app.vagrantup.com/laravel/boxes/homestead
Find the latest version, v6.4.0
for example, copy the url https://app.vagrantup.com/laravel/boxes/homestead/versions/6.4.0
, append /providers/virtualbox.box
, it will be https://app.vagrantup.com/laravel/boxes/homestead/versions/6.4.0/providers/virtualbox.box
.
Download it to the homestead directory, and create a file virtualbox.json
:
{
"name": "laravel/homestead",
"versions": [{
"version": "6.4.0",
"providers": [{
"name": "virtualbox",
"url": "virtualbox.box"
}]
}]
}
Add virtualbox to vagrant¶
Under the homestead directory:
$ vagrant box add virtualbox.json
==> box: Loading metadata for box 'virtualbox.json'
box: URL: file://D:/_dev/homestead/virtualbox.json
==> box: Adding box 'laravel/homestead' (v6.4.0) for provider: virtualbox
box: Downloading: virtualbox.box
box: Progress: 100% (Rate: 892M/s, Estimated time remaining: --:--:--)
==> box: Successfully added box 'laravel/homestead' (v6.4.0) for 'virtualbox'!
TOR¶
Just TOR
\ Sort by:\ best rated\ newest\ oldest\
\\
Add a comment\ (markup):
\``code``
, \ code blocks:::
and an indented block after blank line