Posts

Showing posts from 2019

how to use Curl cmd

curl -X POST -H "x-api-key: xscsss" -F "file=@/path/to/OLSTXNRF_tcbs_20191226_01.TXT" https://host:2189/ftpdata/tcbs/user_input/OLSTXNRF_tcbs_20191226_01.TXT Method: POST x-api-key: header -F chỉ ra là file file: là filename @/path/to/OLSTXNRF_tcbs_20191226_01.TXT    : Đường dân tới file, bao gồm cả @ https://host:2189/ftpdata/tcbs/user_input/OLSTXNRF_tcbs_20191226_01.TXT   : là url api  ------------------------------------------------------------------------------------ pull a GET request from a url or uri curl http://www.example.com/index.html pull and save response to a file curl http://www.example.com/index.html -o out.exxxx  -------------------------------------------------------------------------------------- post data to url  curl -d '{"id":9,"name":"baeldung"}' -H 'Content-Type: application/json'    http://localhost:8082/spring-rest/foos/new pass a file containing ...

How to start, stop & restart services in ubunt

List all service systemctl or service --status-all Start a service systemctl start <service-name> or service <service-name> start Stop a service systemctl stop <service-name> or service <service-name> stop Restart a service systemctl restart <service-name> or service <service-name> restart Check the status of a service systemctl status <service-name> or service <service-name> status

how to use 'alias' in linux

Many a times, you might need to create new commands from existing commands. Sometimes, existing commands have complex options to remember. In such cases, we can create new commands as follows: $ alias ll='ls –l' $ alias copy='cp –rf' To list all declared aliases, use the following command: $ alias To remove an alias, use the following command: $ unalias copy

how to use git config

$ git config --global alias.co checkout $ git config --global alias.br branch $ git config --global alias.ci commit $ git config --global alias.st status Dùng để tạo cú pháp ngắn gọn cho câu lệnh git Ví dụ $ git config --global alias.unstage 'reset HEAD --' thì 2 câu lệnh duwois là tương đương $ git unstage fileA $ git reset HEAD fileA

how to use git tag

git tag -a v1.4 -m 'my version 1.4' Dungf để tạo một version tag git tag Dùng để show list of tag git show v1.4 Dùng để show chi tiết tag

how to use git reset

git reset Lệnh này sẽ move tất cả file ở trong vùng index(staging) sang vùng working git reset fileName Lệnh này sẽ move fileName ở trong vùng index(staging) sang vùng working Đây là cách để bạn revert sau khi dùng lệnh git add --------------------------------------------------- Giả sử bạn commit 1 thay đổi , nhưng bạn thấy thay đổi này k ổn vậy cần phải bổ sung thêm, Thì bạn có thể sửa lại file rồi dùng lệnh git commit -amend  Lệnh này sẽ gộp last commit với commit vừa rồi tạo thành một commit --> bạn có thể push ----Cách 2 Bạn nghĩ rằng tôi sẽ xóa commit vừa rồi và làm lại nó Bạn có thể dùng cách này git reset --soft id_commit Lúc này nó giống như là commit cuối đã được xóa và vùng index vẫn giữ nguyên nội dung của commit cuối, hiểu đơn giản là giờ bạn đang có thay đổi đó ở index rồi, bạn thoải mái sửa và add lại rồi commit. Đây cũng là cách hay dùng nhất nè git reset --mixed id_commit hoặc git reset id_commit  Bằng cách này thì comm...

how to use git branch --merged and git branch --no-merged

Bạn đang ở nhánh master Để xem các branch đã merger vào master thì dùng git branch --merged   iss53 * master Còn để xem các branch chưa merge vào master thì dùng git branch --no-merged

how to use git merge

