Jun 19, 2013

Write XMLType Column to File using dbms_xslprocessor [Oracle] [Solved]

Posted Jun 19, 2013
Declare your desired directory:

create or replace DIRECTORY XMLDIR AS 'C:\tmp';

Use dbms_xslprocessor to write XMLType column to file:

BEGIN
  for cur in (select XML_COLUMN from YOUR_TABLE) loop
    dbms_xslprocessor.clob2file(cur.XML_COLUMN.getClobVal(), 'XMLDIR', 'NAME.xml');
  end loop;
END;
/

Clear Oracle DB Cache [Solved]

I used these 2 commands to clear cache in between queries in Oracle DB especially when testing for performance:

ALTER SYSTEM FLUSH BUFFER_CACHE;

ALTER SYSTEM FLUSH SHARED_POOL;

Jun 14, 2013

[Solved] NoClassDefFoundError, cannot find VirtualMachine when using HotThread

Posted Jun 14, 2013
I got a NoClassDefFoundError when trying to execute HotThread.jar in Cent OS Linux using java -jar command, seems it cannot find com/sun/tools/attach/VirtualMachine which is part of tools.jar.


[root@ALFSYSTEST4-VM bin]# ./java -jar /home/samba/HotThread.jar 3223
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/attach/VirtualMachine
        at hotthread.Main.main(Main.java:52)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
        ... 1 more


The solution is to just use the java -classpath approach and load the two libraries then execute the HotThread program:

java -classpath "/opt/jdk1.6/lib/tools.jar:/home/samba/HotThread.jar" hotthread.Main 3223



Mar 23, 2013

[Solved] File to import not found or unreadable: compass/css3

Posted Mar 23, 2013
I'm on Windows 8 and I tried installing sass and compass and when I tried "compass watch" on an existing project which has an "@import "compass/css3";, I got an error:  File to import not found or unreadable: compass/css3

The solution is to install rails-compass

gem install compass-rails

After that "compass watch" now worked.

Mar 14, 2013

Convert Twitter's created_at to Javascript Date

Posted Mar 14, 2013
There are several solutions found on the web to parse Twitter's date, but some seems outdated, maybe Twitter changed its date format. But as of March 2013, the code below works:

function parseTwitterDate(aDate)
{   
  return new Date(Date.parse(aDate.replace(/( \+)/, ' UTC$1')));
  //sample: Wed Mar 13 09:06:07 +0000 2013 
}

Source 

Feb 7, 2013

Rounding a number to two decimal places in Javascript / Node JS

Posted Feb 7, 2013
Rounding numbers with decimals in Javascript is not straightforward. Javascript has a utility Math.round but it only rounds to the nearest integers. Some uses toFixed function e.g. (2.55555).toFixed(2) but it doesn't work consistently across all browsers, sometimes it just truncates the value which makes it troublesome for computations.

Creating a simple function for rounding numbers to two decimals in Javascript should be easy:

function roundTo2Decimals(numberToRound) {
  return Math.round(numberToRound * 100) / 100
}

//test
roundTo2Decimals(2.55555555);

If you want to use a library, numeraljs is a good one. It also formats numbers with commas. Very useful.


Feb 1, 2013

How to Get the email address from Twitter Developer API [Rant]

Posted Feb 1, 2013
You can't; sorry to disappoint. As of writing, this is an unresolved issue and many developers are hoping for a positive reply from the Twitter development team: See this discussion and this one for more information. Seems that the Twitter dev team has no plan to support getting the user's email address from Twitter API.


It is unfortunate that this is the case. One big factor of going through the pain of setting up a 3rd party single sign on service is to avoid the process of verifying the user's email address (which takes developer effort). In Twitter's case, you have to do both (set-up authentication AND verify user's email). The same goes for the user who still has to undergo the email verification process. -1 for usability.

I don't know if it's privacy issue that Twitter decided to opt this out, but Facebook and Google, along with other services, are allowing it. Just be transparent and say to the user, this application will know about your email address. What's the big deal, Twitter?