Search This Blog

Aug 20, 2014

MYSQL TRIM() and REPLACE()

Using TRIM() and REPLACE() syntax will help you to get rid off of extra space, tabs, and new line in your database records. These two are useful in cleaning up your records for accurate QUERY especially when using WHERE conditions.

Using TRIM() - function returns a string after removing all prefixes or suffixes from the given string.

Syntax

TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM ] str)

Examples

TRIM(' test');
Result: test
TRIM(LEADING 'test' FROM 'testleading'); 
Result: leading
TRIM(TRAILING 'test' FROM 'leadingtest'); 
Result: leading
TRIM(BOTH 'test' FROM 'testleadingtest'); 
Result: leading As you can see, TRIM() only remove extra white space in the prefix, leanding and trailing text but not text/character in between. That's where REPLACE() took the spot. MySQL REPLACE() replaces all the occurrences of a substring within a string.

Syntax

REPLACE(str, find_string, replace_with)
Example:
REPLACE('webdosh','os','o');
Result: webdoh

Jul 15, 2014

GIT Commads Aliases

Using GIT commands Aliases are very helpful. I use them to make my your work easier with regards on GIT. In order to add aliases, simply run the following commands in GIT BASH or by adding it on the .gitconfig file.
Using GIT Bash
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
git config --global alias.hist 'log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short'
git config --global alias.type 'cat-file -t'
git config --global alias.dump 'cat-file -p'
Using .gitconfig
[alias]
  co = checkout
  ci = commit
  st = status
  br = branch
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
  type = cat-file -t
  dump = cat-file -p
That's it, you can now start using those aliases. For example, instead of using git status you can use git st and so on. Happy GIT-ing!

Jul 3, 2014

Setup Virtual Host XAMPP on Linux

I always forgot on "How to set up virtual host on Linux" so I decided to create a blog post for my future reference (and for you too... you're welcome!)
I assume that you already install a XAMMP program on your system so lets jump in creating the virtual host.

1. Open your terminal and make sure you log as SU
2. Type in this command "gedit /opt/lampp/etc/httpd.conf" to open httpd.conf in the gedit editor.
3. Uncomment the "Include etc/extra/httpd-vhosts.conf" line by removing the "#".
4. Type in your terminal "gedit /opt/lampp/etc/extra/httpd-vhosts.conf" to edit httpd-vhosts.conf then add the following lines:

DocumentRoot /opt/lampp/htdocs
ServerName localhost
ServerAlias www.localhost



DocumentRoot /home/[YourCompName]/samplesite
ServerName www.samplesite.loc
ServerAlias www.samplesite.loc

IMPORTANT: Please make sure that you entered correct directory.

5. Then, edit your hosts file by typing “gedit /etc/hosts” on the terminal. Add your server alias like the following.

 127.0.0.1 localhost2
 127.0.0.1 samplesite

6. Lastly, restart your lampp by executing "/opt/lampp/lampp restart"

Again, you're welcome!