Monday, April 9, 2018

CentOS 6 - Set Static IP

In order to set static ip on CentOS 6:

  1. Open ifcfg-Auto_eth0 file at /etc/sysconfig/network-scripts folder
    1. sudo vi /etc/sysconfig/network-scripts/ifcfg-Auto_eth0
      1. The file name could be different. It could be ifcfg_eth0, too.
  2. Change the content to something like below:
    1. TYPE=Ethernet
  3. :wq
  4. Open resolv.conf and check or correct the nameserver
    1. sudo vi /etc/resolv.conf
    2. It should be like the following.
      1. nameserver
      2. nameserver
  5. Restart network
    1. sudo /etc/init.d/network restart

Other admins use /etc/sysconfig/network file to specify the default gateway. They may not specify DNS1 or DNS2 in ifcfg-eth0 or ifcfg-Auto_eth0 file. Instead, only the /etc/sysconfig/network file is used to specify the nameservers. 

Below is another example of setting up static ip on CentOS 6

## Configure eth0
# vi /etc/sysconfig/network-scripts/ifcfg-eth0

NAME="System eth0"

## Configure Default Gateway
# vi /etc/sysconfig/network


## Restart Network Interface

/etc/init.d/network restart

## Configure DNS Server
# vi /etc/resolv.conf

nameserver      # Replace with your nameserver ip
nameserver       # Replace with your nameserver ip

CentOS 6 - Change hostname

To check the host name of CentOS 6,

hostname -f

To change the host name on CentOS 6,
  1. sudo vi /etc/sysconfig/network
    1. Update HOSTNAME=[] to match the FQDN.
    2. For example,
  2. :wq
  3. If necessary, update /etc/hosts file for internal networking. Change the host that is associated with the IP address.
    1. sudo vi /etc/hosts
    2. change the host name as needed.
  4. Run the hostname command to change the hostname on the server. For example,
    1. sudo hostname
  5. Restart network 
    1. sudo /etc/init.d/network restart

CentOS 6 - Add a user to sudoers

Here are steps in adding a user to sudoers in CentOS 6

  1. Log on as root ( or switch to su with root password).
  2. On the command window, do the following.
  3. Enter "visudo". 
  4. vi loads the sudoer file.
  5. Look for %wheel in the sudoer file by entering " /%wheel "
  6. Remove # from the line "#  %wheel  ALL=(ALL)  ALL" to enable the wheel group with same privileges as root.
  7. Save and exit vi via  :wq.
  8. To create a new user:
    1. adduser   [new_user_name]
    2. passwd    [new_user_name]   [password]
  9. Use the usermod command to add the user to the wheel group:
    1. usermod   -aG   wheel   [user_name]
  10. Switch to the non-root user by entering "su  -  [user_name]"
  11. Test by running a command that's allowed for root only.
    For example, /root is generally accessible only by root user. Try listing the content of /root. 
    1. sudo  ls  -al  /root

Friday, March 9, 2018

Git could not pull because there were uncommitted changes

Recently, I could not pull from origin master on my Visual Studio 2017. Git could not pull because there were uncommitted changes. I forgot that every change in my local repo must first be committed before pull.

One easy way to commit uncommited changes and then pull was using command-line on the Visual Studio solution folder as follows.

git add -A
git commit -m "your message"
git fetch origin master
git pull origin master
git push origin master //To push to the git

Saturday, December 16, 2017

Broken Korean Text Fix

Due to a unique character encoding widely used for Korean text in Korea, you may run into broken, unrecognizable text when opening a file (txt, smi, hwp, doc, etc) created on the Korean Windows platform.

Use Notepad++ to fix such broken Korean text. Notepad++ is an open-source software freely available to download ( It is available for Windows only.

  1. Download and install Notepad++ on Windows.
  2. Open the original text in another text editor like the "Notepad".
  3. Copy all broken Korean text.
  4. On Notepad++, start a new blank file. 
    1. Go to Menu --> Encoding --> Character Sets --> Western Europe --> Windows 1252.
    2. Paste the copied broken Korean text on Notepad++'s new file.
    3. Go to Menu --> Encoding --> Encode in UTF-8
    4. When prompted to save the file, go ahead and save it.
    5. As the file is saved, the broken Korean text are fixed.

Wednesday, December 6, 2017

Age calculation based on today's date and birthday

To calculate the exact age based on today's date and birthday, it might be a little tricky to implement it in SQL. Below is one way to do it.
declare @BirthDate datetime = '12/1/2016'
declare @Today datetime = DateAdd(dd, DateDiff(dd, 0, getdate()), 0)

declare @age int = 
  ( CONVERT(int,CONVERT(char(8),@Today,112)) - CONVERT(char(8), @BirthDate, 112)) /10000

select @age 
/* returns 1 if today's date is 12/1/2017. */
/* returns 0 if today's date is 12/2/2017. */

Sunday, November 19, 2017

Full-Page Background Image CSS

Using CSS3, the following can be used for most modern browsers to produce full-page background image.
html {
  background-image: url('images/background-image.jpg') no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
Make sure to start the style with background-image: url(''). This style should work with IE9 or above.