An Experiment In Web Fonts

DeltaNova might look a little different from today. I have changed the font of the site to something I think is a little easier to read. I am using one of Google's Web Fonts, meaning a font downloaded during the page loading, rather than using the font on your hard disk. Why do this? The main reason is that not all fonts are available on all devices. This was easy to cater for when most people accessed the web with a desktop or laptop with known default fonts, but more people are accessing from varying mobile devices. Using a Web Font will allow me to style the site as I intend it to look without caring what fonts the end user has access to.

So currently I am thinking of sticking with this font. However I have found a small issue. Whilst the site displays correctly on IE & Firefox (Win&Linux) on the desktop I am having mixed results with Chrome on my Nexus 7. The N7 will display correctly in landscape mode but for some reason, portrait mode causes some of the fonts to revert to the fall-back font. I'm left scratching my head on this one but I may need to consider designing a dedicated mobile version of the site.

Fedora 17 – Sluggish Firefox

The upgrade to Fedora 17 on my main system had gone well with no significant issues aside from one. When trying to start Firefox with multiple tabs loading it would hang locking the browser up. After trying the DNS problem route to upgrade problems etc. I finally traced the problem. The Flash plugin was out of date and the older version was being caught by the system as the log files outline. Upgrading the Flash plugin solved the problem and everything is back to normal.

Visit to check if your plugins need to be updated.

The Rat Saga Continues

My recent posts have been detailing my war with the local rodent population. The battle has moved from the kitchen into the loft in recent weeks. During the loft insulation project several large holes were sealed trapping the enemy in the loft, numbers unknown. A clean kill and subsequent silence on the front lead me to believe a victory had been achieved. A scouting mission today showed the bait had been taken and my foe had gone to ground avoiding detection. Cut off from its usual supply line it had taken the tainted food cache. I can't see my enemy but they are there. The signs of droppings not present before are an indicator of the restriction in their movements. The trap has been set, it is only a matter of time before their desperation leads to their downfall.

Fixed: Fedora 16 Printing

During my upgrade from Fedora 15 to 16 several things broke, this is nothing new there were alot of major graphical components updated. Those issues were resolved in the week following the F16 release. What I had not expected to break was my network printing setup. In all the years I used Gentoo and upgraded over and over I never had many issues and when I did it was usually my fault.

This time nothing much was apparent aside from printing not working on either the host or client machines. First point of failure was the lack of a running CUPS service on each machine. Ok, so it was stopped during the upgrade and not restarted, annoying but not the end of the world. Still no joy. In the end I found I my previously set sharing settings had changed. With all the other changes in config files being highlighted allowing for manual updates this had slipped through the net. Sharing my printer again in the settings and bingo, everything works as before and auto detects. It has only taken a few minutes of fiddling around to fix but it has been finding those few minutes and being in the right mood to fix it. Hopefully the next upgrade will go a little more smoothly.

Fedora 15 – Initial Thoughts

I took the plunge a few days ago and updated my machines to Fedora 15. The results have been mixed. My netbook and laptop were the first to be upgrades with Intel and Nvidia graphics respectively. Both upgraded fine and the Gnome 3 experience was ok, if a little strange. The problems started with my server with an AMD/ATI graphics. The screen was tearing in places and the smooth experience I was getting on the netbook and laptop had been lost. I still have not fully resolved this problem and it proving difficult to use gnome 3 without it.

The one thing I am finding an issue with in Gnome 3 is the change in panel functionality. I previously minimised some applications like my RSS client to run as a minimised icon. Whilst there is a sort of similar function present I think apps need to be updated to take advantage of it.

Another problem presented itself in the form of a reboot leading to the a message saying the lan cable was unplugged. Rebooting again didn't solve the issue. I had to shut the machine down completely and cold boot before the network stated working again. At least one problem is solved. I will review again once a few more bugs are fixed.

The Rodent Confusion

For the past few weeks I have been having some performance glitches with the way my mouse interacts with my Linux machine. The mouse would move and the buttons operate normally except for when trying to press and hold the left button for example. The action would appear to terminate after a few seconds and reinitialise. This behaviour was making it impossible to move windowed applications around the desktop. Today however I have solved the problem, which is good from the point of view that it solves the issue and also it means I don't have to spend the next 48hrs recompiling Gentoo and all my applications.

