Posts
Keeping leading zeros in Microsoft Excel
There are situations where you need leading zero in your data. For instance, product codes (SKU) or ZIP codes.
For example, when copy and pasting “0800” into Excel, it will be converted to “800”.
That’s because when you copy and paste this data into Microsoft Excel, by default Excel tries to parse the value according to that cells format. Therefore, Excel recognizes data as numeric and strip out the leading zero.
Posts
Fetching data from a CSV file using PHP
To open a CSV file, start by opening the file by using PHP function fopen.
<pre class="lang:php decode:true ">$filePointer = fopen(CSV_FILE_PATH, "r"); // Modes: 'r' for read-only, 'w' for write-only, 'a' for append After opening the file (creating file pointer), cycle through the content using fgetcsv function. This function reads the file line by line and parse it based on fields in CSV.
<pre class="lang:php decode:true ">while (($list = fgetcsv($filePointer)) !
Posts
Ignoring SSl certificate when debugging in Android WebView
During development process if you are accessing a web page with SSL certificate you could either get a “Blank Page” or “Page Not Found” error.
To prevent this from happening while developing your app, simply override “onReceivedSslError” of WebViewClient object and continue the execution process.
By doing this, the SSL is being completely ignored and therefore could have a serious result if you forgot to remove the code after development and push the code into production.
Posts
Adding shake effect in Android
To add a shake effect to a textbox when an error occurs, first add the following 2 XML files in your anim folder
1) Control how fast or slow the shake should be in this file.
2) Control how far the shake go from left to right.
<pre class="lang:java decode:true "><translate xmlns:android="http://schemas.android.com/apk/res/android" android:fromXDelta="0%" android:toXDelta="1%" android:duration="500" android:interpolator="@anim/cycle" /> Control how many times you want the shake animation to occur.
<pre class="lang:default decode:true "><cycleInterpolator xmlns:android="http://schemas.
Posts
Validating an email address with PHP
Steps to validate an email address:
Sanitizing the email address: strtolower($emailAddress); filter_var($emailAddress, FILTER_SANITIZE_EMAIL); // remove bad characters from the email. Validating the email adress: filter_var($emailAddress, FILTER_VALIDATE_EMAIL); Note: For email addresses containing Internationalized Domain Names (IDN) you need to convert it to punycode before validating the email address.
<pre class="lang:php decode:true ">function validateEmail($emailAddress) { $emailAddress = strtolower($emailAddress); $sanitilzedEmail = filter_var($emailAddress, FILTER_SANITIZE_EMAIL); if ($emailAddress == $sanitilzedEmail && filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) { return $emailAddress; } else { return false; } }
Posts
Unix file permissions
There are two ways to represent Unix permissions:
Symbolic notation Numeric notation Symbolic notation
Consists of three sets of symbols called permission class.
First set represents User/Owner class Second set represents Group class Third set represents Others/everyone else class Each set consists of 3 symbols each represents a permission:
“r” for read permission “w” stands for write permission “x” show execution permission
Numeric notation
Posts
Introduction to Builder design pattern in PHP
The Builder Pattern is a software design pattern which helps to simplify creation of complex objects by reducing the number of parameters in the object constructor.
This pattern uses a builder object to collect parameters of the complex object and return the final constructed object.
Problem:
Imagine we have a car object with many attributes.
The following is the class definition and object instantiation code:
<pre class="lang:php decode:true">class Car { protected $make; protected $model; protected $badge; protected $series; protected $year; protected $kilometers; protected $bodyType; protected $engineSize; protected $fuelType; protected $cylinders; protected $transmission; protected $color; public function __construct($make, $model, $badge, $series, $year, $kilometers, $bodyType, $engineSize, $fuelType, $cylinders, $transmission, $color) { $this->make = $make; $this->model = $model; $this->badge = $badge; $this->series = $series; $this->year = $year; $this->kilometers = $kilometers; $this->bodyType = $bodyType; $this->engineSize = $engineSize; $this->fuelType = $fuelType; $this->cylinders = $cylinders; $this->transmission = $transmission; $this->color = $color; } } $carObj = new car('Toyota', 'Camry', 'Altise', 'ACV36R', '2005', '60000', 'Sedan', '2400', 'Petrol', '4', 'Auto', 'White'); var_dump($carObj); As you can see everything we want to create a Car object we have to pass all those attribute to the constructor.
Posts
How to install Sublime on Ubuntu
Sublime Text is a popular IDE that we can now install via PPA – thanks to Webupd8 team.
To install Sublime text in Ubuntu run the following commands in your terminal (Ctrl + Alt + T):
sudo add-apt-repository ppa:webupd8team/sublime-text-3
sudo apt-get update
sudo apt-get install sublime-text-installer
If you don’t want to install Sublime text and prefer to use it as a standalone application you can download it separately from http://www.
Posts
Installing LAMP stack (Apache, MySql, PHP) in Ubuntu
Notes;
The steps in this tutorial require the user to have root permission. There are many different ways to achieve the same result but I found the following steps simpler than other methods. This tutorial has been tested on a fresh copy of Ubuntu 14.04 on a Virtual Machine (VM) To restart apache web server you can run the following command: sudo /etc/init.d/apache2 restart instal Apache2 by running the following command in command line (Ctrl + Alt + T): sudo apt-get install apache2
Posts
Geography Master Geography Master is a multi level geography game designed to test and improve your knowledge about different countries around the world in a fun and interactive way. This app consists of more than 400 questions about flags, maps and capital cities of countries in our beautifully diverse planet. Learning is reinforced by reviewing and retrying past mistakes.
Geography Master helps to improve your knowledge of countries around the world