December 16, 2016

SVN : sqlite[S5]: database is locked error

Once in a while I get this error, happened due to network issue while a svn command is being executed but wasn't able to finish.

svn: E200033: Another process is blocking the working copy database, or the underlying filesystem does not support file locking; if the working copy is on a network filesystem, make sure file locking has been enabled on the file server 
svn: E200033: sqlite[S5]: database is locked 
svn: E200042: Additional errors: 
svn: E200033: sqlite[S5]: database is locked

Fix :

$ cd /my/repository/.svn 
$ mv wc.db wc.db.old 
$ sqlite3 wc.db.old 
sqlite> .backup main wc.db
sqlite> .exit

Afterwards, do a svn cleanup. Then, you're good to go.

October 10, 2016

Creating automatic backup in Solus

This morning I accidentally (well, I was not aware that I was not in the correct folder) all my project files today.

Lesson learned - recovery for (rm -rf *) is almost impossible.

The good thing is that I worked on the project over the weekend, so some stuff are still fresh in my mind. But first, I am going to create back up and automate it for every 2 hours because I am paranoid like that. I am going to leave the backup on my desktop.

 In Solus, cron is not installed by default and they use systemd/Timers (https://wiki.archlinux.org/index.php/Systemd/Timers) instead for replacement.

Create a file named as backup-workspace.service in /etc/systemd/system

cd /etc/systemd/system
sudo touch backup-workspace.service
Add in the following  using your favorite text editor:

# Systemd
# Service (/etc/systemd/system/backup-workspace.service)
[Unit]
Description=automatically backup workspace 

[Service]
ExecStart=tar -cvpzf /home/raf/Desktop/Workspace-backup.tar.gz /home/raf/Workspace 

# Timer (/etc/systemd/system/backup-workspace.timer)
[Unit]
Description=Runs backup-workspace service every hour

[Timer]
# Time to wait after booting before we run first time
OnBootSec=1min
# Time between running each consecutive time
OnUnitActiveSec=1h
Unit=backup-workspace.service

[Install]
WantedBy=multi-user.target

I created an alias/shortcut key to do the backup manually too by editing my ~/.bashrc file.

alias backup="tar -cvpzf /home/raf/Desktop/Workspace-backup.tar.gz /home/raf/Workspace"

October 5, 2016

Getting a software developer job

Ask yourself :


  • Your past projects/coding style
  • You technical knowledge on your stated skills
  • Your personality
  • Your workflow - do you have a clear thought process behind what you do and why you do it
  • Ability to take constructive criticism
  • A love of coding - because there will be constant learning throughout your career and if you aren’t prepared to do that, you will seem like a poor long term investment
  • An excellent understanding of the tools you use: frameworks, IDE, language, task-runner, version control, graphics software.


September 30, 2016

My bashrc file (for reference)



# reload other bash script file, if any
source /usr/share/defaults/etc/profile

# set PATH
export PATH=$PATH:/usr/sbin:/usr/local/mysql/bin:.:/home/raf/Tools/gwt-2.7.0:/home/raf/Tools/apache-log4j-2.6.2-bin

# other environment variables
PROJECT_HOME=/home/raf/Workspace/trunk-umobile-work
export PROJECT_HOME

ANT_HOME=/opt/apache-ant-1.9.7
export ANT_HOME

GWT_23_HOME=/home/raf/Tools/gwt-2.3.0/gwt-2.3.0
GWT_27_HOME=/home/raf/Tools/gwt-2.7.0
GWT_HOME=${GWT_23_HOME}
export GWT_HOME

APACHE_HOME=/usr/local/apache/htdocs
export APACHE_HOME

MSYQL_HOME=/usr/local/mysql
export MYSQL_HOME

AXIS2_HOME=/home/raf/Tools/axis2-1.5.4
export AXIS2_HOME

JUNIT=/home/raf/Tools/eclipse/plugins/org.junit_4.12.0.v201504281640/junit.jar
export JUNIT

JAVA_7_HOME=/opt/jdk1.7.0_80
JAVA_8_HOME=/usr/lib/jvm/java-8-openjdk-
JAVA_HOME=${JAVA_7_HOME}
export JAVA_HOME JAVA_7_HOME JAVA_8_HOME

# to switch between java7 and java8
alias java7="sudo rm /usr/bin/java; sudo rm /usr/bin/javac; sudo ln -s /opt/jdk1.7.0_80/bin/java /usr/bin/java; sudo ln -s /opt/jdk1.7.0_80/bin/javac /usr/bin/javac; export JAVA_HOME=${JAVA_7_HOME}"
alias java8="sudo rm /usr/bin/java; sudo rm /usr/bin/javac; sudo ln -s /usr/lib/openjdk-8/bin/java /usr/bin/java; sudo ln -s /usr/lib/openjdk-8/bin/javac /usr/bin/javac; export JAVA_HOME=${JAVA_8_HOME}"

TOMCAT_WEBAPPS=/home/raf/Tools/apache-tomcat-8.5.4/webapps
export TOMCAT_WEBAPPS

EDITOR=/opt/sublime_text/sublime_text
export EDITOR

# bash setting
export HISTFILESIZE=3000    # the bash history should save 3000 commands
export HISTCONTROL=ignoredups   #don't put duplicate lines in the history.

# define colours
BLACK='\e[0;30m'
BLUE='\e[0;34m'
GREEN='\e[0;32m'
CYAN='\e[0;36m'
RED='\e[0;31m'
PURPLE='\e[0;35m'
BROWN='\e[0;33m'
LIGHTGRAY='\e[0;37m'
DARKGRAY='\e[1;30m'
LIGHTBLUE='\e[1;34m'
LIGHTGREEN='\e[1;32m'
LIGHTCYAN='\e[1;36m'
LIGHTRED='\e[1;31m'
LIGHTPURPLE='\e[1;35m'
YELLOW='\e[1;33m'
WHITE='\e[1;37m'
NC='\e[0m'

# check PID of current running process. Usage : ps java
alias ps="ps -awwef | grep "

# frequently used directories for bookmarking purposes
alias cdt="cd /home/raf/Tools/apache-tomcat-8.5.4/webapps"
alias cdw="cd /home/raf/Workspace/"
alias cdwu="cd /home/raf/Workspace/trunk-umobile-work"
alias cdp="cd ~/Workspace/cpx/source/merchant_portal"

# short forms command for other most used software
alias apache-up="sudo /usr/local/apache2/bin/apachectl restart; tail -f /usr/local/apache2/logs/error_log;"
alias tomcat-up="~/Tools/apache-tomcat-8.5.4/bin/catalina.sh start;"
alias tomcat-log="tail -f /home/raf/Tools/apache-tomcat-8.5.4/logs/catalina.out;"
alias tomcat-clearlog="rm /home/raf/Tools/apache-tomcat-8.5.4/logs/catalina.out; touch /home/raf/Tools/apache-tomcat-8.5.4/logs/catalina.out;"
alias tomcat-clear="rm -rfv /home/raf/Tools/apache-tomcat-8.5.4/work/Catalina/"
alias sub="/opt/sublime_text/sublime_text"
alias nau="nautilus "
alias fire="cd /home/raf/Tools/firefox-24; setsid ./firefox"

# short forms command for favourite linux tools
alias ..="cd .."
alias ...="cd ..."
alias ls="ls -lsaXB"    # sort by extension
alias ls_size='ls -lSar' # sort by size
alias cls="clear"
alias cl="clear"
alias sls="clear"
alias s;s="clear"
alias s:="clear"
alias ;s="clear"
alias hist='history | grep $1'  # check previously executed command. Usage : hist tomcat*
alias sc='source '
alias find_pattern="grep -rnwl . -e "   # find file that contain pattern. Usage : find mytext
alias find="find "  # let it be here. Needed to fix bug betwen find_pattern and find_file
alias find_file="find -name "   # find file by file name. Usage : find_file mytext.txt

# listing files within directory
alias structure="tree -P '*.jar|*.java|*.xml|*.html|*.css' | less "
alias structure-nojar="tree -P '*.java|*.xml|*.html|*.css' | less "
alias structure-nojava="tree -P '*.xml|*.html|*.css' | less "

# command line pre-fix
export PS1="pwd : ${LIGHTGREEN} \w\n${BLUE}\u${RED}:$ ${BLUE}"

# show network info
netinfo ()
{
    echo "--------------- Network Information ---------------"
    /usr/bin/ifconfig | awk /'inet addr/ {print $2}'
    /usr/bin/ifconfig | awk /'Bcast/ {print $3}'
    /usr/bin/ifconfig | awk /'inet addr/ {print $4}'
    /usr/bin/ifconfig | awk /'HWaddr/ {print $4,$5}'
    echo "---------------------------------------------------"
}

# enable programmable completion features
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

# extract things . Usage : extract file.zip
extract () {
     if [ -f $1 ] ; then
         case $1 in
             *.tar.bz2)   tar xjf $1        ;;
             *.tar.gz)    tar xzf $1     ;;
             *.bz2)       bunzip2 $1       ;;
             *.rar)       rar x $1     ;;
             *.gz)        gunzip $1     ;;
             *.tar)       tar xf $1        ;;
             *.tbz2)      tar xjf $1      ;;
             *.tgz)       tar xzf $1       ;;
             *.zip)       unzip $1     ;;
             *.Z)         uncompress $1  ;;
             *.7z)        7z x $1    ;;
             *)           echo "'$1' cannot be extracted via extract()" ;;
         esac
     else
         echo "'$1' is not a valid file"
     fi
}