The fix is a simple one. x11-drivers/xf86-input-evdev-2.3.2 was causing the problem, x11-drivers/xf86-input-evdev-2.4.0 solves the problem but is marked as unstable at time of writing. The upgrade from xorg-server-1.6.5-r1 to xorg-server-1.7.6 seems to have been the reason the evdev driver wasn't working as expected, possibly handing the input devices slightly differently from the previous version.

I can happily say the rodent has ceased to be confused.

Plugin Enhancement

My previous modification to the CodeColorer syntax highlighting plugin for WordPress has been integrated into the official 0.9.8 release. I received a request to enhance the modification furthur. Instead of having a long comma separated list of individual line numbers to be highlighted it would be beneficial if ranges of numbers could be specified. I spent a few hours today playing about with PHP again and I have the following solution. The lines are highlighted using [cc lang="php" highlight="161-180"] rather than listing individual line numbers. You can specify a list of comma separated line numbers, number ranges or a combination of both.

codecolorer-core.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<?php
/*
CodeColorer plugin core part
http://kpumuk.info/projects/wordpress-plugins/codecolorer
*/
/*
    Copyright 2006 - 2010  Dmytro Shteflyuk <kpumuk@kpumuk.info>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

class CodeColorer {
  var $blocks = array();
  var $comments = array();

  var $geshiExternal = false;
  var $geshiVersion = '1.0.8.6';

  var $samplePhpCode = '
   [cc_php]
   /**
    * Comment
    */
   function hello() {
     echo "Hello!";
     return null;
   }
   exit();
   [/cc_php]
 ';

  /** Search content for code tags and replace it */
  function BeforeHighlightCodeBlock($content) {
    $content = preg_replace('#(\s*)\[cc([^\s\]_]*(?:_[^\s\]]*)?)([^\]]*)\](.*?)\[/cc\2\](\s*)#sie', '$this->PerformHighlightCodeBlock(\'\\4\', \'\\3\', $content, \'\\2\', \'\\1\', \'\\5\');', $content);
    $content = preg_replace('#(\s*)\<code (.*?)\>(.*?)\</code>(\s*)#sie', '$this->PerformHighlightCodeBlock(\'\\3\', \'\\2\', $content, \'\', \'\\1\', \'\\4\');', $content);

    return $content;
  }

  function AfterHighlightCodeBlock($content) {
    $content = str_replace(array_keys($this->blocks), array_values($this->blocks), $content);

    return $content;
  }

  function BeforeProtectComment($content) {
    $content = preg_replace('#(\s*)(\[cc[^\s\]_]*(?:_[^\s\]]*)?[^\]]*\].*?\[/cc\1\])(\s*)#sie', '$this->PerformProtectComment(\'\\2\', $content, \'\\1\', \'\\3\');', $content);
    $content = preg_replace('#(\s*)(\<code .*?\>.*?\</code>)(\s*)#sie', '$this->PerformProtectComment(\'\\2\', $content, \'\\1\', \'\\3\');', $content);

    return $content;
  }

  function AfterProtectComment($content) {
    $content = str_replace(array_keys($this->comments), array_values($this->comments), $content);
    $this->comments = array();

    return $content;
  }

  /**
   * Perform code highlightning
   */
  function PerformHighlightCodeBlock($text, $opts, $content, $suffix = '', $before = '', $after = '') {
    // Preprocess source text
    $text = str_replace(array("\\"", "\\'"), array (""", "\'"), $text);
   $text = preg_replace('/(< \?php)/i', '<?php', $text);
   $text = preg_replace('/(?:^(?:\s*[\r\n])+|\s+$)/', '', $text);

   // Parse options
   $options = CodeColorerOptions::ParseOptions($opts, $suffix);

   if ($options['escaped']) {
     $text = html_entity_decode($text, ENT_QUOTES);
     $text = preg_replace('~&#x0*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $text);
     $text = preg_replace('~&#0*([0-9]+);~e', 'chr(\\1)', $text);
    }

    $result = '';
    // Check if CodeColorer has been disabled for this particular block
    if (!$options['enabled']) {
      $result = '<code>' . $text . '';
    } else {
      // See if we should force a height
      $num_lines = count(explode("\n", $text));

      $result = $this->PerformHighlightGeshi($text, $options);

      $result = $this->AddContainer($result, $options, $num_lines);
    }

    if ($options['inline']) {
      $blockID = $this->GetBlockID($content, false, '<span>', '</span>');
    } else {
      $blockID = $this->GetBlockID($content);
    }
    $this->blocks[$blockID] = $result;

    if ($options['inline']) {
      $result = $before . $blockID . $after;
    } else {
      $result = "\n\n$blockID\n\n";
    }

    return $result;
  }

  /**
   * Perform code protecting from mangling by Wordpress (used in Comments)
   */
  function PerformProtectComment($text, $content, $before, $after) {
    $text = str_replace(array("\\"", "\\'"), array (""", "\'"), $text);

   $blockID = $this->GetBlockID($content, true, '', '');
   $this->comments[$blockID] = $text;

   return $before . $blockID . $after;
 }

 /**
  * Perform code highlighting using GESHi engine
  */
 function PerformHighlightGeshi($content, $options) {
   /* Geshi configuration */
   if (!$this->geshi) {
     $this->geshi = new GeSHi();
     $this->geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS, 1);
     if (is_feed()) {
       $this->geshi->set_overall_style('padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap');
     }
   }

   $geshi = $this->geshi;
   $geshi->set_source($content);
   $geshi->set_language($options['lang']);
   $geshi->set_overall_class('codecolorer');
   $geshi->set_tab_width($options['tab_size']);
   if (!is_feed()) {
     $geshi->enable_classes($options['theme'] != 'geshi');
     if ($options['nowrap']) {
       $geshi->set_overall_style('white-space:nowrap');
     } else {
       $geshi->set_overall_style('');
     }
   } else {
     $geshi->enable_classes(false);
   }
   if (!is_null($options['strict'])) $geshi->enable_strict_mode($options['strict']);
   if ($options['no_links']) $geshi->enable_keyword_links(false);
   /* Modification */    
    if ($options['highlight']){
       $hlines = explode(',',$options['highlight']);
       $b = array(); /* Empty array to store processed line numbers*/
       foreach($hlines as $v) {
           if (strstr($v,"-")) {
               $c = explode("-",$v);

               for ($i=$c[0]; $i< =$c[1]; $i++) {
                   array_push($b,$i);
               }
           }else{
               array_push($b,$v);
           }
       }
       sort($b); /* Sort the array in ascending numerical order */      
       $geshi->highlight_lines_extra($b);
       $geshi->set_highlight_lines_extra_style('background-color: #ffff66;');
   }
    /* End Modification */



    if ($options['inline']) {
      $geshi->set_header_type(GESHI_HEADER_NONE);
    } else {
      $geshi->set_header_type(GESHI_HEADER_DIV);
    }

    $result = $geshi->parse_code();

    if ($geshi->error()) {
      return $geshi->error();
    }

    if ($options['line_numbers'] && !$options['inline']) {
      $table = '<table cellspacing="0" cellpadding="0"><tbody><tr><td ';
      if (is_feed()) {
        $table .= 'style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"';
      } else {
        $table .= 'class="line-numbers"';
      }
      $table .= '><div>';
      for ($i = 0, $count = substr_count($result, '<br />') + 1; $i < $count; $i++) {
        $table .= ($i + $options['first_line']) . '<br />';
      }
      $result = $table . '</div></td><td>' . $result . '</td></tr></tbody></table>';
    }

    return $result;
  }

  function AddContainer($html, $options, $num_lines) {
    $custom_css_class = empty($options['class']) ? '' : ' ' . $options['class'];
    if ($options['inline']) {
      $theme = empty($options['inline_theme']) ? 'default' : $options['inline_theme'];
      $result  = '<code class="codecolorer ' . $options['lang'] . ' ' . $theme . $custom_css_class . '">';
      $result .= '<span class="' . $options['lang'] . '">' . $html . '</span>';
      $result .= '</code>';
    } else {
      $theme = empty($options['theme']) ? 'default' : $options['theme'];
      $style = 'style="';
      if ($options['nowrap']) $style .= 'overflow:auto;white-space:nowrap;';
      if (is_feed()) $style .= 'border:1px solid #9F9F9F;';
      $style .= $this->GetDimensionRule('width', is_feed() ? $options['rss_width'] : $options['width']);
      if($num_lines > $options['lines'] && $options['lines'] > 0) {
        $style .= $this->GetDimensionRule('height', $options['height']);
      }
      $style .= '"';

      $css_class = 'codecolorer-container ' . $options['lang'] . ' ' . $theme . $custom_css_class;
      if ($options['noborder']) $css_class .= ' codecolorer-noborder';
      $result = '<div class="' . $css_class . '" ' . $style . '>' . $html . '</div>';
    }
    return $result;
  }

  /**
   * Generate a block ID that will be replaced at the end (after all that
   * crazy WP text work!) with the right code
   */
  function GetBlockID($content, $comment = false, $before = '<div>', $after = '</div>') {
    static $num = 0;

    $block = $comment ? 'COMMENT' : 'BLOCK';
    $before = $before . '::CODECOLORER_' . $block . '_';
    $after = '::' . $after;

    // Just do a check to make sure the user
    // hasn't (however unlikely) input block replacements
    // as legit text
    do {
      ++$num;
      $blockID = $before . $num . $after;
    } while (strpos($content, $blockID) !== false);

    return $blockID;
  }

  function GetDimensionRule($dimension, $value) {
    $rule = '';
    if (!empty($value)) $rule = "$dimension:$value" . (is_numeric($value) ? 'px;' : ';');
    return $rule;
  }

  function ShowWarning($type, $title, $message) {
    $disable = ' <a href="options-general.php?page=codecolorer.php&amp;disable=' . $type . '">' . __('Close', 'codecolorer') . '</a>';
    echo '<div id="codecolorer-' . $type . '" class="updated fade"><p><strong>' . $title . "</strong> " . $message . $disable . "</p></div>\n";
  }

  function ShowGeshiWarning() {
    if ($this->geshiExternal) {
      $this->ShowWarning('concurrent', __('CodeColorer has detected a problem.', 'codecolorer'), sprintf(__('We found another plugin based on GeSHi library in your system. CodeColorer will work, but our version of GeSHi contain some patches, so we can\'t guarantee an ideal code highlighting now. Please review your <a href="%1$s">plugins</a>, maybe you don\'t need them all.', 'codecolorer'), "plugins.php"));
    }
  }

  function ShowOptionsPage() {
    $page = $this->GetOptionsPage();
    $page->Show();
  }

  function GetOptionsPage() {
    if (!$this->optionsPage) {
      if (!class_exists('CodeColorerAdmin')) {
        $path = dirname(__FILE__);
        if (!file_exists("$path/codecolorer-admin.php")) return false;
        require_once("$path/codecolorer-admin.php");
      }
      $this->optionsPage = new CodeColorerAdmin($this);
    }
    return $this->optionsPage;
  }

  function GetCodeHighlighted($code) {
    $content = $this->BeforeHighlightCodeBlock($code);
    return $this->AfterHighlightCodeBlock($content);
  }

  function GetSampleCodeHighlighted() {
    return $this->GetCodeHighlighted($this->samplePhpCode);
  }

  function &GetInstance() {
    static $instance = null;

    if (null === $instance) {
      $path = dirname(__FILE__);
      if (!class_exists('CodeColorerOptions')) {
        if (!file_exists("$path/codecolorer-options.php")) return null;
        require_once("$path/codecolorer-options.php");
      }

      $instance = new CodeColorer();

      # Maybe GeSHi has been loaded by some another plugin?
     if (!class_exists('GeSHi')) {
        if (!file_exists("$path/lib/geshi.php")) return null;
        require_once("$path/lib/geshi.php");
      } else {
        $instance->geshiExternal = true;
      }
    }

    return $instance;
  }
}

Site Maintainance

Yesterday I finally completed my modifications to the current version of the site theme. Ever since I modified the date formatting the look had been inconsistent with some page layouts breaking. Hopefully all should be working again. Time to get back to making some worthwhile content.

November Update

As usual it has taken me until the end of the month to get round to posting something. Normally this is just an update of the mail server saga or something about a site update. Not wanting to miss out such information that will follow. More interesting news is that I am changing my job, moving from a Field Engineer covering the entire country to something a little more localised. It should mean that I have a bit more of a life outside work; about time too.

Now the mail server is still working and I need to keep working on it to ensure stability and security but its mostly running itself. The website as a whole needs a few tweaks, the design is looking a little old. I am thinking of moving to a darker theme. Currently viewing the site in a darkened room on a 24" monitor is quite blinding. Something less intense and more readable is in order.

Since I am on holiday this week I may get some changes rolled out sooner rather than later.

Mailserver Project – October Update

The mailserver project which I have been working on for many months now is getting to the point where it will soon be taking over the role of hosting all my email. No problems have been discovered over the past month and my upgrade script to regenerate the security certificates worked perfectly. A recent update to Dovecot, the IMAP system, means that a little more testing is in order due to modifications made to the config files.

When I finally release my documentation for the process it will outline the working setup at that time. No point in releasing something out of date.