Friday, 31 May 2013
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.
/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.
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
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.
- 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 )
- 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.Solutoin 2
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
Subscribe to:
Posts (Atom)