Scala, Java, Unix, MacOS tutorials (page 409)

Here's a little Java code sample that shows how to try to perform a Java String to int conversion. In this example, if the conversion works, the variable pageNum will hold the int version of the pageNumString. If the conversion doesn't work a NumberFormatException will be thrown, and you'll need to deal with that.

Java String "alphanumeric" tip - How to remove non-alphanumeric characters from a Java String.

Wow, I haven't worked with images in Java in a while, and it turns out that opening and reading an image file in Java is very easy these days. Just use the read method of the Java ImageIO class, and you can open/read images in a variety of formats (GIF, JPG, PNG) in basically one line of Java code.

Mac drag and drop FAQ: How do I copy files on a Mac OS X system using drag and drop between one or more Mac Finder windows?

It turns out that when you drag and drop a file between two Finder windows on the same Mac OS X filesystem you end up moving the file. Unfortunately that's not usually what I want to do; usually I want to copy the file, which recently begged the question "How do I copy files when using drag and drop?"

Some times when you're editing a file with really long lines it's easier to work with the file if the lines don't wrap on screen. That's usually when I use the "no wrap" feature of the vi (or vim) editor.

If you don't want the lines to wrap in vi just type this command:

:set nowrap

That command tells vi not to wrap the lines. The result is that any line that was wrapped before will now scroll off the screen to the right. If you want to return it to the default wrapping mode just type this command:

If you get a Postgresql error message like this:

ERROR:  must be owner of relation [your_table_here]

don't worry too much, it probably means what it says: You don't own the table (or relation) you're trying to modify. Well, I guess you can worry if you can't get someone to fix the permissions, but if you can it's no big deal.

Here's a quick example of how to use a JDBC PreparedStatement with an SQL SELECT query when accessing a database. To make it a little more complicated I added a LIKE clause to the SELECT statement. So, this is really an example of a PreparedStatement that uses a SELECT query that uses a LIKE clause.

With Postgresql (or Postgres, as I call it) you can execute commands from a file like this:

\i your_file_name_here

I just did that to run a subset of the restore commands from a backup file that I created, and it worked just fine. In my case I put the file in my current working directory, but I'll guess that you can also supply a path to the file and it will work from there as well.

 

Summary: A quick look at "The Toyota Way", and how information technology (IT) is looked at from the framework of The Toyota Way. 

Here's an interesting quote from a book called The Toyota Way:

For better or worse, I sold half of my Apple stock this morning. I bought the stock earlier this year around $85, and it's currently at $165. Last week it was at $187, and I thought "I need to put in a sell order around $175" in case it went down, and sure enough it lost $23 while I wasn't paying attention. So this morning I sold off enough to cover my initial investment, and I'm leaving the rest in AAPL for the long term.

Mac SVN FAQ: How do I install Subversion (SVN) on a Mac OS X system?

SVN commands reference FAQ: Can you share some SVN command examples (an SVN commands cheat sheet)?

I just got SVN (Subversion) installed on my MacBook Pro, so I'm throwing these SVN commands out here as a reminder to myself. This is a list of SVN command examples that can be used from the svn command line client:

I just got a Subversion (svn) server running on my MacBook Pro, and thought I'd put this svnserve man page out here as reference:

If you ever want/need to use AppleScript to drive another program that doesn't have AppleScript support, there are a few things you can do. Here's a snippet of code where I'm opening new tabs in Safari, and typing text into the location field:

AppleScript keystroke FAQ: Can you share an AppleScript keystroke/keyboard example?

When I created my AppleScript program to open a list of URLs in Safari I needed a way to type the URLs into Safari. That turned out to be pretty easy, I did it like this:

keystroke "http://www.apple.com/"

The much harder part was figuring out how to simulate typing the Enter (or Return) key from AppleScript. Without further ado, here's the answer:

AppleScript FAQ: How can I run an AppleScript script from the Mac Unix terminal (Unix command line)?

A cool thing about Mac OS X is that you can run AppleScript programs from the Unix shell. (Well, I guess it's cool if you're a Unix user.)

Running an AppleScript program from the Unix shell turns out to be surprising easy. For instance, if my current working directory has a script named OpenUrls.scpt in it, I can run that script from the command line like this:

Once you know that you can run an AppleScript program from the Unix command line it's easy to run it at scheduled intervals using the Unix cron facility. Here's an example of how to run my Safari script at the 7:30 a.m. every day.

30 7 * * * /Users/al/tmp/OpenUrls.scpt

I'm not going to get into the cron facility in any detail here, I just wanted to show how this is done. I will say that I modify the cron script by using this command:

AppleScript application FAQ: How do I save an AppleScript script as an AppleScript application?

I just finished writing an AppleScript program to open multiple URLs in multiple tabs in Safari, and -- being incredibly lazy -- I want to put this script on my desktop and have it run whenever I double-click it. That's all the work I'm willing to put into it, no other approach will do.

Well, I set out to write a simple tip on how to activate a Mac application using AppleScript, and I ended up writing a program to open a list of URLs in separate tabs in Safari using AppleScript. (Yeesh, I really took a detour. Oh, well.)

Without any further ado, here's the source code for this AppleScript program:

AppleScript “list” FAQ: How do I do something for every item in an AppleScript list? (or, How do I loop over an AppleScript list?)

Loop over an AppleScript list with the every keyword

I've shown examples of the AppleScript every keyword in other posts, so rather than create anything new, here's a repeat of one of those examples: