fogbound.net




Sun, 18 Oct 2015

Yii mystery on Mac

— SjG @ 3:07 pm

I upgraded the Mac to Yosemite a year or so ago. Yesterday, I wanted to do some development on a project that I’d been idly thinking about. Unfortunately, it required a dependency in a package I’d installed via Mac Ports. I tried to upgrade it, but got an error that I was compiling for the wrong Darwin version. This means I haven’t actually updated any of my Ports since upgrading to Yosemite! For shame.

Rather than fix Mac Ports for Yosemite, and then again when I upgrade to El Capitan, I decided it was time to do that upgrade and then fix it. I went through and did so, and upgraded all my ports, and it all seemed to go well. I went from PHP 5.3 to PHP 5.5, and MySQL from 5.1 to 5.5, and it went without a snag — the web server came up and my old configuration was good, databases same. Everything seemed sweet and easy!

Ha! Sweet and easy with software? Not so fast, buckeroo! Working on another project, I found that Yii was crashing — but only from the command line!
exception 'CDbException' with message 'CDbConnection failed to open the DB connection: could not find driver' in /Users/samuelg/project/unicorn_rainbows/framework/db/CDbConnection.php:399

I quickly through a page up with phpinfo(), and saw that all the usual suspects were valid:

  • I was running the PHP I thought I was (Mac Ports version 5.5, not the built-in Mac OS version)
  • It was using the php.ini file I thought it was (in /opt/local/etc/php55/)
  • PDO was installed
  • PDO’s MySQL driver was installed
  • PHP’s configured recognized the drivers
  • Paths to any config files were correct
  • Ports were all normal
  • Default path to MySQL socket file was correct

Of course, this all makes sense, because my web pages that access the database were working.

So why not from Yii’s console program from the command line?

A quick php -version revealed the problem. It wasn’t the database configuration at all! Well, not exactly.
samuelg$ php --version
PHP 5.6.14 (cli) (built: Oct 15 2015 16:20:41)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

Wait, what? PHP 5.6? But… how?

samuel$ port installed | grep php
...
php55-mysql @5.5.30_0+mysqlnd (active)
php55-sqlite @5.5.30_0 (active)
php56 @5.6.6_0+libedit
php56 @5.6.14_0+libedit (active)

Yup, somehow, I’d installed some PHP 5.6 packages as well!

To solve the problem quickly, I uninstalled PHP 5.6. I could have upgraded everything to 5.6 (or just inactivated them, I suppose), but I just wanted to work on my original problem, not spend my day on system configuration.


Tue, 29 Sep 2015

Doorbell

— SjG @ 9:14 pm

The Quagg Wedding Chapel has had a cheap wireless doorbell system, and over time the plastic case for the button itself got corroded and ugly.
db01

Aha! This looks like a good Saturday project!

So, I disassembled the plastic button to get at the actual circuit board. Then I selected some nice wood stock and measuring devices, and started designing.
db02Screen-Shot-2015-09-29-at-9.51

As mentioned before, my primary fabrication/making tool here is my Nomad 883 CNC device. I create my designs using Moment of Inspiration (MoI), convert them to GCode using MeshCAM, and carve them from wood, plastic, or metal with the Nomad.

