Posts

Showing posts from September, 2014

Installing Git in Ubuntu

To install git, run: sudo apt-get install git After installing git, you may setup the following configuration: git config --global user.name "Your Github Name" git config --global user.email "email@example.com" git config --global color.ui true

Git Configuration: Colorize Output

Git has this feature that allows its terminal output to be colorized. There are various options to do that, and one of it is through the color.ui You can choose how you want the terminal coloring but if you want to colorize all git output, set color.ui to true git config --global color.ui true Here are the settings you may use for color.ui : true → set colors to all git terminal output false → never colors the output always → always set colors to the output even when piping git with another command Setting specific colors to git commands git config --global color.branch true git config --global color.diff true git config --global color.status true git config --global color.log true

Installing MySQL in Fedora

Install MySQL yum -y install mysql mysql-server Enable MySQL service: /sbin/chkconfig mysqld on Start the MySQL server: /sbin/service mysqld start Set the MySQL root password: mysqladmin -u root password 'MyNewPassword123'

PHP Pagination with Bootstrap 3

Image
In this guide, I will show you how to create a very simple pagination in PHP using Bootstrap 3. With just a few steps you will be able to create something like this: Before we start, prepare the following files and folders: - bootstrap/ - index.php - pagination.php Step 1: Download Bootstrap 3 and extract its content inside bootstrap directory: - bootstrap/ ├── css/ │ ├── bootstrap.css │ ├── bootstrap.min.css │ ├── bootstrap-theme.css │ └── bootstrap-theme.min.css ├── js/ │ ├── bootstrap.js │ └── bootstrap.min.js ├── fonts/ │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ └── glyphicons-halflings-regular.woff - index.php - pagination.php Step 2: Copy the basic template and paste it in index.php . Step 3: Remove the line: <h1>Hello, world!</h1> And replace with: <div class="container"> <div class="row"> <?php requi...

Create Bash Aliases With Arguments In Ubuntu

Image
The scenario here may not be the same with you but the point is you want your bash alias to work with parameters. Say I want to display a file's content in colors and I want the output to display line numbers as well. For the color part, I used python's syntax highlighter called pygments and I used bash built-in line numbering command called nl . Now to achieve my goal, I have to pipe nl to the result of pygmentize: pygmentize test.php | nl This is quite a hassle especially if you have to do it frequently only with different files. Unfortunately, bash alias does not directly accept parameters. The solution is to create a bash function. ccat() { pygmentize $1 | nl } or multi-line: function ccat() { pygmentize $1 | nl } I named the function ccat (custom cat) because it works like a cat command but the syntax is highlighted. Put this function in ~/.bashrc and then restart your terminal or use source: ccat test.php

Ubuntu 14.04 Changing Apache2 Document Root to Home Directory

The default DocumentRoot setting for Apache is in /var/www/html/ . During development, this is sometimes troublesome cause we might ran into permission issues. To prevent that we can change our document root to a location where we have more control ie. your home directory. Here is what you need to do to change your document root. 1. Look for the ff. lines in /etc/apache2/apache2.conf . <Directory /var/www/html> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> 2. Change /var/www/html to your home directory /home/<user>/public_html 3. Look for the ff. line in /etc/apache2/sites-available/000-default.conf DocumentRoot /var/www/html 4. Change /var/www/html to your home directory /home/<user>/public_html 5. After saving the changes, create a public_html folder in your home directory, restart apache. sudo service apache2 reload 6. To test if it the document root is now pointed at your home directory, ...

Show/Hide or Toggle Content with Javascript

Here is a simple javascript snippet that you can use to toggle the contents of a div. function toggleDisplay() {     var e = document.getElementById('toggle_div');     e.style.display = (e.style.display == 'none') ? 'block' : 'none';  } <input type="button" value="Toggle Display" onclick="toggleDisplay()" /> <div id="toggle_div" style="display: none"> Hello World. </div>

Display File Content with Colors and Line Number - Alternative to cat (Ubuntu)

Image
Sometimes you may want to quickly display the contents of a file directly on the command line with the `cat` command. And sometimes the contents of that file is the source code of a program. If you want to display the source code markup with colors and line numbers, then this trick is what you are looking for. What you need to do first is install Pygments , a python syntax highlighter. sudo apt-get install python-pygments python3-pygments After installing pygments, you can now view source code with colored markups. just run the ff: pygmentize testfile.rb Now for the line numbers, you will have to pipe the `nl` command pygmentize testfile.rb | nl --body-numbering=a The option --body-numbering means it will accept a style for line numbering and it is any of the ff: a - number all lines t - number only nonempty lines n - number no lines I used  a so that everything will be numbered including empty lines. We can actually add nl options in bash alias so that we do not...

Ubuntu Color in Terminal

Image
In ubuntu, you can actually add colors to the plain old terminal simply by turning on a flag in your terminal settings. Open your shell prompt and edit the file `.bashrc`, a configuration file for the terminal. It's usually in the home directory. $ nano ~/.bashrc Now look for the line and remove the `#`: # force_color_prompt=yes Save the changes. Then source the file for the changes to take effect or restart your terminal. $ source ~/.bashrc Now you will see your terminal colorized.

Creating Bash Aliases

In bash scripting, you can create aliases for the shell commands you frequently used. The most simple way to create an alias is to assign it directly in your terminal: alias ll='ls -l' The ls command list the files and directories in the current directory. Now if you run the ll command in your terminal, this will list the files in long format as specified by the -l option. The disadvantage is that the alias will only work in the current shell. This means that if you open a new tab or window, the ll command will not work there. Also, the ll command will not work anymore once you closed the terminal. If you want to create an alias that will work in any shell instance, you can add your aliases in ~/.bash_aliases. After adding your alias fire up this command to make it effective immediately: $ source ~/.bash_aliases