fogbound.net




Page 1 of 41234

Tue, 7 Jun 2016

JavaScript compares things weirdly

— SjG @ 2:52 pm

We’ve already established that PHP compares things weirdly.

It shouldn’t surprise us that JavaScript does too.

Consider the following:

> var k=['hello'];
undefined
> (k=='hello'?'Equals':'Nope');
Equals

Now, purists will point out that that’s an “equals” operator not an “identity” operator, but I mean seriously? We’re just going to pretend that


> ['hello']=='hello'
true

I think I’ll just go and rewrite all my client side code in C now.


Mon, 28 Mar 2016

PHP Compares Things Weirdly

— SjG @ 10:36 am

This is a known .. uh … situation, but it bit me today.

So, consider the following:
$ php --version
PHP 5.4.16 (cli) (built: Jun 23 2015 21:17:27)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
$ php -a
Interactive shell
php > $v1 = '479014103257633139480';
php > $v2 = '479014103257633139481';
php > echo ($v1==$v2?'Equal':'Not Equal');
Not Equal

Seems sane, yes? Reasonable. Kind of what you expect.

But then, consider this:

$ php --version
PHP 5.3.3 (cli) (built: Feb 9 2016 10:36:17)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
$ php -a
Interactive shell
php > $v1 = '479014103257633139480';
php > $v2 = '479014103257633139481';
php > echo ($v1==$v2?'Equal':'Not Equal');
Equal

Yeah. Let that sink in for a moment.

Some versions of PHP (before 5.4.mumble) will preëmptively convert strings to numbers before comparing them (if they contain only digits). But if the number is large enough, you may lose the precision to compare them correctly.

Wow. I mean, just … well… I dunno.

For what it’s worth, strcmp will do the right thing regardless of PHP version. But seriously. I mean. Why do I use this turdburger of a language?


Fri, 27 Nov 2015

Manzanar

— SjG @ 1:48 pm

(This is a post from the end of September. I didn’t finish writing it then, but recent events made me revisit it).

I just finished reading Camp and Community: Manzanar and the Owens Valley, an oral history compiled in the mid 1970s by Jessie A. Garrett and Ronald C. Larson. Unlike many of the oral histories of Manzanar, these interviews are not of internees. Rather, this is a collection of interviews of twenty some odd people who lived and worked in the area. Some of them worked at the camp itself (including one director of the camp), while some had no connection to it at all.

It’s a fascinating read. Not unexpectedly, people often contradict one another and the memories are rife with inconsistencies, but it paints a picture of a small, relatively isolated community being confronted with substantial change and influx of outsiders (both within the camp and with the outside personnel the camp required). The change was an economic boon in a lean time, and it brought outside attention to the area. Both of these factors affected the attitudes of the community.

There is a strong impression that some people’s feelings changed in the twenty-five to thirty years between when the events took place and the interviews occurred.

Among the people whose opinions changed against the internment, there were all of the expected explanations: it wasn’t actually so bad, some of the the internees came voluntarily, it was for their own protection, the internment was a fait accompli and there was nothing to be done, there were legitimate mutual threats against America and Japanese Americans so this was sadly necessary, and so on. Among the people who supported the internment then and now, the arguments were also the expected ones: it was war, these were people of suspect loyalty, internees were treated better than the Japanese would treat Americans, to do otherwise would be to invite disaster.

One theme, as valid today as any time, is that fear is easily stirred up and manipulated to make people do things they would ordinarily oppose. Several of the interviewed people reflected on the fact that American citizens were unconstitutionally stripped of their rights, but excused it because there was a foreign threat to the country. It was also clear that the sense of “otherness” was key. Many of the people interviewed said they’d never seen (much less met) a person of Japanese descent before the establishment of the camp.

Another theme is essentially the William Goldman adage to “follow the money.” People like newspaperman Manchester Boddy helped establish the camps — and profited greatly on buying up the property of Japanese-Americans at firesale prices when they had twenty-four hours to liquidate their belongings before being shipped out.

