Friday, June 10, 2011

Restarting Tomcat6 Service

When you are using Tomcat 6 as the web service then restarting it is as follows:

sudo service tomcat6 restart

Simple eh?

Monday, May 16, 2011

Rounding Off to the “Nearest Five”

Problem:

Given a real number, write a JavaScript code to round it off to the “nearest five”. Examples:

  • 12.4 ==> 10
  • 12.6 ==> 15

Analysis:

The result would be an integer which is a multiple of 5.

Solution:

We will write the JavaScript code as part of an HTML file:

<html>

<head>

<script type=”text/javascript”>

// PART 2: the rounding off javascript code will be here

</script>

</head>

<body>

</body>

<!-- PART 1: this section will contain the HTML elements to visually display to user the transformation -->

</html>

Part 1:

We need three elements: a text box for the inputting of the number, a button to trigger the rounding off javascript code, and another text box to display the rounded off.

<input type="text" id="txtInput">

<input type="button" onClick="doRoundItOff();" value="Round It!">

<input type="text" id="txtOutput" >

Here the trigger is on the onClick event of the button which calls the doRoundItOff JavaScript function.

Part 2:

Here is the JavaScript code:

function doRoundItOff() {

var txtInput = document.getElementById("txtInput");

var txtInputValue = parseInt(txtInput.value,10);

var remainder = txtInputValue % 5;

var roundedValue = 0;

if (remainder == 2 ) {

var offsetDecimal = parseInt(txtInput.value*10,10) % 10;

if (offsetDecimal < 5)

{

roundedValue = txtInputValue - remainder;

}

else

{

roundedValue = txtInputValue - remainder + 5;

}

}

else if (remainder > 2)

{

roundedValue = txtInputValue - remainder + 5;

}

else

{

roundedValue = txtInputValue - remainder;

}

var txtOutput = document.getElementById("txtOutput");

txtOutput.value = roundedValue;

}

Explain! Explain! Explain!

We started the doRoundItOff function with identifying the txtInput HTML element. It is noteworthy to say that I usually make use as var in the JavaScript the id in the HTML element.

Next we take into account the remainder when the integer part of the input is divided by five. This remainder will determine which multiple of five we have to choose.

If the remainder is two then we take into consideration the decimal value of the input. If it is less than five then the input is closer to the largest multiple of five less than the input. Hence, we round down. Otherwise the input would be closer to the smallest multiple of five greater than the input and we round up.

If remainder is greater than two, the input is closer to the smallest multiple of five that is greater than the input. Thus, we round up. Otherwise, the input is closer to the largest multiple of five less than the input and we round down.

Tuesday, May 10, 2011

Any fix to SQL Server Management Studio timing out when Adding a New Column to a Table

A while back I posted the inquiry http://nullpointer.ph/questions/3204/any-fix-to-sql-server-management-studio-timing-out-when-adding-a-new-column-to-a-table

Thanks to Alistair sharing his knowledge. After some research got the following fix

tools-options-designers-tables-and-database-designers

that is, navigating Tools > Options then looking at Designers > Table and Database Designers node you will have Table Options. Override the default value of Transaction time-out after: [____] seconds with your desired length of time.

Saturday, May 7, 2011

Extracting Data from an XML file in MS SQL Server

 

Assuming you have an XML file structured as follows

<questionnaire>

<question>

<id>1</id>

<text>Which of the following is TRUE?</text>

<option1>6 is a perfect number.</option1>

<option2>All prime numbers are odd.</option2>

<option3>None of the Above</option3>

<answer>B</answer>

<explanation>B is FALSE because 2 is prime and even.

Perfect Numbers are such that the sum of their prime factors and 1 equals the number. Since the prime factors of 6 are 2 and 3 and 2+3+1 = 6, then 6 must be perfect.</explanation>

</question>

</questionnaire>

 

and there are a thousand more <question> … </question> set in it but you are interested only in retrieving the id and answer. Using SQL Server 2008, what SQL statements should you use?

Here it is:

-------------------------------------------------

DECLARE @FilePath AS VARCHAR(50)
DECLARE @Query AS NVARCHAR(MAX)
DECLARE @QuestionData XML

-- set the path to xml file

SET @FilePath = 'C:\Users\test\questions.xml'

