Posts

Showing posts from 2020

How to understand and use @property in Python

 https://www.machinelearningplus.com/python/python-property/

How to identity False value in Python

  constants defined to be false:  None  and  False . zero of any numeric type:  0 ,  0.0 ,  0j ,  Decimal(0) ,  Fraction(0,   1) empty sequences and collections:  '' ,  () ,  [] ,  {} ,  set() ,  range(0)

Install Pyenv and virtualenv

Install pyenv in Ubuntu https://www.codegrepper.com/code-examples/shell/install+brew+ubuntu+20.04 https://github.com/pyenv/pyenv/wiki/Common-build-problems Tại sao cần Install Pyenv? Vì pyenv là một phần mềm cho phép bạn có thể cài nhiều version của python đơn giản là  pyenv install 3.7.3 hoặc uninstall bằng cách  pyemv uninstall 3.7.3 sau khi có python version 3.7.3 rồi thì bằng cách setup nó và dùng nó như là python defaut  pyenv global 3.7.3 để kiểm tra version python dùng  which python python -V  để kiểm tra pip which pip  pip -V Oki vậy là đã có python cho máy, sau này cần nâng cấp python version 3.8.2 thì chỉ cần instal 3.8.2 và dùng pyenv global để apply it ------------------------DONE install python-------------- Tiếp theo để dùng python trong dự án thì chúng ta cần thiết lập một môi trường ảo cho nó cài virtualenv pip install --upgrade virtualenv virtualenv .venv vào project và dùng lện  virtualenv  .venv để tạo thư mục .venv cho dự án s...

if x: #x is treated True except for all empty data types [],{},(),'',0 False, and None

  if x: #x is treated True except for all empty data types [],{},(),'',0 False, and None https://stackoverflow.com/a/7825137
 http://xxx:8090/prometheus/api/v1/query_range?query=sum by (instanceId,instancePhase,project_id)(sum_over_time(porta_downstream_rq_5xx{instanceId="ltv-verda-porta",instancePhase="alpha",project_id="1cd9bc91b48e4d0b8c34cd6932f221a0",product_id=~".*",api_id=~".*", api_key_id=~".*"}[59s]))&start=1603436397&end=1603436657&step=60s

How to create a remote git branch

https://www.w3docs.com/snippets/git/how-to-create-a-remote-branch-in-git.html Step 1: you are on master branch then you are planning to create a new branch on the master branch use the following command git checkout -b <new-branch-name> this command is used to create a local branch on the current local branch ex:  git checkout -b feature/ixu then after that  git push -u origin your_remote_branch_name  ex:  git push -u origin feature/ixu

First step on makefile

 https://opensource.com/article/18/8/what-how-makefile https://www.tutorialspoint.com/makefile/index.htm https://makefiletutorial.com/

Docker and Docker-compose

 Docker compose: Hiểu nôm na nó là một bản soạn thảo Nó soạn thảo cái gì? -> Nó soạn thảo một danh mục các Docker image cần khởi tạo thành container Ví dụ bình thường bạn có 1 restful service, service dùng redis để cache và dùng mysql để lưu dữ liệu, và dùng kafka hoặc rabbitMQ để dùng Message Như vậy bạn hoàn toàn có thể tạo docker file cho service rồi build thành image và chạy manual thành container Bạn cũng có thể kéo Redis image về và chạy thành docker container Tương tự Mysql, hoặc Kafka hoặc rabbitMQ --> Việc cài đặt bằng tay thủ công cho các thành phần trên là khá ok, nhưng đó k phải là 1 cách hoàn hảo để deploy trên docker --> dẫn đến khái niệm docker-compose  Nó là 1 file định nghĩa các image cùng nhau được khởi tạo thành các docker trong một mạng network riêng --> với cách này bạn chỉ cần soạn thảo file docker-compose  cho các docker đó rôì dùng lệnh docker-compose up -d để build và run containers  Với cách này chỉ cần cài đặt docker trên môi t...

First steps for learning python

