Monday, July 22, 2013

DB Isolation Levels, Locks, Dirty Reads, Non-Repeatable Reads, and Phantom Reads

A good wikipedia article on Isolation (of the I in ACID): https://en.wikipedia.org/wiki/Isolation_(database_systems).  Introduces well the concepts of the various levels of isolation, the required locking for each level, and the observed results per level.

Thursday, July 18, 2013

Maven built GWT Project in Eclipse Running on Standalone Tomcat 7


Vogella has an excellent tutorial on GWT in Eclipse here: GWT Tutorial.  Playing around with the 'userService' in Eclipse (just name changes of some resources), I decided to convert the GWT example to a maven gwt-archetype project.  


What's Needed


- Eclipse with m2e plugin and maven-gwt-plugin
Tomcat 7 installation (OSX: download the tar and untar the dir wherever you want; I put it in /Applications/apache-tomcat-7.0.42)


Installing Plugins and Tomcat

Install the m2e plugin (through the 'Help->Install New Software...' link in Eclipse), as well as the maven-gwt-plugin (through modifying a dummy maven project's POM to include the plugin as a dependency).  I think this step is a bit awkward because you can't install the plugin through a site like you can the m2e plugin, but I am thankful to the developers who have created the plugin.  You can try to install it like how it's shown here, though I wasn't successful with this on two separate machines (gwt archetype wouldn't show in the filter list).  This didn't work either.

Install the Tomcat server by adding it in the Eclipse Preferences -> Server -> Runtime Environment -> Add.  Point it to your installation directory.  You should see it in Server view (Window -> Show View -> Other -> type: server).  Here's my setup: 
Right clicking the instance and going to properties shows the location.  Ensure it is not the workspace location.


Creating the Project


- Create a new 'Maven Project' in Eclipse (File->New->Other... type: 'maven')
- Uncheck 'Create simple project...' and click Next
- Type 'gwt' in the 'Filter' textbox and select 'gwt-maven-plugin'
- type your Group Id, Artifact Id, Package, and give the module the same name as that described in your *.gwt.xml file; ensure you are careful with all of these properties (uniform across other descriptors, property files, and code), and click Finish

Ensure your web.xml references your servlet name, servlet path, and the webapp (the HTML file in this tutorial) correctly!  The web.xml file will highlight a syntax error if the welcome-file-list is present before the servlet-mapping config.  Here is my web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
  
  <!-- Servlets -->
  <servlet>
    <servlet-name>userServlet</servlet-name>
    <servlet-class>test.server.MyUserServiceImpl</servlet-class>
  </servlet>
  
  <servlet-mapping>
    <servlet-name>userServlet</servlet-name>
    <url-pattern>/test/userService</url-pattern>
  </servlet-mapping>

  <!-- Default page to serve -->
  <welcome-file-list>
    <welcome-file>HelloUniverse.html</welcome-file>
  </welcome-file-list>


</web-app>

Ensure that your welcome HTML file correctly references the generated *.nocache.js file and other resources like CSS files:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link type="text/css" rel="stylesheet" href="HelloUniverse.css">
    <title>Web Application Starter Project</title>
    
    <script type="text/javascript" language="javascript" src="hellouniverse/hellouniverse.nocache.js"></script>
  </head>

  <body>
</body>

</html> 

You also need to modify the project's Deployment Assembly property (right click the project -> Properties -> type: deployment, and it should pop up).  Add the /target/<project-name><version>-SNAPSHOT/<modulename> to be deployed on a directory <modulename> (hellounivere in my case):

Building and Running the Project

Now you can build the project by right clicking it-> Run As -> Maven Install.  Then add the project to the server by right clicking the server -> Add and Remove, then move to the right the project you want to deploy.

Go to your URL (localhost:8080/HelloUniverse) and the Click Me button should popup in a second.  If you don't, use the appropriate browser Developer Tools to debug.  A 404 on the *.nocache.js file is likely due to some issues in your web.xml or HTML file.  You should see this upon success:

Project Zip File

You can import my project and server setup from here.

Tuesday, March 19, 2013

A Note on String, StringBuffer, StringBuilder

When String (an immutable [not modifiable] type) construction or modification involving dynamic values (whose values are not known at compile time) is required by a single thread, the mutable StringBuilder will perform faster than StringBuffer.  The reason for the performance hit is likely that StringBuffer is thread-safe through synchronization.  StringBuilder is also mutable but not thread-safe, hence the faster predicted performance.

Saturday, March 9, 2013

My OS X Mountain Lion How-Tos, Shortcuts, & Notes

This collection of apps, how-tos, and notes is for my own record.  Hopefully someone will find them useful too.

Skipping .DS_store files while copying directories between two USB mounted volumes
rsync -rv --exclude=.DS_Store <source> <destination>
Source: Skipping .DS_Store files when copying between two external drives 

Showing and Hiding Hidden Files
defaults write com.apple.finder AppleShowAllFiles -boolean true
killall Finder

The reverse is
defaults delete com.apple.finder AppleShowAllFiles

killall Finder


Open Minimized Windows Using Command Tab
This is rather long.
1. Command + Tab to the window
2. unpress Tab
3. press and hold Option (alt)
4. unpress Command

For windows with multiple items open, play with the arrow keys

(Custom) Maximize Current Window (vertically)
Ctrl + m

Switching Between Multiple Safari Windows
Command + ~ (tilde)

Safari Tabs
Ctrl + Tab

Installing Tar Files (example)
   [frodo:~] testuser% tar xf fink-0.34.5.tar.gz
   [frodo:~] testuser% cd fink-0.34.5
   [frodo:~/fink-0.34.5] testuser% ./bootstrap

Building and Installing a C project?
./configure
make
sudo make install

or?

$ mkdir build
$ cd build
$ cmake ../
$ make
$ make install

Installing a Python project from tar

* Unpack: tar zxvf sslstrip-0.5.tar.gz
* Install twisted:  sudo apt-get install python-twisted-web
* (Optionally) run 'python setup.py install' as root to install,
 or you can just run it out of the directory.

IP Forwarding on OS X Lion+
It is a known fact that IP Forwarding (port forwarding) does not work on OS X Lion by default.
But there is a fix!
Modify your /Library/Preferences/SystemConfiguration/com.apple.Boot.plist file and a <string></string> tag set
with the following:
net.inet.ip.scopedroute=0

PATH in OS X Mountain Lion
/etc/paths
http://architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion
http://superuser.com/questions/28344/path-env-variable-on-mac-os-x-and-or-eclipse

Disable or modify mouse acceleration
SmoothMouse

Snap Windows to Corners
BetterTouchTool

Wednesday, February 27, 2013

Environment Variables in OSX 10.8.2

I'm still fairly new to OSX, and only recently started tinkering with env variables.  After some confusion on this SO thread, I found this pref pane to be very promising: EnvPane.

Thursday, February 21, 2013

Iterative Solution for Tower of Hanoi in Java

Going through some practice problems, and came across the Tower of Hanoi. The implementation of the iterative solution follows the following steps (borrowed from the wiki article):

"Simpler statement of iterative solution
Alternating between the smallest and the next-smallest disks, follow the steps for the appropriate case:
For an even number of disks:
-make the legal move between pegs A and B
-make the legal move between pegs A and C
-make the legal move between pegs B and C
-repeat until complete
For an odd number of disks:
-make the legal move between pegs A and C
-make the legal move between pegs A and B
-make the legal move between pegs C and B
-repeat until complete In each case, a total of 2ⁿ-1 moves are made."

Code: IterativeHanoi.java