SET @Query = N'SELECT @data = CAST(BulkColumn AS XML) FROM OPENROWSET(BULK N''' + @FilePath + ''', SINGLE_BLOB) AS XmlData'

EXEC sp_executesql @Query, N'@data AS XML OUTPUT', @QuestionData OUTPUT

DECLARE @hdoc int

EXEC sp_xml_preparedocument @hdoc OUTPUT, @QuestionData

SELECT
    *
FROM
    OPENXML (@hdoc, '/questionnaire/question', 10)
    WITH (
        id INT,
        answer CHAR(1)
    )

EXEC sp_xml_removedocument @hdoc

-------------------------------------------------

Simple eh?

Friday, April 22, 2011

Using a Different mahout Algorithm from the taste-getting-started Example

We were successful in running the taste-getting-started example as seen here: http://teachitshem.blogspot.com/2011/04/simple-java-wicket-using-mahout.html. However, mahout offers other recommendation algorithms which are so interesting to study. For instance, the PearsonCorrelationSimilarity whose parameters are similar to that EuclideanDistanceSimilarity used in the original taste-getting-started example.

How then can do this?

First, we duplicate the taste-getting-started folder say to tgs and we achieve this by issuing cp taste-getting-started tgs –R in the command line.

Second, we change the node <artifactId>taste-getting-started</artifactId> to <artifactId>tgs</artifactId> from the pom.xml file.

Third, open the recommeder-context.xml file at src/main/webapp/WEB-INF folder and replace euclideanDistanceRecommeder with pearsonCorrelationSimilarityRecommender, euclideanDistanceSimilarity with pearsonDistanceSimilarity, and similarity.EuclideanDistanceSimilarity with similarity.PearsonCorrelationSimilarity.

Fourth, run mvn package against tgs.

Fifth, in order to compare results with the original taste-getting-started we have run both the original taste-getting-started and the new tgs web applications using different ports. Thus for taste-getting-started we can use the usual mvn jetty:run-war that uses port 8080 but for tgs we must use something like mvn –Djetty.port=9090 jetty:run-war which uses the URL http://localhost:9090/tgs/movies.

Simple eh?

Monday, April 18, 2011

Simple Java Wicket using Mahout

While continuing the study of mahout, it is inevitable to write code that uses the various algorithms stored with it. So I asked a colleague to help out and one option was to start with a java wicket found here: http://blog.jteam.nl/wp-content/uploads/2010/04/taste-getting-started.zip

Using it is quite straightforward. Download the zip file. Unzip it to some folder (say taste-getting-started in the mahout machine). Using Ubuntu’s Terminal application, go to that folder and run mvn package. After packaging is complete, run mvn jetty:run-war. Once the jetty server is up, you can make use of the wicket by browsing http://localhost:8080/taste-getting-started/movies.

Although the above is the straightforward usage of the said wicket, setting it up requires some effort such as

  • downloading the MovieLens’ 100K Ratings Data Set: http://grouplens.org/system/files/ml-data_0.zip
  • Unzipping it to some other folder.
  • Copying u.data to taste-getting-started/src/main/resources/grouplens/100K/ratings
  • Copying u.item to taste-getting-started/src/main/resources/grouplens/100K/data
  • Executing the initialize_movielens_db.sql using the following command mysql --user=mysqluser --password=mysqlpassword < initialize_movielens_db.sql while at the taste-getting-started/src/main/resources/sql folder.

Oh and if you do not have MySQL yet, install it by issuing the following command sudo apt-get install mysql-server mysql-client.

Thursday, March 31, 2011

Journey to Mahout Land

 

Problem: Research about mahout.

Solution: Obtain a running mahout code but this would require an VirtualBox with Ubuntu instance on my Windows machine.

Here are the steps I underwent:

  1. Download Oracle VM VirtualBox for Windows host.
  2. Install VirtualBox to your Windows machine.
  3. Download ISO of Ubuntu.
  4. Burn ISO to CD/DVD.
  5. Before “Starting” the VirtualBox instance, click on Settings and choose the boot device to CD/DVD. Click OK to save the settings.
  6. Click the Devices menu, select the CD/DVD Devices of the Host.
  7. Click Start to turn on the VirtualBox instance and initiate Ubuntu installation.

 

After Ubuntu has been installed, run the Applications > Accessories >Terminal

  • type java and see the suggested <java-package>
  • type sudo apt-get install <java-package>
  • type javac and see the suggested <javac-package>
  • type sudo apt-get insatll <javac-package>
  • type mvn and see the suggested <maven-package>
  • type sudo apt-get install <maven-package>
  • type svn and see the suggested <subversion-package>
  • type sudo apt-get install <subversion-package>
  • type cd /etc
  • type sudo chmod 777 bash.bashrc
  • type vi bash.bashrc
  • at the end of the file append the path to your java installation

JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export $PATH

  • reboot the VirtualBox instance
  • type cd ~/Documents
  • type mkdir mahoutcode
  • type cd mahoutcode
  • type svn co http://svn.apache.org/repos/asf/mahout/trunk
  • type cd trunk
  • type mvn install
  • type cd core
  • type mvn compile (or mvn install)

 

Whew! I am just barely starting the journey… more to follow!

sudo apt-get install made my day

 

I just have installed Ubuntu 10.10 on an instance of an Oracle VM VirtualBox on my Windows 7 machine when I tried to install the prerequisites of mahout (http://mahout.apache.org/). So I opened the Terminal app, keyed in java and it suggests that I should use sudo apt-get install <package> to initiate the installation which I did.

Now in the next steps of mahout install procedure I saw the need for subversion. So I tried keying in svn and again Ubuntu suggests the use of sudo apt-get install <package>.

Very well indeed, this suggestion saved me time where to find the correct installers, time to download them, and fire up the installation.

Wednesday, February 16, 2011

iPhone Application Development 20110216

I’ve been reading http://www.amazon.com/Teach-Yourself-iPhone-Application-Development/dp/0672330849 and here’s what I’ve learned today

Xcode

  • Launching Xcode.
  • Choosing a Project Type
  • Adding Resources to a Project
  • Editing and Navigating Code
  • Jumping to Methods with the Symbol Menu
  • Code Completion
  • Configuring the Build Output
  • Building and Executing the Application
  • Correcting Errors and Warnings
  • Setting an Application Icon
  • Setting a Launch Image
  • Setting the Status Bar Display

iPhone Simulator

  • Generating Multitouch Events
  • Rotating the Simulated iPhone

My Gears

Tuesday, February 15, 2011

Cost of Becoming an iOS Developer

 

So you want to know the upfront cost of programming apps for Apple’s iOS?

That’s all you need: no more than Php 60K.

Wednesday, February 9, 2011

BPI Branch Locator

Sometimes you want to find the BPI Bank closest to your area and here’s a self-service URL:

http://info.bpiexpressonline.com/bpiprod/prodserv.nsf/Pop-Ups/BranchesSearch

 

Wednesday, February 2, 2011

Displaying Custom Error Messages / Enabling Detailed Errors on IIS 7

 

I was deploying an ASP.NET MVC 2 default application to one of my GoDaddy hosted sites when I encountered the below screen:

20110203-1524-Runtime Error

How can I know the underlying problem?

Simply edit the web.config file.

(1) Inside <system.webServer> node add

<httpErrors errorMode=”Detailed” />

<asp scriptErrorSentToBrowser=”true” />

(2) Inside <system.web> node add

<customErrors mode=”Off” />

<compilation debug=”true” />

 

Wasn’t that so easy?!

 

NOTE: Remove the said lines after you have found and applied the fix to your problem. You don’t want your regular website visitor know the internals of your application, right? Smile

Monday, January 31, 2011

ASP.NET MVC 3.0

 

Time flew so quick and I guess I was left out in the know. So to catch up I’ll get to review http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part1-cs and download the installer here: http://go.microsoft.com/fwlink/?LinkID=208140

Monday, January 24, 2011

Firing Up CodeIgniter over XAMPP

 

So you want to develop web sites/applications using CodeIgniter framework on XAMPP? Here are the initial steps to make your first page work:

We will assume (1) you have successfully installed XAMPP at C:\XAMPP\ folder on your Windows machine. Otherwise, you have to read about it. (2) you have downloaded (and extracted)CodeIgniter.

STEP 1: Copy the extracted CodeIgniter files to at C:\XAMPP\htdocs\somewebfolder\

image

At this point you can open your favorite browser and navigate http://localhost/somewebfolder/ and you’ll see something like the below:

image

I know you want to see your own work! Let’s move to the next step.

STEP 2: Open \somewebfolder\system\application\config\config.php and change as follows:

FROM:

   $config['base_url'] = http://example.com/;

TO:

   $config['base_url'] = http://localhost/somewebfolder/;

STEP 3: Open \somewebfolder\system\application\config\routes.php and do the following change:

FROM:

   $route['default_controller'] = "welcome";

TO:

   $route['default_controller'] = "home";

Now, if you try to navigate http://localhost/somewebfolder/ you’ll be seing a 404 Page Not Found message. That’s fine! We just need to add home.php at the controllers folder and add another home_view.php file at the views folder.

Initial content of home.php can be

<?php

class Home extends Controller {

    function Home()
    {
        parent::Controller();   
    }
   
    function index()
    {
        $this->load->view('home_view');
    }
}

/* End of file home.php */
/* Location: ./system/application/controllers/home.php */

 

While home_view.php can have as follows

<html>
<head>
    <title>Home Page</title>
</head>
<body>
<h1>This is the home page!</h1>
</body>
</html>

There you have it! You have successfully created a home page in CodeIgniter over XAMPP.

Tuesday, January 11, 2011

Enabling Remote Desktop on Windows 7

 

Have you ever wanted to use another computer running Windows 7 within your local area network but does not want to physically move to the said machine? Here’s what you can do:

Configure the other computer to allow remote desktop connections!

STEP 1: Navigate Start Menu > Computer > Properties

1-computer-properties

STEP 2: Click the Remote Settings link.

2-remote-settings

STEP 3: Select “Allow connections from computers running any version of Remote Desktop” option. Hit the OK button.

3-system-properties-remote-tab

And there you have it. The other computer can now be remotely accessed from your machine.