Friday, 31 May 2013

For iPhone Users :)


Sunday, 19 May 2013

Copy or Rename multiple files to another extension in Linux

Recently I came across a problem of renaming multiple files to a different extension in linux. Basically what I had was a folder with template files and I wanted to create php files from them while keeping the original ones intact. Here is my folder structure.

/Config
 - Database1.template
 - Database2.template
 - Database3.template

And this is what I wanted to achieve


/Config
 - Database1.template
 - Database2.template
 - Database3.template
 - Database1.php
 - Database2.php
 - Database3.php

It turned out that you can do it using just one simple command ( instead of writing a shell script ). A command called "rename" is what I was looking for.

$ rename 's/\.template/.php/' *.template

The above command tells linux to look at all the template files in the current folder, search for template text and replace it with php. Hope this helps you as well.

Cheers.




Sunday, 5 May 2013

All Your Brain Suck - Awesome talk by Paul Fenwick


I attended codemania 2013 few days back. Really loved the talk given by Paul Fenwick so sharing it over here.

P.S The video is from OSCAN 2011 but the content is same as of codemania 2013.

Cheers

Friday, 3 May 2013

Thinking OOP in php ( Part 1 )

This is part 1 of thinking OOP ( some people even say OOPs ) in php series. The aim of this series is to pick up some real world problem ( kinda ) and then to solve it using Object Oriented Concepts and Design Patterns and Principles. Let's get started then.

Problem
Let's assume that you are working as a programmer in a company and a new requirement has just come up. Your page will be passed a parameter called color and based on that color you have to display a button ( obviously of that color ).

Solutoin 1
Let's review our code for some potential problems.

  1. The logic of how our button is displayed is naked. ( We will have to modify this script file if we decide that our color should begin with capital letter )
  2. The logic of what to do based on the value of parameter is tightly coupled with the client ( For example, if in some other script file we want to reuse the button display logic we will end up copying these lines or do an include or whatever )
Let's address problem number 1 first. We can hide the implementation of button by creating a class. Lets create classes called BlueButton and GreenButton.
Solutoin 2
Our Solution 2 looks slightly better than solution 1. We have solved the problem of implementation of button being naked by encapsulating it in to a class. However, we still have logic of which class to instantiate and knowledge of all the classes ( BlueButton, GreenButton and all the future ButtonClasses ) coupled in the client. To solve this issue, we are going to use Factory Design Pattern.

Builder In our case, ConcreteProduct is Button class. We do not have an AbstractProduct class but we will create one.
Solutoin 3 And that's basically it. We have successfully applied design pattern and OOP concept ( encapsulation ) to the given problem. Next time I will cover a new problem and one more design pattern. Cheers

Tuesday, 23 April 2013

How to find hostname from ip address in Windows?

Recently, I came across a problem of finding a hostname from ip address. Basically I needed to find who made an api call within our network (LAN). The solution turned out to be rather too simple. Here is what you need to do.


  1. From Start Menu, navigate to Command Prompt. ( Keyboard shortcut is Ctrl + R, then type cmd and press Enter )
  2. Type nbtstat -A <ip_address> and press Enter.
  3. You will see a table with name,type and status. Just look in the name column and Bingo.
Now here is the interesting bit. If your target machine is not using Windows then you would see nothing. In my case it was only one machine not using Windows so I was able to identify it quite easily.

Give it a try and let me know what you think.

Windows 8 : The missing Start button


If you are like me and are quite used to the Windows Start button, Windows 8 may come to you as a disappointment. The good news is that there is a free tool available called Classic Shell that will bring back the joy of having a start button in your windows. Cross device functionality of Windows 8 comes at the cost of some usability issues but people at Classic Shell have done an excellent job of not only adding the start button back to your windows but also adding some usability features to the file explorer. Give it a try and let me know if you find it useful

Cheers.

Adding Static ARP Entry in Windows Vista

NOTE : I have decided to write a blog again. Following was the most popular post on my last blog so I am publishing it again. 


I had a real tough time trying to configure my internet connection on Windows Vista. The entry for my DNS was dynamic and I was using arp -d "" as a quick fix. Yesterday, I decided to fix this problem once and for all. I knew that in Ubuntu its quite easy to add a static entry in to the ARP Table. I used the following command which worked quite well in Ubuntu.

arp -s "xx.x.x.x" "mm:mm:mm:mm:mm:mm"

where xx.x.x.x was the ip address and "mm:mm:mm:mm:mm:mm" was the MAC Address. So feeling quite confident about the solution of the problem, I performed the following steps.

  1. Went to Start > Run
  2. Typed in "cmd" and pressed enter.
  3. In the command prompt I entered the command arp -s "xx.x.x.x" "mm-mm-mm-mm-mm-mm"
Result : The ARP entry addition failed : 5

Oops, I realized that Windows Vista needs elevated mode to perform such operations. So, I went to the desktop and right clicked on the "Command Prompt" shortcut and selected Run as Administrator option. A window appeared asking for the confirmation and I selected to continue.
I repeated the above procedure with the administrative privileges and yet again... the same result. What the hell? If I can delete an entry so easily then what's wrong with the addition. Thinking that Vista is a real crap, I decided to google my problem. There were numerous posts on the same topic and people complaining about the same problem and yup...there was a solution to my problem. Lets see how it works.

  1. Open command prompt with administrator rights.
  2. Type the command == > netsh -c "interface ipv4"
  3. You would get the command prompt like "netsh interface ipv4>"
  4. Next , you type the command == > add neighbors "Local Area Connection" "xx.x.x.x" "mm-mm-mm-mm-mm-mm" (Replace Local Area Connection with the name of the connection)
  5. Bingo !!!
This solution fixed the problem and my internet connection started to work properly. Hope you found this solution useful.

Cheers