Using YUI to Create Nested Tabs

Recently, I was browsing the YUI JavaScript forums and found a post about nesting the tab control. I haven’t done that before personally, but have done things where my tabs had Ajax or DHTML dependencies inside the tabs. I decided I’d take a whack at this one and see what I could come up with.

Continue reading

Posted in Programming, Web | Tagged , , , , | 10 Comments

Using Multiple Python Environments With Gentoo

It’s been some time since Python 2.5 became stable and released. Version 2.5 has plenty of new features that have helped me in deciding that it was time to go ahead and start using it for primary development of all my new projects. One of the reasons I was still using version 2.4 is that Gentoo hadn’t upgraded 2.5 to the stable package system.

I decided to go ahead and unmask version 2.5 anyway. Installing Python 2.5 isn’t very complicated and I’ll leave the details out. I’ll just mention that after unmasking Python with the ~x86 keyword and installing the package, you’ll need to run the python-updater. Python-updater had it’s own problems with not being able to find some packages it thought needed to be re-emerged but I found pretty much all of those were unneeded old dependencies and I simply un-emerged them.

When you update Python, you can still get to your old version of Python by tacking on the version number to the python command, e.g., /usr/bin/python2.4. Since the Python updater uses emerge to install your python dependencies in the site-packages of your Python installation and emerge unmerges the old versions, your old Python probably doesn’t have all the site-packages any longer. This is only an issue if you find you need the old Python.

For me, I have a couple applications that didn’t quite want to work with Python 2.5 for some reason. I decided to use VirtualEnv to work on those applications.

