WeiNote

yyrcd

web

TA

pl

2019

Dec 11

Mongo add archive field to every documents.

db.wikis.update(
  {},
  { $set: {"archive": false} },
  {upsert:false,multi:true}
)

2019

Oct 26

curl

curl github.com

Node.js

var request = require('request');

var options = {
    url: 'github.com'
};

function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body);
    }
}

request(options, callback);

python

import requests

response = requests.get('http://github.com')

2019

Oct 05

Backup mongodb

  1. backup.sh
#!/bin/bash

MONGO_DATABASE="roitberg"
APP_NAME="roitberg-web"
MONGO_HOST="ds8888.mlab.com"
MONGO_PORT="88888"
USER="username"
PW="password"

TIMESTAMP=`date +%F-%H%M`
MONGODUMP_PATH="/usr/bin/mongodump"
BACKUPS_DIR="/home/richard/production/backup/$APP_NAME"
BACKUP_NAME="$APP_NAME-$TIMESTAMP"

$MONGODUMP_PATH -h $MONGO_HOST:$MONGO_PORT -d $MONGO_DATABASE -u $USER -p $PW

mkdir -p $BACKUPS_DIR
mv dump $BACKUP_NAME
tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tgz $BACKUP_NAME
rm -rf $BACKUP_NAME

# only keep the newest 30 backups
cd $BACKUPS_DIR
ls --color=no -t | sed -e '1,30d' | xargs -d '\n' rm
  1. Automatic backup
# install mongodb backup tools
sudo apt install -y mongodb-org-shell
sudo apt install -y mongodb-org-tools
# edit the crontab file
sudo crontab -e
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any')
# m h  dom mon dow   command
00 01 * * * /bin/bash /home/richard/production/backup/scripts/backup.sh

Online crontab editor: https://crontab.guru/

 sudo service cron restart

2019

Jun 30

Wireguard

Install

Set Up WireGuard VPN on Ubuntu | Linode

IPv6

IPv4 only环境下通过Wireguard获取全局IPv6地址

tcpdump

richard@miami > sudo tcpdump -i wg0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wg0, link-type RAW (Raw IP), capture size 262144 bytes
12:05:06.856663 IP 172.22.2.2 > 172.22.2.3: ICMP echo request, id 28433, seq 0, length 64
12:05:06.856721 IP 172.22.2.2 > 172.22.2.3: ICMP echo request, id 28433, seq 0, length 64
12:05:06.876567 IP 172.22.2.3 > 172.22.2.2: ICMP echo reply, id 28433, seq 0, length 64
12:05:06.876592 IP 172.22.2.3 > 172.22.2.2: ICMP echo reply, id 28433, seq 0, length 64
12:05:07.859800 IP 172.22.2.2 > 172.22.2.3: ICMP echo request, id 28433, seq 1, length 64
12:05:07.859827 IP 172.22.2.2 > 172.22.2.3: ICMP echo request, id 28433, seq 1, length 64
12:05:07.879684 IP 172.22.2.3 > 172.22.2.2: ICMP echo reply, id 28433, seq 1, length 64
12:05:07.879707 IP 172.22.2.3 > 172.22.2.2: ICMP echo reply, id 28433, seq 1, length 64

ping

richard@mbpr > ping 172.22.2.3
PING 172.22.2.3 (172.22.2.3): 56 data bytes
64 bytes from 172.22.2.3: icmp_seq=0 ttl=63 time=32.214 ms
64 bytes from 172.22.2.3: icmp_seq=1 ttl=63 time=32.074 ms
^C
--- 172.22.2.3 ping statistics ---
2 packets transmitted, 2 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 32.074/32.144/32.214/0.070 ms

2019

Jun 28

pm2

pm2 save  # Saving current process list
pm2 resurrect  #Manually resurrect processes

NY

pm2 stop wlm liwei qianchen aria gigim

2019

Jun 23

2019

Jun 13

npm install so slow, this might because no swap space enabled. https://stackoverflow.com/a/32444643/9581569

sudo fallocate -l 2G /swapfile #Create a 4 gigabyte swapfile
sudo chmod 600 /swapfile #Secure the swapfile by restricting access to root
sudo mkswap /swapfile #Mark the file as a swap space
sudo swapon /swapfile #Enable the swap
echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab #Persist swapfile over reboots (thanks for the tip, bman!)

2019

Jun 12

Multiple CSS/JS Dropdowns https://stackoverflow.com/a/49745579/9581569 The dropdown buttons used in this website are based on this answer (Jquery way).

2019

Jun 07

mongodb sort

db.getCollection('music163s').find({}).sort({ _id: 1})