Page 10 of 56« First...89101112...2030...Last »

Wed, 13 Jun 2012

Building Direct IO library for PHP with Mac Ports

— SjG @ 11:47 am

Say you’re developing on a Mac, and want to test some PHP code that has calls to the direct IO library. You may not actually have a physical serial port, but your unit tests will fail in the wrong way if the library isn’t present. You want the unit tests to fail in the right way!

If you do the expected thing, you’ll find that dio is currently beta:

root# pecl install dio
Failed to download pecl/dio within preferred state "stable", latest release is version 0.0.5, stability "beta", use "channel://" to install
install failed

So you have to try to do it the hard way:

samuel:~ root# pecl install channel://
downloading dio-0.0.5.tgz ...

Easy-peasy, eh? Not so fast!

/private/tmp/pear/temp/dio/dio.c: In function 'zif_dio_fdopen':
/private/tmp/pear/temp/dio/dio.c:138: error: 'EBADFD' undeclared (first use in this function)
/private/tmp/pear/temp/dio/dio.c:138: error: (Each undeclared identifier is reported only once
/private/tmp/pear/temp/dio/dio.c:138: error: for each function it appears in.)
make: *** [dio.lo] Error 1
ERROR: `make' failed

Fortunately, via this bug report, we can see what to do:

# pecl download channel://
# tar xzvf dio-0.0.5.tgz
# cd dio-0.0.5
# phpize
# ./configure

Then edit dio.c, and change line 138 to:

if ((fcntl(fd, F_GETFL, 0) == -1) && (errno == EBADF)) {

Then, finish up:

# make
# make install

Then, create a file called “dio.ini” in /opt/local/var/db/php5/ containing:

Now you can run your tests!

Tue, 12 Jun 2012

Spelling Suggestions from Solr using Yii-solr

— SjG @ 7:48 pm

So a Yii app wants to query Solr using the Yii-solr extension, and wants to provide spelling suggestions for the provided search term. We need the suggestions to be unique, i.e., no repeated suggesttions, and we don’t want negative suggestions, i.e., if the user’s search wanted to exclude “foo”, we don’t want to suggest “foo” as a possible correction. There’s probably a better way to do all this, but I couldn’t figure it out. Here’s what I did instead (as always, forgive the code style/formatting):

I created a subclass of ASolrConnection that switches to using the “spell” Solr servlet:

class SolrSpellingConnection extends ASolrConnection {
public $servlet_type;
public $servlet_path;
public function resetClient()
if (isset($this->servlet_type) && isset($this->servlet_path))

This is instantiated in the app’s config file:

'solr' => array(

Then, my Solr query data-provider looks something like:

$criteria = new ASolrCriteria;
$criteria->query = $queryterm;
$dataprovider = new ASolrDataProvider(ASolrDocument::model(),array('criteria'=>$criteria,'pagination'=>$pages));
return $dataprovider;

In my controller, I add some code to process the suggestions:

public function buildSuggestionList($dataprovider, $originalQueryString)
$suggestions = array();
$terms = array();
if ($dataprovider != null)
$facets = $dataprovider->getQueryFacets();
$resp = $dataprovider->getSolrQueryResponse()->getSolrObject();
if (isset($resp['spellcheck']))
if (isset($resp['spellcheck']['suggestions']))
foreach ($resp['spellcheck']['suggestions'] as $thisSuggest)
if (is_object($thisSuggest) && get_class($thisSuggest) == 'SolrObject')
if (isset($thisSuggest['suggestion']) && is_array($thisSuggest['suggestion']))
foreach($thisSuggest['suggestion'] as $thisTerm)
foreach($terms as $termKey=>$val)
// Solr adds negated or added terms to suggestions if they don't match case
if (!preg_match('/\b'.$termKey.'\b/i',$originalQueryString))
$suggestions[] = CHtml::link($termKey,'/index.php/mysearchcontroller?q='.urlencode($termKey));
return $suggestions;

I can then display the main collection of results using a CWidget. For displaying suggestions, however, a bit of specific code is required:

$suggestions = $this->buildSuggestionList($dataprovider, $originalQueryString);
if (count($suggestions) > 0)
echo '<p>Did you mean '.implode(' or ',$suggestions).'?</p>';

When this is all in place, you should get decent suggestions from Solr. Of course, you will need to have Solr build a spelling index! The easiest way to do that is simply connect to Solr’s web interface and tell it to build the index:


Sun, 6 May 2012

My Fan Club

— SjG @ 3:20 pm

So the server that operates the security cameras at the house suddenly started making a nasty wheezy noise. The periodicity of the noise suggested a fan bearing going bad or running dry.

So I shut the machine down, and tore it apart. I disassembled and lubed the case- and power-supply fans. I put everything back together and fired up the machine, but the noise was still there. I tried to remove the CPU heat-sink fan, but it’s held in by plastic snappers, and I didn’t want to fight with them. In the end, I went on e-Bay and ordered replacement case- and power supply fans, along with a new CPU heat-sink / fan assembly.

The new stuff arrived Thursday, and I swapped out the old stuff. Then reassembled. The noise was still there. I started pulling my hair out.

Today, I was going to solve it, or die trying. I unplugged the hard drive and the CD drive. Still made the noise. I unplugged the case fan. Still made the noise. I unplugged the CPU heat-sink fan. Still made the noise. I physically moved the power supply away, while powering the chassis. At this point, there are no moving parts whatsoever within the chassis. Still noisy!

When I finally stopped punching the wall and kicking the cat, I leaned my head into the machine, and tried to find the source of the noise. And there it was. The crappy little graphics card’s heat sink has a fan in it, completely obscured from view. I pulled the card, tore it apart, and lubed the fan, and now, finally, the machine runs silently again.

I think if I ever rebuild the thing, it’s going to be 100% solid state.

Filed in:

Mon, 12 Mar 2012

Royal Flutter

— SjG @ 10:49 am

Well, now, over the weekend was the 10,0000th download of our Royal Flutter font from (the original distribution site). Of course, any free font distributed on is copied and distributed through dozens of other sites such as MaxFonts, FontRiver, FFonts, Fonts2U, WebToolHub, and more.

I wonder what percentage of the downloaders actually use the font. I know there are plenty of font collectors out there. It can be addictive, looking at all the type faces, and thinking “yes! I could use that some day!”

Work progresses on a new (commercial) font which will likely be called Lunatrix. It’s a techno/space font, and will be available in five weights. Something more for the collections!

Sat, 25 Feb 2012

Bad Business

— SjG @ 9:48 am

Now, I don’t shop at Target stores any more because they give campaign money to candidates who have regressive social agendas. However, being a realist, I know that it’s not always possible to live in modern society and remain pure to ideals. Instead of buying clothes at Target, I could buy them at Amazon, for example, but they have their own labor issues. So, despite my ethical concerns, I visited the Target web site.

Access Denied!
Are you f'n serious???

Yep. That’s right. They won’t even let you look at their site unless you accept their evil tracking cookies.
I guess it goes without saying that they failed to win me back.

(P.S. If you’re not running Ghostery, or the equivalent, you should be.)

Page 10 of 56« First...89101112...2030...Last »