DevNotes

Concise, Handy and Elegant Notes for Developers

0%

Django uses SQLite database by default, now we want to switch it to postgreSQL. Firstly, we fetch postgreSQL docker image and start an instance

1
2
docker pull postgres
docker run --name my-postgres -v /tmp/my-pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=my-password -p 127.0.0.1:5432:5432 -d postgres

The docker instance name can be whatever you want, here it’s named my-postgres for instance, and we mount a volume (e.g /tmp/my-pgdata) to our container, so that the database files are easier to access for other tools or applications on our host system. And remember to forward the default postgreSQL port and use -d to put it to background. Next, we install postgreSQL command line client if you haven’t done that yet.

1
sudo apt-get install postgresql-client

Then, we connect to postgreSQL, either command below should work, postgres is the default database and user name

1
2
psql postgresql://postgres:my-password@127.0.0.1:5432/postgres
docker exec -it my-postgres psql postgresql://postgres:my-password@127.0.0.1:5432/postgres
Read more »

Previously, we have Setup the blog using Hexo and deploy it to Github page. Additionally, we can deploy it to Vercel(formerly zeit). We can either go to their website to connect it to our Github, Gitlab, etc, or install command line interface and deploy with one hit.
npm i -g vercel

Just run vercel or vc inside the project, it will guide you to setup for the first time and deploy automatically. Note, the command was used to be called now.

When we need help in Linux command line, man is usually the first friend we check for more information. But it became my second line support after I met other alternatives, e.g. tldr, cheat and eg.

tldr

tldr stands for too long didn’t read, it is a simplified and community-driven man pages. Maybe we forget the arguments to a command, or just not patient enough to read the long man document, here tldr comes in, it will provide concise information with examples. And I even contributed a couple of lines code myself to help a little bit with the project on Github. It is very easy to install: npm install -g tldr, and there are many clients available to pick to be able to access the tldr pages. E.g. install Python client with pip install tldr,

To display help information, run tldr -h or tldr tldr.

Take curl as an example

Read more »

Tcpdump is a very useful tool to capture network packets.
e.g. to capture TCP packet from interface lo0 via port 9999

1
sudo tcpdump -i lo0 port 9999 -XX -v

Here demostrate sending some UDP packets, using tcpdump to capture them and using Tcpreplay to playback.

Read more »

A recent project, we have to send TCP and UDP data from Host to Docker, back and forth. Docker is great and it is easy to expose port to provide service inside Docker instance. For example:

1
docker run -itd --name my_instance -p 1111:2222 -p 8888:9999/udp my_image

Here we map the TCP port 1111 from host to 2222 inside docker instance, and UDP port 8888 on host to 9999 in docker, and some help commands we use frequently such as

Read more »

Air Quality Index

I’v been experimenting to fetch data related to AQI in China recently.

A good resource is http://aqicn.org, which provides air pollution data in a good way by city, and I try to write a python script to crawl the data from it.

Read more »

Previously I am using spf13 for my vim configuration. However it is a bit sluggish for me since it includes too much settings and plugins which might not be needed for my daily usage, therefore I deicide to move to this vimrc.

New plugins installed manually such as vim-rails, vim-autoformat, YouCompleteMe, tagbar, vim-ctrlp-tjump etc.

Ctags is also needed for go to definition.

I remove/comment out the line to have deafault key mapping for multiple selection in plugins_config.vim

1
let g:multi_cursor_next_key="\<C-s>"

Here is how it looks for my_configs.vim

Read more »