“To record for posterity, those things I once knew, but might otherwise forget.”

Going Public

For the past couple of years, there have been no links to this site. After all, it’s really just notes to myself. But there have been tons of visitors! I have no idea how the robots find these things, but they did. And I had left the settings so that visitors could create accounts in order to post comments.

PHP and CSV files

If you have ever tried to use PHP to process CSV files that contain non-ASCII characters, you know there is a problem out there with lots of solutions that may or may not work. Mostly the latter from what I can tell. Herewith some comments from a PHP command line program that I use to populate a PostgreSQL table with data derived from a spreadsheet.

This is all command-line stuff under OS X.

Opera Sucks

The IEEE-754 analyzer project fails when using the Opera web browser. I have reported the problem to Opera (Bug DSK-303966), but there is no way to track it, and it has not been fixed as of version 10.60. The problem shows up when I check for decimal recurrences. I keep an array of remainders (numeric strings) in an array, and compare each to remainder (also a numeric string) to all the elements in the array. If remainders[0] contains the string '1' and the remainder is also the string '1', Opera evaluates (remainders[0] === remainder) as false.

IEEE-754 Numbers

I see from my previous post on this project that I've been working on it for over three months now. I had no idea it would take so long. (That can be properly translated into, “I had no idea how ignorant I am!”)
A major source of complication has been my decision to let people enter values in “natural” ways. That, to me, means that the code should be able to handle real, rational, mixed, binary, and hexadecimal representations of values, have the code figure out which is which, and to generate equivalent decimal, binary, and IEEE-754 representations of whatever value the user enters. Regular expressions make the task of recognizing the input format pretty straight forward. (There are radio button to force a particular interpretation in cases where the same input string is ambiguous.) The problems so far have come from the need to translate between decimal and binary values while maintaining precision that exceeds that of the floating-point standard so that final results, after rounding, are accurate.
Herewith, some lessons learned so far and some notes to myself.

The width of a table

If you want to center a table horizontally, you need to apply a CSS rule that specifies margin:auto;. But for that to work, you need to give the table a width, which is a problem because the browser is going to set that based on the contents. Percents, ems, and pixels all have disadvantages in this situation.

But you can specify a width of zero, and all browsers tested (current versions of IE, Chrome, Safari, Firefox, and Opera) will render the table in its natural proportions.

IEEE Calculators

If you search for IEEE-754 calculators, you are likely to find http://babbage.cs.qc.cuny.edu/IEEE-754/. The page was written by a student who went beyond the scope of a homework assignment (write a C program to parse IEEE-754 floating point numbers) to provide a JavaScript based set of pages that let you enter decimal numbers and see the 32 and 64-bit hexadecimal representations, and vice versa. An engineer from Delco Electric got interested and put a lot of effort into making the "calculators" precisely accurate. The calculators are used a lot and have been translated into foreign languages. I regularly get questions from people about them, almost always from people who don't understand what they are doing. But I've always hated the UI: there is no need for three different pages, you have to click a button "rounded" or "not rounded" to get them to perform, and they have a certain ugliness about their appearance that I'd like to clean up "one of these days." But that JavaScript code is so hairy, that I kept putting the update further onto the back burner. Then I got email from someone who had a question about 39.998 -- can it be represented exactly in an IEEE-754 double? That coupled with the fact that I'm teaching a JavaScript course got me to thinking ...

Learning to live with OS X updates

The main point of this blog is to record the stuff I need to remember. Like, what to do when Apple does a security update and breaks my web server. Which happened again today. I've learned when there is an update to wait a day until info about it actually shows up on the Apple updates page. There is always a link to the info in the update dialog box, but they push the update before updating the info about the update.

AppleScript can run arbitrary programs, but I don't need to process IMAP email programmatically after all.

Just use the built-in do shell sript command:

display dialog(do shell script "/Users/vickery/script_test")

The docs make a big deal about the code being run by sh rather than by your login shell,
but a she-bang at the beginning takes care of that:

#! /bin/bash
echo hello

psql tunnel

This will set up a tunnel between the local machine and a computer named example.com where I have already added the public key for my local machine to the .ssh/authorized_keys file.

ssh -N example.com -L 2110/localhost/5432

Then you could do, for example:

psql -h localhost -p 2110 dbname

Add -f to make the ssh command run in the background.
The -N option says just to set up the tunnel without running any commands on the remote host.

Email verification: Using Sieve

I’d like to be able to have visitors fill in a form that includes their email address, send a message to that address, and have a program process the email. Standard user verification stuff. On Solaris or Linux, I know how to do it: use procmail to recognize the messages to be handled, and pipe the message to a processing script. The only thing is, I want to do this on my OS X server, and as usual, I want to keep the Apple software (for email in this case) intact. So I need to learn the “Apple Way” of doing things. As of this writing, I still don’t have it working, but here is what I have learned about using Sieve to filter my email.

Syndicate content