Saturday, 10 December 2016

dos and don'ts of writing c++ code

  1. Use namespaces - when you have huge code and classes, add them into a name spaces by categorizing them. Like a namespace for database, namespace for logger, namespace for ui etc. 
  2. Follow C++ coding conventions and remain consistent in project and with team ( and with global c++ community).
  3. In header files, avoid the use of forward declaration as much as possible and included the required header files.

Wednesday, 7 December 2016

Android create apk release with date

#
# script to create a release for apk with current date time
#

PROJECT="SpeedRiderApp"
DATE=`date +%Y-%m-%d`

echo "Preparing APK For ${PROJECT}"
echo "Removing previous releases of date: ${DATE}"

rm -fr "${HOME}/Desktop/${PROJECT}-${DATE}.apk" "${HOME}/Desktop/${PROJECT}-${DATE}" "${HOME}/Desktop/${PROJECT}-${DATE}.zip"

cp "app/build/outputs/apk/app-debug.apk"  "${HOME}/Desktop/${PROJECT}-${DATE}.apk"

echo "----- DONE MAKING APK -----"


cp -a . "${HOME}/Desktop/${PROJECT}-${DATE}"
cd "${HOME}/Desktop/${PROJECT}-${DATE}"

echo "Removing build"
rm -fr build

echo "Removing app/build"
rm -fr "app/build"

cd "${HOME}/Desktop/"
zip -r "${PROJECT}-${DATE}.zip" "${PROJECT}-${DATE}"

# back to project dir
cd -

Wednesday, 30 November 2016

Shell script To Make release zip for project

PROJECT="SpiritedRepublic"
DATE=`date +%Y-%m-%d`
DIR="${HOME}/Desktop/${PROJECT}-src-${DATE}"

# remove previous DIR
echo "removing $DIR"
rm -fr "$DIR"
mkdir "$DIR"

