I've been working on a few Ajax and DOM scripting projects at work using prototype.js and scriptaculous. Now we're looking at a "Web 2.0" upgrade for some of our sites, so I'm looking at several libraries:
Prototype JavaScript Framework
script.aculo.us
The Dojo Toolkit
Rico
Yahoo! UI Library (YUI)
mootools framework
MochiKit
JQuery
There are many, many more...
OSA Foundation - Survey of Ajax/JavaScript Libraries
Here's an accoridion demo I created with Rico:
My Rico Accordion Demo
Tech Tidbits - Ruby, Ruby On Rails, Merb, .Net, Javascript, jQuery, Ajax, CSS...and other random bits and pieces.
Thursday, June 7, 2007
Monday, June 4, 2007
DocBook
I've been tackling some documentation at work and decided to take a look at docbook.
There are a few good resources to start with:
With DocBook, you can use SGML (Dsssl styesheets) or XML (XSL stylesheets). I've chosen to work with XML. "DocBook XSL" provides the details of all the tools that are needed. At the moment I'm working on a Mac laptop, using the following:
I installed everything in my home directory and worked from there, but LSB proposal is:
Create a DocBook XML file (book.xml, for example)
Procss to generate html:
You can validate XML using xmllint (parser won't necessarily do it).
No output will be seen unless there is an error.
I haven't covered other formats (like converting to pdf using FOP), Java parsers, catalogs, makefiles, and Ant.
Speaking of Ant, here's a resource for DocBook and Ant:
DocBook and Ant.
I've already started looking at using Cocoon with DocBook, but that will be material for another post...
There are a few good resources to start with:
- DocBook.org the home of "DocBook: The Definitive Guide" by Norman Walsh and Leonard Muellner (published by O'Reilly & Associates, Inc.), the official documentation for DocBook.
- "DocBook XSL: The Complete Guide" by Bob Stayton.
- Single-Source Publishing with DocBook XML by Dan York.
With DocBook, you can use SGML (Dsssl styesheets) or XML (XSL stylesheets). I've chosen to work with XML. "DocBook XSL" provides the details of all the tools that are needed. At the moment I'm working on a Mac laptop, using the following:
- DocBook DTD: The DTDs can be found at http://www.oasis-open.org/docbook/xml/. I downloaded
version 4.5 (docbook-xml-4.5.zip). - DocBook XSL Stylesheets: The XSL stylesheets can be downloaded from http://sourceforge.net/project/showfiles.php?group_id=21935. I downloaded docbook-xsl 1.72.0.
- XSL processor: xsltproc (already installed on my system). There are a few others as well (Saxon, Xalan).
I installed everything in my home directory and worked from there, but LSB proposal is:
- DTD: /usr/share/sgml/docbook/xml-dtd-4.5
- XSL: /usr/share/sgml/docbook/docbook-xsl-1.72.0/
Create a DocBook XML file (book.xml, for example)
<?xml version="1.0"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5/EN"
"/path/to/dtd/docbook-xml-4.5/docbookx.dtd">
<book>
<bookinfo>
<title>My Book Title</title>
</bookinfo>
<chapter>
<title>Chapter Name</title>
<para>Some text</para>
</chapter>
</book>
Procss to generate html:
$ xsltproc --output book.html /path/to/docbook-xsl-1.72.0/html/docbook.xsl book.xml
You can validate XML using xmllint (parser won't necessarily do it).
$ xmllint --noout book.xml
No output will be seen unless there is an error.
I haven't covered other formats (like converting to pdf using FOP), Java parsers, catalogs, makefiles, and Ant.
Speaking of Ant, here's a resource for DocBook and Ant:
DocBook and Ant.
I've already started looking at using Cocoon with DocBook, but that will be material for another post...
WebSphere Application Server V6.1 on Linux
I recently downloaded the full-featured trial download of WebSphere Application Server V6.1 to my old Fedora Core 5 laptop.
The installation was amazingly easy...
After starting WebSphere, you can check out the sample application:
The installation was amazingly easy...
$ tar zxvf websphere.tar.gz
$ cd WAS/install
$ java -jar WAS/setup.jar
$ cd /opt/IBM/WebSphere/AppServer/bin
$ ./startServer server1
After starting WebSphere, you can check out the sample application:
http://localhost:9080/WSsamples
Friday, May 25, 2007
Audio file conversion
Here's a collection of small scripts for converting audio file formats using lame, mpg123, and mplayer.
wav2mp3.pl
wav2mp3.sh
mp32wav.sh
wma2mp3.sh
m4a2mp3.sh
wav2mp3.pl
#!/usr/bin/perl
use strict;
use warnings;
my $in = "/home/doug/music/somedir/";
my $out = $in;
opendir DH_IN, $in || die "Can't open $in: $!";
foreach my $name (sort readdir(DH_IN)) {
next unless $name =~ /\.wav$/;
print "NAME: $name\n";
my($base_name) = ($name =~ /^(.*)\.wav$/);
my $in_file = "${in}$base_name.wav";
my $out_file = "${out}$base_name.mp3";
`lame -b 192 $in_file $out_file`;
}
close DH_IN;
wav2mp3.sh
#!/bin/sh
bitrate="192"
for wavfile in *.wav
do
echo "input: $wavfile"
mp3file=`echo $wavfile | sed s/\\.wav/.mp3/`
echo "output: $mp3file"
lame -b $bitrate $wavfile $mp3file
done
mp32wav.sh
#!/bin/sh
for mp3file in *.mp3
do
echo "input: $mp3file"
wavfile=`echo $mp3file | sed s/\\.mp3/.wav/`
echo "output: $wavfile"
mpg123 -w $wavfile $mp3file
done
wma2mp3.sh
#!/bin/sh
if [ -z "$1" ]
then
echo "Usage: wma2mp3"
exit 1
fi
name=`echo $1 | tr ' ' '_' | tr '[A-Z]' '[a-z]'`
name="`basename "$name" .wma`.mp3"
cp "$1" $name
mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader $name && lame -m s -h --vbr-new audiodump.wav -o $name
m4a2mp3.sh
#!/bin/sh
MPLAYER=mplayer
LAME=lame
for m4a in *.m4a
do
mp3=`echo "$m4a" | sed -e 's/m4a$/mp3/'`
wav="$m4a.wav"
if [ ! -e "$mp3" ]; then
[ -e "$wav" ] && rm "$wav"
mkfifo "$wav" || exit 255
mplayer "$m4a" -ao pcm:file="$wav" &>/dev/null &
lame "$wav" "$mp3"
[ -e "$wav" ] && rm "$wav"
fi
done
Finding installed Perl modules
I don't recall where I came across this little script, but it's quite handy for finding installed Perl modules along with their versions.
#!/usr/bin/perl
use strict;
use ExtUtils::Installed;
my $instmod = ExtUtils::Installed->new();
foreach my $module ($instmod->modules()) {
my $version = $instmod->version($module) || "???";
print "$module -- $version\n";
}
Wednesday, May 16, 2007
iBATIS - part 1
Very basic and simple iBATIS tutorial for a simple SELECT:
Download iBATIS from http://ibatis.apache.org/
Unpack the tar ball and install the jar file (it's now a single file - something like ibatis-2.3.0.677.jar) somewhere on your classpath...or if using with Tomcat or another servlet container, add it to "/WEB-INF/lib" in your for the webapp.
Database (MySQL)
SqlMapConfig.xml
BookMap.xml
Book.java
BookTest.java
Download iBATIS from http://ibatis.apache.org/
Unpack the tar ball and install the jar file (it's now a single file - something like ibatis-2.3.0.677.jar) somewhere on your classpath...or if using with Tomcat or another servlet container, add it to "/WEB-INF/lib" in your for the webapp.
Database (MySQL)
mysql> describe book;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| title | varchar(50) | NO | | | |
| authors | varchar(50) | YES | | NULL | |
| editor | varchar(50) | YES | | NULL | |
| chapters | text | YES | | NULL | |
| page_count | int(11) | YES | | NULL | |
| status | char(1) | NO | | P | |
| price | decimal(5,2) | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
mysql> SELECT * FROM book;
+----+----------------------+---------+--------+----------+------------+--------+-------+
| id | title | authors | editor | chapters | page_count | status | price |
+----+----------------------+---------+--------+----------+------------+--------+-------+
| 1 | Learning Perl 3rd Ed | NULL | NULL | NULL | NULL | P | 29.99 |
| 2 | Learning Java 4th Ed | NULL | NULL | NULL | NULL | P | 29.99 |
+----+----------------------+---------+--------+----------+------------+--------+-------+
SqlMapConfig.xml
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<!-- These settings control SqlMap configuration details -->
<settings
useStatementNamespaces="true"
/>
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>
<property name="JDBC.ConnectionURL" value="jdbc:mysql://localhost/bookdb"/>
<property name="JDBC.Username" value="yourusername"/>
<property name="JDBC.Password" value="yourpassword"/>
</dataSource>
</transactionManager>
<!-- Identify all SQL Map XML files to be loaded by this SQL map -->
<sqlMap resource="BookMap.xml" />
</sqlMapConfig>
BookMap.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap namespace="Book">
<resultMap id="get-Result" class="Book">
<result property="id" column="id"/>
<result property="title" column="title"/>
</resultMap>
<select id="getById" parameterClass="string" resultMap="get-Result">
SELECT * FROM book WHERE (id = #value#)
</select>
<select id="getAll" parameterClass="string" resultMap="get-Result">
SELECT * FROM book WHERE (status = 'P') ORDER BY title
</select>
</sqlMap>
Book.java
import com.ibatis.sqlmap.client.SqlMapClient;
import java.sql.Date;
public class Book {
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
public char getStatus()
{
return status;
}
public void setStatus(char status)
{
this.status = status;
}
private Integer id;
private String title;
private char status;
}
BookTest.java
import com.ibatis.sqlmap.client.*;
import com.ibatis.common.resources.Resources;
import java.io.Reader;
import java.util.List;
import java.util.Iterator;
public class BookTest {
public static void main(String arg[]) throws Exception {
String resource = "SqlMapConfig.xml";
Reader reader = Resources.getResourceAsReader(resource);
SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
List bookList = sqlMap.queryForList("Book.getAll",null);
System.out.println("Selected " + bookList.size() + " records.");
if(bookList.size() == 0){
System.out.println("OOOPS - bookList size is 0\n");
}
Iterator books = bookList.iterator();
StringBuffer bookBuffer = new StringBuffer();
while(books.hasNext()){
Book bookX = (Book)books.next();
bookBuffer.append("ID: " + bookX.getId() + " TITLE: " + bookX.getTitle() + "\n");
}
String bookOptions = bookBuffer.toString();
System.out.println(bookOptions);
}
}
$ java BookTest
Selected 2 records.
ID: 2 TITLE: Learning Java 4th Ed
ID: 1 TITLE: Learning Perl 3rd Ed
Sunday, May 13, 2007
Tomcat - How to run stand alone on port 80
With Apache, all ports below 1024 are privileged ports, so normally to run Tomcat as a stand alone server, you'd have to run as root, which is a Very Bad Idea. Using the jsvc interface, it is possible to bind Tomcat to a privileged port, such as port 80.
First, change server.xml to use port 80:
and make this change:
With Tomcat 5 & 6, there will be a
I had to add a few packages on Ubuntu to compile jsvc...
You can start Tomcat as "tomcat" user (use which ever existing non-privileged user you want, or create a new user):
There is a sample starup script in the
Now you can start Tomcat:
More info can be found at Apache Jakarta Project - commons daemon (Java Service)
First, change server.xml to use port 80:
$ cd $CATALINA_HOME/conf
$ sudo vi server.xml
and make this change:
<!--<Connector port="8080" protocol="HTTP/1.1" -->
<Connector port="80" protocol="HTTP/1.1"
With Tomcat 5 & 6, there will be a
jsvc.tar.gz file in the bin directory of your $CATALINA_HOME directory.
$ cd $CATALINA_HOME/bin
$ sudo tar zxvf jsvc.tar.gz
$ cd jsvc-src
$ sudo autoconf
$ sudo ./configure
$ sudo make
$ sudo cp jsvc ..
I had to add a few packages on Ubuntu to compile jsvc...
$ sudo apt-get install libc6-dev g++ gcc
$ sudo apt-get install make
$ sudo apt-get install autoconf
You can start Tomcat as "tomcat" user (use which ever existing non-privileged user you want, or create a new user):
$ cd $CATALINA_HOME
$ sudo ./bin/jsvc -cp ./bin/bootstrap.jar \
-user tomcat \
-outfile ./logs/catalina.out \
-errfile ./logs/catalina.err \
org.apache.catalina.startup.Bootstrap
There is a sample starup script in the
$CATALINA_HOME/bin/jsvc-src/native directory, which can be modified to work on your system:
$ cd /etc/init.d
$ sudo cp tomcat tomcat.bak (if needed, and make sure it will start on the run levels you need for startup on server boot)
$ sudo cp $CATALINA_HOME/bin/jsvc-src/native/Tomcat5.sh ./tomcat
$ sudo vi tomcat (edit for your system)
Now you can start Tomcat:
$ sudo /etc/init.d/tomcat start
More info can be found at Apache Jakarta Project - commons daemon (Java Service)
Subscribe to:
Posts (Atom)
About Me
- Doug Sparling
- Developer (Ruby on Rails, iOS), musician/composer, Buddhist, HSP, Vegan, Aspie.
Labels
- .NET (8)
- accordion (1)
- ActiveRecord (1)
- ajax (2)
- APT (1)
- apt-get (1)
- ASP (1)
- ASP.NET .NET (5)
- Audio (1)
- aws (1)
- Bash (1)
- bdd (1)
- C# (1)
- cache_fu (1)
- caching (1)
- DocBook (1)
- DOM (1)
- Eclipse (1)
- Excel (1)
- Firefox (1)
- gem (5)
- Gems (5)
- git (1)
- GridView (2)
- Hibernate (1)
- iBATIS (1)
- Java (9)
- javascript (9)
- javascript css (1)
- jQuery (4)
- jsspec (1)
- mdb2 (2)
- Merb (2)
- mongrel (2)
- mp3 (2)
- Music (2)
- MySQL (2)
- nginx (1)
- openssl (1)
- osx (3)
- pdocast (1)
- pear (2)
- Perl (7)
- php (5)
- plugin (2)
- podcast (1)
- prototype (1)
- REST (1)
- RMagick MacOSX (1)
- rspec (1)
- ruby (14)
- ruby on rails (21)
- RubyGems Merb (1)
- s3 (1)
- screencasts (1)
- scriptaculous (1)
- scriptrunner ruby rails erlang (1)
- Sortable (1)
- subversion (1)
- testing (1)
- testing erlang tsung (1)
- tomcat (1)
- ubuntu (2)
- WebSphere (1)
- will_paginate (1)