# WELCOME SCREEN
################################################## #####

clear

echo -ne "${PURPLE}";cal;
. /etc/lsb-release
echo -ne "${BROWN}Linux Kernel : $gras$(uname -r)$fin \n"      
echo -ne "Distro       : $DISTRIB_ID $DISTRIB_RELEASE ($DISTRIB_CODENAME)$fin \n${BLACK}"

September 26, 2016

Markdown for blogger

Well, it seems like I have to get familiar with markdown since my company's WIKI is written using it.

Here's one useful tool : StackEdit

I would like to re-write all posts from this blog by using markdown. Still waiting for official support from Blogger but it does not seem it's going to happen real soon.

Any ideas?

September 23, 2016

Posting code snippet to blogspot post (no syntax highlighting)

Encode your code using an online HTML Encoder and then put it inside pre
<pre>
    <%--your encoded code goes here--%>
</pre>
HTML Encoder

Logging with GWT

1. First, modify our module configuration file (X.gwt.xml) where X is the class which holds the EntryPoint of your application.

<inherits name="com.google.gwt.logging.Logging" />
<set-property name="gwt.logging.logLevel" value="INFO"/>
<set-property name="gwt.logging.enabled" value="TRUE"/>
<set-property name="gwt.logging.consoleHandler" value="ENABLED"/>
<set-property name="gwt.logging.popupHandler" value="DISABLED" /><!-- Disable PopupLogHandler -->
<set-property name="gwt.logging.simpleRemoteHandler" value="DISABLED" />


