Translate
Friday, July 24, 2015
Tuesday, July 14, 2015
How to find which Linux distribution and version you are using?
To know which Linux distribution and version you have installed on your computer, follow this steps:
1-Open your terminal
2- Type the following command
cat /etc/issue
Output:
Monday, June 29, 2015
How to find a computer serial number from command prompt
Sometimes, you will want to find the computer serial number on your computer to do that in an easy way you can do it typing the following code in your command console.
wmic bios get serialnumber
You will see something like this:Ouput:
Tuesday, June 16, 2015
How To Find Duplicate Records in MYSQL
In this tutorial, I will explain how to find duplicate records in MYSQL.
I think the best way to explain is using an example:
This is our table called actors:
As you can see, we have the name JULIO several times, which is fine because it won't affect anything, but what would happen if someone told you how many JULIO'S we have in our actors tables?
To do that, we need the next SQL statement:
select count(a.first_name)as 'Duplicate Records',
a.actor_id,a. first_name
from actor a
group by a.first_name
HAVING count(a.first_name) > 1
Output:
Basically, we've created an extra column called duplicate Records that will tell us how many time the name of Julio and the others names are repeated.
Friday, June 5, 2015
AngularJs + Symfony2 Dealing with routes
This tutorial intends to explain how to integrate Symfony2 routes and angularJs routes in order to understand how they are going to communicate.
Step1: First of all, we need to install a bundle called FOSJsRoutingBundle that will help us to access to the symfony2 route from javascript.
Actually,it's easy to install this is the GIT repository: FOSJsRoutingBundle
And this is installation Method : How to install FOSJsRoutingBundle
Step2: Configure our symfony2 routes.We need to create our routes to access specific actions or method.
in the file: src/REVC/BlogBundle/Resources/config/routing.yml
rou_dispacher:
path: /dispath/{template}
defaults: { _controller: REVCBlogBundle:Default:dispatch }
options:
expose: true
Because we are using the bundle FOSJsRoutingBundle, we need to expose our route.To avoid creating routes for each action,I've designed this route to receive a parameter which is the template name.
Step3: Create our controller for the route created.
in the file: src/REVC/BlogBundle/controller/ArticleController.php
public function dispatchAction($template)
{
return $this->render('REVCBundle:'.$template);
}
Having that controller, you will be able to access to any template you want.
Of course, don't forget to create yours template in :src/REVC/BlogBundle/Resources/views/Article
Step4: Finally, we need to create our AngularJs route:
I have created my angular files in : src/REVC/BlogBundle/Resources/public/js/app.js
app.config(['$routeProvider',function($routeProvider){
$routeProvider
.when('/home',{
templateUrl: Routing.generate('rou_dispacher',{template:"Article:home.html.twig"})
})
.when('/',{
templateUrl: Routing.generate('rou_dispacher',{template:"Article:home.html.twig"})
})
.when('/edit',{
templateUrl: Routing.generate('rou_dispacher',{template:"Article:edit.html.twig"})
})
.when('/create',{
templateUrl: Routing.generate('rou_dispacher',{template:"Article:create.html.twig"})
});
}]);
As you can see , I have used the functions called Routing.generate that allows us to communicate with the symfony2 route.
Basically, the Routing.generate will accept the following parameters:
Routing.generate('route_name',{variable});
Having that configuration, it will be easy to work with AngularJs and Symfony2.
This is the screen shot about the structure folder of my application.
Sunday, May 31, 2015
Adding HTML tag in Rails link_to
Recently ,I've been working on Ruby on Rails and had to do something like the example shown below, but using the helper link_to:
Example:
<a data-method="delete"rel="nofollow" href='sign_out'>
<i class="fa fa-sign-out fa-fw"</i>Logout
</a>
After researching, I found the answer, you should add your html to the link_to helper as shown below:Wednesday, May 27, 2015
ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint
If you have ever had this error, is because you want to truncate a table that has foreign key in another table. Let me put it this way.
Having this structure, where "articles" can have multiple users , and you want to delete the table users using the function TRUNCATE, Mysql will throw this error: ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint
There is a way to avoid this error, but you have to understand, if you want to delete the users tables and reset the auto increment field , you have to do the same with the articles table.
This is a basic example, but what would happen if you want to clean an entire database and reset the auto increment? That would be very complicated without the following code.
I know this code could be useful for you:
SYNTAX:
SET foreign_key_checks = 0;
TRUNCATE `users`;
TRUNCATE `articles`;
SET foreign_key_checks = 1;
Doing that, you will temporarily disabling referential constraint, and at the end you will enable the referential constraint.
Subscribe to:
Posts (Atom)