Posts

Showing posts from 2017

Get commits between two tags in Git

We often need to get commits between two git tags. For example, we want to prepare a release note. So we want to get the commit messages between the two release tags. Here is the command to do this: git log --pretty=oneline tagA...tagB # three dots Example: git log --pretty=oneline v3.9.0...v3.9.1 Source:  https://stackoverflow.com/questions/5863426/get-commit-list-between-tags-in-git

Installing Python 2.7.13 on CentOS 6.5

This post describes how to install python 2.7 from source without affecting the existing python installation. It'll install the python2.7 in a separate location other than the standard location in CentOS. Install required packages:  yum -y update yum groupinstall -y 'development tools' yum install -y gcc zlib-devel bzip2-devel openssl-devel xz-libs wget Download and extract python source: wget http://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz  xz -d Python-2.7.13.tar.xz  tar -xvf Python-2.7.13.tar Create a directory where to install python e.g. ~/localpython: mkdir /home/nayan/localpython Go to extracted python source directory: cd Python-2.7.13 Run the configure: ./configure --prefix=/home/nayan/localpython --enable-shared Compile and install it:  make make altinstall Check if python installed by running python2.7 Make a link to Python library path: On 32 bit OS ln -s /home/nayan/localpython/lib/libpython2.7.so.1.0 /usr

Generate model class in peewee

peewee is a very lighweight but rich orm for python. Often we need to generate model classes from an existing database table. It's possible to do this in peewee using an addon pwiz model generator . After installing pwiz, use the following command to generate model classes from an existing database. python -m pwiz -e mysql -u root -H localhost -P pesp_db > models.py Here is a brief description of the options: -e : name of the database engine e.g. mysql, postgresql -u : name of db user -H: name of db host The last parameter pesp_db in this case is the name of the database schema. If you run this command, you'll be prompted to provide your password. After providing the password, the model classes will be generated and written in the models.py

Generate a Excel file from Spring

We often need to generate a spreadsheet file from server and allow users to download the file. Here is how to do that with Spring using the Apache POI library. Dependency: We need to add the following dependencies in our spring application. Here is the Gradle dependencies. compile group: 'org.apache.poi', name: 'poi', version: '3.15' compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.15' Once we add the dependencies we'll be able to access the POI library in our application. Generate WorkBook We need to generate a Workbook object in POI. Here is a sample method that returns a Workbook object public Workbook downloadPersonList() throws IOException {     // sample list. this can be the output of a DB query     List<Person> personList = new ArrayList<>();       personList.add(new Person("nayan", 29));     personList.add(new Person("rafiq", 35)) ;     personList.add(new Perso

Print a progress in Python

Here is how to do this: import sys sys.stdout.write("\r%d" % i) sys.stdout.flush() Writing '\r' will move the cursor back to the beginning of the line. If we want to print a %, we need to print an additional % like the folllowing: sys.stdout.write("\r%d%%" % i)