Thursday, March 18, 2010

mod_wsgi + apache

mod_wsgi

sudo vim /etc/sysconfig/apache2
sudo /usr/sbin/rcapache2 restart

Monday, March 15, 2010

Netstat + find process Id

Many a times you would get a "Bind Exception", "Address already in use" kind of errors and need to find the process that's using the port. For example say the port is 8080. The following command will get you the pid and program name as well.

netstat -nlept | grep "8080"

The result might look something like this...

Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp6 0 0 :::8080 :::* LISTEN 1000 994652 4024/java
Where 4024 is the pid and it's a java app.

Friday, March 12, 2010

IBM Cloud

It looks like arbitraty ports are firewalled by IBM (other than port 80 and 22 and maybe some others), so when I wanted to connect to one of my machine in the IBM Cloud on port 18080 http for example, I have to setup a reverse proxy for it.

<Proxy http://mywebsite:18080 >
Order deny,allow
Deny from all
Allow from 123.123.123.123
</Proxy>

ProxyRequests Off
ProxyPass / http://localhost:18080/
ProxyPassReverse / http://localhost:18080/

Sunday, March 7, 2010

Javascript stop event bubbling and stop browser default action

// stop event bubbling
function stopBubble(e) {
if( e && e.stopPropagation ) {
e.stopPropagation();
} else {
//IE
window.event.cancleBubble = true;
}
}

// stop browser default action, i.e, clicking an html link will open up that link.
function stopDefault(e) {
if( e && e.preventDefault )
//Other than IE
e.preventDefault();
else
//IE
window.event.returnValue = false;
}

function loadLi() {
var li = document.getElementsByTagName("li");
//alert(li.length);
for ( var i = 0; i < li.length; i++ ) {
li[i].onmouseover = function() {
this.style.backgroundColor = 'blue';
};

li[i].onmouseout = function() {
this.style.backgroundColor = 'white';
};
}
}

function loadAnchor() {
var anchor = document.getElementsByTagName("a");
for ( var i = 0; i < anchor.length; i++ ) {

anchor[i].onmouseover = function(e) {
this.style.backgroundColor = 'red';
stopBubble(e);
};

anchor[i].onmouseout = function(e) {
this.style.backgroundColor = 'white';
stopBubble(e);
};

anchor[i].onclick = function(e) {
iframe.src = this.href;
return stopDefault(e);
}
}
}

Spring Framework + RMI + JBoss

Use RMI port 1199 (other than the default port 1099, JBoss RMI) with org.springframework.remoting.rmi.RmiServiceExporter.

<bean id="escortLocationService" class="com.don.remoting.EscortLocationServiceImpl" >
</bean>

<bean id="rmi" class="org.springframework.remoting.rmi.RmiServiceExporter" >
<property name="service" ref="escortLocationService" />
<property name="serviceName" value="EscortLocationService" />
<property name="serviceInterface" value="com.don.remoting.EscortLocationService" />
<property name="registryPort" value="1199"/>
</bean>

<bean id="escortLocationServiceClient" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value="rmi://127.0.0.1:1199/EscortLocationService" />
<property name="serviceInterface" value="com.don.remoting.EscortLocationService" />
</bean>

<bean id="escortLocationClient" class="com.don.remoting.EscortLocationClient" >
<property name="escortLocationService" ref="escortLocationServiceClient" />
</bean>

Friday, March 5, 2010

Oracle multiple case select statement

In a table, I have 3 columns (checkbox1, checkbox2, checkbox3) representing values about "Where does the knowledge come from?".
if checkbox1 == 1, that means the knowledge comes from "My_Course",
checkbox2 -> Internet,
checkbox3 -> Staff.

if the checkbox1,2,3 == 0, then it's empty string.

Basically I want to concatenate values from multiple columns into one value "Know_from_where":

select student_type,
(case checkbox1
when 1 then 'My_Course, '
when 0 then '' end ) ||
(case checkbox2
when 1 then 'Internet, '
when 0 then ''
end ) ||
(case checkbox3
when 1 then 'Staff, '
when 0 then '' end ) Know_From_Where
from infolit

Wednesday, March 3, 2010

springsource tool suite oracle jdbc driver + maven2 depend


<repository>

<id>repo1 maven org</id>

<name>repo1 maven org</name>

<url>http://repo1.maven.org/maven2</url>

</repository>



<dependency>

<groupid>ojdbc</groupid>

<artifactid>ojdbc</artifactid>

<version>14</version>

</dependency>




Then you have to download ojdbc14.jar from oracle website (or wherever) and do:
mvn install:install-file -DgroupId=ojdbc -DartifactId=ojdbc -Dversion=14 -Dpackaging=jar -Dfile=/path/to/ojdbc14.jar

Xml re-generated using http://www.simplebits.com/cgi-bin/simplecode.pl?mode=process