CSC309 A1: kääntää Translations

February 4th, 2010 No comments

One of the more fun courses that I’m taking this semester is  CSC309: Intro to Web Programming.  Although I do a lot of coding in general, I’ve actually never worked with Javascript or other web technologies.  Sure, I’m using Wordpress right now, but Bluehost is nice enough to have one-click installs!

For our first assignment, we were tasked with creating a simple chart that would allow users to add, remove, and edit translations.  We were not allowed to use Javascript libraries, and none of the changes would be persistent (no servers…yet!).

The assignment was due yesterday night, so I think it should be okay for me to post my page up on my blog.  I wrote up a nice design document for it, so I’ll be sure to post it up later on my Projects page.  But for now, you can play around with it at this link here:  http://www.pioverpi.net/csc309/a1/main.html

Update: I’ve put up the project description, it has a description of the implemented features.  You can view it here: http://www.pioverpi.net/projects/csc309-a1-kaantaa-translations/

Categories: Tech, UofT Tags: , , ,

Python Shell Commands, /bin/sh: Syntax error

January 29th, 2010 No comments

This semester, Derek and I have been doing some work on Postgres’ buffer management system for my CSC443 Database Systems Technology course.  Derek, wrote a nice little Python script that parses various Postgres outputs and does a bit of math on it.

However, when I tried to run his script on my machine, I got an error:

/bin/sh: Syntax error: Bad fd number

The problem was that the script relied on an os.system() call execute some shell statements. This script worked fine on the Debian systems at school, but it barfed on my Ubuntu.

A series of Google searches led me to this useful thread http://ubuntuforums.org/showthread.php?t=382548

It turns out that the command wasn’t being executed through bash, but through sh

The fix in the forum post is a bit overkill, the suggestion is to completely delete sh. I’d rather stick to the safe side and rename sh and then create the sym-link:

sudo mv /bin/sh /bin/sh.bak
sudo ln -s /bin/bash /bin/sh
Categories: Linux, Tech Tags: , , , , , , , ,

Speed Reader

January 22nd, 2010 No comments

I spent a small portion of my free time this week working on a small Java application that would help me do a bit of speed reading.

For those who are unfamiliar with the concept, you can read more about it on the wiki article here.  The basic idea is to increase the speed at which you read words by trying not repeating the sound of the word to yourself internally.  A lot of the tools out there will help you do this by taking a large portion of text and flash each word in front of you very quickly.  ZAP Reader or Spreader are both online tools which do this quite well.

However, as a challenge to myself, I worked towards writing one up using Java.  Suprisingly, the applicaiton itself wasn’t that hard to write up, I had a working prototype within 4 hours of coding!

So here it is, Jama’s Speed Reader!

Features

  • Paste words into it to read words very fast!
  • Adjust the reading speed (words per minute, or WPM)
  • Can display multiple words “per flash”
  • Can pause on larger words
  • Can pause at the end of a sentence
  • Will combine english honorific titles so that words like “Mr. Jones” will appear on the same screen, instea of “Mr.” and “Jones” seperately

Screencast

And now for the first time, a screencast!

Download

Categories: Linux, Mac, Tech, Win32 Tags: , , , , , , ,

Column Select/Edit With Eclipse

January 21st, 2010 No comments

I recently upgraded to newest version of Eclipse (Galileo) and I was pleasantly surprised to find that it now comes with column select.  I first encountered this feature while using TextMate, and ever since I switched back to Win32 I’ve been itching to find an editor with a similar feature!

To activate it, simply press Alt+Shift+A to go into column select mode. From there, you can edit blocks of text to your heart’s content. If you want to revert back to the normal text editing mode, simply press Alt+Shift+A again.

Categories: Tech Tags: , ,

Drawing Strings in Swing using Graphics2D

January 14th, 2010 No comments

I’ve started a new project again, and this time I’m working on a speed-reader application using Java (more details on that later)

One of the problems that I’ve always had with Java Swing UIs is figuring out how to directly draw centered Strings while inside of a paintComponent(Graphics g) method of some JComponent

So let’s say you’re trying to draw some fancy graphics inside some custom JPanel. You’ve created your own class MyClass which extends JPanel, and you’ve overrided the paintComponent(Graphics g) class.

You can use Graphics g from within paintComponent(Graphics g) to draw a string on the screen at position (x,y) by using the following snippet:

g.setColor(Color.black);

Font textFont = new Font("Arial", Font.BOLD, 16);
g.setFont(textFont);
g.drawString("This is my string", this.getWidth()/2, this.getHeight()/2);

However, doing so will give you a jaggy, uncentered string. The problem is that Graphics will draw the string starting at the center of the string.

We can work around this by using Graphics2D and FontMetrics.  We can use these two objects to help us find the width and height of the drawn text, and from there we can adjust the coordinates:

Graphics2D g2d = (Graphics2D) g;

String words = "This is my string";

g2d.setColor(Color.black);

Font textFont = new Font("Arial", Font.BOLD, 16);
FontMetrics textMetrics = g2d.getFontMetrics(textFont);
g2d.setFont(textFont);

int centeredX = (this.getWidth()/2) - (textMetrics.stringWidth(words)/2);
int centeredY = (this.getHeight()/2) + (textMetrics.getHeight()/2);

g2d.drawString(words, centeredX, centeredY);

Now, you might notice that the text itself is very jaggie. We can fix this by telling Graphics2D Rendering Hints to turn on anti-aliasing. This can be done by using the line:

g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
				RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

And there we have it! Nicely smooth and centered strings!