Sassy CSS

Cascading Stylesheets are a brilliant and now ubiquitous mechanism for styling webpages. Draw borders, add colors, arrange the content, and make the whole site look presentable. Of course, CSS is not perfect.

The major annoyance for me has been the lack of support for variables. I’d like to say, “I want the same color on this border, this text, and this background,” or, “I want this padding to be the same as this margin and that border width.”

Sass solves this problem by extending the CSS language. Any valid CSS file is already valid SCSS, but in an SCSS file you can do a lot more. Whenever you change your SCSS file, sass automatically recompiles it into a valid CSS file. Browsers are indifferent, since they’re just getting standard CSS all along, but web authors get a much better development experience.

Variables are of particular interest to me, and sass supports them:

$color = #efefef;
.something { border-color: $color; }
.something-else { background: $color; }

And that’s only the beginning. Variables can also be used in mathematical expressions (e.g., width: $standard-width - 10px; to account for some padding, perhaps), and even in functions that generate CSS rules with slight variations.

I also particularly like the ability to add “parent references”:

#some .lengthy .selector a {
    color: black;
    &:hover { text-decoration: underline; }
    &:visited { color: purple; }

I just started using SCSS, and I already love it.

Drivers, Ms. Daisy

A relative’s Dell XPS 8000 recently suffered a hard drive failure and had to be restored from backup onto a new drive. Naturally, it could no longer connect to the Internet.

Problem 1: The machine’s BIOS no longer recognized any USB keyboard that Dell didn’t create, and so wouldn’t boot with my keyboard in order to fix the problem. I had to borrow a Dell keyboard.

Problem 2: Windows did not have valid drivers for either the wireless or wired network cards. Dell distributes the drivers via its website, but without already having the drivers it’s impossible to connect to the Internet. I had to download them from my iMac, burn a DVD, and load them from DVD on the PC.

Problem 3: When given the “Service Tag” for this machine, supposedly identifying the specific machine so Dell can provide the correct drivers, Dell provides 64 bit drivers which are completely incompatible with the 32 bit processor. This one was a doozy. I had to ask Google to find every possible driver for any model Broadcom NIC and then try them all until one worked.

Just for a little comparison, my own iMac suffered a hard drive failure last year. Apple installed a new drive, I restored from Time Machine, and it was like nothing had ever happened.

I don’t mean to insight a religious Mac vs. PC debate, and in fact Apple does plenty of stuff I dislike, but that much effort to connect to the Internet (via a wired connection, no less) is just ridiculous.

This is a UNIX System! I Know This!

It's a UNIX System

It's a UNIX System

Movies are infamously terrible at depicting computers with even a modicum of accuracy. Even UNIX gurus raised an eyebrow in confusion when Lex announced in Jurassic Park, “It’s a UNIX system! I know this!” (In fairness, she was at least looking at a real application, but not one readily recognizable as “UNIX”.)

In delightful contrast to the stereotypical Hollywood computer experience, Joshua Nimoy describes creating the special effects for Tron Legacy. I particularly enjoy the use of emacs.

(via kottke)

Open Two Instances of Mac OS X Applications

Whitson Gordon at Lifehacker just revealed the most exciting thing I’ve ever learned about Mac OS X: the secret to opening two instances of the same application simultaneously.

Unlike Windows, Mac OS X normally only opens each application one time. Then as you try to open new files the application just creates a new window for each one. This is ordinarily no problem at all — you can still have as many PDFs open in Preview as you want; there will just be only one Preview icon in the dock or in the ⌘→ switcher.

But what if you want to open the same file twice? That’s not possible! And what about applications like VLC that only open one window at a time? There, each new video you start playing replaces the previous one.

Opening a file with open -n changes all that. And my life is now happier for it.

Itty Bitty Applications Only?

Oh, hosting provider. I understand why you want to impose a limit on how much memory PHP applications can use on your servers, but you may be taking it just a little too far:

Fatal error: Allowed memory size of 64 bytes exhausted (tried to allocate 54 bytes)

For the non-programmers out there, that means the application is asking for 54 more bytes of memory to store some information, but is being told it’s already used up the entire 64 bytes available to the entire application.

To put that in context, that error message (having 71 letters, spaces, and punctuation marks) takes up 71 bytes. So 64 bytes isn’t even enough to store a single error message, much less an entire application.

Put another way, when VisiCalc (often described as the “first killer app” for personal computers) came out in 1979, it wouldn’t run on low-end Apple II computers since they had only 16,384 bytes of memory available.