Nếu muốn merge một nhánh A vào nhánh B Thì cần phải checkout về nhánh B trước đã Dùng lệnh git checkout B Sau đó dùng lệnh git merge A ------------------------------------------------------------------- Tình huống thực tế là bạn có một nhánh master Và cần hotfix một lỗi issue-cacheerror khi đó bạn gần làm là Di chuyển về nhánh master với lệnh git checkout master  Sau đó dùng lệnh dưới để tạo một nhánh mới từ *Head trên master và vào nhánh đó git checkout -b issue-cacheerror  Như vậy bạn đã ở nhánh hotfix rồi, bạn sửa và test ok Sau đó bạn sẽ về lại nhánh master và dùng lệnh sau git checkout master git merge issue-cacheerror Done

how to push code from feature to develop

Git resolve conflict dev Khi bạn đang ở nhánh feature/xxx code và đẩy lên dev. Vấn đề là khi đẩy lên dev thì khả năng cao là code sẽ bị conflict vậy bạn cần phải resolve trước khi push. Bạn cần làm là Switch  nhánh feature git pull origin develop Lấy code mới nhất rồi resolve và commit lại và push là ok

how to use git stash

Git stash Dùng để lưu một bản sao trạng thái thay đổi hiện tại Git stash list  dùng để view danh sách các stash git stash apply  nó sẽ apply stash{0} nhưng k xóa stash đó đi git stash pop  nó sẽ apply stash{0} và xóa stash đi git stash drop  sẽ k apply nhưng sẽ xóa stash{0} git stash apply stash@{1} sẽ k xóa stash, và apply stash{1} Nhưng tất cả apply trên sẽ chỉ áp dụng cho tại vùng Working, không áp vào vùng Staging Để stassh vào cả vùng staging thì thêm option --index git stash apply --index

how to use git checkout -b

Để tạo một  local branch mới và checkout tới remote đó luôn thì dùng $ git checkout -b iss53 Switched to a new branch 'iss53' ---------------------------------- This is shorthand for: $ git branch iss53 $ git checkout iss53

how to use git checkout

git checkout fileName Lấy file trong index để copy vào working place, nhưng vẫn giữ file trong index, lệnh này khác lệnh git reset filename vì reset sẽ move file từ index về working git checkout HEAD fileName Lấy file trong commited để copy vào working place, và xóa trong index những thay đổi của file đó

how to use git diff

git diff Dùng để so sánh file trong vùng Working và vùng Staging git diff --cached  dùng lệnh này để so sánh sự thay đổi của file trong Staging và trong vùng Commited git diff  HEAD  so sánh file working và Commited git diff  id_commit1 id_commit2 Dùng để show diff giữa 2 commit khác nhau git diff  id_commit1 id_commit2   fileName Dùng để show diff giữa 2 commit khác nhau của fileName git diff branch1 branch2 ./diff_test.txt Dùng để so sánh 2 file ở hai branch khác nhau git diff --name-status SHA1 SHA2 [tên file] cho thấy status của các file đã thay đổi từ 2 version trên

delete branch in git

To delete a local branch git branch -d yourBranchName --------- To force delete a local branch git branch -D yourLocalBranch -------------- To delete a remote branch git push origin --delete remoteBranchName

How to use chmod in linux

Image
user (u),  group (g),  other (o) all (a)  The permission r for read,  w for write and  x for execute For example: Change mode a file as below, that group has not write, execute permission, the other is too chmod go-wx filename Example 1: The file should have read, write and execute permissions to user, read and execute permissions to group and read, and execute permissions to others. read, write and execute permissions to user =7 read and execute permissions to group =5 read and execute permissions to others=5 So total permissions will be 755 chmod 755 filename Example 2: Providing write access to a user chmod u+w filename Example 3: Adding write permissions to a group chmod g+w filename Example 4: Adding executable permissions to others chmod o+x filename Example 5: Adding executable and write permissions to all chmod a+wx filename Example 6: Replicating user permissions to a group chmod u=g filename ...

Install font in ubuntu

https://askubuntu.com/questions/3697/how-do-i-install-fonts https://itsfoss.com/install-fonts-ubuntu/ https://askubuntu.com/questions/386160/how-to-install-multiple-ttf-fonts-for-system-wide-usage

install oci8 in ubuntu