https://realpython.com/intro-to-pyenv/  for ubuntu  https://opensource.com/article/19/5/python-3-default-mac  for macos You should install python, and pip by pyenv , it is easy to install several versions of python on your machine and it is so easy to switch each version -------------------- install RUST and Cargo  and apply  Rust has multiple compilers and nightly contains some of the more experimental features. I was able to upgrade from stable Rust to nightly following the advice on the  Rust-Lang-Nursery GitHub Page : Install nightly toolchain: $ rustup install nightly Switch to nightly toolchain as default toolchain: $ rustup default nightly

First steps on Ansible

 https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-on-ubuntu https://docs.ansible.com/ansible/latest/user_guide/playbooks_best_practices.html Ping remote server with ansible ansible all -i 122.248.226.169,  -m ping -u ubuntu 122.248.266.169 is the remote host -m ping: is ping -u ubuntu: is remote user

5. Thứ năm: Tự mãn

ref:  https://cafef.vn/5-thoi-quen-tu-huy-hoai-ban-than-cua-nguoi-tre-bat-tin-nong-nay-luoi-bieng-vo-on-va-dieu-thu-5-la-thu-khien-con-nguoi-ta-that-bai-nhanh-nhat-2020091914312849.chn Càng tiếp xúc với những người đẳng cấp, bạn sẽ càng phát hiện ra khuyết điểm của mình. Khách quan mà nói, sức người có hạn nên khả năng và kiến ​​thức của bất kỳ ai cũng tương đối hạn chế, vì vậy, có thể nhận ra khuyết điểm của bản thân chính là hiện thân của trí tuệ. Thế nhưng, không ít người chưa nhận thức được điều này. Họ tìm mọi cách che giấu khuyết điểm mà chỉ thổi phồng những gì đang có. Nên nhớ rằng, ranh giới giữa sự tự tin và tự mãn rất mỏng manh. Càng có thói quen chủ quan và ảo tưởng về bản thân, họ sẽ càng tụt hậu, thậm chí trở thành "ếch ngồi đáy giếng". Con người có thể bỏ một năm, mười năm hay nhiều hơn thế để xây nên thành công, nhưng tính tự mãn như một liều thuốc độc có thể giết chết thành công đó chỉ trong tích tắc. Mỗi người chúng ta phải biết quản trị, kiểm soát bản thân, ...

Tư duy dài hạn thực sự giúp chúng ta đưa ra quyết định đúng đắn của cuộc đời

 Người suy nghĩ thiển cận dễ thất bại, muốn thành công cần nhìn xa trông rộng, vạch kế hoạch dài hạn trong 5, 10, 20 năm tới. Con người thường có xu hướng suy nghĩ mọi thứ trong thời gian ngắn hạn nhưng lại không hay nghĩ đến những hậu quả sau này từ những hành động ở hiện tại. Những áp lực trong cuộc sống ngày nay đôi khi khiến chúng ta gặp khó khăn trong việc trù hoạch những quyết định hay công việc ở tương lai xa. Stelian Nenkov, Nhà nghiên cứu định lượng cao cấp tại WorldQuant, lập luận rằng: "Khi chúng ta sống trong một xã hội phức tạp và được kết nối, những suy nghĩ ngắn hạn được coi là yếu tố chính để đạt được tương lai thành công và bền vững. Nhưng thực tế chìa khóa để đạt được thành tựu thật sự là bạn cần lập kế hoạch cuộc sống và công việc có tính dài hạn.” Để thay đổi được cuộc sống theo cách thông minh, đừng nhầm lẫn giữa cái được gọi là “mong muốn” với “mục tiêu”. Hãy cẩn thận với những quyết định không được cân nhắc kỹ lưỡng vì chúng có thể dẫn tới những hậu quả mà b...