The Steps

  1. To install virtualenv, you need setuptools. That package was one of the packages transfered to the 2.5 site-packages install and was no longer available with python2.4.

    To get around the issue, use ez_setup.py to install a 2.4 version of setuptools instead of using emerge.
    cd <working dir>
    wget http://peak.telecommunity.com/dist/ez_setup.py
    /usr/bin/python2.4 ez_setup.py setuptools

  2. I simply used the virtualenv command that came with python2.5 but changed the interpreter to by python2.4 instead of python.

    cp /usr/bin/virtualenv .
    # edit virtualenv to have the correct interpreter line
    vim < or whatever editor > virtualenv
    ------ snip local virtualenv ------
    +#!/usr/bin/python2.4
    -#!/usr/bin/python
    ------ snip ----------------------
    ./virtualenv --no-site-packages <virtual env install dir>
    cd <virtual env install dir>/bin/
    ln -s python2.4 python
    cd <working dir>

  3. Use the old python in it’s virtual environment:

    source <virtual env install dir>/bin/activate
    python
    Python 2.4.4 (#1, Mar 5 2008, 10:47:15)
    [GCC 4.1.2 (Gentoo 4.1.2)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>>

Anyway, that’s it. You can have a virtual environment that uses any version of Python you like on your system. I imagine this procedure would be somewhat similar on pretty much any Linux Distribution.

Posted in Programming | Tagged , , , , | Comments Off on Using Multiple Python Environments With Gentoo

Using YUI components in a templated environment

If you develop sites anything like I do, you’ll end up setting up a site wide layout and theme before you start coding any individual pages. I like to add YUI components where they are useful, but I’ve come across a couple little quirks that were annoying me. Here are my observations and what I did to get around them.

Templating Quirks with YUI

The root of my annoyance is that I don’t need all the components I want to use on all my pages. I do however need some components on more than one page as well as sometimes needing a few components on one page. Somewhere along the line, I gained a believe that doing things more than once was not good. Copying and pasting header files and setup code between pages is on my list of less desirable behavior. This led me down the path of adding all the YUI header files to my master template for my site.

Advantage: All my pages have the header files already and I don’t need to worry about that on each page I’m working on.
Disadvantage: Pages with no need for a YUI component still use up bandwidth/time downloading the headers.

If you weight the disadvantages of putting the header files on every page higher than the advantages like I did, you might go the opposite route and try adding them only to the pages where you need the components.

Advantage: Only pages with the components are now loading the dependencies.
Disadvantage: You’re back to redoing setup work and/or copying and pasting a lot.

Dynamically Loading YUI Components

Well, I wasn’t entirely happy with either solution so I came up with a hybrid. I’ve watched the YUI-Loader with some interest since it was introduced a couple versions ago. It is now no longer marked as “Beta” and I figured it was worth looking at for my current project. The basics are this:

  1. Include the loader script.
  2. Create a loader with a list of objects you’ll be using.
  3. Use the loader to grab all the required resources.
  4. Use the resources you need.

Sounds like a good idea to me but I didn’t want to copy/paste loader initialization code in my template pages any more than I wanted to copy/paste header files. My solution is to create a generic loader in my master template and then override the required resources at the page level.

Here is part of my master template

<script type="text/javascript" src="http://yui.yahooapis.com/2.5.1/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script src="http://yui.yahooapis.com/2.5.1/build/yuiloader/yuiloader-beta-min.js"></script>
<script type="text/javascript">
var yuiLoaderRequires=[];
var myOnLoad=function() {}
function init() {
var yuiLoader = new YAHOO.util.YUILoader({
require: yuiLoaderRequires,
onSuccess: myOnLoad
});
yuiLoader.insert();
}
</script>
<!-- Using your template language, insert the child template javascript here -->
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(init);
</script>

Then, just override yuiLoaderRequires and myOnLoad in the subpages:


<script type="text/javascript">
yuiLoaderRequires=['treeview','colorpicker'];
myOnLoad=function() { doSomething....; }
</script>

I find that a lot less annoying than looking up requirements for each component on each page. Also, running the loader in the onDOMReady function causes the requirements to be loaded after the HTML has been rendered, this ought to give the appearance of a faster page load for most users. It might not work for every case though, so use with care. Hope you enjoy.

Posted in Programming | Tagged , , , , | 2 Comments

Serving JavaScript Fast

I found this excellent writeup on serving JavaScript files posted on Digg.com. I think I’ll convert some of those ideas to Python but I thought it worth posting here in the mean time with the link to the story.

The next generation of web apps make heavy use of JavaScript and CSS. We’ll show you how to make those apps responsive and quick.

read more | digg story

Posted in Programming | Tagged , , | Comments Off on Serving JavaScript Fast

Using a Makefile to generate Latex documents

So, you’re using Latex to compile a paper, article, or book. If you have any type of table of contents, index, or bibliography, you’ve probably noticed that you have to run latex two (or sometimes 3) times to generate the final document. In addition, you probably have to run a conversion program to get your document into its final format (like pdf).

If you’re like me, I was getting tired of typing those commands every time I wanted to view a final copy of my paper. I decided to combine a couple great tools to “make” the job easier!

Makefiles aren’t just for compiling code. You can use them to generate commands that produce any final document. There really isn’t a limit as to what you can produce other than the commands available on your system.

For my current Latex document, I am creating an index.

\usepackage{makeidx}

I’m not going to go into the details of index creation with Latex here. There are good references all over for that [1]. Basically, you just add \index{Some Entry} at each point in your document that you want an item indexed. Then at the end, you include a “\printindex” command at the point you want your index to be output in your document.

After those commands are in place, your “latex mydocument” command produces a mydocument.idx file. You’ll also see a notice that there is no mydocument.ind file. That is because the final index file that is included is not the idx (which is just all of your entries with their page number), but an ind file which is the idx file’s entries, aggregated according to entry, and then combined with the appropriate style information to be printed correctly.

You have to run the following to create your .ind file:

makeindex mydocument

After you make the index, you can run latex again and your \printindex command has an ind file to include. You’re now set with a dvi file that you can convert into another form for publishing.

Now, lets automate all that. The format for a Makefile rule is:

TARGET : PREREQS
   COMMANDS

All you have to do is add a rule for each output that you created with the process manually.

Here is a simple Makefile that I am using to create my document. The rules work in reverse order from the way I listed them in this post. I’ve added a rule for each step that I listed for creating my document and index. Don’t forget to name it “Makefile”

mybook.pdf : mybook.dvi
   dvipdf mybook
mybook.dvi : mybook.ind
   latex mybook
mybook.ind : mybook.idx
   makeindex mybook
mybook.idx : *.tex
   latex mybook

Once your Makefile is saved, all you have to do is run “make”. Of course, you might have figures or other resources that need to be included in your prerequisites for your sources, but the general idea ought to be the same for most projects. If you have questions or comments, feel free to leave them here.


[1] http://web.image.ufl.edu/help/latex/latex_indexes.shtml

Posted in Software | Tagged , , , | 4 Comments

Gentoo with an Intel DQ35MP Motherboard

I’m slightly sad to see my old radeon 9600 card with Compiz being obsoleted. My motherboard in that machine shorted out somewhere and I was left with a bricked machine. Since the product was essentially about 5 years old, I decided to go ahead and buy new equipment. I’m now the proud owner of an Intel Core 2 Duo E6750 with an Intel DQ35MP Motherboard. I copied my old hard drive data to a new drive and am back up and running without a lot of headaches.

What better opportunity to explain how to get Gentoo working on this hardware. Continue reading

Posted in Hardware | Tagged , , , , , , | Comments Off on Gentoo with an Intel DQ35MP Motherboard