user

Java properties: How to get the user’s home directory

Java properties FAQ: In Java, how do I determine a user’s home directory?

Answer: I often need to do this when creating Java/Swing GUI applications. Fortunately it's simple (once you know how to do it), just use a line of code like this, using the Java System class getProperty method:

String homeDir = System.getProperty("user.home");

On my Mac OS X system, the String homeDir now contains the following content:

What is my Drupal user login URL?

Drupal user login URL FAQ: What the heck is my Drupal user login URL?

A funny story about this Drupal website (alvinalexander.com) is that after I first installed it with my own custom theme where I don’t display the Drupal login link, I couldn’t remember where the Drupal user login page was located. With my Drupal theme changes I didn’t have a link to the Drupal login page anywhere on my Drupal website pages.

After a little bit of poking around, I finally realized the Drupal login page is located at this pretty obvious URI:

How to test for a valid user session in a JSP

Note: This approach is very old; Java/JSP scriptlets were deprecated a long time ago. I don't have time to update this article to the correct, modern approach, but I hope this JSP session example will point you in the right direction.

Every once in a while I'm asked something like, "How can I tell if I have a valid user session in my JSP code?"

How to determine the directory your Java application was started in (user.dir)

If you ever need to determine what directory your Java code is being run from (essentially the current working directory), you can get this information from the system properties, specifically the System.getProperty or System.getProperties methods.

The following line of Java code shows how to determine what directory your Java application was started in. This information is stored in the user.dir system property, which you access like this:

The beginning of a MySQL database script

Here is some code that I use at the beginning of a MySQL database script to (a) create a database, (b) create a local user to access that database ('foo_user'@'localhost'), (c) create a remote user that can access the database ('foo_user'@'%'), and (d) then use that database (which I need to do before starting a bunch of CREATE TABLE statements):

Nagios error code 127, make sure your plugin actually exists

Nagios FAQ: I'm trying to get Nagios to work, but when it starts running there is an error message in the log file that says something like "Nagios, Error Code 127, Make sure the plugin you're trying to run actually exists". How I can fix this?

AppleScript dialog - prompt for a response

A frequent AppleScript question I get is "How do I get information back from a user after I've prompted them with a dialog?" The following example demonstrates how I typically do this. I prompt the user to enter some text, then get their reply back. In this case the reply is stored in the variable named theName.

set theName to the text returned of 
  (display dialog "What is your name?" default answer "")

For your reference, the dialog created by this code looks like this:

Linux crontab example: How to run a program as another user

Assuming you are the root user on a Linux computer, here's a quick example of how to run a program with a Linux crontab entry as another user. Specifically in this example, the program being executed is run as the user nobody.

Relationship between software quality and the distance between programmers and users

In the software development industry, the physical distance between developers and users is an important, often-overlooked variable to the success of a project. I'm currently working on a project where my development team is several hundred yards away from our users, and we're also in another building. Because developers don't seem to like telephones, or perhaps don't like talking to other people that aren't developers, I contend that this 300 yards could easily be 30 miles.