1   Resetting JavaScript RegExp [2010-05-25]

I tried to re-use regular expression in my script, but I couldnt find a way to reset their state. Now, I have it:

var RE = new RegExp('blah blah blah', 'gi');
for (idx in tests) {
  RE.lastIndex = 0; // reset
  if RE.test(tests[idx])
    console.log(tests[idx]);
  }

But I do some test:

n_re = 100;
var re_strs = [];
for (var i=0; i<n_re; i++)
  re_strs.push("(([a-zA-Z][a-zA-Z0-9+\\-.]*):)(//((([a-zA-Z0-9\\-._~%!$&\\'()*+,;=:]+))?([a-zA-Z0-9\\-._~%!$&\\'()*+,;]+)(:(\\d+))?))?([/a-zA-Z0-9\\-._~%!$&\\'()*+,;=:]*)(\\?([/a-zA-Z0-9\\-._~%!$&\\'()*+,;=:?]*))?(#([/a-zA-Z0-9\\-._~%!$&\\'()*+,;=:?]*))?");
console.log('Number of re:', n_re);

n_test = 100;
var test_urls = [];
for (var j=0; j<n_test; j++)
  test_urls.push('http://example.com/');
console.log('Number of url:', n_test);
console.log('Number of total test:', n_re * n_test);

console.time('no precompilation');
for (var i in re_strs) {
  for (var j in test_urls) {
    var re = new RegExp(re_strs[i], 'gi');
    re.test(test_urls[j]);
    }
  }
console.timeEnd('no precompilation');

console.time('precompilation');
console.time('precompilation: compilation time');
var res = [];
for (var i in re_strs)
  res.push(new RegExp(re_strs[i], 'gi'));
console.timeEnd('precompilation: compilation time');
for (var i in re_strs) {
  for (var j in test_urls) {
    res[i].lastIndex = 0;
    res[i].test(test_urls[j]);
    }
  }
console.timeEnd('precompilation');
Number of re: 100
Number of url: 100
Number of total test: 10000
no precompilation: 1271ms
precompilation: compilation time: 3ms
precompilation: 20ms

Its not really worth precompiling if you dont have huge amount of tests in a short time.

2   Google Groups Picture [2010-05-25]

The background transparency issue of group picture, I always got the picture with white background even I was sure the original image was with transparent background. I had a group picture with transparency but others (made with GIMP) are not. Then, I recalled that special one was created with Inkscape, so I imported the others picture and exported from Inkscape, that worked.

I used identify -verbose (from ImageMagick) to figure out whats the differences. Here is the diff:

--- logo_solid.txt      2010-05-25 01:54:14.000000000 +0800
+++ logo_trans.txt      2010-05-25 01:54:01.000000000 +0800
 -33,15 +33,9 
       2400: (  0,  0,  0,255) #000000 black
        200: (  0,  0,  0,127) #0000007F rgba(0,0,0,0.498039)
       3800: (255,255,255,  0) #FFFFFF00 rgba(255,255,255,0)
-  Rendering intent: Saturation
-  Gamma: 0.45455
-  Chromaticity:
-    red primary: (0.64,0.33)
-    green primary: (0.3,0.6)
-    blue primary: (0.15,0.06)
-    white point: (0.3127,0.329)
+  Rendering intent: Undefined
   Interlace: None
-  Background color: rgba(1,1,1,1)
+  Background color: white
   Border color: rgba(223,223,223,1)
   Matte color: grey74
   Transparent color: none

After a few tries in GIMP save dialog, I found out the problem was with Save Background Color, uncheck resolved the issue. Here is the new diff:

--- logo_solid.txt      2010-05-25 01:54:14.000000000 +0800
+++ logo_solid_fix.txt  2010-05-25 02:16:28.000000000 +0800
 -41,7 +41,7 
     blue primary: (0.15,0.06)
     white point: (0.3127,0.329)
   Interlace: None
-  Background color: rgba(1,1,1,1)
+  Background color: white
   Border color: rgba(223,223,223,1)
   Matte color: grey74
   Transparent color: none

The change was on Background color from rgba(1, 1, 1, 1) to white, I didnt understand how this could resolve the issue, but I am not complaining.

3   Emerging sys-fs/encfs [2010-05-26]

I got building error about Boost, this comment saved me. I had two Boost versions:

% eselect boost list
Available boost versions:
  [1]   boost-1.35/default
  [2]   boost-1.41/default *

After unemerged Boost 1.35, EncFS emerged successfully. I installed it for this.

4   Synaptics Touchpad button only mode

My external mouses left button has been killing me for a while, it likes to think I want to double click most of time. I dont have battery to power up another Bluetooh mouse, and wired mouse works really better. So I think why not to use the buttons on touchpad, but the problem is I can find a simple way to disable the sensing area. Finally, I came up with a trick:

synclient MaxSpeed=0
# Also need to disable all scrolls, e.g.
synclient VertTwoFingerScroll=0 HorizTwoFingerScroll=0

You can still keep those scrolling methods, they are more easier to use than mousewheel to me.