How to write email

 1. ĐỐI VỚI EMAIL LẦN ĐẦU GỬI CHO NGƯỜI KHÁC XIN THAM KHẢO MẪU SAU: Chủ đề email: "Về việc (nêu ra công việc cụ thể nhưng ngắn gọn thôi)" Chào chị A, (ghi tên cụ thể chứ đừng Dear anh/chị, và tuyệt đối không ghi sai tên người nhận) Em là ... đến từ (cơ quan/đoàn thể tương ứng). Em có được email này của chị do anh B bên công ty C giới thiệu (nêu ra hoàn cảnh có được thông tin liên lạc hoặc gợi nhắc người ta về dịp đã được gặp nay email liên hệ nói chuyện thêm). Em viết email này để (nêu ra công việc cần thảo luận, cụ thể hơn phần email title nhưng đừng có trình bày hết một cục chữ dày đặc ở đoạn này). (Chấm, xuống dòng, sang ý khác. Mỗi đoạn một ý ngắn gọn thôi.)  Về việc A, .... Về vấn đề B, ... Tuy nhiên, một khúc mắc có thể xảy ra là ... Vì vậy, em đề xuất mình có thể ... Bước tiếp theo, mong chị gửi em... . Nếu cần thêm thông tin, chị cứ nói với em hoặc có gì gấp chị có thể gọi em/trợ lý của em tại... (thêm một kênh liên lạc khác nhanh chóng hơn) Mong sớm nhận được phản hồ...

mockgen

 mockgen -source=client.go -package=mocks -destination=./mocks/client.go

How to choose a plan for your career

 https://waitbutwhy.com/2018/04/picking-career.html

Thread vs Process

  https://www.guru99.com/difference-between-process-and-thread.html Properties of Process Here are the important properties of the process: Creation of each process requires separate system calls for each process. It is an isolated execution entity and does not share data and information. Processes use the IPC(Inter-Process Communication) mechanism for communication that significantly increases the number of system calls. Process management takes more system calls. A process has its stack, heap memory with memory, and data map. Properties of Thread Here are important properties of Thread: Single system call can create more than one thread Threads share data and information. Threads shares instruction, global, and heap regions. However, it has its register and stack. Thread management consumes very few, or no system calls because of communication between threads that can be achieved using shared memory.

Why is TCP more reliable than UDP

https://www.ques10.com/p/11133/how-is-tcp-better-than-udp-explain-services-offe-1/  TCP is better than UDP because of following reasons: TCP is Reliable as it provides reliability of delivery of packets to the receiver while UDP is Non-reliable and does not give information about the packets. TCP is Connection oriented it means connection is to be setup before data is sent that is done in form of 3-way handshake while UDP is Connectionless. TCP provides flow control and error control characteristics while UDP doesn't provide it. TCP gives guarantee that a packet will reach on the destination without any duplication and the order of data will also be same.

What is the difference between 2 code blocks

