Vim : Arrow Keys Adds Different Characters In Editor

I had this problem sometimes on my application server, which can sometimes be old machines. When I tried to use arrow keys in insert mode in vim editor the following characters are being inserted in the editor:

for ↓ I get B for ↑ I get A for ← I get D for → I get C

…and it’s super annoying.

From what I found out, this is how the original Vi behaves.

However, VIM is the successor to Vi. By default, it set to be in Vi-compatible mode, which includes this behavior for the arrow keys.

To remove the compatible mode, create a file named .vimrc in home directory add this line to the top of the file:

vim  ~/.vimrc

set nocompatible

Save the file and this should fix the problem.

Git : How To Stop Relogin On Every Push

Lets permanently authenticating with Git repositories using username and password.

Run following command to enable credential caching:

$ git config credential.helper store

Afterwards, make some changes, commit and try with git push.

No more relogin.

Fedora Add New Monitor Resolution

Sometimes when you plug in your new monitor, the best fit resolution for it doesn’t come out as one of the option in the Display Setting.

Use these commands to add new resolution to your monitor, modify the resolution to what you need :

gtf 1920 1024 60

xrandr --newmode "1920x1024_60.00"  163.83  1920 2040 2248 2576  1024 1025 1028 1060  -HSync +Vsync

xrandr --addmode DP-1 "1920x1024_60.00"

Linux Memory Usage By Apps

Memstat.sh is a shell script that calculates linux memory usage for each running application.

#!/bin/bash 

#Source : http://www.linoxide.com/linux-shell-script/linux-memory-usage-program/
#Parent : http://www.linoxide.com/guide/scripts-pdf.html

# Make sure only root can run our script

if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

### Functions
#This function will count memory statistic for passed PID
get_process_mem ()
{
PID=$1
#we need to check if 2 files exist
if [ -f /proc/$PID/status ];
then
	if [ -f /proc/$PID/smaps ]; 
	then
		#here we count memory usage, Pss, Private and Shared = Pss-Private
		Pss=`cat /proc/$PID/smaps | grep -e "^Pss:" | awk '{ sum+=$2} END {print sum}' `
		Private=`cat /proc/$PID/smaps | grep -e "^Private" | awk '{ sum+=$2} END {print sum}'`
		#we need to be sure that we count Pss and Private memory, to avoid errors
		if [ x"$Rss" != "x" -o x"$Private" != "x" ]; 
		then

			let Shared=${Pss}-${Private}
			Name=`cat /proc/$PID/status | grep -e "^Name:" |cut -d':' -f2`
			#we keep all results in bytes
			let Shared=${Shared}*1024
			let Private=${Private}*1024
			let Sum=${Shared}+${Private}

			echo -e "$Private  + $Shared = $Sum \t $Name"
		fi
	fi
fi
}

#this function make conversion from bytes to Kb or Mb or Gb
convert()
{
value=$1
power=0
#if value 0, we make it like 0.00
if [ "$value" = "0" ];
then
	value="0.00"
fi

#We make conversion till value bigger than 1024, and if yes we divide by 1024
while [ $(echo "${value}" | awk '{if($1 > 1024) {print 1} else {print 0}}') -eq 1 ]
do
	value=$(echo "${value}" | awk '{printf "%.2f", $1 / 1024}')
	let power=$power+1
done

#this part get b,kb,mb or gb according to number of divisions 
case $power in
	0) reg=b;;
	1) reg=kb;;
	2) reg=mb;;
	3) reg=gb;;
esac

echo -n "${value} ${reg} "
}

#to ensure that temp files not exist
[[ -f /tmp/res ]] && rm -f /tmp/res
[[ -f /tmp/res2 ]] && rm -f /tmp/res2
[[ -f /tmp/res3 ]] && rm -f /tmp/res3


