After 27 months I have published posts and videos at Youtube, I decided to have a new chapter of my life. I will stop to blogging at May 1st 2013. If you want to contact me, please contact me via Twitter. I would like to thanks to my readers and God for opportunity to blogging tutorials and another stuff.
Tuesday, April 30, 2013
Thursday, April 25, 2013
How to create a virtual interface on CentOS or Debian
I was working on my DNS server and I wanted to create a virtual interface to distinguish internal requests from external requests. The command to create a virtual interface is:
Tuesday, April 16, 2013
Design Patterns - Observer Pattern
Introduction
A design pattern is a specific way of solving a particular problem. They are not simply about reusing code; they are more abstract and generalized than that. They are about using reusing ideas.
The Observer Pattern
Often, you'll have data in your application in your application that changes over time. Say that you have some GUI components that are required to show this data and update it when it changes. How would you handle it? One solution might be to pass the newly updated data to a method of the GUI component so that could redraw the information. A problem with this approach is remembering to do that each time the data is updated. What if it's not clear how often the data will be updated, and whether you want the GUI to update automatically when it does?
The observer pattern solves this problem by using two interfaces, Observer and Observable. As the names suggests, the Observer "watches" the Observable to see whether it changes.
Keeping with the theme of human senses, an Observer is sometimes called a Listener, but for this chapter we stick with the former name.
In its most basic implementation, the Observable can add Observers. Observable then is responsible for notifying them if anything about its state has changed, and the Observer is responsible for reacting to the change. In this example, our data is the Observable and the GUI components are the Observers. If the data changes, those changes will automatically be reflected in any GUI component that is an Observer of the data. Next figure demonstrates the observer pattern
Widgets
Continuing with the previous example, you'll use the observer pattern to handle displaying price information for some of the instruments within graphical elements on a Web page. First, you'll need to define some simple graphical components. These components will be basic HTML table structures whose functionality will be contained within an object. Such components often go under the all-purpose term of widgets.
Designing the Widgets
A graphical widget will have two responsibilities. It will need to draw its own HTML so that it can be seen on a Web page, and it will need to update the data it displays. You may have noticed (from previous figure) that an update method is defined in the Observer interface.
Each widget is an Observer. The item being observed is the data representing the instrument name and price information. The data source is Observable.
All widgets, then, should implement the Observer interface. In addition, each one should descend from an abstract class that defines some shared functionality between widget objects. This is an example of using interfaces and abstract class together. Because the update() method is the same for all widgets, it can be implemented in the abstract class. The class diagram is shown in next figure.
Now all concrete implementations of widgets will descend from the AbstractWidget class. The AbstractWidget class in the turn implements the Observer interface. Notice the update() method in the class diagram for AbstractWidget is not shown in italics. This means that the method is actually implemented at that point. The # symbol indicates that the internalData property is protected. That means subclasses of AbstractWidget have access to it. If it were private, subclasses would not be able to access it.
How to configure NTP Server and Client on CentOS
Introduction
NTP is widely used to synchronize a computer to Internet time servers or other sources, such as a radio or satellite receiver or telephone modem service. It can also be used as a server for dependent clients. It provides accuracies typically less than a millisecond on LANs and up to a few milliseconds on WANs. Typical NTP configurations utilize multiple redundant servers and diverse network paths in order to achieve high accuracy and reliability.
Configure NTP Server
- yum install ntp (and type 'y' when show up two questions);
- vi /etc/ntp.conf
- Add the next statement for accept requests from another servers (DNS server, LDAP server, etc.) on your LAN:
restrict 10.50.0.0 mask 255.255.255.0 nomodify nopeer noquery - Add the next statement for public servers NTP synchronize with server's internal clock on your LAN:
server 0.europe.pool.ntp.org
server 1.europe.pool.ntp.org
server 2.europe.pool.ntp.org
server 3.europe.pool.ntp.org - This command allow to set current time from indicated NTP server:
ntpdate pool.ntp.org - The same server can be defined on configuration file:
vi /etc/ntp/step-tickers
pool.ntp.org - service ntpd start
- Make sure the ntpd is active from beginning Linux boot;
chkconfig ntpd on - Checking synchronization status of service NTP.
nptq -pn
tail -f /var/log/messages
Configure NTP Client
- This file allows to set server NTP to use for initial adjust clock during starting of ntpd:
vi /etc/ntp/step-tickers
10.50.0.254 - On the file /etc/ntp.conf, all you need is add server NTP's IP address to use:
vi /etc/ntp.conf
server 10.50.0.254 - Checking synchronization status of service NTP.
nptq -pn
tail -f /var/log/messages
It can take long to see message of success. When I was configuring, it took about 1 hour.
Conclusion
This protocol allows to keep operating system's clock synchronized with high accurate, running at information of synchronism got from another NTP servers.
Although the configuration is relatively simple, NTP performances a very important role. The possibility to make sure that clocks from many servers are kept with right time is relevant and it is a important factor to correct of many applications. The correction of local time in operating system allows also ensure that logs recorded in operating system have correct time and that is important when I use logs to diagnostic problems of some services.
Validation Email Address: Server side vs Client side
The week ago I was programming my web application using PHP5.
There is two ways to validate email:
- On server side (using filter_var from PHP5)
- On client side (using input type email from HTML5)
PHP5 example
$email = "xpto@email.com";
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "This ".$email." email address is considered valid.";
}
HTML5 example
<form action="file.php" method="post"> E-mail: <input type="email" name="useremail"><br> <input type="submit"> </form>
In my opinion it is better validate email on client side instead server side. So don't validate email on server side because it takes a lot work to warn user that has an invalid email address. With client side to validate email, it saves a lot work to warn user that has an invalid email address.
But if you are programming a web application using OOP, it is good idea to validate email from server side because you are not using form to validate email but you are using object, for example:
class User{
private $name, email;
public function __construct($name,$email){
$this->name=$name;
$this->email=validate($email);
}
private function validate($email){
$mail = "";
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
$mail = $email;
}else{
echo "This $email is not valid!";
}
return $mail;
}
}
$user = new User("Peter","peter@xpto.com");//valid email
$user = new User("Paul","kjfddks");//prints "This kjfddks is not valid!"
Sharing folders without login - Samba
Samba is an open source software that allows to solve communications problems between Windows and Linux. With Samba, you can share folders, printers for Windows clients and can perform as a Primary Domain Controller (PDC) or as domain member. Samba can also be part of an Active Directory (AD) domain.
As a Systems Administrator, one of first things I wanted to do was share folders on Debian with my Windows to transfer easily files. My Debian is a local Web Server to test my PHP5 applications (yes, I am also PHP5 developer). Why do I want share folders without password? Because it is painful every time I need to login and I am working at home where is no danger around me. No one can crack me at home. At home, it is a great way to share files without login.
- How to install and configure samba
- su -
- insert your root's password
- mkdir /home/yourusername/mysharedfolder
- chown nobody /home/yourusername/mysharedfolder
- apt-get install samba
- nano /etc/samba/smb.conf
- security = share
- guest account = nobody
[mysharedfolder] writable = yes path = /path/to/directory public = yes guest ok = yes guest only = yes guest account = nobody browsable = yes
- Ctrl+X and then y
- service samba restart
Optionally, you can use Samba Web Administration Tool (SWAT) to configure the settings of shared folder.
- How to install SWAT
- apt-get install swat
- Go to your favorite web browser and type the next URL: http://localhost:901
- insert your root login
- watch the next video how to configure samba
Samba is very useful tool for who want share files between Windows and Linux and SWAT is also very useful for who want configure settings of sharing easily.
I have created another article about Samba before but this one requires a login. If you want to do login, please read this article.
Box Model - CSS Tutorial
After I want to get better my skills as Web Designer, I decided to study again all concepts of CSS! And there is one thing I consider very important: Box Model.
But what is Box Model and why is it very important?
The Box Model is a box that wraps around HTML elements. It is very important because it allow the design become more organized and clean.
What consists Box Model?
Box Model consits of four things:
- Margin - Clears an area around the border. The margin does not have a background color, it is completely transparent;
- Border - A border that goes around the padding and content. The border is affected by the background color of the box;
- Padding - Clears an area around the content. The padding is affected by the background color of the box
- Content - The content of the box, where text and images appear

