Just today while driving back home, a random question came across my mind,

What is my age in number days?

Now, I am not good at maths to figure it out manually but since I am decent php programmer, I wrote this small code snippet which helps calculate my age counting in terms days. And its just one line!

$birthday = '1989-03-06';
$now = date("Y-m-d");
echo 'You are '. date_diff(date_create($birthday), date_create($now))->format('%a days old');

So according to this,
Today is the 8,244th day of my life. Cheers! :D

 

Google Analytics (GA) is a free service offered by Google that generates detailed statistics about the visitors to a website. Its hugely popular tool which is used  57% of the 10,000 most popular websites on the currently, the list includes Twitter,myspace etc. GA tracks visitors & provides you useful information such as

  • Traffic source: If it was direct traffic, Purchased traffic via Ads or some other source
  • Information about Visitor: Their IP Address, country, Browser,time spend on site & lots of other information that could help you understand your visitors
  • And lots of other such useful bits of information.
What GA could not track until recently was social engagement, if someone click Like button,tweets or shared your site on social network. How do you track it? by default that social media traffic would be shown as DIRECT traffic which is not what you want.  But good news is Google analytics now support this and they are calling this _trackSocial method

the syntax is as follows: Continue reading »

 

Often when I look other people’s code, I feel like vomiting. Why? Because most of the time the code is badly written, has bugs & is hard to read. so what is it that makes up “good code”. some might say:

good code = easier to read + lot of comments.

Sure, readability is important but its last thing on my list.

what are the 3 most important things for writing “good code”?

  1. Expect the unexpected: Sounds oxymoron? But that’s what you got to do: Expect all cases. Practically what this means is you have to do error handling & validation at every step of program. Example, Don’t just assume connection to database works now, so it will work forever. if you are passing a type array to a class method, don’t assume in that method will receive that argument of array type,. things can go wrong anytime. Always be prepared to Expect Everything! Check Everything
  2. Exploit your own code: As programmers our mind always focuses on how to make things work which is fine but this leads so to locked mindset; trained to think in just one way. This is specially bad from security standpoint. An Excellent example is bug in opensource blowfish C Libary. This bug existed from 1998, nearly 13years in which hundreds of highly talented developers must have looked at the code & yet not noticed the bug. Wonder Why? Because when reading the code, we are reading the programmers indent instead of actually seeing what the code is doing. What we should be doing is trying to break our own code: think of all possible way you can bypass & do something dangerous. essentially think like a cracker/hacker. If you can’t develop that mindset — make sure atleast one person from your team can
  3. Never Trust the Client: never ever trust the client! By client I mean web browser etc. This means any data retuned from functions you have written in javascript have to  validated again server side. Don’t trust any data that is sent by client & always sanitize your inputs. Because people can modify headers, edit form values, change javascript logic completely. so its very important that you always double-check everything on server & make sure its what you expect.developers should treat web browsers as hostile environment over which they have partial non-exclusive control.
So these were my 3 tips for writing good code. The others can be Better Docs,making code readable, performance but the Above 3 according to me are most important.  What you think? Let your thought in comments below
 

In between chaos created by bomb blasts in Mumbai & news channels constantly flashing horrific images in name of “live reporting”, there is some other related news which caught my eye.

Delhi resident Nitin Sagar created a public spreadsheet on Google Docs(Now taken offline) where anyone willing to help Mumbai blast victims can give their contact details & list things they are willing to do for helping. Shortly after that, it got retweeted like crazy & gone viral

Several users have offered overnight house stays, the use of their car, and listed their blood types under the #here2help tab. The spreadsheet also has #needhelp, Blood group, Missing, and Injured tabs which residents are still filling out. serendipity of finding that there are hundreds of people more than willing to offer you place to stay, donate blood,free rides, give money is amazing. It Certainly reinforces that humanity is not dead.

This is where technology can play its part to connect people — instantly & spontaneously. Like in this case,  tools like Twitter,Google Docs have organize an ongoing rescue effort where people are helping each other without help from Govt which you can see by this map of tweet users in mumbai. This allowed every person with internet connection to add their tiny bit.

This exactly why I love technology! Technology enables normal people to do great things.

We are for Peace, ALWAYS!

 

I was reading a review on amazon and unfortunately the person has posted in all uppercase. I tried to read but all uppercase text is harder to read, not to mention it is considered shouting on the web.In other words, you are reading the text on random site and just want to change it to lowercase. here is how:-

I used clever JavaScript bookmarket to transform all text on the current page into lowercase.

Convert text into Lowercase.

Drag the above link to bookmarks bar & click on this whenever you want to convert text into lower caps. quite cool and handy!

the code:

document.body.style.textTransform = "lowercase"
 

Many of times I keep talking about advance JavaScript or various other technologies that might not be geared towards beginners. And the most common feedback I get by emails from my readers is that they want to learn the basics of web development and are confused on where to start. If they should take classes,buy a book etc. But there I am suggesting a different approach to  learn the very basics of web-development – the basic building of the web. by Watching Cool Videos!

Client Side Web At its Core, it powered by three technologies

HTML: Gives out the meaning

CSS: Styling & Presentation

JavaScript: Def Continue reading »

© 2011 Gaurish Sharma Live Suffusion theme by Sayontan Sinha