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

Ruby FAQ: How do I create a variable length argument list in a Ruby method?

One thing I really dig about Ruby is that I can create methods and functions that support variable-length argument lists. It's not something you need all the time, but it sure is nice to have it when you need it.

Here's how you create and then call a Ruby function/method that can take a variable number of arguments:

For some reason I can never remember the command to show Ruby documentation (the rdoc stuff that is a lot like Javadoc) from the command line, so this blog post is especially for me ...

To show Ruby rdoc documentation from the command line, just use the ri command, like this:

Ruby exec FAQ: How do I execute a shell command from a Ruby script?

It's very easy to execute an external shell command from a Ruby script. Off the top of my head there are at least two ways to do this. First, you can use the traditional backtick operators. Second, you can use the %x syntax. I'll demonstrate both examples here.

Use the backtick operator

First, I'll use the backtick operator to execute a shell command. Here's how you can run a simple command, like the ls command, using Ruby and the backtick operator:

Ruby file FAQ: How do I open and read from a file in Ruby?

How many ways are there to open a file with Ruby and process the file contents? I don't know for sure, but here are two different ways to do it.

Ruby file processing, version 1

First, I'll use Ruby and the File.open method to open a file and process its contents, like this:

This OpenSSO tutorial is probably the best "getting started with OpenSSO" tutorial around, but I'll add one caveat to it: Until you know what you're doing, just follow this tutorial to the letter, and I mean to the letter. Specifically, when they say "use Glassfish", you want to use Glassfish, and not something else, like Tomcat.

I can dig the rumors about Apple developing a new "media pad" device. (Some rumor-mongering here and here.) I had one of the early-model Windows-based Toshiba tablets that had a small display (maybe 10-12"), and the "display" part of it spun on an axis.

Before I get too far away from this code, I wanted to present my examples related to PHP and OpenSSO in a more logical order than the way in which I originally posted them. To that end, here is my collection of PHP/OpenSSO tutorials, showing how a PHP application can manually interact with an OpenSSO server in a single sign-on, identity-management world:

Still in my early days working with PHP, I've learned that it's really easy to generate the dreaded "headers already sent" error message. If for some reason you actually want to generate this error message intentionally, I've learned that all you have to do is try to send HTML body content (any non-header content) before calling the header() or setcookie() methods, and you'll get that PHP error message right away.

PHP redirection FAQ: How can I redirect a user in a PHP script?

I've been working with OpenSSO a lot lately (Sun's open source identity management product), and one thing you see right away is that they redirect the user's browser a lot during the login process. During a typical login process a user will attempt to access a protected page; an OpenSSO agent will redirect the user's browser to the OpenSSO login page; and after a successful login they redirect you back to the protected resource.

PHP OpenSSO FAQ: Can you share a PHP script to validate a user's OpenSSO cookie?

PHP here doc FAQ: Can you share some examples of the PHP "here" doc (heredoc) syntax?

"Here" documents in many languages are provided as a way to address the following problems:

PHP OpenSSO FAQ: Can you share a PHP script to manually authenticate OpenSSO users during a login process?

I've been working on a single sign-on project lately, evaluating both OpenSSO and IBM's trio of TIM, TAM, and WebSeal, and I noticed that Google has only 32,000 links to real WebSeal resources. By contrast, even as a young open source project, OpenSSO already has over 100,000 links.

Out of curiosity, I decided to google a variety of web languages and tools, and here are my search results:

This blog post is part of a series of planned articles regarding OpenSSO and PHP, specifically how to use the OpenSSO Identity Services from within a PHP application.

It used to really amaze me that some people always knew immediately when there were new updates to software applications -- and this goes back to the old days when many applications weren't self-updating. I always wondered how they knew about these software updates so fast. With today's RSS feeds it's pretty easy.

In light of those recent Microsoft ads that show that Windows PCs are cheaper than Macs (without ever using the word "Windows"), here's my first problem with Microsoft Windows:

Three minutes and two seconds, how long it took to log into my Windows PC

It's so easy with Ruby to get a list of files in the current directory that I hesitate to write this, but hey, this blog is for me and my bad memory, so here's a quick note on how to use Ruby to get a list of files of a certain type in a directory.

To have a little fun with this, I'll use irb (the interactive Ruby shell environment) to show how to do this.

Java command-line input FAQ: How can I read command-line input in a Java application?

Note: To see a more modern approach to this problem, see my article, How to read interactive command-line input in Java. That article demonstrates the use of the Java Scanner class, which came into existence as of Java 5.

Over the weekend I was trying to configure Apache as a reverse-proxy server (specifically as a reverse-proxy server working in conjunction with OpenSSO), and I couldn't get it to work at all. It's been a while since I last installed Apache, and I assumed it was configured with the modproxy module by default, but it turns out that it's not: You have to configure Apache with the mod_proxy module at installation time in order for things like the ProxyPass configuration to work.

Here's a simple PHP program I wrote to test how PHP works with OpenSSO, specifically how it works with OpenSSO identity information.

I saved this file with the name info.php, then put it in a directory on my Apache web server that is protected by an OpenSSO login policy. To access this page, I enter the URL for the page in my browser and try to access it, with the URL being something like this: