Heartbleed Relief: Replace the Default SSL Certificate in Parallels Plesk Panel

Heartbleed logoIf you have a web site with an SSL certificate then you are probably affected by the Heartbleed vulnerability which popped into general visibility. If your server is vulnerable, you need to do two things:

  1. Update openssl
  2. Replace your SSL certificate (since you have to assume that the certificate’s private key has been stolen).

Anyone in possession of your private key can a) impersonate your web site; and b) decrypt all past, present, and future traffic.

One little piece of the recovery is replacing the default certificate for your control panel. If you only have one server then clicking around in the control panel is OK. But if you have a lot of servers, that will quickly drive you bonkers.

Here is a shell script which will replace the default SSL certificate for Parallels Plesk Panel. The new certificate will be valid for 1095 days (three years). It will then use the new SSL certificate to secure the Plesk Panel itself. Continue reading Heartbleed Relief: Replace the Default SSL Certificate in Parallels Plesk Panel

MySQL + UTF-8 + PHP 5.3.10 + JSON = Trouble

Yesterday, I spent longer than I care to admit debugging an update to an old PHP script. It fetched a string from a MySQL database and (here’s the new part) passed the string to json_encode(). That call failed when the data included the multibyte characters ¼ or ½ or ¾. All of my attempts to remove the multibyte characters from the strings (replacing them with “1/4″ or “1/2″ or “3/4″) failed.

The problem turned out to be PHP 5.3.10’s default for the character set of the MySQL connection and the fix was easy. Explicitly set the character set to UTF-8:

Once that was set, json_encode() properly recognized the string as UTF-8 and it ran without error.

This problem will not occur with newer versions of PHP. They have the default character set as UTF-8.

Python Singleton

I needed a singleton database class in a Python 2.7 program and wrote it this way.

I like this pattern but I realized that this is even more elegant:

It works because I do not really need the whole Database class to be a singleton. All I really want is a single database connection.

Mitsubishi i-MiEV Electric Car Range

Several of us have been discussing the range of the Mitsubishi i-MiEV electric car in a Google+ community. What started as a simple query, “What kind of range do you guys get?  62 EPA miles?” made me realize that I rarely think about our i’s range in terms of miles. Instead, I am simply concerned with whether the car can take me where I want to go (and it almost always can).

Battery charge meter
Mitsubishi i-MiEV battery charge level indicator (on left) and gear selector indicator (on right)

When I first started driving the i-MiEV, I was obsessed with range. The car is “only” rated for 62 miles and that distance can be significantly reduced by highway speeds (more air friction), running the heater, and running the air conditioner. I would focus on the battery meter and carefully count how many bars remained (16 bars is a full charge). Continue reading Mitsubishi i-MiEV Electric Car Range

Mitsubishi i-MiEV Mileage

Shortly after we picked up our Mitsubishi i-MiEV electric car, I bought a Kill-A-Watt meter, so that I could measure the amount of energy that goes into charging the car’s battery. I know that I pay 11¢ per killowatt-hour so this allows me the calculate the cost of running the car. I am intentionally measuring the amount of energy that comes out of my wall socket, not the amount of energy that is used to drive the car’s motor. My measurement includes energy used to run the heater, energy lost in the charger, inefficiency in the battery, etc. It is, in other words, the actual cost to operate the car and not the theoretical energy used just for propulsion.

Here are the results, after driving the Mitsubishi i-MiEV for a little more than two weeks:

  • 351.8 miles
  • 118.0 killowatt-hours (kWh) @ $0.11/hour = $12.98
  • 3.7¢ per mile

My technique is pretty straightforward. With the battery fully charged, I reset the trip meter to 0.0 miles. After driving the car, I fully charge the battery and read the number of killowatt-hours off of the Kill-A-Watt meter. Sometimes, I don’t have time to fully recharge the car before I need to drive it again. When that happens, I do not reset the trip meter and do not reset the Kill-A-Watt meter. I then continue charging the next evening. When that happens, I end up measuring the total miles and the total energy, even if it is more than one battery charge could have sustained.

