Posts

Showing posts from 2009

Working With HTML's Underrated UL and LI Tags

Image
I think it is important to note that the HTML tag ul is short for unordered list. Many novice html coders think ul and li (and indeed ol) tags are for bullet points, but the main purpose of these tags is to define lists. A list can run verticaly, or horizontally, and elements can be separated by any manner of means - the default rendering of a list just happens to be that of a series of bullet points.

Tutorials illustrating how to use css to turn a list into a top navigation bar for a website abound on the web, so I'm no need to go there. Instead, I'm going to illustrate how to use the ul and li tags to get a nice bottom navigation, that would typically include a privacy policy, and a copyright declaration.

First lets define the list of elements to go in our bottom navigation in HTML:


© Copyright 2009
EazyBusiness

Company
Support
Privacy Policy
Terms of Service
Affiliates



Now that we have defined the content in a structured way, we have to turn our attentions to the style.


#footer-nav …

Using Groovy Scripting To Remove Unwanted MySQL Databases

Doing some Autumn cleaning on a server, I wanted to delete a lot of redundant mysql databases. There were over 900 databases, of which about 90% could be deleted or archived.

To create a list of databases from a terminal window first create a file show_db.sql
:

echo "show databases" > show_db.sql

Then use this file to generate a text file containing a list of your databases

mysql -p < show_db.sql > dblist.txt

The resulting text file had unwanted characters and spaces. Fortunately file manipulation is easy in groovy.

def file = '/tmp/dblistOriginal.txt'
def targetFile = new File('/tmp/dblistClean.txt')
if (targetFile.exists()) targetFile.write("")
new File(file).text.eachLine { line ->
targetFile.append( line.replace('|', '').trim() )
}

I reasoned it was better to keep the archieve and deletion tasks separate incase something went wrong in the process. So, firstly I created an archieve script to dump all the databases, and tar the…

Overriding Domain Class Getters and Setters in Grails

One might assume that it is possible to override getters and setters in the following manner:


def setName(String name){
//do stuff
}
def getName(){
//do stuff
return name
}


but infact static typing is required

public void setName(String name){
//do stuff
}

public String getName(){
//do stuff
return name
}

My Data Nest Registration Error

mydatanest can't handle us Irish, or at least our names.
This error appeared to me, on my first attempt at registration:

MySQL Error: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near 'Connell',`address`='Dublin',`refferal_id`=NULL,`phone`='',
`max_messages`='20000'' at line 1 on line 244
in /home/datan3st/public_html/account.php

Grails doesn't handle gstrings in controllers

You would expect Groovy gstrings and plain strings to be interchangable in Grails, but today I discovered that it is not so. In a Grails controller calling the redirect operation like this works:

redirect(action:'step1') // redirects to step1

but like this does not, and it redirects to the default index action

redirect(action:"step${getNextStep()}") //redirects to next step if it worked

the temporary solution to achieve dynamic actions is to convert the gstring into a string like so:

redirect(action:"step${getNextStep()}".toString())

Kris Kindle / Secret Santa the Groovy Way

In efforts to explain to folks in the office how secret santa works I directed them to take a look at this secret santa definition or alternatively to examine the following groovy code:


def ezbPeeps = User.findByCompanyName('eazybusiness')
def hatOfNames = ezbPeeps.collect{it.name}
ezbPeeps.each { peep ->

def goodPick = null
while(!goodPick){
def randomInteger = RandomInteger.getGenerate()
assert randomInteger > 0
def index = randomInteger%hatOfNames.size()
switch( hatOfNames[index] ){
case peep.name:
goodPick = false
break
default:
goodPick = true
print "${peep.name} gets ${hatOfNames[index]}"
hatOfNames.remove(index)
break

Ubuntu adds did you mean to command line

Just miss spell a command in the the terminal window to see what I mean.

I mistyped pico as pioc and recieved the following response:


pioc
No command 'pioc' found, did you mean:
Command 'pico' from package 'nano' (main)
Command 'pico' from package 'alpine-pico' (universe)
Command 'pic' from package 'groff-base' (main)
pioc: command not found


This appears to be one of the added benefits of the Karmic release. Pretty cool!

Git Pack Error

I believe this error occurred when a pack operation was interupted during a push operation:


Counting objects: 338, done.
warning: suboptimal pack - out of memory
fatal: Out of memory, malloc failed
error: pack-objects died with strange error
error: failed to push some refs to 'ssh://build@192.168.0.17/~build/dev/git-public/platform/billing/billing'


The solution that worked for me:

git repack -adf --window-memory=100M

Hibernate Exception in Grails when dealing with exceptions

HibernateException: Found shared references to a collection

Like me, you may have have caused this error by having something like the following

sale2.discounts = sale1.discounts
sale2.save()


The solution in my case was to do the following:

sale1.discounts.each { d->
sale2.discounts << d
}

Quick Solution to Godaddy Certs not working in Java

If your experiencing problems with godaddy certs (generally an SSLHandshakes error) when using Java (perhaps with HttpClient), the following may solve your problem quickly.

Note: this was done on Ubuntu, so you may need to adjust it to your OS.

wget 'http://blogs.sun.com/andreas/resource/InstallCert.java'

javac InstallCert.java

java InstallCert $mydomainname
#respond to prompt with return

sudo cp jssecacerts $JAVA_HOME/jre/lib/security

grails remotefunction limitation

I stumbled apon a limitation of the grails remote function today. I have two drop down lists Products and Prices, with the Prices dependent on the particular Product selected, and also the customer in question. In order to achieve this, I needed to pass two params to the remote method.

There are two ways of using the params attribute of the remotefunction.

Option 1:

You can pass a string


<select onchange="${remoteFunction(action:'getRightPriceForProduct',update:'price', params:'\'productId=\' + this.value\'' )}">
product1
product2
</select>


Option 2:

you can pass a map


<select onchange="${remoteFunction(action:'getRightPriceForProduct',update:'price', params:[customerId:customer.id])}">
product1
product2
</select>


Option 1 allows me to use 'this' in javascript to send the product selected, and option 2 allows me to pass the customer's id at the page rendering time, but neither option allow…