alvin's blog

How to print a Ruby hash sorted by value

I recently needed to print the information in a Ruby hash, with the results sorted by value. Here's a general recipe on how to print the hash results sorted by value. I've created a sample hash, and populated the hash with sample data, to show how this works.

First, here's the sample code, using the first name of each person as the key, and the last name as the value of the key/value pair:

vi commands - the most common vi navigational commands

There are a lot of commands for navigating through a file with the vi editor (or, more recently, the vim editor), but the reality is that I've used various forms of Unix (Ultrix, AIX, CLIX, SCO Unix, etc.), Linux, and more recently Mac OS X, and there are only a few vi commands that I use for moving around in a file.

So I thought I'd list those here, the most common vi commands.

JFormDesigner - How to create a ButtonGroup

I just learned how to create a ButtonGroup using JFormDesigner, and it's pretty easy and pretty cool.

First, add all the related buttons you want on your JFormDesigner form. Next, click all the buttons while holding down the [Control] or [Apple] key, depending on your platform, so the all the buttons are selected at one time. Then right-click one of the buttons, then select the "Group Buttons" option from the popup menu.

JFormDesigner - how to set the column width of a JTable

I just noticed that you can set the preferred size of a column in a JTable using JFormDesigner. If you're looking at a JTable in the normal JFormDesigner view, click the ellipsis button for the model property in the Properties list. This brings up the JTable model editor.

Next, click a cell in the column you want to modify. Then on the bottom-right of this dialog you'll see a few fields labeled "Pref. Width", "Min. Width", and "Max. Width". Just type in a value you want for the preferred width of your column.

AppleScript time example - current time as hours and minutes

AppleScript time subroutine FAQ: Can you share an example of an AppleScript subroutine (function) that returns te current time?

Here's an example AppleScript subroutine (also known as a function or method) that returns the current time as hours and minutes, along with the AM/PM modifier. For the purposes of creating an alarm clock AppleScript program, I didn't like the default format of the AppleScript current date command, so I use this method to extract the current time information I want.

AppleScript result output - How to display output in the ScriptEditor Result tab

AppleScript result output FAQ: How can I display the output of my AppleScript script (the AppleScript result)?

Cool, I just learned how to get AppleScript output to show up in the ScriptEditor Result tab. In short, just leave a string at the end of your AppleScript script, and it is printed in the ScriptEditor Result tab.

ScriptEditor Result output: An AppleScript output "Hello world" example

Here's a quick AppleScript result example that puts "Hello world" in the ScriptEditor Result tab:

Syndicate content