Measure the execution time of small bits of Python code with the “timeit” module

# The “timeit” module lets you measure the execution # time of small bits of Python code >>> import timeit >>> timeit.timeit(‘”-“.join(str(n) for n in range(100))’, number=10000) 0.3412662749997253 >>> timeit.timeit(‘”-“.join([str(n) for n in range(100)])’, number=10000) 0.2996307989997149 >>> timeit.timeit(‘”-“.join(map(str, range(100)))’, number=10000) 0.24581470699922647

Swap two variables using Python easily

#Why Python Is Great: # In-place value swapping # Let’s say we want to swap # the values of a and b… a = 23 b = 42 # The “classic” way to do it # with a temporary variable: tmp = a a = b b = tmp # Python also lets us #…

Hiển thị file, folder dạng tree trên MacOS

Nếu như bạn là người quen làm việc với Linux hay MacOS và bạn muốn hiển thị các files, thư mục dưới dạng tree. Thì lệnh dưới đây sẽ giúp bạn điều đó: Hiển thị dưới dạng tree trên Linux tree Hiển thị dưới dạng tree trên MacOS find . -print | sed -e ‘s;[^/]*/;|____;g;s;____|;…

Find all files containing specific text on Linux

grep -rnw ‘/path/to/somewhere/’ -e ‘pattern’ -r or -R is recursive, -n is line number, and -w stands for match the whole word. -l (lower-case L) can be added to just give the file name of matching files. Along with these, –exclude, –include, –exclude-dir flags could be used for efficient searching: This will only search through…

Location of docker images downloaded by Docker on Mac OS X

To elaborate on how to open these folders in case you are getting now directory because it is a mounted on virtual host not your Mac regular volume screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty ls -ltrh /var/lib/docker/volumes If you want to control the volume from your mac, you can map it while you are creating the container docker run…

Xem git log dưới dạng đồ thị

Để hiển thị git log dưới dạng đồ thị trong cửa sổ command line, các bạn có thể sử dụng cmd bên dưới. git log –graph –pretty=format:”%C(yellow)%h%Creset%C(cyan)%C(bold)%d%Creset %C(cyan)(%cr)%Creset %C(green)%ce%Creset %s” More git log –name-status –since=midnight | grep -E ‘^[A-Z]\b’ | sort | uniq git log –name-status –since=midnight –pretty=format:”%cr” | uniq git log –name-status –since=”2018-06-29″ –pretty=format:”%cr”…

Git log with date

Thực hiện xem log với tên và trạng thái cùng với thời gian: git log –name-status –since=”2018-05-29″ | grep -E ‘^[A-Z]\b’ | sort | uniq >> bbbb.txt

Odoo – How to change defaul port 8069

In Odoo, the default port is 8069 However, we can change it if we want. First, go to the odoo source folder. vi odoo/tools/ Find 8069 and change to your port you want. After above, you need to restart odoo service. Good luck!

Code test connect to postgresql database by using PHP

error_reporting(E_ALL); ini_set(‘display_errors’, TRUE); ini_set(‘display_startup_errors’, TRUE); $host = “host = localhost”; $port = “port = 5432”; $dbname = “dbname = db_test”; $credentials = “user = root password = 123@123”; $db = pg_connect( “$host $port $dbname $credentials” ); if(!$db) { echo “Error : Unable to open database\n”; } else { echo “Opened database successfully\n”; }