Sunday, September 20, 2015
Top of a page in Mac OSX
Page Top (Home) - Command Up Arrow Key.
I had to google for far too long to discover the key above.
I've been going through a low intensity keyboard-shortcut-learning-spree as of late. I've learned a number of new ones for windows, chrome, eclipse, and a couple for mac. I find this to be highly effective during peer programming.
I'll compile a comprehensive list of the ones I know, sometime soon.
Saturday, June 13, 2015
Rant on the often condescending and patronizing culture on SE and SO
- inspire answers that explain “why” and “how”
- tend to have long, not short, answers
- have a constructive, fair, and impartial tone
- invite sharing experiences over opinions insist that opinion be backed up with facts and references
- are more than just mindless social fun
Wednesday, April 22, 2015
How to move a window back on screen in Windows
With windows 7 and 8, right clicking on the taskbar item no longer displays that menu, nor does the ALT + down always work. So, here's what gets you to that menu for a given hidden taskbar item: ALT + SPACE. Pressing M will select move. Clicking the left or right arrow keys will move the window.
Friday, October 17, 2014
Switching between JDKs and Displaying Hidden Files on OSX 10.9.5
- defaults write com.apple.Finder AppleShowAllFiles YES; killall Finder
- sudo chflags -R nohidden /*
- defaults write com.apple.Finder AppleShowAllFiles -bool YES; killall -HUP Finder
- http://serverfault.com/questions/16355/how-to-set-global-path-on-os-x?newreg=4e5834a8f05247cfa9028f1ee6b4475c
- http://stackoverflow.com/questions/15826202/where-is-java-7-installed-on-mac-os-x
- http://monkehworks.com/set-java-7-as-default-jvm-on-mac-osx-mountain-lion/
- http://stackoverflow.com/questions/17885494/how-can-i-change-mac-oss-default-java-vm-returned-from-usr-libexec-java-home
- http://stackoverflow.com/questions/21964709/how-to-change-default-java-version
- http://stackoverflow.com/questions/11685179/how-i-can-see-hidden-files-on-finder-on-a-mac
- http://www.guigarage.com/2013/02/change-java-version-on-mac-os/
Monday, January 6, 2014
Connecting to MSSQL Server from Java
public class TestDBConnectivity { public static void main(String[] args) { String connectionUrl="jdbc:sqlserver://remoteServer:8081;DatabaseName=master;user=userName;Password=userPassword"; Connection con = null; Statement stmt = null; ResultSet rs = null; try { con = DriverManager.getConnection(connectionUrl); String SQL = "SELECT GETDATE() AS CurrentDateTime"; stmt = con.createStatement(); rs = stmt.executeQuery(SQL); while (rs.next()) { System.out.println("result: " + rs.getString("CurrentDateTime")); } } catch (Exception e) { e.printStackTrace(); } finally { if (rs != null) try { rs.close(); } catch(Exception e) {} if (stmt != null) { try { stmt.close(); } catch(Exception e) {} } if (con != null) { try { con.close(); } catch(Exception e) {} } } } }
Source: Connecting to SQL Server 2008 from Java
Wednesday, August 28, 2013
Monday, July 22, 2013
DB Isolation Levels, Locks, Dirty Reads, Non-Repeatable Reads, and Phantom Reads
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:
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:
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
Project Zip File
Tuesday, July 16, 2013
Friday, April 19, 2013
Bitbucket with Eclipse
Monday, April 15, 2013
Java Software Developer with over 3 years of experience looking for full-time work
Tuesday, March 19, 2013
A Note on String, StringBuffer, StringBuilder
Saturday, March 9, 2013
My OS X Mountain Lion How-Tos, Shortcuts, & Notes
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
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
make
sudo make install
or?
$ mkdir build
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.
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
Thursday, February 21, 2013
Iterative Solution for Tower of Hanoi in Java
"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
Thursday, October 18, 2012
Classic Shell: great replacement for missing windows 8 start menu
Pokki constantly Page Faulting
My mac is overheating, possibly in part due to this (and parallels itself), and I'm not running anything else intensive. I've contacted Pokki help/support, and I'll update with what they say. Edit: They replied saying that this behaviour is normal and should not be a cause for concern. Hm.
Tuesday, October 9, 2012
Demonstrating usage of a Binary Search Tree in Java
What is a Binary Search Tree?
Binary Search Tree (BST) is a tree in which each node has up to two child nodes (subtrees). If pointers are used, then each node contains references to the left, right, and parent nodes. Otherwise, like the implementation I found for Java, each node contains a left and right subtree in the form of a left and right node (each of which have their own two subtrees and so on...) along with the data associated with the node.
A BST is said to have a binary-search-tree property:
Let x be a node in a binary search tree. If y is a node in the left subtree of x, then key[y] <= key[x]. If y is a node in the right subtree of x, then key[x] <= key[y].1
Since Java doesn't have pointers that we can use, we won't keep track of keys. We'll work directly with node data.
Cormen et-all mention that BSTs support the following operations:
Search trees are data structures that support many dynamic-set operations, including
SEARCH, MINIMUM, MAXIMUM, PREDECESSOR, SUCCESSOR, INSERT, and
DELETE. Thus, a search tree can be used both as a dictionary and as a priority
queue.
What are some applications of BST?
This StackOverflow question answers this well:
What are the applications of binary trees?
Apparently, it is also used in the solution to the Traveling Salesman Problem and the related Shortest Path Problem. I'll be checking these out soon.
How do I use a BST in Java?
I found a good Java BST impl here:
BST.java
BSTNode.java
Class BST contains a root BSTNode node and provides most BST operations (as identified by Cormen et-all). The PREDECESSOR and SUCCESSOR operations are not implemented. Search is implemented, though not exposed directly (it's exposed as isInTree(T el)).
I've slapped together an Eclipse project that demonstrates the usage of this BST implementation. I added some code to BST.java (the one in the Eclipse project) borrowed from this Stanford CS Library page on BSTs. I also borrowed some inspiration from this SO page: How to print binary tree diagram. The class BTreePrinter in the project is pretty much directly from this SO page.
It would be worthwhile to study at least the BST.java and BSTNode.java.
>Download BST_Demo (Eclipse Project)
Here is the output:
>String arrays:
|
1 Introduction to Algorithms Second Edition (Cormen, Leiserson, Rivest, Stein), page 254
Thursday, October 4, 2012
Synchronization and Thread Safety in Hashtable, Hashmap, ConcurerntHashMap
Here are three examples of thread unsafe usage, followed by three examples of safe usage:
1. Unsafe
package unsafe.demo;
|
1. Unsafe cont.
package unsafe.threads;
|
2. Unsafe
package unsafe.demo;
|
2. Unsafe cont.
package unsafe.threads;
|
package unsafe.demo; |
package unsafe.threads;
|
Examples of safe usage:
1. Safe
package safe.demo;
|
package safe.threads;
|
2. Safe
package safe.demo;
|
2. Safe cont.
package safe.threads;
|
3. Safe
package safe.demo;
|
package safe.threads; |