For comparison, we get about 29 miles-per-gallon with our Fiat 500 Sport, burning premium gas. Using today’s gas prices of about $3.10 per gallon, that works out to 10.7¢ per mile.

There are two other small costs worth mentioning. Missouri requires us to buy an alternative fuel sticker for the electric vehicle. The $75 annual fee for the sticker replaces the gasoline taxes that we are not paying and supports road maintenance. The Fiat, like any internal combustion engine vehicle, has higher maintenance costs associated with the more complex engine (oil changes, tune-ups, etc.)

This Google spreadsheet has the raw data for our Mitsubishi i-MiEV mileage calculations.

No No No Vibrations

Mitshubishi i-MiEV
Mitshubishi i-MiEV with Fiat 500 (background)

I have been driving our new Mitsubishi i-MiEV electric car almost exclusively since we got it, two weeks ago. I still grin like a fool as I glide virtually silently from a stop up to cruising speed. I grin even more when I lift my foot off of the accelerator pedal and the gauge on the dashboard indicates that the car is recharging the battery as it slows down.

The other night, Candy and I had tickets to a play. The theater is 26 miles from our house, almost all interstate. It was also cold, which necessitated running the heater in the car. A round trip of 52 highway miles with the heater running was farther than I am comfortable taking the Mitsubishi. I sure did not want to be “out of gas” at 10:30pm on a cold night. This was clearly a trip for the gas-powered car.

We hopped in our Fiat 500, I started it up, and was immediately struck by the vibration. The Fiat is a pretty smooth car, especially at idle in the driveway. But after spending two weeks driving a car with no vibrations, it was surprisingly noticeable. I knew that electric cars are quiet and smooth but did not expect to become to accustomed to it, so quickly.

It’s nice. :-)

Our New Mitsubishi i-MiEV Electric Car

We just bought a Mitsubishi i-MiEV electric car and boy-oh-boy is it fun! This little gem drives “just like a car,” costs about 3 cents per mile to run, has four doors (plus a hatchback), and is surprisingly spacious. Believe it or not, the Mitsubishi i-MiEV is the “big” car in our family, being 10 inches longer than our Fiat 500 and with six inches more interior width. Here is a photo of our two cars together (click to see a larger version of the photo).

Mitshubishi i-MiEV
2012 Mitshubishi i-MiEV SE with 2011 Fiat 500 Sport

A couple of weeks ago, I had an free evening and decided to test drive the Mitsubishi i-MiEV. I had read about the i on the internet and was honestly intrigued when Car & Driver dismissed it with stuff like, “When merging onto a freeway, you’ll wish for at least 67 horses” and “If a range of 62 miles works for your life and you want an electric car, the i delivers. Its weirdness even makes it interesting, or as interesting as a 2552-pound car with 66 horsepower can be.” I like technology. I like small cars. I like unusual cars. I couldn’t resist.

Lou Fusz Mitsubishi had an i on the lot so I headed over, expecting to find it lackluster and not something that I would spend money for. I was completely surprised. In normal traffic, both on city streets and on I-70, the i-MiEV had more than enough get-up-and-go to make me happy. Other than when merging onto the interstate, I never floored the “gas” pedal. I did not spend much time with the car, because looking at a car with a black interior on a moonless night is less than revealing.

I went back the next afternoon for a second test drive. This time the temperature was hot enough to need the air conditioning. I wanted to see how well the A/C cooled the car and how it affected performance. I had one of those doh! moments when I realized that the A/C would not affect the performance at all; it is electrically driven and not hooked to the drive motor at all. Turning on the A/C reduces your range from about 62 miles on a fully charged battery to about 52 miles but it has absolutely no effect on the car’s acceleration or top speed.

I took the car on a 16 mile trek, some city streets and some highway. It has a “range remaining” gauge, which displays how many miles you can drive before the battery is drained (based on how you have driven the previous 15 miles). It was fascinating to drive the first 4.3 miles on city streets yet have the range remaining decrease by only 2 miles. This magic happens, in large part, through “regenerative braking.” When you take your foot off of the accelerator pedal, the motor turns into an electrical generator, which puts drag on the wheels and recharges the battery. It feels just like downshifting in a regular car except it is smooth and quiet. When you begin to depress the brake pedal above about 20 MPH, you get more regenerative braking before the traditional friction brakes begin to grab.