Development (Ubuntu) Download ( https://www.oracle.com/technetwork/database/database-technologies/instant-client/overview/index.html )[Oracle Instant Client] and ( https://www.oracle.com/technetwork/database/database-technologies/instant-client/overview/index.html )[Oracle Instant Client SDK Package] to your  ~/Downloads  directory, then install them: mkdir -p ~/apps/oracle mv ~/Downloads/instantclient-* ~/apps/oracle cd ~/apps/oracle unzip instantclient-basic-linux.x64-18.3.0.0.0dbru.zip unzip instantclient-sdk-linux.x64-18.3.0.0.0dbru.zip Create the config file  oci8.pc vim ~/apps/oracle/oci8.pc with the content as file  conf/oci8.pc  (change  /opt/oracle/instantclient_18_3  to  /home/<your_username>/apps/oracle/instantclient_18_3 ) Add to the end of your  .profile  or  .bashrc export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/<your_username>/apps/oracle/instantclient_18_3 export PKG_CONFIG_PATH=$PKG_CONFIG...

Dockerfile tutorial

FROM golang:latest Lệnh này là khai báo base image được dùng để tạo new image. golang: tên base image latest: version của base image, bạn cũng có thể dùng sha256 để xác định rõ một version golang@sha256 RUN mkdir /app câu lệnh này dùng để thực thi một câu lệnh cmd trên new image, tương tư như câu lệnh trên terminal thông thường Tạo một layer trong new image Câu lệnh này đượng thực thi trong vòng đời "build time" nghĩa là build new image ADD      .       /app/ Lệnh này dùng để copy thư mục hiện tại (.)  vào thư mục app trên new image WORKDIR /app câu lệnh này tương tự như câu lệnh cd trong terminal, ý là chỉ con trỏ tới thư mục working /app RUN go build -o main .  Lệnh này tương tự như bạn chạy câu lệnh trong terminal là "go build -o main" CMD ["/app/main"] lệnh này tương tự như lệnh RUN là chạy một câu lệnh nhưng nó cho phép bạn truyền thêm tham số Lệnh này là lệnh running time trong vòng đời. Nó chỉ thực thi khi ảnh đã...

Docker push image to docker hub

https://hub.docker.com/ Bạn cần tạo tài khoản ở trang web docker registry bên trên với username và password ví dụ là bonh/12345678 ---------------- Sau đó đăng nhập trong docker cli với cú pháp docker login --------------- Bước tiếp theo là bạn cần có 1 cái ảnh là:  demo_image:latest Bạn muốn đẩy ảnh này lên thì cần phải commit trước Muốn commit được thì cần phải có một containner đang chạy với ảnh đó Bạn chạy với local 1 containner trên ảnh đó với tên là : abc_xxx dùng lệnh: docker commit abc_xxx bonh/demo_image:tag_name với tag_name là tag bạn tự đặt có thể k cần trùng với latest --------------- Sau khi có tag_name rồi thì bạn dùng lệnh docker push bonh/demo_image:tag_name -------------- https://hub.docker.com/repositories check image đã đẩy lên ------------- để kéo về thì bạn dùng lệnh docker pull bonh/demo_image:tag_name

/etc/enviroment

This file is used for setting up enviroment variable in linux Such as JAVA_HOME, MAVEN_HOME

maven-jar-plugin

<plugin> <!-- Build an executable JAR --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.1.0</version> <configuration> <archive> <manifest> <!-- <addClasspath>true</addClasspath>--> <!-- <classpathPrefix>lib/</classpathPrefix>--> <mainClass>main.Application</mainClass> </manifest> </archive> </configuration> </plugin> Nếu bạn có một file .jar hoặc .war và dùng câu lệnh java -jar app.jar mà không thực thi được chương trình thì khi đó bạn cần add plugin bên trên vào file pom.xml và build lại toàn bộ suorce code. Lúc này trình maven sẽ chỉ rõ fil...

maven-compiler-plugin

<build> <plugins> <plugin> <groupId> org.apache.maven.plugins </groupId> <artifactId> maven-compiler-plugin </artifactId> <version> 3.8.0 </version> <configuration> <source> 9 </source> <target> 9 </target> </configuration> </plugin> </plugins> </build> Khi bạn tạo một Maven project để thực hiện được các lệnh như mvn clean : dùng để xóa toàn bộ các file java.class và làm sạch thư mục target khi build mvn compile : dùng để compile toàn bộ file .java trong ứng dụng thành file .class mvn install : dùng để build toàn bộ tập file .class thành .jar hoặc .war thành file có thể thực thi được --------------- trong file trên chúng ta để ý tới version 3.0.8 đây chỉ là version của plugin, nó giống như version của app của bạn vậy source 9: nghĩa là code của ...

Cài đặt app từ SOURCE trong linux

Tải source về dưới dạng *.tag.gz 1. Giải nén ra thư mục source_app 2. vào thư mục /source_app và dùng lệnh ./config 3. make 4. make install

/etc/sysconfig/network - Cấu hình ip tĩnh và DHCP

Cấu hình IP tĩnh: NETWORKING=yes HOSTNAME=my-hostname FORWARD_IPV4=true GATEWAY="XXX.XXX.XXX.YYY" -------------------- Cấu hình phía client dùng DHCP : NETWORKING=yes HOSTNAME=my-hostname

Kiểm tra và cài đặt cấu hình mạng

Thao tác Ý nghĩa ping host-ip Cấu hình NIC OK? ping GW Cấu hình mạng cục bộ OK ping live public IP Cấu hình mạng OK ping live domain name Cấu hình DNS OK telnet Kiểm tra dịch vụ máy từ xa traceroute Kiểm tra đường đi của các gói tin ifconfig Cấu hình mạng của các NIC route Bảng chọn đường cat /etc/resolve.conf DNS đã được cấu hình hostname Tên máy Cấu hình bằng câu lệnh Đặt địa chỉ IP:        ifconfig NIC-name IP netmask MASK Đặt GW:                route add default GW IP Khởi động lại dịch vụ mạng: sudo /etc/init.d/network restart Tắt dịch vụ mạng: sudo /etc/init.d/network stop Tắt NIC:  ifconfig eth0 down Bật NIC:  ifconfig eth0 up Đặt tên cho máy:  hostname

/etc/hosts - using for specify the ip that not resolve by DNS

ff02::1 ip6-allnodes ff02::2 ip6-allrouters 10.7.1.11 viniduat.tcbs.com.vn

/etc/resolv.conf - using for config DNS in your network

domain mydomain.com search mydomain.com nameserver 192.168.x.x nameserver 8.8.8.8 nameserver XXX.XXX.XXX.XXX - IP address of primary name server nameserver XXX.XXX.XXX.XXX - IP address of secondary name server

~/.bashrc vs ~/.bash_profile

if you login your account -> .bash_profile will be executed, if .bash_profile is not exist the the .profile will be read When you open new bash terminal session then ~/.bashrc will be executed According to the bash man page, .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells. ==> ~/.profile is the place to put stuff that applies to your whole session, such as programs that you want to start when you log in (but not graphical programs, they go into a different file), and environment variable definitions. ~/.bashrc is the place to put stuff that applies only to bash itself, such as alias and function definitions, shell options, and prompt settings. (You could also put key bindings there, but for bash they normally go into ~/.inputrc.) ~/.bash_profile can be used instead of ~/.profile, but it is read by bash only, not by any other shell. (This is mostly a concern if you want your initialization files to work on multiple ma...

Winston Leonard Spencer-Churchill

Image
Khi chân tướng vẫn còn đang đi giày thì lời nói dối đã chạy hết cả thành phố. Winston Leonard Spencer-Churchill (30/11/1874-24/1/1965) là một nhà chính trị người Anh, nổi tiếng nhất với cương vị Thủ tướng Anh trong thời Chiến tranh thế giới thứ hai. Ông từng là một người lính, nhà báo, tác giả, họa sĩ và chính trị gia. Churchill, nói chung, được coi là một trong những nhà lãnh đạo quan trọng nhất trong lịch sử Anh. Ông là Thủ tướng Anh duy nhất nhận giải Nobel Văn học và là người đầu tiên được công nhận là Công dân danh dự Hoa Kỳ. Winston Churchill Dưới đây là 29 câu nói kinh điển rất đáng suy ngẫm của ông: 2. Thành công là đi hết từ thất bại này tới thất bại khác mà vẫn không đánh mất nhiệt huyết. 3. Người lạc quan nhìn thấy cơ hội trong nguy cơ, người bi quan nhìn thấy nguy cơ trong mỗi cơ hội. 4. Tiếp tục kiên cường, không phải vì chúng ta thực sự mạnh mẽ, mà đó là bởi chúng ta không còn lựa chọn nào khác. 5. Đừng thử đi làm điều mà bạn thích, hãy thích điều mà...

Linux command line

https://findwords.info/term/uname 1. uname -m Uname uname (short for unix name) is a computer program in Unix and Unix-like computer operating systems that prints the name, version and other details about the current machine and the operating system running on it. The uname system call and command appeared for the first time in PWB/UNIX. Both are specified by POSIX. 2. Check running service in Linux for example check docker.service //Run this command on Linux systems not using Systemd $ service docker status docker start/running, process 29393 //Run this command on Linux systems that are using Systemd $ systemctl is-active docker active

Golayout TCBS

Follow this introduction https://github.com/techcomsecurities/golayout after getting it, you should check in your go/bin and see the golayout excutable file In linux, use this command line ./golayout gen -n ~/Workspace/go/crud -m gits.tcbs.com.vn/service/crud After successful excution, it will generate your project which structure by gomodule +-- api | +-- home.go | +-- server.go | +-- user.go +-- app | +-- <<YOUR_PROJECT_NAME>> | | +-- cmd +-- service | +-- main.go +-- conf | +-- config.yml +-- store | +-- imdbuser.go | +-- sqluser.go | +-- store.go +-- user | +-- userinfo.go +-- uuid | +-- gen.go +-- config.go +-- go.mod +-- store.go +-- user.go To run the app, using this command line cd <<YOUR_PROJECT_NAME>> go run app/service/main.go -c conf/config.yml

Careful with Parallel Streams in java 8

List<String> list = new ArrayList<String>() ; //contains about 1000 element List<String> listA = new ArrayList<String>() ; // zezo element now List<String> listB = new ArrayList<String>() ; //zezo element now list.parallelStream().forEach(e -> { if (e.equals( "A" )) { listA .add(e) ; } else { listB .add(e) ; } }) ; list.stream().forEach(e -> { if (e.equals( "A" )) { listA .add(e) ; } else { listB .add(e) ; } }) ; Maybe some guys will think that the above codes with parallelStream () is faster and better than the code with stream () If you try to run it in fact with parallelStream() then it may throw IndexOutOfArrayException, but with stream() is well. Why????? 1. listA.add(e); and listB.add() is not supported using in mutilthread. Your code is not good 2. why it throw IndexOutOfArrayException? please read codes of ArrayList :-) Note:  1. you should use    ...

Go module

go run -mod=vendor  main.go -c=config.yml The above cmd will run app with the vendor libs that downloaded go mod vendor The cmd will create vendor lib folder in vendor folder go mod init  This will generate file go.mod

Install Oracle Java in Debian

Image
You should visit Oracle JDK Home page to download newest JDK for linux, window, macOS https://www.oracle.com/technetwork/java/javase/downloads/jdk13-downloads-5672538.html then select your jdk you can select  jdk-13.0.1_linux-x64_bin.deb , or *.rpm or *.tar.gz I selected *.deb to install on my Debian OS ----------------------- Step 1: use this command line sudo        dpkg      -i        path/to/jdk-13.0.1_linux-x64_bin.deb Step 2: check in folder  /usr/lib/jvm/        or      /usr/java/   you will see the folder  jdk-13.0.1 Step3: sudo nano /etc/environment Copy and paste this to the file and save PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk-13.0.1/bin" JAVA_HOME = "/usr/lib/jvm/jdk-13.0.1" Step4: sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk...