Archive for the ‘computing’ Category

cannot read watchtower on ubuntu 10.04

Sunday, August 8th, 2010

Watchtower worked great on ubuntu 8.04, but after my update to 10.04, we can no longer read anything. All characters have been replaced by empty squares.

The reason for this is that msttcorefonts package is no longer available. It has been replaced  by ttf-mscorefonts-installer.

The solution is simply to install this package: sudo apt-get install ttf-mscorefonts-installer

Restart watchtower, it should know be displayed properly.

change your language of windows vista / 7 without upgrading to Ultimate

Saturday, May 1st, 2010

We just bought a brand new computer with windows 7 on it, and once at home, we tried to change the language because although living in the country where we bought it, our native language is not the one that was on the computer.

Guess what, if you want to change the language that your windows speaks, well you have to spend 190 euros!!!!
You cannot do it without having windows ultimate, and when you buy a new computer you don’t have any choice and just have windows premium or equivalent. Now you have to upgrade just to change OS language, simply because some crazy people at Microsoft tried to  earn quick and cheap money stating that changing your OS language is equivalent to being a new user so that you have to buy another windows licence!!!

Simply pure non-sense and commercial-driven thinking.
All the more when you consider that windows 7 is merely a service pack of vista and you should not have to pay for it.

Well anyway, by chance, there are some skilled people in town that tries to make this world fairer. And thanks to them you don’t have to pay microsoft their crazily overpriced language-fee, use tools and instructions described on this website: http://www.froggie.sk

It worked for me pretty well.

High 5 to froggie!

ps: due to a windows bug (well done crofties…), I had to move downloaded MUI file to another location (desktop) prior to loading it through Vistalizator

sources

ip phone thomson st2022 frozen on “loading” with empty circles

Tuesday, December 8th, 2009

After several electricity cuts, my voip phone (thomson st2022) hung on “Loading” with empty circles and with the 3rd bottom at the bottom of the phone turned on with a green light, and did not go any further. I tried rebooting it several times, but each time it hung on “Loading” after no more than 5 seconds. I left it that way an entire day, nothing changed.

It was not a problem of ip-address nor internet access, the boot process did not even go up to these steps. I contacted my service provider and they answered with a solution that actually worked for me pretty well!

To force a hard reboot of your thomson st2022 voip phone, do as follow:

  1. power off the device
  2. power it on & keep pressing down both the speaker button (green) and silence bottom (above it, red) during the entire boot process
  3. wait until your phone successfully rebooted (you should be able to access the admin menu on your phone right now)

That’s it!

acer aspire 2930 – dead touchpad [solved]

Sunday, June 14th, 2009

When I bought my acer aspire 2930 (great computer by the way), touchpad went dead after two weeks of usage, for no reasons.

It did not work on windows, neither on linux and driver updates did not change anything.

At first I thought it was simply dead (broken connector or something) and I believed it during 6 months, until I recently flashed my bios (for another reason) with latest available version (1.1 to 1.7) and miraculously it worked again!

=> if you have an acer aspire 2930 with a dead touchpad, try flashing your bios!

links

MySQL: increment a field within sql query

Friday, March 13th, 2009

If you need to increment a field by a number, you may not need to retrieve your row, update it in your programming language and then saving back into db.

Instead, simply update it with your sql query.

Let’s say we want to track number of downloads of a file, such query would be:

UPDATE `downloads` SET nb_downloads = nb_downloads + 1 WHERE download_id = <download_id>

sources

PHP SimpleXMLElement::xpath() returns boolean false

Saturday, February 28th, 2009

PHP (5.2.6) SimpleXMLElement is supposed to return an array, well that’s not always the case.

Sometimes it simply returns boolean false even if your xpath query is correct.
=> make sure to check returned value prior to looping on it!

Example:

<?php
$string = <<<XML
<a>
<b>
<c>text</c>
<c>stuff</c>
</b>
<d>
<c>code</c>
</d>
</a>
XML;

$xml = new SimpleXMLElement($string);

/* Search for non-existing path WITHOUT specifying namespace */
$result = $xml->xpath('//x/y');
var_dump($result); // array(0) {}

/* Search for non-existing path SPECIFYING namespace */
$xml->registerXPathNamespace('default', 'foo');
$result = $xml->xpath('//default:x/default:y');
var_dump($result); // bool(false)

sources

Put files/folders out of svn revisionning

Thursday, February 5th, 2009

WARNING: below information work for data that is not yet under versionning control (ie. that appears with ‘?’ prefix when running ‘svn status’)

Unfortunately it looks like it’s not possible to ignore a file that’s already under versionning => move its content into a file that won’t get modified, unversion your file and flag it to be ignored as explained below.

If you have some file or folders that you do not want svn to track them, you need to set “ignore” property as explained below.

Let’s say we have the following structure:

  1. go to parent folder of the item you want to be ignored (cd /myproject)
  2. run ‘svn propedit svn:ignore <parent_folder_name>’
  3. your favorite text editor is automatically open, simply list here all file/folder names that are in your parent_folder and that you want to be ignored by svn, separate them with a new line feed
    for example, to ignore all file/folders starting with tmp_, write “tmp_*”
  4. save your list of file/folder names to be ignored
    svn should print something like: “Set new value for property ‘svn:ignore’ on ‘<parent_folder_name>’”
  5. That’s it!

To view your changes, if you run “svn status”, your files should no longer be visible.
To make them appear, run “svn status –no-ignore”, your files should now be visible with an “I” flag.

note: I ran into the following svn error: “File or directory ‘XXX’ is out of date; try updating svn: The version resource does not correspond to the resource within the transaction”.
As stated within error msg, a simple “svn update” on that folder solved the issue

sources

PHP bug with __set() magic method on recursive call

Monday, January 26th, 2009

I found the following php bug while using Zend Framework:

If you recursively set a non-existing property to an object (which should call __set() magic method), instead of throwing an error, PHP simply no longer call __set() magic method and simply create a real property on your instance!

Example:

class Fruits{
  protected $_props = array(); // inner array mapping properties to values

  public function __set($name, $value)  {
    $this->_props[$name] = $value;
    if ('apple' == $name) {
      $this->apple = 'green';
    }
  }
}

$a = new Fruits();
$a->banana = 'yellow';
var_dump(property_exists($a, 'banana')); // output: 'false' as expected
$a->apple = 'red';
var_dump(property_exists($a, 'apple')); // output: 'true'!

As highlighted in above example, instead of throwing a recursivity error, PHP has created ‘apple’ property on the instance. If you try then to update $a->apple, magic method __set() is no longer called since the property do exist! (which is very very annoying).

Here is the link to corresponding php bug ticket: http://bugs.php.net/47215

**************************************
*                            UPDATE                     *
**************************************

After all I think it may not be a bug but expected behaviour, otherwise we could not be able to define object properties from within __set() method.

PHP: array_flatten function

Wednesday, January 21st, 2009

I looked for an array_flatten in PHP but did not find any.

Basically flattening an array is merging it with all its values that are themselves array (and so on, recursively) so that you end up with a single array of dimension one containing all values, including those within nested arrays.

As statted above, unfortunately I did not find such native function in php, here is the one I wrote:

<?php
/**
 * Flatten an array so that resulting array is of depth 1.
 * If any value is an array itself, it is merged by parent array, and so on.
 *
 * @param array $array
 * @param bool $preserver_keys OPTIONAL When true, keys are preserved when mergin nested arrays  (=> values with same key get overwritten)
 * @return array
 */
function array_flatten($array, $preserve_keys = false)
{
  if (!$preserve_keys) {
    // ensure keys are numeric values to avoid overwritting when array_merge gets called
    $array = array_values($array);
  }

  $flattened_array = array();
  foreach ($array as $k => $v) {
    if (is_array($v)) {
      $flattened_array = array_merge($flattened_array, call_user_func(__FUNCTION__, $v, $preserve_keys));
    } elseif ($preserve_keys) {
      $flattened_array[$k] = $v;
    } else {
      $flattened_array[] = $v;
    }
  }
  return $flattened_array;
}

// example
$a = array ('k1' => 'a', 'k2' => array('k1' => 'b', 'k4' => array('k3' => 'c')));
var_export(array_flatten($a)); // output: array(0 => 'a', 1 => 'b', 2 => 'c')
var_export(array_flatten($a, true)); // output: array('k1' => 'b', 'k3' => 'c') // first 'k1' value is overwritten by nested array
?>

sources

How top print ‘%’ with printf / sprintf functions?

Thursday, January 15th, 2009

To print ‘%’ with printf and sprintf functions, you simply need to escape your ‘%’ not with a backslash ‘\’ but rather with another ‘%’ sign.

Example:

printf('%%%s%%', 'koko'); #output: '%koko%'

sources