Category Archives: Uncategorized

Conflicts when syncing branch with master on bitbucket

If you get a conflict when syncing the branch with the master. First checkout the branch on your local machine and then run the following command to merge the changes from master.

$ git merge --no-ff -m 'Merged in master (pull request #40)' remotes/origin/master

Then manually resolve the conflicts before committing and pushing again.

2014 in review

The WordPress.com stats helper monkeys prepared a 2014 annual report for this blog.

Here’s an excerpt:

A New York City subway train holds 1,200 people. This blog was viewed about 7,700 times in 2014. If it were a NYC subway train, it would take about 6 trips to carry that many people.

Click here to see the complete report.

How to host your website on Google App Engine for free.

Ok Guys and Girls. Today I am going to teach you how to host your website on Google App Engine for free. This is quite easy, but please note that this method is for a website that doesnt use a Database. So if your website is using a CMS like WordPress this will not work. You can do that as well by using the method given on this link but you have to pay for Google Cloud SQL then.

Ok lets get started.

Step 1

First go to the following link,

https://console.developers.google.com

You will get a screen like following,

Google Developers Console - Google Chrome_2014-06-08_15-42-42Step 2

Click the big red button that says “Create Project”

You will get the following screen,

Google Developers Console - Google Chrome_2014-06-08_15-46-27

On that enter a project name and a project id, for this you can use Your website name as the project name and create a unique project id (you can combine yourname-yourwebsite to get a unique name)

Then click the Create button to create the project. This will take a few moments.

Step 3

Ok now your project is created. Now you just need to upload your website content to the App Engine project you just created.

To do that first you need to download Google App Engine Launcher which is a simple tool available for all platforms. It comes free when you download the Google App Engine SDK which you can do by going to this link.

https://developers.google.com/appengine/downloads#Google_App_Engine_SDK_for_PHP

Download the setup file for your platform and install it. (You need to have python installed on your computer for the Google App Engine Launcher to work, Get Python from here. Make sure you get Python 2.7.6 newer version is sometimes not supported.)

Then you will get an icon like this on your desktop or start menu.

_2014-06-08_15-52-06

Click on that to launch The Google App Engine Launcher.

Greenshot image editor - _2014-06-08_15-52-06

Step 4

Ok on the Google App Engine Launcher.

Go to file->Create New Application

on the window that you get,

Google Developers Console - Google Chrome_2014-06-08_15-59-14

Enter the project id you gave on the Google Cloud Console when you created the new project.

Browse and select the Parent Directory of the website files on your computer. This creates a folder under that parent directory in the project id you gave. So you will have to move the website files into that folder.

Select PHP as the runtime.

Click Create button.

Step 5

This will create App Engine files in the website files folder.

In that you need to edit the App.yaml file. This is where you tell the app engine app where all your files are and how you want them to be launched.

So go to your website project folder on your local computer and open app.yaml file on notepad. Or on the Google App Engine Launcher click the newly created project and Click the Edit Icon.

Greenshot image editor - Google Developers Console - Google Chrome_2014-06-08_15_2014-06-08_16-04-50

I am adding my app.yaml file here to show you how you need to add code sections to load Javascript, Css, images and main url files.

Like I have given you will have to give all the static file folders in your website. Here in my website all traffic is directed to my index.php file. If you have other files you will have to modify that part like following.

For each of your links you have to give like above.

Ok now your ready to upload the files.

Step 6

Go to your Google App Engine Launcher, Select your project and click the Deploy button at the top.

app

It will start uploading the files. Once completed you can go to the following link to see if you website is working properly.

projectid.appspot.com (project id is the unique project id you gave when you created the project on Google Cloud Console.)

Ok If your website is working fine, the Next step is to point your domain to the Google App Engine hosted website.

Step 7

Go to Google Cloud Console (https://console.developers.google.com)

Click your project Name

Google Developers Console - Google Chrome_2014-06-08_16-15-53

You will get your project view. This has lots of functionality, explore at your own risk 😉

For our purpose click the App Engine link on the side bar, under that you get a link called Settings Click on that. After that click the custom domains tab on the top.

_2014-06-08_16-18-46

 

Ok on that its pretty self evident what you need to do, But let me explain each step.

1. Verify you domain

Enter your domain and click verify, it will open a new tab and show you verification options. Easiest way is to select your domain provider and click verify. If your domain registrar is not in the list, click Other and you will get a TXT record which you need to add to your DNS settings. (If you dont know how to edit your DNS better to check with your domain provider. It can mess up your website if you get it wrong.)

2. Select your domain in the second step and it will show you DNS records as the Step 3, which you need to add to your DNS Settings.

Google Developers Console - Google Chrome_2014-06-08_16-26-18

That’s all. It looks like a long process, but its quite simple. Try and let me know how you did. 🙂

Regular Expression – Javascript- To check filename to see if alpha numeric characters

Ok here is a quick regular expression to check if a file name only contains alpha numeric characters  also we need to allow the period sign.

/^[0-9a-zA-Z\.]*$/

This allows numbers, letters and the period symbol.

The full code,

var filename = fullfilepath.replace(/^.*[\\\/]/, ''); // this is to get only the file name, file upload field gives the full path

 if (!filename.match(/^[0-9a-zA-Z\.]*$/)) {
 alert('File name should only containg letters and numbers, please rename image file and upload.');

 }

WP Query Sorting by Custom Field

Hi, When developing themes you might have encountered and requirement to sort the posts by a custom field. Well I got that requirement and this is how I did it,

Need to define ‘meta_key=keyname’ in your WP_query arguments. This is to speficy your custom field.

Then in the ‘order_by’ argument give ‘meta_value’ if its a Alphabetical value or ‘meta_value_num’ if its a numeric value.

Complete query is given below,

$loop = new WP_Query(array(‘post_type’ => ‘doctors’, ‘posts_per_page’ => 10000, ‘meta_key’=>’rank’
, ‘orderby’ => ‘meta_value_num name’, ‘order’ => ‘ASC’));

Web Development Classes

I just started a web development class and I love teaching people who are interested in learning how web sites are developed.

My classes range from basic stuff like HTML and CSS to more advanced subjects like CMS’s and Frameworks.

If you are also interested in learning web development that meets industry requirements let me know.

Im free on saturday and sunday of each week for one to two hour classes. Individual and group classes can be conducted.

My current class includes three students and it is conducted in Moratuwa every Saturday from 9AM to 12PM… you can join that if you like.

Areas that I cover normally are,

  •  HTML
  • CSS
  • Javascript
  • PHP
  • MySQL
Any additional subjects are taught according to individual needs.