Feeds:
Posts
Comments

When you do rake rails:freeze:gems it will copy the most recent version of rails to your project’s vendor/rails directory. But what if you’re developing with an older version of rails?

rake VERSION=2.2.2 rails:freeze:gems

Drawing a square in Java

O’Reilly’s Head First Java is a good book, but it doesn’t do enough hand holding for my tastes. I need more repetition before something sinks in. For example, on page 364, basically¬† it says, “It’s easy to add a square to a screen, just make your own widget!” Then it shows you how to make a widget:

import java.awt.*;
import javax.swing.*;

//OK, that part I understand.

class MyDrawPanel extends JPanel {

//JPanel is a widget that can be added to a frame just like the button in a previous example in the book.

public void paintComponent(Graphics g) {

//Here’s what I’m guessing this means. We’re overriding the paintComponent method in JPanel, and we’re passing it a Graphics method as an argument. Where this comes from, I don’t know, somewhere in java.awt.* or javax.swing.*

g.setColor(Color.orange);
g.fillRect(20,50,100,100);

}

}

So that will compile as javac MyDrawPanel.java.

But, what the book doesn’t explain in big red crayon so an idiot like me can understand is that you have to create another class to make the window that contains the frame that you’ll stick this widget into. The authors assume that if they explain something once, hell, you ought to be able to figure it all out by now, and the lack of explanation in cases like this makes me wish I could take a course in Java in a real school where I could ask my stupid questions to a real live brainy (but patient) person and get answers.

To get the above code to do anything useful, you have to create this other class too, as a separate file:

import javax.swing.*;
import java.awt.*;

public class SimpleGuiRectangle {

//You can call this class anything you want. It’s not part of the Java library, you’re creating it using bits and pieces from awt and swing.

public static void main (String[] args) {

//You know what, either they never explain what that (String[] args) means or I was sleeping when I read it. It’s so that you can call arguments when you run the class like “java SimpleGuiRectangle -v -h –chuckyoufarley”

MyDrawPanel rectangle;

// You’re setting up the variable that will contain an instance of the MyDrawPanel class you made up there.

SimpleGuiRectangle gui = new SimpleGuiRectangle();

// This is a recursive thing? Inside the class you’re making, you’re creatubg a instance of it. Confuses the heck out of me still.

JFrame frame = new JFrame();

// The JFrame is the outer part of a Java window. The actual guts are in the contentPane that’s inside the JFrame.

rectangle = new MyDrawPanel();

//OK, this is an instance of that class you copied from page 364 and complied. Now you’re actually going to do something useful with it.

frame.getContentPane().add(rectangle);

//What this means (I think) is getContentPane is a method in the JFrame class. It has a method called “add” which takes an object and adds it to the pane. So instead of adding a bigass button like they showed in the book, you’re adding an instance of thar rectangle class you made.

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//You have to put that in so you’ll be able to actually close the damn window

frame.setSize(300,300);
frame.setVisible(true);

}

}

So you compile “javac SimpleGuiRectangle.java” then run “java SimpleGuiRectangle and for all your trouble you get a 300 x 300 window with an orange square in it. Seems like a lot of frikkin’ work to do something so simple, and it makes me wonder why Java is described as being supposedly so quick and easy. Or maybe I’m just a really slow learner.

SOBI and JoomFish

SOBI is the directory plugin I found.

To be able to translate the categories, download the JoomFish extension and

copy the file to /administrator/components/com_joomfish/contentelements/

I forget how I installed JoomFish, nor did I document the process, but it’s working. The two problems I encountered were:

  1. Japanese translated text that I inputted was displaying properly, but when I viewed the source of the page I could see that it was actually encoded in escape characters, like #1234#4758#2847.
  2. Every single, goddamn time I entered a new translation via the administrator interface, the administrator session would be lost and I’d have to log back in again.

Here’s the solution to the first problem:

http://www.joomfish.net/how-to-…/joom-fish-encodings-and-utf-8.html

Namely, to set the charset meta tag in the HTML header.

The second problem was caused by a bugfix in version 1.0.13 apparently causing some problems with backwards compatibility. I found the solution in this thread:

http://joomlacode.org/gf/project/joomfish/forum/?action=ForumBrowse&forum_id=755&_forum_action=ForumMessageBrowse&thread_id=6282

In that forum thread there’s a link to a new administrator/index2.php file to replace the broken one in the core.

One year from now

To create a date one year from now:

require ‘date’
next_year = Date.today >> 12

fixing FCGI on Dreamhost

To get rid of the 500 server errors:

http://convergentarts.com/pages/fastcgi

There’s also this but I didn’t use it.

http://work.alexyoung.org/archives/102/dreamhost-and-rails-500-errors

Handy rake commands

rake db:schema:dump Create a db/schema.rb file that can be portably used against any DB supported by AR

rake log:clear Truncates all *.log files in log/ to zero bytes

There’s an excellent cheat sheet here:

http://blog.nanorails.com/pages/rails_1.1_cheat_sheet