Design Patterns - Facade Pattern
Introduction
A design pattern is a specific way of solving a particular problem. They are not simply about reusing code; they are more abstract and generalized than that. They are about using reusing ideas.
The Facade Pattern
The best way to understand the facade pattern is to look at a component diagram of a system before and after using a facade.
The next figure shows the front end of a Web site communicating with an application on the Web server. In the right side of the diagram, the front end code is accessing various objects in the application. On the left, showing the facade, the front end communicates only with the facade object, which in turn delegates responsibilities to the internal objects.
Monday, April 1, 2013
Design Patterns - Decorator Pattern
Introduction
A design pattern is a specific way of solving a particular problem. They are not simply about reusing code; they are more abstract and generalized than that. They are about using reusing ideas.
The Decorator Pattern
The two concrete widgets created for the observer pattern have a different appearance. If you needed to add a new style of widget, you would subclass Widget and implement the draw() method to write the HTML. Say that needed to add a feature to all existing widgets, such as border. You could go into each draw() method and add some more HTML to each, but then the border would be hard-coded and all widgets would be forced to have a border. You could create a new set of subclasses of existing concrete widgets that implemented the border in the draw() method. If you had only two widgets, as in the Observer example, this might be an option - you would end up with four widgets. However, if you had five widgets to start with, it might not seem so appealing. Suddenly you have a lot of widget classes to worry about.
There is another way to handle situations like this, one that doesn't require you to create a new subclass for every widget you want to add a border to. Using the decorator pattern allows you to add features or functionality to existing objects without using inheritance. Next figure shows the class diagram for the decorator pattern.
The class diagram indicates that Decorators are a type of Widget, too. This is good because we don't want to change the way we access a Widget, whether it's decorated or not.
Thursday, March 21, 2013
Design Patterns - Composite Pattern
Introduction
A design pattern is a specific way of solving a particular problem. They are not simply about reusing code; they are more abstract and generalized than that. They are about using reusing ideas.
Composite Pattern
The next figure shows the general case for the composite:
The composite pattern has two parts: the Component abstract class and the Composite, which is a concrete implementation of the Component class. All Composite objects descend from the abstract Component class. Any Component can contain other Components. A Component with no children can be thought of as an empty Composite.
Moving back from the general case, it will be necessary to make a change in the design and switch the Instrument interface to an abstract class. Interfaces and abstract classes are similar because neither one can be used directly to instantiate an object. The key difference is that an abstract class can have some fully implemented methods, whereas interfaces just have method declarations.
Monday, March 11, 2013
Commands Vi/Vim editor
As system administrator, I have needed to edit configuration files of some services such as DNS (Domain Name System), LDAP (Lightweight Directory Access Protcol) and etc.
The editor I was using frequently was nano and rarely I used pico. All those editors were used on Ubuntu. When I decided to fit in CentOS, I noticed that I had to install package nano. But I did not want to! I wanted to vary and then I searched and found editor Vi (also it is equal to Vim, although Vim has more features than Vi). I confess, at first time, it was very confused. I did not know what commands to edit file and much less how to save the changes and exit. So I googled and found some commands useful to edit files.
Hereafter, you will see a list of commands to Vi/Vim editor:
| Command | Description |
|---|---|
| :wq | Save the file and exit |
| :w | Save the file |
| :q | Quit and Vi/Vim refuses to exit if any changes was made |
| :!q | Quit without changes to save |
| :a | Append after cursor |
| :i | Insert after cursor |
| ESC | Exit insert/overwrite mode and go back to command mode |
Tuesday, February 19, 2013
How to create tabs with JavaScript and HTML
If you want to create tabs on your website, it is good idea and you should do it! But how to create tabs? Good question!
To create tabs you will use HTML elements and some code of JavaScript. Hereafter will show up HTML code.
<!-- tabs --> <ul class="tabs"> <li><a href="#">Tab One</a></li> <li><a href="#">Tab Two</a></li> </ul> <!-- panes --> <div class="panes"> <div>Pane One</div> <div>Pane Two</div> </div>
Next you need JavaScript code to bind tabs to panes and enable the tabbing effect. Here is JavaScript code you need to.
$(function(){
$("ul.tabs").tabs("div.panes > panes ");
});
After HTML code and JavaScript Code, you can use your imagination to coding CSS. I like this snippet because it is minimal, easy and fast to see results.
Tuesday, February 5, 2013
Configuring TCP/IP with CentOS
The configuration of network TCP/IP allows prepare a server Linux to communicate on network IP, trough setting network interfaces, addresses IP and remaining parameters of configuration. On this article, I will analyse how the way can commands to be used on Linux server.
I had a chance to analyse the main files of network configuration used on Linux CentOS and I saw that a lot of those files appears on most Linux distro. Also it is important to have a knowledge of some commands like ifconfig and route. Why is it important? Because those commands will allow you to analyse and solve problems of network configuration in future.
Tuesday, January 22, 2013
What is your favorite mobile operating system? - Results
On December 31st 2012, the poll "What is your favorite mobile operating system?" closed! There was 21 votes to indicate the favorite mobile operating system .
I have to say that I am not surprised for Android's votes but I am very surprised with Windows Phone's votes. Is Windows Phone ahead of Mac iOS? That I was not expected for!!!
Friday, January 4, 2013
How to return a page before current
To create a link "Back" that allow come back to previous page before current, I use a variable called $_SERVER['HTTP_REFERER']. Hereafter, you will see a example:
... <body> ... <a href="<?php echo $_SERVER['HTTP_REFERER']?>">Back</a> ... </body> ...
Be careful when you refresh the page!
Monday, December 31, 2012
Monday, December 24, 2012
Wednesday, November 7, 2012
How to check Ubuntu version using command line
I wanted to see what was my Ubuntu version using command line. After I found this website, I could to see my Ubuntu version.
- Open terminal (CTRL+ALT+T)
- Type lsb_release -a and press Enter
- The Ubuntu version will displayed on the screen
At the time, my Ubuntu version is Ubuntu 11.10 (oneiric).
Monday, November 5, 2012
Sunset Software OS
After of making videos related with Linux, I decided that it is time to create a distro Linux which contains some software used on videos. I found a amazing site that allows to create own distro Linux.
The distro Linux created with help from SUSE Studio calls Sunset Software OS. This OS is destined for developer software, web developer software and systems administator. You can download a image ISO right here! Language and Keyboard Layout will be ask at first boot.
- There is two users:
- root (password: linux)
- user (password: peter)
