Run php from command line without script file

Do you want to run a quick php script, a line or two, without having file? Thanks for PHP’s cute command line option you can do that.
If you have some file the way to run it, as you know would be

php file.php

But without file if you want to run a simple function like date then use -r option

php -r "echo date();"

would do the trick

Also if you want to get explanation on some built-in function

php --rf strtoupper

would give you an explanation that is something like

Function [  function strtoupper ] {

  - Parameters [1] {
    Parameter #0 [  $str ]
  }
}

For more use php –help!!

python headers are required to build mercurial error while installing

OK, I have been biking mercurial for a while and wanted to upgrade to the latest version
In the process of that, I got the error python headers are required to build mercurial
Here is the fix.
Just add

sudo apt-get install build-essential gcc python-dev

which it was missing.

For re-installation follow the steps listed on https://help.ubuntu.com/community/Mercurial

Using JSF form fields with jQuery – Can’t use jQuery with : (colon) problem

if you have a jsf page of the following

<h:body>
<h:form id="frmRegistration">
<h:panelGrid columns="2" rules="rows">
<h:outputLabel id="lblFirstName" value="First Name"  />
<h:inputText id="txtFirstName" value="#{memberRegisterBean.member.name}" label="First Name" required="true"/>
.
.
.

And say you want assign default value from javascript to the text box you would use:

    $("#frmRegistration:txtFirstName").val("this val");

Since that is how JSF would generate the id of the component
But, you wont see any effect as jQuery don’ like the generated colon (:).
use this instead> ‘escape it’

    $("#frmRegistration\:txtFirstName").val("this val");

Component ID id:compid has already been found in the view JSF error

This error is quite explanatory in JSF.

I got once in a while when I work with dynamic generation of the components.

If you have this, the most common cause of this error would be you are trying to attach the an html component from your bean again.

Especially, if you have session scoped managed bean and you are attaching dynamically elements, may be one of your methods has already attached the component to the view (like the grid you are using for your component) and the other method is trying to attach it again.

If that is the case you might need to check the existence of the component in the grid (or any component you are using) before attaching it.

Also: see how to add session bean to request

Adding Unicode character to mysql from Java-hibernate

How to enable/add unicode character in hibernate with mysql

Unicode is ruling, it would come handy when working with non ASCII characters like when dealing with Chinese or Ethiopian alphabet amharic characters.

With internalization being the main concern in softwares, bit it website or mobile application, there is a chance you will need unicode in your application.

Hibernate is an ORM, object relational mapper, that is being used with Java and .net. It will allow to abstract all the database related stuffs with simple interface. In this unicode hibernate tutorial, I will show how you can insert, select update and delete records with unicode.

Why do I get No provider for Entity manager Error and how should I fix it

I will show the fix from the hibernate side for MySQL. But keep in mind that unicode characters have to be enabled on the database side as well with proper encoding.

See how you can avoid could not open hibernate session error

The solution for having unicode characters to be recognized as they are passing though the hibernate world would be done on the config file.

Enabling unicode character in hibernate

Here are the steps to follow:

1. go to your hibernate.cfg.xml file

2. make your the connection url something like: jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=UTF-8 – make sure the the ampersand is the html-encoded ampersand.

Do you know you can have boilerplate java app with maven?

Find k complementary numbers – algorithm in Java

Eclipse Helios Classpath Error While Working With Maven

I usually work on both terminal and Eclipse for my development.
Like compiling, creating of the war using maven and usage of Tomcat from terminal, and for coding Eclipse.
But, there are times I might need Eclipse like for debugging. And I want to run Tomcat from Eclipse itself.

I was using Helios, the project runs great from terminal. But, when I try it from Eclipse, it is not publishing it b/c it can’t get the jars.
I have updated the maven dependency and everything seems there. Like when I am developing, Eclipse knows about the imported files and I had no problem.

In short, eclipse can’t import the jars from maven or eclipse class path error was there while reading from maven.

Solution to how to import dependencies from maven to eclipse or how to import jars from maven to eclipse

1. Make sure you have the M2E plugin on your eclipse. To check that:
1.a Go to Eclipse–Help–Install new software
1.b On the work with text box insert Sonatype – http://m2eclipse.sonatype.org/sites/m2e and follow the wizard
When you are done restart your eclipse

2. Check if M2_REPO class path variable is there. To check that:
2.a Window–Preferences–Java–Build Path–Classpath Variable in this there should be M2_REPO variable being set. If it is not set, click the New button and add the repository of your maven path there.

3. Go to Window–preference–Maven–User Settings and check if there are not any warnings there. Mostly on User Settings. If there is one, update with the correct one. I am on Ubuntu and mine is on /etc/maven2/settings.xml

Go to your terminal and issue mvn eclipse:eclipse
then, right click on your project–maven and hit update dependencies.
Here is the fun part::
right click on your project, select build path and look at the library tab your dependencies would be listed there with M2_REPO path at the beginning
Then, Click on Deployment Assesment, it is right above Java Build Path, Select Java Build Path Entries
Hit next, select all the listed ones and hit finish

Refresh the project, clear the tomcat and all should be fine.

This should fix your eclipse class not found exception only because it not reading from maven correctly problem

Adding NULL as value to mySql database

Have you wondered how to update/insert NULL as value to the existing row in mysql? Too simple:

UPDATE table_name SET field_name = NULL WHERE some_criteria 

Watch! there is no any quote on the NULL part, if you do so, it would be inserted/updated as string with value “NULL”

Cannot forward after response has been committed JSP Error J2EE

This would happen if you try to forward the request twice.
Say you are forwarding to page result.jsp like this

      		 getServletConfig().getServletContext().getRequestDispatcher(
 	        "/result.jsp").forward(request,response);

if you have the same call down the line, BINGO.. you are forwarding it twice.. Have your variables to be sent multiple times but forward them at once.

Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml maven on war

You might come across this error when building a web application on maven using the command

mvn war:war

This would be caused if maven is not aware of where the web.xml file is located.
If you follow the standard maven directory structure as

src/main/java
src/main/resources
src/main/webapp

You would have to copy the contents of WebContent [WEB-INF AND META-INF] to src/main/webapp folder – there maven would get it as expected.