Some of the defenses of the creation of Manzanar are true. People were afraid. We were at war. The imperial Japanese army was terrible and cruel to captured peoples. And yet, even if true, these are irrelevant. If our rights as Americans are subject to revocation when we’re afraid, then they’re not rights. If our answer to enemy cruelty is cruelty, then we’re no different than our enemy. If we can strip citizens of their freedom and property just because they look different than the majority, then we descend into mob rule and our lofty appeals to our ideals are just so much hot air.


Mon, 27 Jul 2015

Reactivating an iPhone

— SjG @ 6:34 pm

I upgraded my trusty iPhone 5 to an iPhone 6 back in December. I’ve used the old iPhone as a camera for doing some timelapse work, as a geocaching GPS and Ladybug recorder when taking my nephew on a Lost Ladybug expedition, and as a music player to drive a bluetooth speaker in my office. Now that my Mom is tentatively considering entering the world of smart phones, I thought I’d get it re-provisioned so she could try it and see if she likes it before springing for a bigger / newer phone.

Now, one of the great things about the iPhone 5 (as opposed to earlier generations) is that it has multiple radios in it, and supports multiple carriers. This particular phone is unlocked, and was used successfully in India with a Telestial India Airtel SIM card, and in several areas in the US with various other third-party GSM SIM cards on AT&T’s network.

When Mom’s hiking, her AT&T coverage drops out with her current phone. My Sprint coverage in the mountains is spotty at best, so a process of elimination led me to think it would be a good idea to switch the phone over to Verizon. The internet assured me that this was possible, beginning with the iPhone 5. Thus begins Act I.

Photo-Jul-27,-6-42-22-PM

Reactivating an iPhone, a Tragicomedy in 7 Acts
In which the author wastes over six hours in various retail establishments to get an unlocked phone active with a month-to-month plan.

Act I. The Verizon Store. The first tech looked at me dubiously. “You can’t use a Sprint phone on Verizon,” she said. “It’s unlocked,” I assured her. After recounting the litany of networks above, her suspicion increased. “You sure you weren’t just roaming on other networks?” she asked. Once I had sufficiently convinced her that I had swapped SIMs, she was willing to give it a try. She warned me that she hadn’t seem much success in moving iPhones from Sprint, even when unlocked, due to a “Verizon block.” Being prudent, she tried to use one of the store’s demo SIMs. After half an hour of resetting carrier settings and various other things, the best we could get was an “Invalid SIM” error. “See?” she asked me.

Act II. Another Verizon Store. I had tested my phone’s IMEI on Verizon’s compatibility check, and it said I was good. So I went to another Verizon store, armed with this information, and tried again. This time, I was signed up for an account, assured that it would be simple, given a SIM, and had my credit card charged all between sessions where the technician froze, spellbound by the Mexico/Panama football game on the big TV. But it didn’t work. We got “Invalid SIM” errors. It turns out there is some mysterious Verizon block, after all, even if Sprint considers the phone unlocked. “No problem,” he told me. “We can get you into a free iPhone on a month-to-month plan.” I was skeptical and amazed, but said OK. When it came time to sign on the dotted line, the box I was handed was a Galaxy S4. I made it clear I needed an iPhone. “OK, I can’t get that for free, but I can get you that for $100.” Still skeptical, I again said I’d try it. This time, I was presented an iPhone 5c, a $100 activation fee, $150 in various other up-front fees, and a 2-year contract. At this point, I got my original charge refunded, and left.

Act III. Screw it, thought I. I’ll just keep it on Sprint. If Mom likes it, we can switch networks later when she upgrades. I went to the Sprint store. “No problem,” they said. “We’ll just add it to your existing account as an extra line; it’ll be cheap and easy.” But then they noticed there was no SIM. Somewhere in the long history, the original Sprint SIM had gone missing. If I had known the pain this would engender, I would have given up then and there, and just bought a new goddamn phone. But it seemed no problem. They had a SIM card from an iPhone 6 that someone had returned, we’d just use that. The tech and I had long conversations about travel, Boston, work, school, and such things while she went through the endless steps to provision and reprovision the phone. After a few popups about SIM failure, it seemed to work. I could call to and from the phone! Victory!