2. This configuration cause logs to be printed to standard output, that is usually Eclipse console window. You can also view this logs in Javascript console, which present in Chrome, Firefox and IE.

See here on how to view them in Javascript console : http://webmasters.stackexchange.com/questions/8525/how-to-open-the-javascript-console-in-different-browsers


3. In your class, import the library.

import java.util.logging.Logger;
import java.util.logging.Level;


4. Then, instantiate the logger with whatever name, possibly with the class name to make it more descriptive.

public Logger logger = Logger.getLogger("MyClassLogger");


5. Then it can be used anywhere within it's scope. Examples :

logger.log(Level.SEVERE, "Connection refused: ");
logger.log(Level.INFO, "Query executed : " + executedQuery);


6. The log levels define the severity of a message. The Level class is used to define which messages should be written to the log. You can set the minimum level by the following :

logger.setLevel(Level.INFO); 


7. These are the typical usage of these levels :

ERROR: Any error/exception that is or might be critical.

WARN: Any message that might warn us of potential problems, e.g. when a user tried to log in with wrong credentials - which might indicate an attack if that happens often or in short periods of time

INFO: Anything that we want to know when looking at the log files, e.g. when a scheduled job started/ended.

September 21, 2016

Increment a day in Java or get previous date

1. Using java.util.Calendar in typical Java application

SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
Calendar cal = Calendar.getInstance();
cal.setTime( dateFormat.parse( inputString ) );
cal.add( Calendar.DATE, 1 );

2. Using java.util.Date - this does't take care Daylight saving but might be required for certain use cases and especially in GWT where Calendar is not supported.

Date date = new Date(); 
Date daysAgo = new Date(date.getTime() - (1000*60*60*24)); 

3. Using 3rd party library. For example, http://joda-time.sourceforge.net

Date date = new Date(); // Or where ever you get it from
Date daysAgo = new DateTime(date).minusDays(300).toDate();

Creating a new Github repository and link it to the local existing project in your computer

1. Create a new repository on GitHub

2. Get the remote repository Web URL by pressing the "Clone or Download" button (coloured green). It looks like this : https://github.com/iserifith/ScoreBoard.git

3. Open Terminal and go to your local project folder where you have the files you have been working on.

4. Initialize the local project folder as a Git repository using the following command :
git init

5. Add the files in the project folder into "local git repository" - this is called "staging".
git add .

Note : This does not connect to "remote git repository". Understand the difference between local and remote git repository.

6. Commit the files that you've staged in your local repository.
git commit -m "First commit"

7. Now we set so that our local repository are linked to the remote repository. This command set the remote repository as the "origin".
git remote add origin {remote repository Web URL}

Example : git remote add origin https://github.com/iserifith/ScoreBoard.git

8. Verify that our remote repository are linked properly using
git remote -v

It will prompt you something like this :
origin https://github.com/iserifith/ScoreBoard.git (fetch)
origin https://github.com/iserifith/ScoreBoard.git (push)

9. Once all set, push the all files (that we have committed just now) in your local repository to GitHub using the following command :
git push origin master



Extra :
Now, to make sure you keep updated Github with your work, all you need to are 3 steps :

1. Add all files (staging)
git add .

2. Commit
git commit -m "I did some changes"

3. Push to Github (remote repository)
git push origin master

September 20, 2016

Using EOPKG via proxy

Edit file /etc/eopkg/eopkg.conf

Add the following line

http_proxy = http://yourproxysite
https_proxy = http://yourproxysite

September 14, 2016

Git diff using meld, a graphical file comparator

