Posts

Showing posts from May, 2019

Use Bazel and Gtest

Why Bazel? Because  cmake  or  make  is too hard to learn. How to learn Bazel? Follow its instruction on official website: {% embed url=" https://docs.bazel.build/versions/master/tutorial/cpp.html " %} The  binary BUILD file  may looks like this: cc_binary( name = "hello-world", srcs = ["hello-world.cc"], visibility = ["//visibility:public"] ) The  library BUILD file  may looks like this: cc_library( name = "hello-lib", srcs = ["hello-lib.cc"], hdrs = ["hello-lib.h"], visibility = ["//visibility:public"] ) How to use Gtest with Bazel? {% embed url=" https://docs.bazel.build/versions/master/cpp-use-cases.html\#including-external-libraries " %} The final folder structure may looks like this: ├── external │   └── gtest.BUILD ├── lib │   ├── BUILD │   ├── hello-lib.cc │   └── hello-lib.h ├── main │   ├── BUILD │   └── hello-world.cc ├── test │   ├── BU

Use Nuitka to compile Python Codes to Binary file

pip install nuitka patchelf ordered-set zstandard python3 -m nuitka --follow-imports --standalone --onefile  --remove-output --output-filename="program.run" main.py # or python3 -m nuitka --follow-imports --standalone --output-dir="excutable" main.py Why I say Python is better than C/C++ Python is made for human (codes writing like English speaking) Python can be running at every platform after you compile it to binary file by using Cython or Nuitka Python has countless packages also was intended for humans How to compile Python codes to binary? 1. Let’s say you have a package in this structure: └── auto_everything ├── __init__.py ├── base.py ├── video.py └── web.py 2. After Nuitka was installed, run the following commands: cd .. python3 -m nuitka --module auto_everything --output-dir=outputs or cd .. python3 -m nuitka --module auto_everything --include-package=auto_everything.base,auto_everything.video,auto_everything

Mastering iptables, ip (iproute2)

After you enabled your hotspot and VPN on your android phone, the following commands could be used to let all devices who connected to your hotspot to have the ability to enjoy the VPN without any further work. ``` iptables -t filter -F FORWARD iptables -t nat -F POSTROUTING iptables -t filter -A FORWARD -j ACCEPT iptables -t nat -A POSTROUTING -j MASQUERADE ip rule add from 192.168.43.0/24 lookup 61 ip rule add from 192.168.42.0/24 lookup 61 ip route add default dev tun0 scope link table 61 ip route add 192.168.43.0/24 dev wlan0 scope link table 61 ip route add 192.168.42.0/24 dev wlan0 scope link table 61 ip route add broadcast 255.255.255.255 dev wlan0 scope link table 61 ip route add 172.27.232.0/24 dev tun0 table 61 ``` ___ ``` iptables -t filter -F FORWARD ``` * -t means `table` * -F means `flush`.  flush = clear = delete > Filter: filter is the default table. Its built-in chains are Input, Forward, Output Delete all rules at the `Forward Chain`