Friday, July 18, 2014

javascript object hashmap associative array

i use javascript quite a bit and i program for work in Java, so I wanted to mash them both together and as a result was reading about Rhino, which allows javascript to call Java classes and methods. And I was looking through some sample code and the following blew my mind:
var f = new File(arguments[0]);
var o = {}
var line;
while ((line = f.readLine()) != null) {
 // Use JavaScript objects' inherent nature as an associative array to provide uniqueness
 o[line] = true;
}
for (i in o) {
 print(i);
}
i didn't understand the code!  after some investigation, i found that the base javascript object acts like a HashMap, a TreeSet and an associative array. check out the code below:
<script>
 var tt = {hair:"black,cat,dog",eyes:"brown"};
 console.log(tt);
 tt["eyes"] = true;
 tt[""] = true;
 tt[null] = true;
 console.log(tt);
 console.log(tt[0]);  // should print hair
 console.log(tt[0][1]);  // should print cat
</script>
it's output is:
Object { hair="black,cat,dog", eyes="brown"}
Object { hair="black,cat,dog", eyes=true, =true, null=true}
undefined
TypeError: tt[0] is undefined
the only drawback is that the last two don't work, you can't access it like an array, even though internally it's an array of arrays. anyways that explains how they were able to get unique lines, they were checking the values against the javascript objects keys (which have to be unique).

tomcat oracle spring BLOB OracleLobCreator exception error

I recently switched from an older version of Tomcat 5.5 to 7.0. This created an error because the newer version of tomcat creates database connection pools differently. The error pops up in my application when I try to upload a file, because it creates a BLOB type, which this new pool object doesn't support.

ERROR message: document update Blob error exception:org.springframework.dao.InvalidDataAccessApiUsageException: OracleLobCreator needs to work on [oracle.jdbc.OracleConnection], not on [org.apache.tomcat.dbcp.dbcp.PoolableConnection]: specify a corresponding NativeJdbcExtractor; nested exception is java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.PoolableConnection cannot be cast to oracle.jdbc.OracleConnection

my original Spring beans XML file:
<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor" lazy-init="true"/>
<bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler">
 <property name="nativeJdbcExtractor" ref="nativeJdbcExtractor"/>
</bean>
As you can see, I was using WebSphereNativeJdbcExtractor as the LOB handler, but tomcat passes it's own implementation of the Oracle database connection to the Spring class. I changed it to:
<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor" lazy-init="true"/>
<bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler">
 <property name="nativeJdbcExtractor" ref="commonsDbcpNativeJdbcExtractor"/>
</bean>
<bean id="commonsDbcpNativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"/></b>
This works!

Monday, July 14, 2014

sqlplus connect to database without using the SID

sqlplus connect to database without using the SID
sqlplus connect to database using description string
sqlplus change expired password

here's the command:
sqlplus user_name/password@"description_string"

Example description string (keep all brackets): (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=name_or_IP)(PORT=1521))(CONNECT_DATA=(SID=sid_name)))

In the case of expired password, it will prompt you to enter a new password.

Thursday, July 3, 2014

ship slams into italian port of genoa killing seven

The bridge of the ship that crashed into Genoa harbour, the 'Jolly Nero', is clearly seen behind the wreckage of the control tower in this picture taken shortly after the collision, late on Tuesday, May 7, 2013.
The ship that crashed was the Jolly Nero. It was manoeuvring out of the port at around 23:00 local time with the help of tugboats in calm weather.

Rescuers stand on the rubble of a former harbour control tower, all that remains standing of which is a tilted metal staircase.
The control tower in the Italian port of Genoa was reduced to rubble and a single, leaning staircase after a cargo ship slammed into it late on Tuesday night, killing at least seven people.

The damaged stern of container ship Jolly Nero in the port of Genoa on May 8, 2013, the morning after the crash.
Some damage is visible on the stern of the container ship. The ship's owner, who arrived at the port soon after the incident, told journalists he was "utterly shocked".

The container ship Jolly Nero after the fatal crash. The vessel is almost 240 metres long, painted red, with a gross tonnage of nearly 40.600.
The Jolly Nero is almost 240 metres (787 ft) long. Its captain is being investigated by prosecutors with a view to possible manslaughter charges.

The control tower, looking like one at an airport, pictured in 2011, intact.
The control tower was was more than 50m (164ft) tall. About 13 people were inside at the time of the crash, which happened during a shift change.

Collapsed control tower of Genoa's port (8 May 2013)
The tower crashed backwards into the water, pulling down buildings around it.

Rescue workers in the rubble of the collapsed control tower in the port of Genoa (8 May 2013)
Rescue workers have been sifting through rubble on the dock and in the water. At least two people are still missing and four others were injured, two of them critically.

An operation takes place to remove the wreckage of the control tower from the dock at Genoa's port (8 May 2013)
The BBC's Alan Johnston in Rome says the crash has revived memories of the accident involving the Costa Concordia cruise ship off the Italian island of Giglio in January 2012, which left 32 people dead.

cygwin wget setup proxy authentication

I am behind a corporate proxy server and needed to use wget to get some pages. This is from within cygwin. You can use command line options for wget to set the server and username/password. Or, you can set it up in the wgetrc configuration file. This file is located in the cygwin_install_dir/etc directory. I tried modifying the wgetrc under etc/defaults/etc but that did not work. These are the entries you need:

use_proxy = on
http_proxy=http://blah.company.com:80/
proxy_user=username
proxy_password=password