First, I cut the heart-shaped button piece. This was cut from a piece of recovered Red Oak (the plank had spent some years being a wine barrel). As you can see, to prevent the cut-out piece from breaking free and rattling around before the surface was completely carved, I left some connector supports. They were cut away later.
db03
Next is the main body of the piece, cut from the lighter wood (I think it may be ash). This is a two-sided cut: the basic shape of the button holder is the one side, and the hollowed out interior with areas for the button and circuit board is the other. There are elaborate means that can be used to make a very precise two-sided cut (Carbide 3D sells their recommended “flip-jig”, which is accurate to around 1/100th of an inch, but I don’t have one). For this project, however, the alignment of the two sides only needed to be within a millimeter or two, so I did it mostly by eyeball.
db04
You can see there were two attempts here. The first time, I used an 0.0625″ ball cutter. The thin cut around the edge got clogged with chips, and skipped. The second attempt, I used an 0.125″ ball cutter and vacuumed a few times during the process.
Next, I flipped the piece, and did the hollowing cut. This used an 0.125″ end mill. I’m not positive I know what this lighter wood is — I set the carving parameters for as a soft wood, but I think perhaps I should have chosen hardwood. The feed-rate of the cut (the speed that the cutting bit moves) was a little too aggressive. Part of the way through the finishing phase, the cutter bound briefly and the servos skipped, resulting in an aborted cut. The carving was mostly complete and still usable, however. The damaged areas are on the inside of the hollowed pocket, so they aren’t visible when it’s all assembled. I figured it was good enough, and didn’t bother to redo the whole process.
db05
I sanded everything down a bit, and tested to see that the button portion had clearance. Yup! It works!
db07
db06
Now I separated the main object from the larger piece using an X-Acto knife. I smoothed the edges, and treated the pieces with polyurethane sealant. I slotted in the circuit board, and it all fit together nicely.
db08
Not shown are the screws and the mounting hardware that loops around the circuit board in the slots by the battery. I added that hardware, and, with a silent mental fanfare, I put it up!
db09
My final conclusion is that it’s kind of ugly, but in a much more homey/craftsy way than the corroded plastic it replaced. And hey! It works!


Wed, 29 Jul 2015

Selenium, PHPUnit, and TinyMCE

— SjG @ 8:40 am

Nearly two years ago, I wrote a quick note on how to switch iframes in PHPUnit/Selenium to populate an xhEditor text area.

Because we’re seeing a lot of formatted text cut/pasted from Microsoft Word, we needed to replace xhEditor with a WYSIWYG that does a better job of stripping out all of the horrible cruft that the Word formatting causes. TinyMCE seems to do a decent job (given the impossible nature of the requirements), but my test code no longer works.

Here’s how I got it working again. I added a function to my base WebTestCase:

protected function typeInTinyMCE($text,$field)
{
   $this->getEval("selenium.browserbot.getUserWindow()."+
      "tinyMCE.get('".$field."').setContent('".addslashes($text)."');");
}


Then, in any arbitrary functional test, I can type stuff into my TinyMCE field:

public function testWhatever()
{
   $this->login();
   $this->click("link=WYSIWYG Page");
   $this->waitForPageToLoad("30000");
   $this->typeInTinyMCE('Hey, I can put stuff into my WYSIWYG field!','field_id');
...
}


Wed, 22 Jul 2015

Error: Timeout – Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

— SjG @ 2:04 pm

No, this site’s not crashing. That’s the error message I was getting when running a Karma test of some Angular / JavaScript code.

The usual suspects (when Googling) is having an argument to your it function. But my it function had no argument.

However, my afterEach function *did* have an argument due to a typo. That was the culprit. If it’s not your it function, it could be your beforeEach or afterEach function. Either one will also cause the entire it function to run asynchronously.

As usual, this is likely obvious to everyone but me. I’m posting this in the off chance someone else has the same problem and is as dumb as I am 🙂


Mon, 29 Jun 2015

Failed Javascript Experiment, cont.

— SjG @ 4:38 pm

So I got a few questions about that Javascript experiment, so I thought I’d add some explanation. In the process, I added some features to it.

So what’re all those variables, I was asked. And what do they mean?

To start with, this whole experiment was based on a traditional Islamic tiling pattern. I don’t know the actual origin, but I’m sure it goes way back.

So, step 1, you tile a plane with equilateral triangles. The number of triangles that fit across our page is what I called “Spacing.”

exp-step1

Next, you draw a circle at each intersection of lines. The size of the circle is “Radius” — in this model, a radius of 100% means that the neighboring circles touch.

exp-step2

Last, you divide each circle into twelve equal pieces. Then, according to some predetermined pattern, you connect the points on neighboring circles. Here’s a traditional pattern:

exper-step3

The only other variables of interest are “Column Radius Growth” and “Row Radius Growth” which is the percentage by which the radius of each circle changes depending on the number of the column or row (starting in the upper left-hand corner).

This time around, I’ve added a few different connection patterns.