#if argument passed script will show statistic only for that pid, of not � we list all processes in /proc/ #and get statistic for all of them, all result we store in file /tmp/res
if [ $# -eq 0 ]
then
	pids=`ls /proc | grep -e "[0-9]" | grep -v "[A-Za-z]" `
	for i in $pids
	do
	get_process_mem $i >> /tmp/res
	done
else
	get_process_mem $1>> /tmp/res
fi


#This will sort result by memory usage
cat /tmp/res | sort -gr -k 5 > /tmp/res2

#this part will get uniq names from process list, and we will add all lines with same process list 
#we will count nomber of processes with same name, so if more that 1 process where will be
# process(2) in output
for Name in `cat /tmp/res2 | awk '{print $6}' | sort  | uniq`
do
count=`cat /tmp/res2 | awk -v src=$Name '{if ($6==src) {print $6}}'|wc -l| awk '{print $1}'`
if [ $count = "1" ];
then
	count=""
else 
	count="(${count})"
fi

VmSizeKB=`cat /tmp/res2 | awk -v src=$Name '{if ($6==src) { sum+=$1}} END {print sum}'`
VmRssKB=`cat /tmp/res2 | awk -v src=$Name '{if ($6==src) { sum+=$3}} END {print sum}'`
total=`cat /tmp/res2 | awk '{ sum+=$5} END {print sum}'`
Sum=`echo "${VmRssKB} ${VmSizeKB}" | awk '{print $1 + $2}'`
#all result stored in /tmp/res3 file
echo -e "$VmSizeKB  + $VmRssKB = $Sum \t ${Name}${count}" >>/tmp/res3
done


#this make sort once more.
cat /tmp/res3 | sort -gr -k 5 | uniq > /tmp/res

#now we print result , first header
echo -e "Private \t + \t Shared \t = \t RAM used \t Program"
#after we read line by line of temp file
while read line 
do
	echo $line | while read  a b c d e f
	do
#we print all processes if Ram used if not 0
		if [ $e != "0" ]; then
#here we use function that make conversion 
		echo -en "`convert $a`  \t $b \t `convert $c`  \t $d \t `convert $e`  \t $f"
		echo ""
		fi
	done
done < /tmp/res

#this part print footer, with counted Ram usage
echo "--------------------------------------------------------"
echo -e "\t\t\t\t\t\t `convert $total`"
echo "========================================================"

# we clean temporary file
[[ -f /tmp/res ]] && rm -f /tmp/res
[[ -f /tmp/res2 ]] && rm -f /tmp/res2
[[ -f /tmp/res3 ]] && rm -f /tmp/res3

Tanam Cili Dalam Pasu

Cara Tanama Cili Dalam Pasu

  1. Sebaiknya jangan gunakan tanah di halaman rumah anda kerana kebiasaannya tanah tersebut tidak subur. Gunakan tanah campuran yang mengandungi dua bahagian tanah, satu bahagian kompos dan satu bahagian pasir. Isikan pasu dengan tanah campuran tersebut sehingga 5cm dari permukaan pasu.

  2. Semai 3 atau 4 biji benih ke dalam pasu sedalam 2 hingga 5 cm.

  3. Apabila anak pokok mulai tumbuh, siram pokok pada awal pagi dan lewat petang setiap hari kecuali pada hari hujan.

  4. Taburkan sebanyak satu sudu teh atau 5 gram baja di sekeliling pokok pada setiap minggu.

  5. Gunakan juga rumput-rumput kering untuk diletakkan di sekeliling pokok sebagai sungkup.

Ancaman Terhadap Pokok Cili.

Layu Bakteria

Penyakit Layu Bakteria disebabkan oleh Phytium spp atau Fusarium spp yang mengakibatkan pokok yang diserang akan layu dan boleh mati jika tidak dikawal dengan segera. Penyakit ini mudah menyerang tanaman cili terutama jika kawasan tersebut pernah ditanam dengan cili atau famili Solanaceae lain dan tanah yang agak lembab. Kawalan untuk penyakit ini adalah dengan kaedah amalan pertanian yang elok seperti mencabut pokok yang telah diserang dan membakarnya, semburan racun kulat, memilih anak benih rintang penyakit, kebersihan ladang dan jalankan giliran tanaman. Serangan boleh berlaku dari peringkat awal pertumbuhan sehingga pokok matang dan berbuah. Jika berlaku pada peringkat awal, penanaman perlu dijalankan sulaman anak benih. Jalankan pemantauan di kawasan tanaman cili dari jangkitan pokok yang telah diserang.

Kerinting Daun

Penyakit kerinting daun disebabkan oleh Virus Tristeza yang merupakan satu lagi masalah dalam penanaman cili dan ia sentiasa menjadi ‘kegusaran’ kepada penanam cili. Pemerhatian petani mendapati bahawa apabila ia telah mula berlaku serangan kerinting daun pada satu dahan atau pokok ia akan cepat merebak kepada pokok lain jika tidak dikawal dengan segera. Tanda serangan dilihat apabila daun muda yang aktif mula kerinting atau berkerekot atau bergulung dan kadang-kadang kekuningan sedikit bermula pada satu dahan dan akan membiak ke kawasan lain. Akibatnya pokok tidak dapat menjalankan fotosintesis dengan cekap dan pengeluaran bunga akan terganggu atau tidak berbunga langsung.Lazimnya tunas-tunas baru tidak akan keluar dan jika ada buah pun saiznya adalah sangat kecil. Adalah disyorkan agar dahan pada pokok yang diserang dipotong dan dibakar atau jika serangan yang sangat teruk maka pokok tersebut dicabut dan dibakar. Kalau banyak pokok dalam kebun telah banyak diserang lebih baik musnahkan semua dan tanam baru.

Bintik Daun

Penyakit Bintik Daun (Cercospora spp) pula akan mengakibatkan daun yang diserang berbintik dan mengurangkan aktiviti fotosintesis. Ia boleh dikawal dengan semburan racun Benomyl. Penyakit Antraknos buah cili yang disebabkan oleh kulat Collectotricum spp. akan merosakkan kualiti buah cili dan dikawal dengan semburan racun seperti Mancozeb. Perlu diingat setelah semburan racun dibuat jangan terus memetik buah cili, tunggu TDMH (Tempoh Dilarang Mengutip Hasil) seperti yang dituliskan pada label racun. Anda perlu mengasilkan cili yang berkualiti, bersih, berkhasiat dan yang penting tidak ada sisa baki racun di dalamnya.

Serangga Perosak

Antara perosak tanaman cili adalah Hamama Merah, Kutu Daun dan Aphids serta Koya. Serangga ini merupakan agen peyebaran pathogen pembawa penyakit sama ada kulat, bakteria atau virus.Koya hidup di bawah daun yang telah berkerekot akan menghasilkan cecair manisan (secretion) yang akan menyebabkan semut yang suka akan manisan menghisapnya, berlendir dan menyebabkan wujudnya kulat Jelaga Hitam. Koya juga mampu bergerak keseluruh pokok cili dan menyebabkan kadar serangan penyakit cepat merebak. Bagi mengawal masalah kutu daun anda boleh menggunakan semburan racun kimia seperti chlorpyrifos imidachlorpid mengikut arahan pada label. Serangan Hamana Merah pula boleh dikawal dengan semburan racun Malathion atau Dichlofo.

Installing Oracle 12c Revision 2 On Fedora 26

This writing is based on this article which I followed. However, the steps mentioned were somewhat not in order and some issues tackled were not described properly (at least to me). Please also note that these steps are very specific to Fedora 26. I don’t guaranteed that it will work on other distro or other Fedora or Oracle version.

1- First of all, download the installation files OTN: Oracle Database 12c Release 2 (12.2.0.1) Software (64-bit).

2- Create appropiate Linux groups and users. Set the password for Linux user oracle.

groupadd -g 54321 oinstall
groupadd -g 54322 dba
groupadd -g 54323 oper
sudo useradd -u 54321 -g oinstall -G dba,oper oracle
passwd oracle

3- Create the appropiate directories for Oracle. Note that the installation can be anywhere, but for simplicity sake, lets just use Oracle typical directory structure.

mkdir -p /u01/app/oracle/product/12.2.0.1/db_1
mkdir -p /u01/software
sudo chown -R oracle:oinstall /u01
sudo chmod -R 775 /u01

4- Unzip the installation files from (1) to folder “/u01/software/database”. This will be our installer folder.

unzip linuxx64_12201_database.zip database

5- Setup the host file. Edit the “/etc/hosts” file to add a fully qualified name to our machine. Note that keep everything in one line. For example, (a) below doesn’t work for me, but (b) does. Ensure the file is saved correctly by running hostname

(a)
127.0.0.1       localhost localhost.localdomain localhost4 localhost4.localdomain4
192.168.56.141  fedora26.localdomain  fedora26

(b)
127.0.0.1   localhost 
127.0.0.1   localhost.localdomain 
127.0.0.1   fedora26.localdomain

6- Set the kernel parameters. Add the following lines to the “/etc/sysctl.conf” file.

fs.file-max = 6815744
kernel.sem = 250 32000 100 128
kernel.shmmni = 4096
kernel.shmall = 1073741824
kernel.shmmax = 4398046511104
kernel.panic_on_oops = 1
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 2
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 9000 65500 

Run this to apply the changes : /sbin/sysctl -p

Add the following lines to a file called “/etc/security/limits.d/oracle-database-server-12cR2-preinstall.conf” file.

oracle   soft   nofile    1024
oracle   hard   nofile    65536
oracle   soft   nproc    16384
oracle   hard   nproc    16384
oracle   soft   stack    10240
oracle   hard   stack    32768
oracle   hard   memlock    134217728
oracle   soft   memlock    134217728 

7- Stop and disable firewall

systemctl stop firewalld
systemctl disable firewalld 

8- Set SELinux to permissive by editing the “/etc/selinux/config” file, making sure the SELINUX flag is set as follows :

SELINUX=permissive

9- Now, reboot the machine to ensure all changes we made so far are applied.

10- Login as the Linux user oracle that we created in (2) : su - oracle

11- Ensure all packages needed are installed. Just copy and paste these on terminal and install them.

Package group

sudo dnf groupinstall "Development Tools" -y
sudo dnf groupinstall "Administration Tools" -y
sudo dnf groupinstall "System Tools" -y 

The required packages, including the 32-bit version of some of the packages. Many of the packages should be installed already.

sudo dnf install binutils -y
sudo dnf install compat-libcap1 -y
sudo dnf install compat-libstdc++-33 -y
sudo dnf install compat-libstdc++-33.i686 -y
sudo dnf install glibc -y
sudo dnf install glibc.i686 -y
sudo dnf install glibc-devel -y
sudo dnf install glibc-devel.i686 -y
sudo dnf install ksh -y
sudo dnf install libaio -y
sudo dnf install libaio.i686 -y
sudo dnf install libaio-devel -y
sudo dnf install libaio-devel.i686 -y
sudo dnf install libX11 -y
sudo dnf install libX11.i686 -y
sudo dnf install libXau -y
sudo dnf install libXau.i686 -y
sudo dnf install libXi -y
sudo dnf install libXi.i686 -y
sudo dnf install libXtst -y
sudo dnf install libXtst.i686 -y
sudo dnf install libgcc -y
sudo dnf install libgcc.i686 -y
sudo dnf install libstdc++ -y
sudo dnf install libstdc++.i686 -y
sudo dnf install libstdc++-devel -y
sudo dnf install libstdc++-devel.i686 -y
sudo dnf install libxcb -y
sudo dnf install libxcb.i686 -y
sudo dnf install make -y
sudo dnf install nfs-utils -y
sudo dnf install net-tools -y
sudo dnf install smartmontools -y
sudo dnf install sysstat -y
sudo dnf install unixODBC -y
sudo dnf install unixODBC-devel -y 

12- Edit the release file. Edit the “/etc/redhat-release” file replacing the current release information “Fedora release 26 (Twenty Six)” with the following.

redhat release 7

13- Edit the bashrc file of the oracle user : vim ~/.bashrc. Ensure the hostname is according to what you set in (5).

export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=fedora26.localdomain
export ORACLE_UNQNAME=cdb1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0.1/db_1
export ORACLE_SID=cdb1
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib 

14- There is a bug that requires us to relink some of the libraries used by Oracle. This is probably the cause of error that prompts “TNS : Lost contact” that is typically faced during Oracle installation.

cd $ORACLE_HOME/lib/stubs
mkdir BAK
mv libc* BAK/
$ORACLE_HOME/bin/relink all 

15- Run the installer in GUI mode. Ensure that you set the password for administator and jot it down.

cd /u01/software/database
./runInstaller 

If you’re faced with the error mentioned in 14, what you probably have is Oracle software installed, but database was not created. Moving forward, do again step 14 and afterwards, follow the next step. If you don’t face the error, skip the next step - you probably have database created successfully already.

16- Create database. Run : dbca

17- If you’re faced with not enough space error, delete the installation zip files downloaded in (1).

18- By now, the database should be succesfully installed. In short, there are 2 things that we need to check to ensure our Oracle database is running correctly, the first one is the Oracle database instance and the other one is the Oracle listener.

19- To ensure the Oracle database instance is running, check it using Sqlplus.

sqlplus / as sysdba
startup 

You should see something like this :

ORACLE instance started.

Total System Global Area 2483027968 bytes
Fixed Size		    8795808 bytes
Variable Size		  687868256 bytes
Database Buffers	 1778384896 bytes
Redo Buffers		    7979008 bytes
Database mounted.
Database opened. 

20- To ensure that the listener is running, run :

lsnrctl status

or you can restart the listener

lsnrctl stop
lsnrctl start

You should see something like this :

    LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 31-DEC-2017 21:22:40

	Copyright (c) 1991, 2016, Oracle.  All rights reserved.

	Starting /u01/app/oracle/product/12.2.0.1/db_1/bin/tnslsnr: please wait...


	LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 31-DEC-2017 21:22:15

	Copyright (c) 1991, 2016, Oracle.  All rights reserved.

	Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=fedora26.localdomain)(PORT=1521)))
	STATUS of the LISTENER
	------------------------
	Alias                     LISTENER
	Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
	Start Date                31-DEC-2017 19:52:50
	Uptime                    0 days 1 hr. 29 min. 26 sec
	Trace Level               off
	Security                  ON: Local OS Authentication
	SNMP                      OFF
	Listener Parameter File   /u01/app/oracle/product/12.2.0.1/db_1/network/admin/listener.ora
	Listener Log File         /u01/app/oracle/diag/tnslsnr/fedora26/listener/alert/log.xml
	Listening Endpoints Summary...
	  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=fedora26.localdomain)(PORT=1521)))
	  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
	  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=fedora26.localdomain)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/orcl/xdb_wallet))(Presentation=HTTP)(Session=RAW))
	Services Summary...
	Service "619541c6fa4e61e3e0530100007f47e3" has 1 instance(s).
	  Instance "orcl", status READY, has 1 handler(s) for this service...
	Service "orcl" has 1 instance(s).
	  Instance "orcl", status READY, has 1 handler(s) for this service...
	Service "orclXDB" has 1 instance(s).
	  Instance "orcl", status READY, has 1 handler(s) for this service...
	Service "orclpdb" has 1 instance(s).
	  Instance "orcl", status READY, has 1 handler(s) for this service...
	The command completed successfully 