1. First, install meld (or from source : http://meldmerge.org)
sudo apt-get install meld

2. Then, create a directory named script in home folder
cd ~; mkdir script; cd script;

3. Create a file and name it git_meld.py
touch git_meld.py

4. Insert the following codes :

#!/usr/bin/python

import sys
import os

os.system('meld "%s" "%s"' % (sys.argv[2], sys.argv[5]))

5. Save the file.

6. Then, set git to use this script as part of 'diff' command
git config --global diff.external /home/script/git_meld.py

That's it, we're done. Use git diff as the following

// compares working directory with index
// i.e. shows the changes that are not staged yet.
git diff

// compares working directory with local repository.
// shows the list of changes after your last commit.
git diff HEAD

// compares index with local repository.
// shows the diff between your last commit and changes to be committed next (already staged, but not yet commited)
git diff --cached
Full manual available :
https://www.kernel.org/pub/software/scm/git/docs/git-diff.html

If you want to compare between 2 commits, use
git log and then copy the commit ID of the 2 commits you want to compare
i.e.
commit 8c9dcaa5424a67ddf20cd453bcb6db4c5b04edbf --- copy this
Author: Raf
Date:   Sat Sep 3 17:49:19 2016 +0800

And then, run the following
git diff [commitA] [commitB]




Install terminator, a nice terminal application for Linux

Use terminator if you use terminal alot
- multi tabs
- multi panels
- fast

More info : http://gnometerminator.blogspot.my/p/introduction.html

1. To install, download tar ball from here
http://launchpad.net/terminator/trunk/0.97/+download/terminator-0.97.tar.gz

2. Copy to somewhere you usually install your application
sudo cp -r terminator-0.97 /usr/local/

3. Create a symlink to our application in /usr/bin
This enable you to run it from terminal
ln -s /usr/local/terminator-0.97/terminator /usr/bin/terminator

4. Now you can run terminator from command line.
To run it without the need of the console, run
setsid terminator

September 12, 2016

Compiling and run java program in command line

1. If your code is not in any package, then running the following command will compile and execute your java program just fine

javac TheClassName.java
java TheClassName


 2. However, if the class is in a package such as below :

package thepackagename;

public class TheClassName {
    public static final void main(String[] args) {
        System.out.println("Hello World!");
    }
}

Then calling the same command will give you the following results (or similar) :

Error: Could not find or load main class TheClassName.

This is because, to run your code, it needs to be called with its fully-qualified name (include packagename in it's name) and also note that this command must be called from the directory in which the thepackagename directory exists, not where your class TheClassName is placed (not inside the thepackagename folder itself - must be one level above)

cd {path-to-one-level-above-thepackagename}
javac thepackagename/TheClassName.java
java thepackagename.TheClassName

September 11, 2016

Java basic compilation and execution


  1. Your Java File (source code)
    MyGame.java
  2. Compile the Java File to a *.class file. This is Java bytecode that can be executed on the Java Virtual Machine (JVM). JVM is installed automatically when we install Java and it will be invoked automatically when we run a java program.

    Note : In Eclipse, "run" perform both compilation and execution.
    javac MyGame.java
    • This will create a MyGame.class file 
  3. Execution of the Java File
    java MyGame
  4. Creation of an executable *.jar file. A jar file is simply a file containing a collection of java files.

    First, create a manifest file : touch manifest.mf

    In the manifest file, point Main-Class to our java file that has main entry point i.e. main() method. For example,
    Manifest-Version: 1.0
    Main-Class: MyGame
    Make sure the compiled output class files (myGame.class) and the manifest file are in the same folder.

    Create the .jar file by the following :

    jar cfm MyGame.jar manifest.mf *.class
  5. To run the Jar File
    java -jar MyGame.jar

September 8, 2016

Creating a dump file of a MySQL database for developement in other machine

Create the dump file using the following :

mysqldump --user=username --password --databases MY_DATABASE --single-transaction --add-drop-table --no-tablespaces --skip-disable-keys > dump_sit.sql

Add -h remote-server-address if you're creating from remote database server.

Afterwards, edit the dump file and put these lines at the beginning:

SET AUTOCOMMIT = 0; SET FOREIGN_KEY_CHECKS=0; And put these lines at the end: SET FOREIGN_KEY_CHECKS = 1; COMMIT; SET AUTOCOMMIT = 1;

For example, using sed on Linux to insert at the beginning of the file:
sed -i '1s/^/SET AUTOCOMMIT = 0; SET FOREIGN_KEY_CHECKS=0;\n/' dump_sit.sql

Appending at the end of the file :
echo "SET FOREIGN_KEY_CHECKS = 1; COMMIT; SET AUTOCOMMIT = 1;" >> dump_sit.sql

To understand what these options means, go to :
http://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_compatible

September 5, 2016

Git through proxy

I have to go through proxy at work. Time from time, I took a break and work on my personal projects which are hosted on github and thus, git on my computer needs to be configured for it.

On the terminal, run this :

HTTP_PROXY=http://proxy.site.my:80
git config --global http.proxy $HTTP_PROXY
Back at home, I need to set it back to having no proxy

git config --global --unset http.proxy
Yeah, tedious.

August 23, 2016

Fixing Wifi (Debian Linux Jessie) on Acer Aspire E15 E5-575G-52H9

Do the following :
wget http://mirrors.kernel.org/ubuntu/pool/main/l/linux-firmware/linux-firmware_1.158_all.deb
sudo dpkg -i linux-firmware_1.158_all.deb
and reboot.

Then, install the backported modules and needed firmware :
sudo apt-get install build-essential linux-headers-$(uname -r) git
echo "options ath10k_core skip_otp=y" | sudo tee /etc/modprobe.d/ath10k_core.conf
wget https://www.kernel.org/pub/linux/kernel/projects/backports/stable/v4.4.2/backports-4.4.2-1.tar.gz
tar -zxvf backports-4.4.2-1.tar.gz
cd backport-4.4.2-1
make defconfig-wifi
make
sudo make install
git clone https://github.com/kvalo/ath10k-firmware.git
sudo cp -r ath10k-firmware/QCA9377 /lib/firmware/ath10k/
sudo cp /lib/firmware/ath10k/hw1.0/firmware-5.bin_WLAN.TF.1.0-00267-1 /lib/firmware/ath10k/QCA9377/hw1.0/firmware-5.bin
and reboot. That's it.

However, when a new kernel is installed through updates, the Wifi might fail.

Do the following :
cd backports-4.4.2-1
make clean
make defconfig-wifi
make
sudo make install
and reboot.

Apt-get through proxy

First, try with this :

sudo http_proxy='http://user:pass@proxy.example.com:8080/' apt-get install package-name

If that doesn't work, open the following file sudo nano /etc/apt/apt.conf
Edit the content to be as below :
Acquire::http::proxy "http://:@:/";
Acquire::ftp::proxy "ftp://:@:/";
Acquire::https::proxy "https://:@:/";

August 12, 2016

GNU/Linux

Linux, is in fact, GNU/Linux.

 It is GNU plus Linux.

Linux is not an operating system unto itself, but rather another free component of a fully functioning GNU system made useful by the GNU corelibs, shell utilities and vital system components comprising a full OS as defined by POSIX. Many computer users run a modified version of the GNU system every day, without realizing it. Through a peculiar turn of events, the version of GNU which is widely used today is often called “Linux”, and many of its users are not aware that it is basically the GNU system, developed by the GNU Project.

There really is a Linux, and these people are using it, but it is just a part of the system they use. Linux is the kernel: the program in the system that allocates the machine’s resources to the other programs that you run.

The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. Linux is normally used in combination with the GNU operating system: the whole system is basically GNU with Linux added, or GNU/Linux.

All the so-called “Linux” distributions are really distributions of GNU/Linux.

August 4, 2016

Buying first house

Found some good writing. Thought I share it here.

Already bought a house though. Didn't use these similar methods.

Dapatkan cashback RM35,000 + extra positif cashflow RM100 sebulan dengan pembelian rumah :

Beli rumah RM185,000 je.. Market value untuk rumah RM220,000
Cashback RM35,000 adalah dari lebihan pembiayaan yang anda buat sekiranya anda markup loan..

Jom kita kira kat abwah

loan 100% dari RM220,000.. So bank bagi RM220,000.. Owner nak RM185,000 je.. Balance ada RM35,000 kat tangan

Macam mana boleh dapat cashflow RM200 sebulan?

Market rental RM1,000 sebulan.. Dimana installment untuk rumah ni kalau loan 100% adalah RM1,000.. Skim ini menawarkan bantuan kewangan dari kerajaan sebanyak RM200 sebulan..
.
Installment RM1,000 - RM200 (bantuan kewangan dari kerajaan) = RM800.. Sewa RM1,000 sebulan.. Maka ada lah baki RM200 sebulan sekiranya rumah ini dibeli dan di SEWAKAN..also with RM35,000 cash.
.
Mohd Safuan - 0149045112
REN 16990
Weise International Property Consultants Sdn Bhd.

July 22, 2016

Tomcat - clearing cache

I was doing some works with Tomcat on my current Debian setup and this one issue keeps bugging me the whole day. Today is Friday and lucky for me, I was able to get some times away from that and cleared my mind before getting back at it.

After returning (soaked in wet rain), I came to the conclusion that Tomcat cached some of the apps that I deployed somewhere. This means that re-deploying the apps does not really load up the entirely new App properly as a whole.

Before that, I have checked and did the following, which seemingly "removed" the previous deployment.

| Remove the contents of the folder $CATALINA_HOME/work

Well, that worked for basic UI changes that I made, until I needed to re-point the apps to my local database. In my App, there is a config/properties file that handles this. I made changes to the file, and guess what?

The databases connection was unsuccessful...

It seems that Tomcat still does some cache-ing somewhere....

and then I found out the solution :

Change the content of the following file : $CATALINA_HOME/conf/context.xml

Add inside the tag
     

and that solves my issues.

July 21, 2016

PhoneGap developement on Debian Linux

A friend of mine started a colloboration to create an App which aims to help Orphanage discovery. The main tool to use is PhoneGap. Little that I know, PhoneGap Desktop is not yet supported on Linux. The wine-ported version reported crashing upon launched.

The thing is, I didn't know that PhoneGap has command line tool called PhoneGap CLI. PhoneGap CLI is actually older than the Phone Gap desktop. I have used PhoneGap desktop on Windows before and I found it quite easy to use. I didn't do much with it though. Now that I am on full-time Linux, I will need to use the PhoneGap CLI, thus tutorial below is for those who are interested to develop a PhoneGap app using PhoneGap CLI.


1. First, install Node.js
sudo apt-get update
sudo apt-get install nodejs

2. Simlink Node.js as node (this is how PhoneGap calls it - node instead of nodejs)
sudo ln -s /usr/bin/nodejs /usr/bin/node

3. Install NPM - this is package manager for PhoneGap and other similar javascript programs
sudo apt-get install npm

4. Install PhoneGap using NPM
sudo npm install -g phonegap

5. Install the PhoneGap Developer App from Google Play
https://play.google.com/store/apps/details?id=com.adobe.phonegap.app&hl=en

To get started, lets create hello world app

# create a PhoneGap project, NPM will pull simple hello world project for us to use
phonegap create myApp
# change to project directory 
cd myApp
# build and install the app to Android               
phonegap run android
# start up a local web server to host our application      
phonegap serve           

Get the ip provided and put it in the PhoneGap Developer App on your phone.
The first page displayed is stored at YourAppDirectory/www/index.html

That's it. You're good to go!

To learn what's there in hello world page, go to here :
http://docs.phonegap.com/tutorials/develop/hello-world-explained/




Some screenshots :





July 20, 2016

Git & Github

Intro

Git is the name of this software.

Github is the 'hosted' version of this software - stored in a remote server.

Git stores the project's codes and files.

Git helps programmers in Versioning the codes - each changes they make to the codes will be tagged to a running number, normally with a comment what changes has been done.

Git helps several programmers to collaborate - work together in a single project by making sure everyone can have the latest updated codes at any time and everyone is aware what changes are done to the codes - by reading their comments.



Some terms


Repository : The storage for the codes.

Trunk : Main version of the codes stored in the repository.

Branch : Codes which are derived from trunk (main version). Normally, a programmer will have their own personal branch to work on instead of working directly on trunk - this is to preserve the trunk. So, this could be the first thing they do - branched from trunk. Branched is done on the remote repository - so, basically we creates a copy of the trunk at the remote repository.

Checkout or Clone : Download the current version of the codes from the remote repository to our pc and saved them locally as "local repository". This is usually done the first time we get the codes - checkout from our personal branch.

Origin or Master : The location where codes are checked out from.

Fetch : Get the latest version of codes from remote repository but not merging to the current codes in local repository yet.

Pull : Fetch and Merge at the same time.

Commit : Save the latest changes we did on the local repository to a version. Typically done with a comment what changes have been done.

Add : Add new file for the next commit (see below)

Push : Upload current codes (which has last commit) of local repository to the remote repository, typically to the remote branch.

Merge : "Compare" and "Combine" two versions of  codes. Normally, once all changes are completed on one branch, the branch will be merged to trunk. This will typically happened at the end stage of development.

Conflicts : The differences between two versions of  codes. Occurs when one tries to merge two versions of codes together (i.e. trunk vs branch) that have some differences. Conflicts need to be "resolved"



Typical Workflow

At remote repository, branch from trunk. We get the most updated version.

Checkout the branch to a local repository at our pc.

Make some changes on the codes.

Commit with a message - versioning will be done automatically.

Make more changes on the codes.

Commit with another message - new version created.

Some more changes and commit cycles.

Work are done.

Push the branch in our local repository to the branch in remote repository.

Try to merge the remote branch to the trunk.
   
Conflicts with occurs at this point since we are updating the trunk with our changes. Resolve them.
   
Once merged to trunk, trunk will have our latest codes.
   
Another programmer will try to merge his branch to the trunk.
   
If any conflicts occurs, he need to resolve them first. Typically, if two programmers don't work at the same issues, there will be not much conflicts or conflicts can be easily resolved.



To start, install Tortoisegit below and start checking out from any Github repos :
https://tortoisegit.org/about/screenshots/#Explorer_integration

June 15, 2016

WAMP Port 80 is in use

Most comprehensive solution yet.

https://www.devside.net/wamp-server/opening-up-port-80-for-apache-to-use-on-windows

Because we, devs, are too lazy to type the port number everytime.

Oracle INS-30131 Initial setup error

Had trouble with it. Found some fixes

Fix 1 :

  • Enable administrative share for C$ (Please check with your System Admin to do this or See Microsoft document http://support.microsoft.com/kb/314984)
  • Check that it is ok:
  • net use \\c$ should work
  • the current user (i.e. user in administrator group) should have all privileges on the default share
  • Retry the installation
  • Remove the administrative share again



Fix 2 :

  • Remove the OracleRemExecService before doing the Oracle Client 12c Release 1 32-bit or 64-bit installation on the same Microsoft Windows x64 (64-bit) after installing the Oracle 64-bit or 32-bit software .
  • Go to the Windows 'Services'
  • Stop OracleRemExecServiceV2
  • ( This service is having a intelligence .Once someone tries to stop it this service gets deleted. This is due to the fact ,that this service is not running from the Oracle Home like other oracle services ,but from temp . For example : C:\Users\AppData\Local\Temp\oraremservi... )
  • Then try to install the Oracle 12c 32-bit or 64-bit on the same Microsoft Windows x64 (64-bit)



Fix 3 :

  • Launch cmd.exe in Administrator mode
  • SET TEMP = C:\TEMP
  • Run the installer from that command window

Eclipse Java Project Files Organization

Think of Java sourcecode packages as one big hierarchical namespace. Commercial applications typically live under 'com.mycompany.myapp' (the website for this application might be 'http://myapp.mycompany.com' although this is obviously not always the case). How you organize stuff under your myapp package is largely up to you. The distinction you make for C# between executable (.exe), DLL's and low-level classes does not exist in the same form in Java. All Java source code is compiled into .class files (the contents of which is called 'bytecode') which can be executed by a Java Virtual Machine (JVM) on many platforms. So there is no inherent distinction in high-level/low-level classes, unless you attribute such levels via your packaging. A common way of packaging is:
  • com.mycompany.myapp: main class; MyApp (with a main method)
  • com.mycompany.myapp.model: domain model classes; Customer, Order, etc.
  • com.mycompany.myapp.ui: user interface (presentation or view) code
  • com.mycompany.myapp.service: services within your application, i.e. 'business logic'
  • com.mycompany.myapp.util: helper classes used in several places
this suggests a standalone Java app, it might be different if it is a webapp using one of the many frameworks.
These packages correspond to a directory hierarchy in your project. When using Eclipse, the root of such a hierarchy is called a 'source directory'. A project can define multiple source directories, commonly a 'main' and a 'test' source directory.
Example of files in your project:
src/test/java/com/acme/foo/BarTest.java
src/main/java/com/acme/foo/Bar.java
lib/utilities_1_0.jar
And inside utilities_1_0.jar:
com/acme/foo/BarUtils.class
BarUtils.class this is a compiled java class, so in platform independent bytecode form that can be run on any JVM. Usually jarfiles only contain the compiled classes although you can sometimes download a version of the jar that also contains the source (.java) files. This is useful if you want to be able to read the original source code of a jar file you are using.
In the example above Bar, BarTest and BarUtils are all in the same package com.acme.foo but physically reside in different locations on your harddisk.
Classes that reside directly in a source directory are in the 'default package', it is usually not a good idea to keep classes there because it is not clear to which company and application the class belongs and you can get name conflicts if any jar file you add to your classpath contains a class with the same name in the default package.
Now if you deploy this application, it would normally be compiled into .class files and bundled in a .jar (which is basically a fancy name for a .zip file plus some manifest info). Making a .jar is not necessary to run the application, but handy when deploying/distributing your application. Using the manifest info you can make a .jar file 'executable', so that a user can easily run it, see [a].
Usually you will also be using several libraries, i.e. existing .jar files you obtained from the Internet. Very common examples are log4j (a logging framework) or JDBC libraries for accessing a database etc. Also you might have your own sub-modules that are deployed in separate jarfiles (like 'utilities_1_0.jar' above). How things are split over jarfiles is a deployment/distribution matter, they still all share the universal namespace for Java source code. So in effect, you could unzip all the jarfiles and put the contents in one big directory structure if you wanted to (but you generally don't).
When running a Java application which uses/consists of multiple libraries, you run into what is commonly referred to as 'Classpath hell'. One of the biggest drawbacks of Java as we know it. (note: help is supposedly on the way). To run a Java application on the command line (i.e. not from Eclipse) you have to specify every single .jar file location on the classpath. When you are using one of Java's many frameworks (Maven, Spring, OSGi, Gradle) there is usually some form of support to alleviate this pain. If you are building a web application you would generally just have to adhere to its layering/deployment conventions to be able to easily deploy the thing in the web container of your choice (Tomcat, Jetty, Glassfish).
I hope this gives some general insight in how things work in Java!

June 8, 2016

Project Management Tool : Redmine

MySQL Cluster

Had a nice informal interview (more like a meetup, really) with one of the partners of Kendra Solutions (https://kendra-solutions.com), Andreas. They work on a payment exchange/gateaway system for Telco companies called Kendra Exchange System. Andreas introduced me to some tools that the company are using for the development of their system and MySQL Cluster is one of them.

Gotta learn what it is.



June 6, 2016

Getting 2-dimensional array data to Excel File with PHP



 header('Content-type: application/ms-excel');
 header('Content-Disposition: attachment; 

 filename=REPORT_ORDER.csv');

 $fp = fopen("php://output", "w");

 $test = array ();
 $test[0]['collumn1'] = '00'; 
 $test[0]['collumn2'] = '10'; 
 $test[0]['collumn3'] = '01'; 
 $test[1]['collumn1'] = '11'; 
 $test[1]['collumn2'] = '20'; 
 $test[1]['collumn3'] = '21'; 

  //insert collumn names
 fputcsv($fp, array_keys($test[0]));

 //insert data rows
 for($x=0; $x
     fputcsv($fp, $test[$x]);
 }

 fclose($fp);
 exit;

?>

June 1, 2016

Re-learning Java Spring Part 1

Relearning Java Spring for next project.














April 6, 2016

What is Agile Software Developement


Found some good videos on Agile Software Developement. Good watch!




March 15, 2016

on Time Travel

Time travel is not possible.

Hear me out.

In the natural order of physical life and existence, time does not exist at all. It is we human who created the concept of time to measure the movements. And we divide each day into 24 hours and one hour into 60 minutes and so on. So, actually, "time" does not move at all because it is a abstract creation made by us. So what moves? It is our biological functions that move. Our body grows from one cell into thousands and then millions, from fetus into a baby and then into a toddler, a child, and finally into an adult. It is the same with plants and animals. We, the objects, have moved. And we measure such movement with the abstract concept of time which we have created.

And you know, a tree or plant can never shrink backwards until it become a seed, nor a human being can have his or her bodily cells reformed backwards until he or she becomes a baby. It is a one way ticket. You SIMPLY CAN'T reverse these process.

Thus, time travel is not possible.

February 22, 2016

[Android] Fast ADB installer


If you need just the adb tool for debugging your mobile app, but you don't need the whole big size SDK, use this tool : Download 15 seconds ADB Installer v1.3

Features:
Small - 9.18 MB
Fast - 15 seconds install
Include - ADB, Fastboot and also Drivers
Easy to install - just run it and program will guide you
Clean - ADB and Google Drivers from latest SDK

Install process:
1. Run it with administrator privileges
2. Press Y/Yes to install ADB and Fastboot or N/No to skip
3. Press Y/Yes to install ADB system-wide or N/No for current user only
4. Press Y/Yes to install Drivers or N/No to skip
5. Continue Driver installation
6. 15 seconds passed - finished!

Notes:
System-wide: ADB and Fastboot are installed to %SystemDrive%\adb directory, and added system-wide path.
Current user only: ADB and Fastboot are installed to %UserProfile%\adb directory, and added path for current user.
CMD can use ADB and Fastboot from any directory.
Drivers are installed to system - no need to install them from directories.
Installer automaticly decides if install 32-bit or 64-bit drivers.
If you have problem with driver enumeration in Windows 8.1 install update KB2917929

February 19, 2016

[SQL] Good practice in writing scripts for Table and Stored Procedures

I learned this from my current project's team leader, Shaun who is a good programmer himself. His attentive to details is off the chart among those that I know. These are good habits to incorporate into my programming skill, specifically for SQL.

All the tips below are to ensure that our SQL scripts can be executed at all times and multiple times. These are also to ensure that MOST preconditions are covered so that our script can be executed successfully until the end of the line - instead of stopping halfway due to errors.. Sometimes, we as developer have no control over the deployment of our scripts. Once we handed them over, the IT guys of the clients will run the scripts and chase us when something goes wrong (which happens, all the time!)



For TABLES

1. To create a new table, do not just DROP and CREATE. The best way is to put in the preconditions check, that is to check first IF EXIST (using schema, sys,object or HASH and then DROP. This will avoid stopping the execution of the script due to the table not found - thus can't be dropped.

Using sys,objects :

IF EXISTS(SELECT 1 FROM sys.Objects WHERE  Object_id = OBJECT_ID(N'dbo.MY_TABLE') AND Type = N'U')
BEGIN
PRINT 'TABLE_EXIST'
ENDIF 

Using Hash :

IF DBO.getTableHash('MY_TABLE') = 0xACE31E3C4550DE4B166F01E78A1D86E5
  DROP TABLE MY_TABLE

2. To insert a new data, ensure that ALL PRIMARY KEYS of the rows are checked against before the INSERT command is executed. This is to ensure that we select exactly the data row that we want - the use of Primary Keys distinguishes this!

IF NOT EXISTS (SELECT * FROM TABLE1 WHERE COL_PK1='A1' AND COL_PK2='A2') 
BEGIN
INSERT INTO SET_INITIAL 
(COL3, COL4)
VALUES 
('A3','A4')
END


For STORED PROCEDURES (StoProc)

1. To alter an existing StoProc or to create a new one, do not use DROP and CREATE. SQL keeps a log somewhere with regards to the creation and modification of any StoProc. For existing StoProc, DROP and CREATE will not be helpful anymore for the logs because CREATE builds a new StoProc altogether instead of referring to the previously existing one that being dropped. Instead, use the following : Check IF NOT EXIST, then CREATE empty StoProc. Then, followed by ALTER StoProc. In the above script, first part creates an dummy StoProc if the StoProc with the specified name in the specified schema does not exist. This is useful for the initial setup, when you are creating this StoProc in a new environment. The second part alters the StoProc always – whether it’s created in the first step or it existed before. So, every time you need to make some changes in the StoProc, only the ALTER PROCEDURE section (second part) of the above script needs to be modified and entire script can be executed without worrying whether the StoProc already exists or not.

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SP_MY_ELEGANT_SP]') AND type in (N'P', N'PC'))
 EXEC('CREATE PROCEDURE [dbo].[SP_MY_ELEGANT_SP]  AS SET NOCOUNT ON;')
GO

ALTER PROCEDURE [dbo].[SP_MY_ELEGANT_SP]
.....

The usual approach what people follow for modifying StoProc is to check IF EXIST, then DROP it (if exists) and CREATE it back. The following are the drawbacks of using this approach:

  • Permissions associated with the object, like GRANT EXECUTE etc., are lost when we DROP and CREATE the StoProc.
  • If ALTER PROCEDURE is used on any prior version in a "maintenance" script, different Script needs to be written to cater for it if the StoProc is already existed.
  • If DROP PROCEDURE and CREATE PROCEDURE approach is used, then all the permissions previously present on the Stored Procedure need to be given again with the help of necessary additional scripts.