package main import ( "fmt" "github.com/sirupsen/logrus" "runtime/debug" "time" ) func main () { defer func () { if err := recover (); err != nil { logrus . Errorln ( "main" , err ) debug . PrintStack () } }() GoInside ( nil ) time . Sleep ( 2 * time . Second ) fmt . Println ( "After panic" ) } type Test struct { X int } func GoInside ( v * Test ) { go NullPointer ( v . X ) } func NullPointer ( X int ) { fmt . Println ( X ) } This above code can handle a panic error , but the code below can not handle a panic ==> why  package main import ( "fmt" "github.com/sirupsen/logrus" "runtime/debug" "time" ) func main () { defer func () { if err := recover (); err != nil { logrus . Errorln ( "main" , err ) debug . PrintStack () } }() GoInside () time . Sleep ( 2 * ti...

How to handle panic error in Golang

ref:  https://ednsquare.com/story/learn-go-panic-and-recover-in-golang------1HSVNg func main () { NullPointer ( nil ) time . Sleep ( 2 * time . Second ) fmt . Println ( "After panic" ) } type Test struct { X int } func NullPointer ( v * Test ) { fmt . Println ( v . X ) } Đoạn code trên dễ dàng gây ra lỗi panic và stop hàm main panic: runtime error: invalid memory address or nil pointer dereference Vậy chúng ta cần làm gì để tránh gây chết hàm main đây Nếu là java hoặc ngôn ngữ khác thì chúng ta đã có try catch finally  Còn trong golang bạn sẽ có một cách trông đẹp mắt hơn func main () { defer func () { if err := recover (); err != nil { logrus . Errorln ( err ) debug . PrintStack () } }() NullPointer ( nil ) time . Sleep ( 2 * time . Second ) fmt . Println ( "After panic" ) } type Test struct { X int } func NullPointer ( v * Test ) { fmt . Println ( v . X ) } Theo cách này thì trong hàm main chúng ta ...

How to use library for stack and queue in golang

package main import ( "container/list" "fmt" ) func main () { stack := list . New () //[] stack . PushBack ( 2 ) //[2] stack . PushBack ( 3 ) //[3,2] stack . PushBack ( 4 ) //[4,3,2] stack . PushBack ( 5 ) //[5,4,3,2] stack . PushFront ( 6 ) //[5,4,3,2,6] e := stack . Front () //-> 6 fmt . Printf ( " %v " , e . Value ) e = stack . Front () fmt . Printf ( " %v " , e . Value ) v := stack . Remove ( stack . Front ()) //remove 6 fmt . Printf ( " %v " , v ) v = stack . Remove ( stack . Front ()) //remove 2 fmt . Printf ( " %v " , v ) v = stack . Remove ( stack . Back ()) //remove 5 fmt . Printf ( " %v " , v ) stack . Len () }

Hiểu về byte và rune trong Golang

tại sao Golang lại có 2 kiểu dữ liệu byte và rune // byte is an alias for uint8 and is equivalent to uint8 in all ways. It is // used, by convention, to distinguish byte values from 8-bit unsigned // integer values. type byte = uint8 // rune is an alias for int32 and is equivalent to int32 in all ways. It is // used, by convention, to distinguish character values from integer values. type rune = int32 Thực ra byte và rune là 2 kiểu alias của uint8 và int32 byte nó đại diện cho các ký tự không dấu rune nó đại diện cho các ký tự unicode nên nó có khoảng rộng hơn byte Ví dụ bạn có 2 chuỗi string như sau s1 := "a123acb" s2 := "a123acbaHôm nay quá đẹp" arr1 := [] byte ( s1 ) fmt . Printf ( " %v \n " , arr1 ) arr2 := [] rune ( s2 ) fmt . Printf ( " %v " , arr2 ) Như vậy khi bạn ép kiểu thì thao tác sẽ không bị mất dữ liệu

Format types in golang

https://gobyexample.com/string-formatting %s  dùng để format cho String:  fmt . Printf ( "%s\n" , "\"string\"" ) %c dùng để format 1 số nguyên về kiểu ký tự fmt . Printf ( "%c\n" , 33 ) %v dùng để format một struct, hoặc số, hoặc boolean, hoặc con trỏ về đúng kiểu giá trị của nó %T dùng để xác đinh type của kiểu dữ liệu fmt . Printf ( " %T\n " , p ) fmt . Printf ( " %t\n " , true ) %d dùng để in giá trị số nguyên %f dùng để in số thực fmt . Printf ( " %.2f\n " , 78.123123 )

Design Pattern in golang

https://golangbyexample.com/golang-object-pool/

how to uninstall a software in ubuntu

sudo snap remove skype  or Uninstall mahjongg  To remove just mahjongg package itself from Ubuntu 16.04 (Xenial Xerus) execute on terminal:  sudo apt-get remove mahjongg  Uninstall mahjongg and it's dependent packages  To remove the mahjongg package and any other dependant package which are no longer needed from Ubuntu Xenial.  sudo apt-get autoremove mahjongg  Purging mahjongg  If you also want to delete configuration and/or data files of mahjongg from Ubuntu Xenial then this will work:  sudo apt-get purge mahjongg  To delete configuration and/or data files of mahjongg and it's dependencies from Ubuntu Xenial then execute:  sudo apt-get autoremove --purge mahjongg

How to make bootable usb from terminal in linux os

https://askubuntu.com/questions/372607/how-to-create-a-bootable-ubuntu-usb-flash-drive-from-terminal https://vitux.com/how-to-create-a-bootable-usb-stick-from-the-ubuntu-terminal/ Step1  To recognize your USB drive's location on your disk. Let's run this command lsblk and you will see this  sda      8:0    0 119.2G  0 disk  ├─sda1   8:1    0  55.9G  0 part / ├─sda2   8:2    0     1K  0 part  ├─sda5   8:5    0   3.7G  0 part [SWAP] └─sda6   8:6    0  59.7G  0 part /home sdb      8:16   1   7.3G  0 disk  └─sdb1   8:17   1   7.3G  0 part  ==> sdb1 Step2: sudo umount /dev/sdb1 Step 3  sudo dd bs=4M if=path/to/input.iso of=/dev/sd<?> conv=fdatasync  status=progress  

how to create bootable usb on linux os

https://elementary.io/docs/installation#installation https://unetbootin.github.io/linux_download.html

Tạo một bài viết phân tích yếu điểm của các hệ thống dùng SMS để xác thực 1 lần và cách cải tiến hệ thống để bảo mật hơn

Issues trong khi build docker image

failed to export image: failed to set parent sha256:1524fb5245903585bbe27769969c45f569583cc0f9b37c3e7d1c26f058bc0b02: unknown parent image ID sha256:1524fb5245903585bbe27769969c45f569583cc0f9b37c3e7d1c26f058bc0b02 rất có thể là do bạn đã xóa mất một layer image nào đó rồi

Function vs Procedure trong Oracle database

Functions A function is compiled and executed every time whenever it is called. A function must return a value and cannot modify the data received as parameters Stored Procedures Stored Procedures are pre-compiled objects which are compiled for the first time and its compiled format is saved, which executes (compiled code) whenever it is called. For more about a stored procedure, please refer to the article  Different types of Stored Procedure .

Procedure demo

--generate checksum for all records in transaction history --remember to change checksumKey DECLARE checksumKey varchar2 ( 100 ) : = 'Tcbs@20022020' ; rawData varchar2 ( 1000 ) : = '' ; newchecksum varchar2 ( 1000 ); BEGIN DBMS_OUTPUT . PUT_LINE ( 'INFO: Workflow initiated' ); FOR txh IN ( SELECT * FROM IXU_TRANSACTION_HISTORY WHERE CAMPAIGN_ID = 2006 ORDER BY ID DESC ) LOOP rawData : = concat ( ':' , txh . HISTORY_KEY ); IF txh . EXPIRED_DATE IS NULL THEN rawData : = concat ( '' , rawData ); rawData : = concat ( ':' , rawData ); ELSE rawData : = concat ( TO_CHAR ( txh . EXPIRED_DATE , 'YYYY-MM-DD' ), rawData ); rawData : = concat ( ':' , rawData ); END IF ; rawData : = concat ( to_char ( txh . OUTSTANDING , 'FM99999999999999990.00' ), rawData ); rawData : = concat ( ':' , rawData ); rawData : = concat ( to_char ( ...

How to create procedure in oracle

CREATE INDEX temp_tcbsid_IXU_TRANSACTION_HISTORY ON IXU_TRANSACTION_HISTORY ( TCBSID ); CREATE INDEX temp_tcbsid_IXU_GENERAL_LEDGER ON IXU_GENERAL_LEDGER ( TCBSID ); create procedure updateCurrentBalanceExactly ( tcbsid_in IN varchar2 , redeemablePoint_in IN number , rankingPoint_in IN number ) is begin update IXU_GENERAL_LEDGER set RANKING_POINT = rankingPoint_in , REDEEMABLE_POINT = redeemablePoint_in where TCBSID = tcbsid_in ; -- caculate checksum here -- commit; end ; create procedure updateHistoryByID ( id_in IN number , outstanding_in IN number ) is begin update IXU_TRANSACTION_HISTORY set OUTSTANDING = outstanding_in where ID = id_in ; -- caculate checksum here -- commit; end ; create procedure arrangeHistoryByIssueDateAndGlIDExactly ( tcbsid_in IN varchar2 , award_type_in IN varchar2 ) is initBalance number ; begin initBalance = 0 ; for txHistory in...