Posts tagged ‘programming’


I’m a fan of SublimeText and it suits well for my work (I code Python, MATLAB, LaTeX and sometime C++). People often tell me that if something works well for me, I shouldn’t change it. However, I’m a curious guy and VIM is recommended to me several times in … 10 years and I was too lazy to try it. So I write this blog post as a simple tutorial, a simple first step for myself. If it isn’t suit my work-flow, it’s still nice to know about this tool. I also hope this would be useful for other people who want to learn VIM from zero.

There is a joke from linux users about Windows user: “The easiest way to generate a random string is telling a Windows User type in VIM”. Starting as a Windows user, it’s funny that it was true for me the first time I used VIM (long time ago) and I don’t have time to use it again, until recently.

To install vim:

 sudo apt-get install vim 

How to create a text file with vim:

Open vim by opening the terminal and input:


Then press Enter, what we should have is like this:

To go to inter mode, press i, to return to command mode (default), press Esc.

We can navigate through text in the command mode with directional buttons as H-J-K-L, equivalent to left-up-down-right.

Now as told earlier, press i to go to Insert mode (VIM will tell us with INSERT at bottom left corner). Insert whatever text you like.

Now, to save it, we need


command, press Esc to quit Insert mode, type

:w testtxt.txt

and press Enter.

As a result, VIM will create a testtxt.txt file, note that because I run the terminal in Home folder, then the saved file is located there.

[to be continued…]



Make python wait for you by sleep function

import time

will make python wait for you 1 second before processing next line. To make python wait for you with another value of time, change 1 to whatever you need, remember the unit here is second.
Very useful when you have to check your code, see the temporary result and so on.

Happy coding!

Hello world by fortran

This is just a very basic script to run a Hello world! program by the language Fortran in Ubuntu.

program hello
print *, "Hello world!"
end program hello

Save the text file as fortran extention, here I save it as hello.f90

To compile in, open terminal and navigate to that folder, run this:

gfortran -o hello hello.f90

Explain: This code define the compiler gcc-fortran, output file has name “hello” and the script file is “hello.f90”.
When the compilation is finished, in that folder we will see the hello program, in terminal, to run it, just input


And you will see the line “Hello world!” in the terminal window.
Have fun programming!

Some programming apps on Android system

To begin with, coding on phone or table is not a fun thing to do, virtual keyboard sucks, and come on! Programming on PC is the best thing. But:

Coding on PC, want to work on your phone + tablet as well? Or just love coding? Android serves you with these apps:

1. C4droid: C/C++ IDE (paid)

This app help you write, compile C/C++ code right on your phone.

2. QPython (free)

Run basic Python on your phone, cannot import numpy or scipy, but for common algorithm, this app runs well, can’t complain for a free, no ad program.

3. DroidEdit (paid):

This one is the one I use the most, why? It helps me read my code everywhere, highlight syntax is good, and for a script, space on phone is like Sahara to a cat. I work only with python and sometimes C++, but DroidEdit supports more than you need, remember Notepad++? Remember gEdit?

4. C# Shell (paid)

I discovered this one recently, and I still haven’t used it, but the first impression is the cleanUI (blue color, yay!)

5. MathStudio (paid)

This expensive app is a little hard to use at the beginning, but when you get used to it, it reminds us, somehow, of Matlab and Maple on PC. Try searching on Google, you may find a free apk of this app somewhere to test it before purchase.

Chạy python qua CMD

Trong window, để bật python và ipython thông qua cửa sổ cmd, cần phải sửa mục path của hệ thống trước, sau đó, vào trong CMD, có thể chạy python bằng lệnh tắt python và enter. Quá trình làm như sau:

1. Control panel –> system –> Advanced .. –> Environment …

2. Tại đây trong cửa sổ PATH, thêm path của python vào. Ví dụ trong trường hợp python 2.7 được cài trong thư mục C:\Python27\python.exe thì giá trị path cần thêm vào là C:\Python27, để phân biệt path này với các path có sẵn, chỉ cần nhét dấu chấm phẩy (;) giữa các path, sau đó save lại. Có thể cần phải khởi động lại để thay đổi có hiệu lực.

Để test tính năng này có thể vào cửa sổ RUN, gõ cmd, sau đó bấm python để kiểm tra.

Python 3 làm tương tự.

Tag Cloud

%d bloggers like this: