Saturday, February 28

How important are side projects?

Recently came across this article and the point to note is that everyone here speaks about side projects. So how important are they? If you have an idea, working on it helps validate it. You can try new technologies and learn a lot building it. Side projects are important because you know what you are building and it is a lot easier to explain it to someone about it. Also you would be building something because you are passionate about it. A project at work may not be that interesting, so to keep your passion alive, a side project may do the trick. 

Programming is something that you cannot learn once and use it over and over again. There are ocean full of opportunities and possibilities. And learning in this profession is a never ending deal. Also reading a book or watching a screencast will not help in long run, if you have not actually sit down and written a piece of code. So it boils down to creating of Side projects.

These days it is angular js that is very popular in the front end dev community. Tomorrow there may be some other technology. However the bottom line is that one has to know how things work and should have a good logical, analytical skill set to grasp new topics very quickly.

I had also come across one article, forgot to bookmark that link, it was on hacker news. The article put across very interesting concept that we should document everything that we do. In blog post, over github or anything you feel comfortable. The moment you realise that you are asking a question to google, make it a point to note it down and write an answer to it that worked for you. Doing this will not only leave a digital print but also will help you remember in future and you will always have reference to the solution if in case you encounter the same problem in future. I really like this idea and I feel that such activities are very important. 

Friday, February 27

How to find if an object is empty in javascript?

I had to find out if an JSON object returned from a web server was empty? Stackoverflow had this documented very clearly. I just wanted note it down here for reference.

var obj = {};
/* Check if an object is empty, you could stringify it and find if it equals to empty set i.e {}*/
if(JSON.stringify(obj) == "{}"){
    console.log("object is empty");
    console.log("object is not empty");

Thursday, February 12

PHP MySql query, when using php variables

Based on certain php variables, we would sometime like to fetch/insert data from mysql. I always forget and find it difficult to pass the variables in the query. So below is just an example for my records.

Plain vanilla MySql query would look something like
SELECT * FROM `task_details` WHERE `users_id` = “1” AND `date` >= CURDATE() AND date < CURDATE() + INTERVAL 1 DAY

Let’s say we want to fetch data depending on the users_id. So in Php we would have a variable/session that has users_id stored in it.

$users_id  = $_SESSION[‘users_id’];
/* Without the variable the query looks like */
$query = mysql_query('SELECT * FROM `task_details` WHERE `users_id` = "1" AND `date` >= CURDATE() AND date < CURDATE() + INTERVAL 1 DAY');

/* With the variable the query would look like */
$query = mysql_query('SELECT * FROM `task_details` WHERE `users_id` = "'.$users_id.'" AND `date` >= CURDATE() AND date < CURDATE() + INTERVAL 1 DAY');

Sunday, February 8

Angular Js - ng-include accepts an expression

Angular js provides a very good functionality or to be more precise a directive to include external files, just like in php (include(“filename.php”);). This directive is ng-include.

To use it you must pass the path of the file as an expression/string to the src attribute where you will be using the ng-include. See below

<div ng-include src=”'templates/header.tpl.html'”><div>

P.S :
1) Don't forgot the include ng-app directive in your HTML file.
2) Include your ng-app directive to the HTML tag. Including it to the doctype does not work. For example the below code will not instantiate ng-app
<!DOCTYPE HTML ng-app=”myApp”>

Instead, you could include your ng-app directive to the HTML tag
<html ng-app=”myApp”>

Reference :

Installing LAMP on ubuntu

Thanks to an article from DigitalOcean, I was successfully able to install LAMP. Very well explained.