Act IV. The phone, sitting on the charger, showed a popup saying “SIM has been locked” and the carrier header said “SIM Fail.” I power cycled the phone, and hey presto! It was back on Sprint. I tried, just for kicks, to bring up the web browser. Immediately, I got a “Data access denied” error, followed rapidly by the “SIM has been locked” and “SIM Fail” notices. Power cycling brought it back. And then the fail cycle happened again.

Act V. Back at the Sprint store. “Sorry, the iPhone 6 SIM must not be compatible. Better to go the Apple store and get an iPhone 5 SIM.”

Act VI. At the Apple store. “Sorry, we’re out of nano SIMs. We don’t have any for the iPhone 5.” but I looked over the shoulder of the tech, and saw numerous SIMs listed. “What about those?” I asked, pointing. The tech went off to talk to another tech. She soon returned. “OK, we have a floater phone, and we’ll use that SIM.” So eventually someone brought over a card with the SIM, and the tech spent a long and frustrating session on the phone with Sprint trying to get the SIM activated. Eventually, this was successful. Strangely, the phone would connect to the network, get three bars, then drop to a single bar and lose 3G and display the “1x extended” data plan. “We have awful Sprint coverage here,” said the tech. I looked at my other phone, at it had three bars. “It may also be that they haven’t activated it yet,” she said. In the settings, we confirmed that it displayed the correct phone number. “I’ll try calling it,” I said. Nothing happened. We power cycled the phone. The phone number in the settings now read “0007423.” The tech said “Well, either your phone is broken, or you need to wait for the activation to go through.” When I asked how it could be broken, she shrugged. “You said yourself that you didn’t use it as a phone for a few months,” was her best answer.

Act VII. At the Sprint Store. I recounted Act VI to the tech. He looked up the SIM in his database, and scowled. “No way, dude, that SIM’s not compatible.” I handed him the iPhone 6 SIM the other Sprint store had given me. The process repeated. “No way,” he said. “Not compatible.” Where could I get a compatible SIM? His advice was to go to a Sprint repair center, where they have more supplies, since the retail stores don’t carry extras. As I was about to leave, he said “wait! Someone returned an iPhone 5 not too long ago. Let me see if it’s still back there, and if it had a Sprint SIM in it.” Wonder of wonders, it was and it did! After a mere ten minutes of typing into the mysterious terminal, it came up. I could call it from another phone, and it could call another phone. It connected to data services with LTE!

Exuent Samuel, cackling with glee.


Tue, 23 Jun 2015

The File Format Future Problem

— SjG @ 4:26 pm

Trying to find inspiration on a current geometric art project, I went to look at some old work I’d done. Well, or I tried to.

See, back in the 1990s, I spent lots and lots of time doing geometric art using my favorite vector graphics package. You know, MacDraw II. And then, oh happy day, I upgraded to MacDraw Pro, and later yet to Claris Draw. I don’t recall whether the file format changed between MacDraw II and MacDraw Pro, but there were definitely changes when it became Claris Draw.

Claris Draw continued to run on Mac OS until Apple abandoned PowerPC code support back in 10.5.

Now, five years ago, I started looking for a way to use those old files, and discovered Intaglio, which would read the files — mostly. Some of the really large files didn’t work so well. Even though I purchased a license, there was an upgrade to Intaglio that would have required I re-buy it to fix some bugs. It didn’t seem like there were new versions being released, and support was half-hearted at best1. So I gave up.

A year ago, I tried a number of other programs. I need to convert an old architectural diagram, and found that EazyDraw’s Retro version would read the formats. What’s more, they had a neat “rent-for-nine-month” license for just $20. I bought that, converted a few files, planned to convert all my old backlog, and promptly got distracted and let the nine-month license expire before doing anything.

So tonight, I bought another nine-month license, and went through and converted a few hundred files.