Cuckoo’s Egg

Clifford Stoll wrote The Cuckoo’s Egg in 1989, telling the true story of how he started investigating 75¢ of computer time nobody had paid for and ended up catching an international hacker passing through his computers to gain access to military secrets. The classic story is a fascinating mix of technical detail and the thrilling action of hunting an invisible criminal through the phone lines.

My favorite passage, though, comes at the very end. After the overseas spy is caught and brought to justice, another hacker slips into Stoll’s system and for a moment the whole process starts over again. Stoll writes:

He got in through an unprotected astronomy computer run by a couple of infrared astronomers. They didn’t care about security . . . they just needed to connect to the network. Because I exchange programs with them, we’d set up our systems to work as one—you didn’t need a password to move from their computer to mine.

A couple days later the SOB called me. Said his name was Dave. From Australia. “I broke in to show that your security isn’t very good.”

“But I don’t want to secure my computer,” I replied. “I trust other astronomers.”

And that’s the moral, as true today as in the 1980s. We don’t want to secure most systems. Certainly I wouldn’t want my online bank account accessible to common thieves, but a database of research or a casual blog shouldn’t require elaborate protective measures.

This is just as true in the physical world. I wouldn’t put my valuables in a bank vault with no lock, but the classroom doors where I went to college were always open.

Unfortunately, in software0 leaving any door unlocked can grant access to resources beyond the application itself, so we sink a fortune into securing even the most trivial of software against all imaginable attacks. That’s a high price to pay for protection against the pranks of mischievous hackers.

Submit Sully

Found in an old bit of code a former student in my department wrote:

<form action=”…” method=”post” onsubmit=”myfun();myfun2();myfun3();return submitSully;”>

If it just called myfun(), myfun2(), and myfun3(), and then returned Sully, that would be mundane.  But it calls myfun(), myfun2(), and myfun3(), and returns submitSully, and that’s just priceless.

Modern Medicine Through JavaScript

I love a medical school that gives online tests (quizzes, maybe?) and evaluates the results through JavaScript.  I especially love when it uses this logic to do it:

if(correct) return true;
else {
  if(guess < 2) {
    alert("That is not correct.");
    guess = guess + 1;
    return false;
  } else {
    alert("You have guessed incorrectly, but may move on.");
    return true;

I hope my (hypothetical) surgeon works the same way.  “You’ve removed three organs.  None of them were right, but you can send him home now anyway.”

Self-Creating Tables

I recently tried creating a new database table only to learn a table with that name exists already.

[me@mysql db] > CREATE TABLE log_search (
, search VARCHAR(255)
, created_by VARCHAR(128), created_on DATETIME)
ERROR 1050 (42S01): Table 'log_search' already exists
[me@mysql db] > DESC log_search;
| Field         | Type                | Null | Key | Default             | Extra          |
| log_search_id | bigint(20) unsigned |      | PRI | NULL                | auto_increment | 
| search        | varchar(255)        |      |     |                     |                | 
| created_on    | datetime            |      |     | 0000-00-00 00:00:00 |                | 
| created_by    | varchar(128)        |      |     |                     |                | 
4 rows in set (0.00 sec)

I love naming conventions!  My favorite part of programming is when I start to write a routine only to learn I already wrote it months ago in preparation for what I knew I’d be doing now.

Verizon LG Bluetooth

I learned today, as evidenced in my previous post, that I can easily transfer pictures from my LG phone to my iMac using Bluetooth.  Since this was not immediately obvious to me, I’ll now share the steps I took for the benefit of all mankind.

First, I made the phone discoverable (Settings > Bluetooth Menu > Options > Discovery Mode > On)

Next, on my iMac I opened the Bluetooth System Preferences pane and clicked the “+” button at the bottom of my list of devices.  After some searching, it discovered my phone and let me select it.  At some point I got to a screen that implied the only thing I could do with this phone was use its Internet connection.  False!

I ignored that screen entirely — in fact, I quit out of the setup wizard at that point — and went back to the Bluetooth System Preferences pane, which now included my phone in the list of devices.

Clicking the “gear” icon at the bottom of that list, I chose “Browse Device.”

There were my files!

It also looks like I could transfer new MIDI ringtones to my phone in that way, although like a civilized adult I want my phone to make a ringing sound when someone calls me.

iMac & Phone: Connected or Not?


You can see that the iMac was somewhat conflicted about whether the phone was connected, but otherwise the whole thing went quite smoothly!