# python files
echo "Copying python files"
cp -a /home/neo/work/qt_projs/SpiritedRepublic/src/*.py "$DIR"

# ui files
echo "Copying ui files"
cp -a /home/neo/work/qt_projs/SpiritedRepublic/src/*.ui "$DIR"

# csv files
echo "Copying csv files"
cp -a /home/neo/work/qt_projs/SpiritedRepublic/src/*.csv "$DIR"

# shell script files
echo "Copying shell script files"
cp -a /home/neo/work/qt_projs/SpiritedRepublic/src/*.sh "$DIR"


# zip
ZIP_PATH="${DIR}.zip"
echo "Creating zip file at: ${ZIP_PATH}"
cd "${HOME}/Desktop"

zip -r "${PROJECT}-src-${DATE}.zip" . -i "${PROJECT}-src-${DATE}/*

Saturday, 22 October 2016

Cygwin Package Manager

wget raw.github.com/transcode-open/apt-cyg/master/apt-cyg
chmod +x apt-cyg
mv apt-cyg /usr/local/bin
Now that apt-cyg is installed. Here are few examples of installing some packages
apt-cyg install nano
apt-cyg install git
apt-cyg install ca-certificates

Tuesday, 18 October 2016

bashrc cool tips

# git commit push all modified files
gcpa() {
    echo "Commit Message: $1"

    echo "Commiting.................."
    git commit -am "$1"

    echo "Pushing...................."
    git push

    echo "Done......................."
}


example:
$ gcpa "Added logs"

# commit single file with msg
# equivalent to add, commit, push
gcpm() {
    echo "Committing: $1"
    echo "Message: $2"

    echo "Adding.................."
    git add "$1"

    echo "Commiting.................."
    git commit -m "$2"

    echo "Pushing...................."
    git push

    echo "Done......................."
}

# example
$ gcpm abc.py "Added exception handler"

bashrc cool tips

# git commit push all modified files
gcpa() {
    echo "Commit Message: $1"

    echo "Commiting.................."
    git commit -am "$1"

    echo "Pushing...................."
    git push

    echo "Done......................."
}


example:
$ gcpa "Added logs"

# commit single file with msg
# equivalent to add, commit, push
gcpm() {
    echo "Committing: $1"
    echo "Message: $2"

    echo "Adding.................."
    git add "$1"

    echo "Commiting.................."
    git commit -m "$2"

    echo "Pushing...................."
    git push

    echo "Done......................."
}

# example
$ gcpm abc.py "Added exception handler"

Monday, 19 September 2016

Nodejs Cheat Sheet


Install express and save it locally in nodejs module list
$ npm install express --save


Thursday, 1 September 2016

Some useful SQL queries

Get Distinct records

select distinct name from user;


Get Repeated records

SELECT
    name, email, COUNT(*)
FROM
    user
GROUP BY
    name, email
HAVING
    COUNT(*) > 1

Monday, 29 August 2016

postgres commands cheatsheet

$ sudo -i -u postgres
$ psql


Create new database
CREATE DATABASE schooldb;

Create new user
CREATE USER schooluser;

Change Password
ALTER USER schooluser with PASSWORD 'pass123';

Change database owner
ALTER database schooldb owner to schooluser;

Rename database name
ALTER DATABASE name RENAME TO newname
Grant All Permissions to database
grant all privileges on database dbname to dbuser;
GRANT ALL ON DATABASE somedb TO someuser;

Show databases
\l


Show tables
\dt


Connect to db
\c schooldb


Friday, 26 August 2016

How to create windows USB installer from windows CD/DVD ?

sudo dd if=/dev/cdrom of=/home/username/image.iso



sudo dd if=/home/username/image.iso of=/dev/sdb


here sdb is your USB drive, change it, it can be /dev/sdc etc.

Tuesday, 19 July 2016

Ubuntu get wifi password

cd etc/NetworkManager/system-connections/ 

sudo cat WIFI_SSID_Name  

“psk”=”PASSWORD”

Monday, 18 July 2016

Heroku Django Commands

Useful commands:
  • heroku run python manage.py migrate
  • heroku config:set DISABLE_COLLECTSTATIC=1

Initialize repo

clone your existing repo from git, remove .git and do following


$ cd my-project/
$ git init
$ heroku git:remote -a quickorders
 
Login to remote shell
$ heroku run bash 


References:
  • https://devcenter.heroku.com/articles/getting-started-with-python#push-local-changes
  • https://devcenter.heroku.com/articles/deploying-python
  • https://devcenter.heroku.com/articles/django-app-configuration


Tips:
  • Do "git push" migrations files


Friday, 15 July 2016

Django with docker


Create super user for django website
docker-compose run website python manage.py createsuperuser

 here website is the name of image


Run custom command in an image
docker run --rm -i -t --entrypoint=/bin/bash albums_website:latest

This will show following promot,
root@618a92c1d9c9:/code# python manage.py <command>



Run
Run the docker-compose up command.


Thursday, 14 July 2016

git commands

Initial Setup
git config --global user.name "John Doe"
git config --global user.email "johndoeabc123@gmail.com"
git config --list


1. Undo Last commit
$ git reset --soft HEAD~1

2. Delete a local branch
$ git branch -d the_local_branch

3. Delete without merging
$ git branch -D the_local_branch

4. Checking logs
$ git log --oneline
$ git log some-file.cpp
$ git log --oneline some-file.cpp
$ git log --author "Navjot Singh"
$ git log --since=12-18-1979
   (mm-dd-yyyy)
$ git log --author "Navjot Singh" --since=12-18-1979
$ git log --since=12-18-1979 --until=12-30-2016

5. Line changed/added/deleted between 2 commits
$ git diff --stat 36baf22 6edb550

6. Diff between two commits
$ git diff 36baf22 6edb550

Docker Devops Commands

Build images
$ docker-compose build
$ docker-compose build --no-cache

Show list of docker-compose processes
$ docker-compose ps                
$ docker ps -a 
$ docker stats [container name]

Remove all docker containers
$ docker rm $(docker ps -a -q)

Remove all docker images
$ docker rmi $(docker images -q)

Show All Images
$ sudo docker images

Some general commands
$ service docker start
$ service docker stop
$ service docker restart

$ docker-compose --version


Run
Run the docker-compose up command.



Edit a container

1. Login to container's shell with root user
$ docker run -it -u root web:latest /bin/bash

You will see a prompt like:
root@78e82f680994$

2. Make you changes in files etc.

3. Exit from shell

 $ exit

4. Commit changes in the container

$ docker commit <container ID> web:latest

here container id is  78e82f680994

so the command will br
$docker commit 78e82f680994 web:latest

 

Sunday, 26 June 2016

vi stop making undo files

.un~ files are undo files generated by vi.

in .vimrc you can write following line to avoid making these files

set noundofile
 
 
To avoid making backup and swap files, write following lines
set nobackup
set nowritebackup
set noswapfile 
set noundofile 

Monday, 20 June 2016

How to install skype on ubuntu ?

sudo dpkg --add-architecture i386
 
sudo add-apt-repository "deb http://archive.canonical.com/ $(lsb_release -sc) partner"
 
sudo apt-get update && sudo apt-get install skype 

Monday, 6 June 2016

Set vi as editor for git commands

Set vi as editor for git

- git config --global core.editor "vi"
- or in bashrc export environment variable
  export GIT_EDITOR=vi

Wednesday, 18 May 2016

How to uninstall tomcat from Ubuntu

Run these commands:- 
 
$ sudo apt-get remove tomcat7
 
$ sudo apt-get remove tomcat7-admin 

Tuesday, 17 May 2016

upwork install on ubuntu

$ sudo wget https://mirror.umd.edu/ubuntu/pool/main/libg/libgcrypt11/libgcrypt11_1.5.3-2ubuntu4_i386.deb

$ dpkg -i libgcrypt11_1.5.3-2ubuntu4_i386.deb


$ sudo apt-get install gdebi-core

$ sudo dpkg -i upwork_amd64.deb 

Install Android Studio on Linux

Install Oracle Java


- remove open jdk

$ sudo apt-get purge openjdk-\*


- download jdk 1.8 from oracle website

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html


sudo mkdir -p /usr/local/java


sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6



Android studio installation error:-

"Unable to run mksdcard SDK tool."


FIX IS:-

$ sudo apt-get update


For 32 bit architecture:-

$ sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6


For 64 bit architecture:-

$ sudo apt-get install lib32z1 lib32ncurses5 libbz2-1.0:i386 lib32stdc++6

 

Monday, 16 May 2016

Quick install LAMP on Ubuntu/Linux

Run these commands:-

sudo apt-get install apache2

sudo apt-get install mysql-server

sudo apt-get install php5 libapache2-mod-php5

sudo /etc/init.d/apache2 restart

For phpmyadmin installation:-


sudo apt-get install phpmyadmin
sudo php5enmod mcrypt

Edit apache conf file as:-

$ vim /etc/apache2/apache2.conf
and add following line in it

# phpMyAdmin Configuration
Include /etc/phpmyadmin/apache.conf


sudo service apache2 restart


Sunday, 15 May 2016

Best Open Source ERP Solutions

1. Odoo

One of the most famous open source ERP solution rich with features.

2. FutureERP

This is a new evolving ERP project by a startup called weavebytes.

You can download the source code from github:-
https://github.com/Weavebytesipl/FutureERP

It is developed using Python and Django web framework.

Saturday, 14 May 2016

Tools to install after fresh install of Linux - Ubuntu

Commonly used tools to install on your Linux development machine

sudo apt-get install git

sudo apt-get install vim-gnome

sudo apt-get install tree

sudo apt-get install gitg

# uget download manager
sudo add-apt-repository ppa:plushuang-tw/uget-stable
sudo apt update
sudo apt install uget

Friday, 13 May 2016

How to install terminator on ununtu

Run these commands

$ sudo add-apt-repository ppa:gnome-terminator
$ sudo apt-get update
$ sudo apt-get install terminator

Thursday, 12 May 2016

How to setup virtualenv for python on ubuntu

Run following commands:


   change to python 3
  $ sudo ln -s /usr/bin/python3.5 /usr/bin/python
   $ sudo apt install python3-pip

   $ sudo apt-get install python-pip

   $ sudo pip install virtualenv

   $ sudo pip install virtualenvwrapper

   $ mkdir ~/.virtualenvs

   $ echo "export WORKON_HOME=~/.virtualenvs" >> ~/.bashrc

   $ echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc

   $ echo "export PIP_VIRTUALENV_BASE=~/virtualenvs" >> ~/.bashrc

   $ source ~/.bashrc


$ mkvirtualenv myenv


If you want to get out/off your virtualenv use this command:

$ deactivate


If you want to jump back on the virtualenv we just created and installed django use this command:

$ workon myenv



And finally if you want to remove the virtualenv altogether

$ rmvirtualenv myenv

Sunday, 8 May 2016

10 Linux Tools For Everyone

1. Gnome Disk Utility

$ sudo apt-get install gnome-disk-utility
$ gnome-disks