The opening of the old files is not perfect. One class of problem is fonts that I no longer have. Some of the problems seem to be positioning of elements (particularly on the oldest MacDraw files), which sometimes all pile up in one corner — but the elements are all there and could be rearranged to restore the original if I wanted to put the work into it. In some cases, it appears that complex elements (like groups) have acquired a background color. That too is easily remedied.

But what to convert to?

My vector graphics program of choice these days is Affinity Designer, and of course I can’t convert directly to their format. SVG worked well, until I discovered that ClarisDraw layers got ignored and left out of the converted file. Also, if you enable SVG Tidy, enough resolution gets removed from points that lines can shift around.

In the end, PDF results in the cleanest transfer. It preserves all the geometry and groupings.

But things do get lost. This is a probably a function of the lack of universal standard for vector images. One program may support the collecting of geometrical objects into layers. Another may not. In my conversion process, I’m losing the original layers. The geometry, however, is still preserved in a way that would let me move things around to different layers in Affinity Designer, so I’m OK with that.

But this is related to a larger problem. Future-proofing is hard. I say this as a fool with boxes of 5.25″ floppies in a DSDD 40-track hard-sector format readable by only a handful of TRS-80s from thirty plus years ago. But even if the media was still good, and even if I could find hardware to read it, what then? What would I do with text files created in Electric Pencil? I have to face the fact that the games I wrote in Z-80 assembler are gone, buried in the sands of time. I mean, maybe I could find a way to read the disks (if they’re not completely faded away), and maybe I could find a TRS-80 simulator that supports some of the hacks I did, and maybe it would all work. But the amount of time required would be substantial. And for what? Revisit some nostalgia of my misspent youth?

But some of my old stuff I’d like to keep around. You could argue that I should have been paying attention and migrating data as I go. Guilty as charged. But it’s hard. And stuff inevitably falls through the cracks. For example, I use Apple’s Aperture for organizing and editing my photography (digital workflow, digital asset management, DAM … whatever you want to call it). Originally, I used a clumsy system of directories. Then I graduated to iView MediaPro. It was the same problem as MacDraw/ClarisDraw — the company behind the software shifted priorities, and support lagged. Then it was acquired by Microsoft, and any future Mac support looked questionable 2. In any case, I went through a painful process to export my edits, labels, keywords, projects from MediaPro into Aperture. But now Apple has ended development of Aperture. There’s a script to migrate to Adobe’s Lightroom. It’ll bring across my keywords and captions and maybe albums or projects, but it doesn’t preserve the nondestructve edits — and how should it, when there’s no real correlation between many of the edits available in the two programs.

I have close to 50,000 pictures, all of which are organized into albums and projects, most of which have keywords, maybe a third of which have edits, and a small set of which are organized into books. So I face a monumental task to migrate, and in the process I lose the “nondestructive” nature of my edits. I’ll have to export an edited version and an original if I think I’ll ever want to re-edit an image. Furthermore, my organizational approach will need to be revisited, and some of the work I’ve put into organizing will vanish. So I procrastinate. Aperture’s still working (for the time being). I’ll wait until I’m forced to do something.

This could turn into a rant supporting RMS’s philosophy of using pure Free / Open Source software. But that’s not really the solution either. I could just stop updating my Mac’s software, and I’d be able to continue to run the application as-is. I’d probably want to disconnect it from the Internet, because a lot of software fixes are security-related. It would be inconvenient, but it’d work. Until I had a hardware failure of some kind. These issues are not exclusive to non-Free software. Free software changes and evolves too. I have a backup server dependent on Fedora Core 6 for one of the drivers. It works, but if I want to do any security patches, I’m on my own. With Free software, I’m guaranteed to be able to maintain a working system, but I still have to be willing to do all the work. There’s no panacea.

And on the pedestal these words appear:
`My name is Ozymandias, King of Kings:
Look on my works, ye mighty, and despair!’
Nothing beside remains.
– Shelley

1 I’m happy to report that today there seems to be new life in Intaglio. There are posts in their support forum, and new versions have been released.
2 Now, it looks like MediaPro’s been spun off from Microsoft again.


Page 1 of 41234