The next 8 miles of highway driving zinged the range reserve significantly. Highway speeds, with the increased air resistance and the lack of any “regen” take a toll. Though the i merges easily into 60+ MPH traffic, cruises handily at 70 MPH, and has a top speed of 81 MPH, you will only go about 40-50 miles on the highway. It is primarily a city car.

The dealership was good enough to let me take their demo car for the weekend so Candy and I had a good chance to fairly evaluate it for the types of real driving that we do. We found an excuse for a 40 mile round trip on the highway to get bagels. We ran all of our around-town errands in the i. It took four of us out to dinner. The i-MiEV did everything we asked of it easily, silently, and efficiently.

The clincher was the price. I wanted an SE model with the “upgraded” interior trim. The one that we bought had a sticker price of $32,150. Mitsubishi Motors has a $10,000 rebate going right now, as they clear out the last of the existing stock of 2012 i-MiEV cars. (There were no 2013 cars shipped to the USA and the 2014 cars are coming soon.) And there is a federal tax credit of $7,500. My net cost for a brand new car, with warranty, was $14,650. How could I refuse?

Candy and I signed on the dotted line, got financing through Mitsubishi for $0.00 down and 1.90% interest, and drove our new black i-MiEV home a week ago.

Thus far, it has gone everywhere that I wanted it to go. There has never been a time when I wanted to drive somewhere but I had to take the “gas guzzler” Fiat 500 because the i did not have enough charge in its battery. I drive it during the day and let it recharge at night (except today, when I intentionally ran the battery almost all the way down before lunch and then plugged it in right away).

I bought a Kill A Watt meter so that I could measure the amount of energy (and pennies) that I “pour” into the car. I am tracking my mileage on a spreadsheet, which you can see if you like. The first three trips that I measured totaled 89.1 miles and cost me 3.3 cents per mile. I already have the silly electric-car-driver grin as I cruise past gas stations without stopping.

Read-Only Python Properties

Following onto yesterday’s post about Python Properties and @property, there is a neat little trick to create a read-only property of a Python class. All you have to do is omit the setter. This Hero class has a read-write property “name”

You can see it used in the the constructor and in the “superman.name=” statement at the bottom.

We can easily make the name attribute read-only like this:

Note that I had to change the constructor, directly setting self.firstname and self.lastname, since it is no longer valid to write “self.name =”.

Python Properties and @property

My son pointed me at PyCharm and, while poking through it’s built-in “intentions,” I discovered Python’s @property decorator, which led me to learn more about the Pythonic way to handle class properties. Unlike Java and C++, Python encourages you to create public class attributes (a/k/a properties). Here is an example:

That works while being beautifully readable. A hero has a name. You can print the name and, when the hero moves to a new planet, you can change the name.

Python makes it easy to change the behavior of the Hero class, and this is markedly different from what you can do in many other languages. Let’s say that you want the Hero class to store not just the hero’s name but also his first name and his last name. The obvious way to implement that would be in the “setter” for the name attribute. You would add some code to parse the name into first name and last name, and then store the two components separately. You might start with something like this:

The problem is that the simple assignment no longer works. Writing “superman.name = ‘Clark Kent'” no longer does what you expect; it only changes his name but does not change his firstname. Instead, you would need to write “superman.set_name(‘Clark Kent’)” which is painful; it requires you to hunt through your whole program and recode all occurrences of “superman.name =”.

This is where Python’s @property decorator comes in. It gives you a straightforward way to add behavior to the setter for the name attribute, so that you can still use “superman.name =” throughout your program.

Voila! Now the Hero class actually stores the firstname and the lastname while providing the illusion that it still has a simple attribute “name”. The @property decorator makes the syntax “superman.name” keep working to get the value of the name property. The @name.setter decorator, makes the syntax “superman.name =…” work to change the value of the hero’s name.

For more information on Python descriptors, see IBM’s excellent article, Introduction to Python descriptors.