SQuirreL SQL
Thursday, March 19, 2009
For a long time I have been looking for an open source database management tool that would be able to access any JDBC compliant database. I've used the great Oracle product, SQLDeveloper, for a long time and found it great for SQL Server management (usually performing quicker than using Microsoft's own Management Studio!). But now I've started using Derby (aka JavaDB aka Cloudscape) and SQLDeveloper is limited to Oracle, SQL Server, and MySQL.
Step in SQuirreL SQL. It has a pretty smooth interface, with great features like SQL syntax highlighting and even code completion. Released under the LGPL license, it is open source and contributions are welcomed, particularly for plugins. The plugins are important as JDBC is obviously a restricted subset of a database's functionality - a number of the existing plugins enable extra features for specific database types (eg. Derby's triggers).
Another very notable plugin is called graph which enables production of simple entity relationship diagrams (ERD) from a database connection. While it doesn't display multiplicity indicators, and some of the image exporting is a bit clunky, it is great to have this functionality in an open source product. (I now use NetBeans' UML Modeling which is great for the common UML diagrams, but lacking ERDs).
secure svn server on osx tiger
Sunday, February 08, 2009
My notes to help remember the processes to get a secure svn server using Apache 2 on OS X Tiger. I know these are documented in lots of places, but it seemed that parts of various HowTos were required in order to do it with current Apache (2.2) and with Tiger. For anyone with Leopard onwards, you can skip the installation of Apache2 as this is now standard from Leopard on (Tiger and earlier used Apache 1.3 and earlier) and here is probably your best bet.
Edit: I drafted this a year ago and never finished (or published) it. Now the server has reverted back to apache1.3 after an update and my ssl cert had expired - time to revive the post! Unfortunately I didn't capture all the steps, especially the setting up of mods-enabled etc, but I'll just use my install as reference. Ask if you need those bits. Meantime, this link may be helpful. Brad.
Edit 2 (16/4/2009): It did it again. If svn access starts to fail, log in to a directory-displaying page or any page that gives the apache http server version - if it says 1.3 then it's reverted back from 2.0 (alternatively, if ls -l /usr/sbin/apachectl shows a single file rather than a symlink to /sw/sbin directory, that also is an indicator it's reverted). Easy fix is (after stopping 'Personal Web Sharing' in System Prefs): sudo ln -sf /sw/sbin/apache2ctl /usr/sbin/apachectl as below. Then start web sharing again; should now be 2.0 running.
Installing Apache httpd 2
1. Apache2 Installation
The bulk of this guide comes from Tim Fanelli's great howto (just the Fink, Apache2, Subversion, and WebDav steps for now). If you don't have XCode Tools installed prior to this, you can get them here (requires free registration). Extra notes to the sections in Tim's guide follow:
- Apache2: At the end of this section you can start up Apache2. Be sure to shut down the 1.3 WebServer first via the Sharing panel of SysPrefs, if it is running. You should then be able to view the Apache2 welcome screen by browsing to http://localhost. You probably won't be able to access this from another machine yet though (even within LAN) as the Mac's firewall won't be allowing it. We'll get to that later.
- Subversion: If you will be carrying this on to use svn, you might as well do this and the WebDAV steps now. You'll need svn-ssl, but may not require svn-client-ssl. I didn't install it.
2. Apache2 Configuration
Next we'll configure Apache2 to be handled by the Sharing panel of SysPrefs, instead of old 1.3.
- cd /usr/sbin
- mv apachectl apachectl1.3 {–> This renames default apache1.3/apachectl command}
- ln -s /sw/sbin/apache2ctl apachectl {–> This creates symlink for Apache2/apachectl command}
Edit /sw/etc/apache2/apache2.conf:
- Change the pidfile location to:/private/var/run/httpd.pid
- In order to easily view logs from Console, and to get free log rotation, change the ErrorLog parameter to:/var/log/httpd/error_log
- And add a new entry:CustomLog /var/log/httpd/access_log common
3. SSL Certificate
Go back to Tim's post and the SSL step. You'll want to follow the link and generate the certificate Important: Ensure you create a CommonName attribute in the certificate. If it is missing then many svn clients will fail to access the site. After doing that though, a couple of the commands given back in the main howto are wrong. Change sudo cp ~/server.key /sw/etc/apache2/ssl.key/ to sudo cp ~/sslcert/server.key /sw/etc/apache2/ssl.key/ and the same for .crt.
Edit (13/5/2009): Looks like Tim's blog is having some technical issues. Here are the ssl certificate creation and installation steps:
- cd /tmp
- openssl genrsa -des3 -out server.key {generates the key}
- openssl req -new -key server.key -out server.csr {generates a certificate-signing request (CSR; holds the information about the certificate) using the created key}
- openssl x509 -req [-days 365] server.csr -signkey server.key -out server.crt {generates the certificate, with information in the CSR, using our key. The bit in the square brackets is optional, and is if you want the certificate to expire.}
- sudo mv server.key /sw/etc/apache2/ssl.key/
- sudo mv server.crt /sw/etc/apache2/ssl.crt/
- sudo chmod 0400 /sw/etc/apache2/ssl.key/ {if server won't start later, try also: sudo chmod u+xw on this path}
- sudo chmod 0400 /sw/etc/apache2/ssl.crt/
For better security, don't do the decryption suggested. However, for
pragmatism and to be able to control the server via the SysPrefs, just
do it :)
mysql quick reference
Sunday, January 25, 2009
Launch mysqld (server) on Linux (if not already running):
sudo /etc/init.d/mysql start
Connect to server [specific database]:
mysql [-h host] -u user -p [dbname to use]
Use the SHOW statement to find out what databases currently exist on the server:
mysql> SHOW DATABASES;
Pick one:
mysql> USE dbname
Create new one:
mysql> CREATE DATABASE dbname;
List tables:
mysql> SHOW TABLES;
Create table:
mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
-> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
List tables columns:
mysql> DESCRIBE tablename;
Generate schema:
mysql> SHOW CREATE TABLE tablename;
use jndi with spring to access external properties file
Tuesday, January 13, 2009
On the surface, external configuration files in a JEE environment provide a simple mechanism to store environment-specific data, but they can be a pain to access. How to access it when file system access isn't allowed? Since it's outside the classpath, where is the file in each environment? If I'm using Spring, how do I access this movable file?
The best solution I've found is to use jndi resources. The following is a solution using Websphere (6) and Spring (2.01).
Step 1: Configure the jndi reference for Websphere
This step was based on information from IBM's page "Using URL resources to manage J2EE property files in IBM WebSphere Application Server V5", steps A and B. Websphere Studio isn't required, however, so briefly:
a) Navigate to Resources > URL > URLs and create a new URL. Make up a JNDI name starting with "url/". In 'specification', enter the path to the properties file as a URI, eg. "file:///E:/project.properties". So now Websphere has a URL Resource pointing to the properties file for this environment.
b) In the code, edit web.xml. Configure a new resource-ref as shown in IBM's figure 6. 'res-ref-name' is the jndi name we set up in a). Then in ibm-web-bnd.xmi, add a new resRefBindings as shown in IBM's figure 7.
That completes the configuration of Websphere and the jndi configuration in the code.
Step 2: Next Spring needs to be able to load the properties file by looking up the jndi location.
c) I'll assume that you want the properties file to be set as a property on a class 'pkg.MyClass'. To do this, we use a PropertyFactoryBean to convert from properties file to Properties class. The PropertyFactoryBean takes a Resource as location property, so we create a UrlResource bean for this, with the java.net.Url as constructor argument. This java.net.Url is the result of using a JndiObjectFactoryBean to look up the jndi name and return the Url object. The following bean config shows these conversions:
<bean class="myclass">
<property name="props">
<!-- Load from the .properties file-->
<bean class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location">
<!-- Generate a UrlResource from the java.net.Url -->
<bean class="org.springframework.core.io.UrlResource">
<constructor-arg>
<!-- use jndi to look up the location of the parameters.properties file -->
<bean class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/url/analysisParametersURL" />
</bean>
</constructor-arg>
</bean>
</property>
</bean>
</property>
</bean>
And that's it. In summary, Spring looks up a jndi URL reference to a properties file, configured in the JEE server. Spring beans are created that convert the URL to a URLResource to a Properties object, available for injection into your custom class.
mobile phone as modem
Sunday, October 26, 2008
There are a number of posts around the place on getting gprs or 3g cellphone connections working on linux. I wasn't interested in bluetooth as I have limited batteries and a usb cable. And you don't always know what your locla settings should be.
Here's all I did on Xubuntu Hardy:
- Plug the phone into the computer using the usb cable.
- In a terminal, type "sudo wvdialconf". (This sets up available baud rates, etc)
- In a terminal, type "sudo vi /etc/wvdial.conf".
- Edit this file with:
- phone = [for my nokia on Vodafone New Zealand, the number is "*99#". I phoned them to find out.]
- name = [the login name, if your mobile company requires it. Vfone NZ doesn't, but wvdial needed something here. I used "name"].
- password = [as with name. I used "password"].
- Save and close the file.
- Connect to the internet via your mobile by typing "wvdial" in a terminal window.
- When done, press ctrl-c in that window.
java modulus for floating point numbers
Thursday, October 09, 2008
The java modulus (or remainder) operator (%) truncates instead of rounds with floating point numbers (ie float, double), so the solution is to use Math.IEEEremainder instead. It's fine to use % for ints.
linux tools
Monday, September 29, 2008
What I use on xubuntu linux for specific tasks:....
| Task | Tool | Date | Ubuntu Package | Comment |
|---|---|---|---|---|
| pdf annotating | flpsed | Sep 2008 | flpsed | Very basic app that enables load/save of ps and pdf. Multi-line text can be added to the docs. No highlighting option or editing of existing content. |
| pdf editing | pdfedit | Sep 2008 | pdfedit | Allows editing of any part of multi-page PDF documents. Can be very slow to use on long documents. New content such as highlighting and single-line text can be added also. |
| vector graphics / single-page pdf annotating | inkscape | Sep 2008 | inkscape | Great tool for vector graphics, quick and easy results. Can import a single page of PDF documents. |
| xml viewing / formatting | XML Copy Editor | Sep 2008 | xmlcopyeditor | Load and view xml. Validate form and against dtd etc, plus nicely format. Quick and easy. |
| diff | meld | Sep 2008 | meld | Excellent visual diff/merge tool. |
| text/source editor | SciTE | Sep 2008 | SciTE | Excellent text editor with awareness of many languages and markups. Tabbed view. |
sql where not with nulls
Wednesday, September 24, 2008
Ah ha! Sound confusing? Why yes it is.
Turns out that SQL (and HQL for that matter) don't allow regular operators to run against a null field. Fair enough, it means:
will evaluate to false if the id is null, so rows with null values won't be returned. Ok.
However, where it gets tricky is in NOT clauses, which also won't return if the value is null. If an operator (other than is null or is not null) is used on a null field, SQL evaluates it to null, which the where clause in turn evaluates to false. So...
will return rows where id is: 1, 2, 3, 4, 5, 7, 8 etc...
but NOT where id is: 6 or null
The way around it? If the field you are 'NOT' selecting on can be null, then you must include a 'is null' OR match:
javascript scripting tricks
Saturday, September 20, 2008
I often write little javascript scripts to get a job done on the web, and usually using greasemonkey. So, to keep track of the little useful tidbits that I tend to forget cos I use them so infrequently, I'll keep this post updated with them as I remember/come across them.
Adding elements to html
Adding a cell to a table row
var row=document.getElementById('myTable').rows[0]; //or however you find the row
var mycell=row.insertCell(2); //0-based index of the insertion position
mycell.innerHTML="NEW CELL"; //raw html content of the cell
Working with greasemonkey
Greasemonkey differs from writing a script that loads with the page, as actions that you define don't implicitly have access to the functions within the greasemonkey script. So setting up things like onclick won't work. My solution to this used to be to add a script element (defining my functions) to the page using addelement. While this worked, it was very messy and hard to maintain. Here's a much better solution, which involves using an event listener rather than just defining onclick (for example).
This is from consuming experience:
In the orignal html page
So our greasemonkey script contains
and then anywhere in the greasemonkey script we can define myFunction
1 million people in a self-sustained bubble
Tuesday, August 26, 2008
Inhabitat has an article about a new concept from a Dubai environmental design firm, touted as a completely green, self-sustained mega-structure that could house a million people. A big leap from what we can comprehend right now, but could this be the way of the future, particularly for the developing world?
Wow