21- I had some issues where the listener just couldn’t reach out the running database instance. To rectify this, shutdown the instance and restart it back using sqlplus

sqlplus / as sysdba
SQL> shutdown
SQL> startup 

Afterwards, check if the listener is picking up the instance by lsnrctl status

22- That’s it. You may want to create some tablespace, some new users to try out your local Oracle database using any database client. I use Dbeaver. Good luck!!

Some Free Udemy Courses

Getting started with Jekyll as the new blogging platform

I’ve been using Blogger for my blogging purposes for quite some time. However, since I found out that I can host my site with Github Pages, I thought about moving to here for good.

Why?

I’ve always been irritated on how I needed to customize each blog post with html to make it pretty and usually ending up messy - sometimes one post use some fonts, style etc while the next one use other stuff. There is no consistency. Especially when I tried to display codes, command etc - the syntax highlighting via html is horrible. I hated the fact that I need to spend some time on styling them properly. And I don’t have that time anymore… (projects are piling up)

So here comes Markdown.

I think Markdown is great. I’m quite used to writing in Texttile at the moment since my company use Redmine for the project management tool and our Redmine is powered by Texttile. I mean, it didn’t take long for me to learn Markdown. FYI, here is a great simple notes on Markdown if you haven’t bookmarked it yet.

So, I have decided from now onward I’ll be blogging through this Github page. I have created the repo a while ago and recently just learned how to create post. I didn’t understand the idea of blogging on static websites in the beginning but now that I understood it, I think this is brilliant. The site is quite fast too.

One extra advantage : Now I can practice using VIM for little bit more. I’m practically writing this post using VIM right now.

Lets get started!

Things to do :

  • Complete the Jekyll site setup (I know some links are 404 at the moment)
  • Fixed individual page styles (For some reason, only the homepage is OK)
  • Find out how I can display some posts from other blogs somewhere on the homepage (not so static anymore, eh?). Well, if that’s not possible, I just put up links to them somewhere on the homepage. Kinda for bookmarking purposes.
  • Redirect my domain to here
  • Move all post from blogger to here. Found some utility
  • Retire nextslides.blogspot.my
  • Celebrate