Archive for the ‘Tips’ Category.

All you need to know about unicode

Recently I stumbled about this great article about ASCII, 7 and 8 Bit, codepages, Multi byte, Wide byte and unicode: http://www.joelonsoftware.com/articles/Unicode.html

If you ever get in trouble with wrong encoding display of chars, give this article a try to know the backgrounds.

As you know, Windows CE and Windows MobileĀ  is always unicode except for serial and socket communication. But the truetype fonts available on Windows Mobile devices mostly support only common chars, there file size is about 600K. The file size of Arial Unicode MS is about 22MB.

regards

Windows Mobile: Disable Low Battery Warning

Although I dont recommend this, it may be usefull if your kiosk mode app watches and manages the battery level: you can disable the low battery warning. Sometimes such hacks are hard to find, now there is one more location in internet.

In the registry find the key

[HKEY_CURRENT_USER\ControlPanel\Notifications\{A877D663-239C-47a7-9304-0D347F580408}]

This is the entry responsible for low battery warnings

Add a new REG_SZ key: “Default” with for example the text “Low Battery Warning”

"Default"="Low Battery Warning"

This entry is used to display the notification in the list of notifications in Start-Settings-Sounds&Notifications. To disable the notification itself it is not really necessary, but easier to control.

The Options entry in the registry defines which options your selected in Start-Settings-Sounds&Notifications, for example play a sound or display a user notification. Set Options to REG_DWORD=0x00 and there will be no notification when the battery goes down to 10% (depends on the device) and lower.

Here is the change in full:

REGEDIT4
[HKEY_CURRENT_USER\ControlPanel\Notifications\{A877D663-239C-47a7-9304-0D347F580408}]
"Options"=dword:00000000
"Default"="LowBattWarning"

You need to reboot the device after the change!

Only a small tipp

WordPress backup fails

Help needed! [Edit: Partially solved, see bottom]

this site is hosted on a cheap hosting site like many others. Recently I tried a backup of the WP database and files without success. The backups stuck (do never finsih and hang at a file or table) or just reported “success” (EZPZ backup). I also tried the hosters PHPAdmin to backup the WP database without success, I got out of memory errors.

Finally the cause of all these strange results is a limitation of the hosting, it has a limit of 20MB per file. As most backup tools for wordpress and even PHPAdmin use temporary files on my host, the backup fails as soon as the limit is reached.

I was finally able to backup the WP database by excluding the larger tables from the backup. To get the table sizes I used the following php script:

Code:
<?php
$link = mysql_connect('xxxxxxx.strato.de', 'username', 'password');
$db_name = "databasename";
$tables = array();
$txtOut="";
mysql_select_db($db_name, $link);
$result = mysql_query("SHOW TABLE STATUS");

while($row = mysql_fetch_array($result)) {
    /* We return the size in Kilobytes */
    $total_size = ($row[ "Data_length" ] +
                   $row[ "Index_length" ]) / 1024;
    $tables[$row['Name']] = sprintf("%.2f", $total_size);
	$txtOut=$txtOut."<tr><td>".$row['Name']."</td><td align=\"right\">".$tables[$row['Name']]."</td></tr>";
}

echo "<h1>Database table sizes</h1>";
echo "<table border=\"1\">";
echo $txtOut;
echo "</table>";
//print_r($tables);
//var_dump($tables);
?>

The “success” failing backups may be related to a problem in php fwrite as described here. Excerpt:

====================================================
This means the example fwrite_stream() code  from the docs, as well as all the "helper" functions posted by others in  the comments are all broken. You *must* check for a return value of 0  and either abort immediately or track a maximum number of retries.

Below is the example from the docs. This code is BAD, as a broken pipe will result in fwrite() infinitely looping with a return value of 0. Since the loop only breaks if fwrite() returns false or successfully writes all bytes, an infinite loop will occur on failure.

<?php
// BROKEN function – infinite loop when fwrite() returns 0s
function fwrite_stream($fp, $string) {
for ($written = 0; $written < strlen($string); $written += $fwrite) {
$fwrite = fwrite($fp, substr($string, $written));
if ($fwrite === false) {
return $written;
}
}
return $written;
}
?>

====================================================

So, if your WP backups fail, check with your hoster about file size limitations. I found this out myself as the backup folder on the site showed backup files with exact same file size of 21MB.

Please leave a mail or comment if you know a WP backup solution thatĀ  use splitted files and handles maximum file size limitations.

And as last guess never trust a backup, always try a restore or at least check the backup files.

[Edit 1. march 2011]

Fortunately strato.de support gave a hint and led me to try MySqlDumper. This sql dumper is able to split files and works also with limitted file size on the host. I even got a perl script now that I can simply invoke and that backups the whole database. The uncompressed dump is about 52MB and MySqlDumper did backup it into a 6MB gzipped dump file.

The only wish left is to have it run periodically but that would need cronjob access on the hoster site and is not included with the package I own at the hoster.

So if you need to backup a large WordPress MySql database you may give MySqlDumper a try.

<?php

$link = mysql_connect(‘rdbms.strato.de’, ‘U402706’, ‘chopper’);

$db_name = “DB402706″;
$tables = array();

$txtOut=””;

mysql_select_db($db_name, $link);
$result = mysql_query(“SHOW TABLE STATUS”);

while($row = mysql_fetch_array($result)) {
/* We return the size in Kilobytes */
$total_size = ($row[ “Data_length” ] +
$row[ “Index_length” ]) / 1024;
$tables[$row[‘Name’]] = sprintf(“%.2f”, $total_size);
$txtOut=$txtOut.”<tr><td>”.$row[‘Name’].”</td><td align=\”right\”>”.$tables[$row[‘Name’]].”</td></tr>”;
}

$keynames=array_keys($tables);

echo “<h1>Database table sizes</h1>”;
echo “<table border=\”1\”>”;
echo $txtOut;
echo “</table>”;

//print_r($tables);
//var_dump($tables);

?>
<!–
$sql = ‘SELECT TABLE_SCHEMA AS \’Database\’, TABLE_NAME AS \’Table\’,’
. ‘ CONCAT(ROUND(((DATA_LENGTH + INDEX_LENGTH – DATA_FREE) / 1024 / 1024),2),” Mb”) AS Size FROM INFORMATION_SCHEMA.TABLES LIMIT 0, 60 ‘;
–>

Monodevelop: Howto add a WinForm project and file template

I am running MonoDevelop 2.4 on my acer aspire one x150 netbook running Ubuntu 9.04 (Jaunty).

From time to time I needed to write and run little test applications in C#. As I am alsos running another PC with Visual Studio 2005 and 2008, I like these for providing me a WinForm template, so I dont have to start from scratch.

Unfortunately MonoDevelop does not come with a WinForm template and I searched the internet on how to extend the templates provided by MonoDevelop to add a WinForm template. Although I found some resources on how to add templates to MonoDevelop, none of them worked as described.

Adding a template by using addins directory

Some sources state you can add templates by creating two files within the MonoDevelop home dir. For example adding HelloTemplate.xpt.xml and MyTemplates.addin.xml to “~/.config/MonoDevelop/addins”. I tried this approach, but it did not work as a WinForm project template.

Adding a template by using a packed template

Similar to the previous attempt but using mdtool to pack the files:
mdtool setup pack addins/addin.xml -d:addins
and
mdtool setup rep-build addins
where you finally get a mpack file with your xml template files. Unfortunately this did also not work for project templates.

Adding a template to the sources and recompile

As I already had the MonoDevelop sources as I have compiled and installed MonoDevelop 2.4 from sources, I looked for the existing templates and added my WinForm project and file template.

Screenshot Start New WinForm project

Screenshot Add New WinForm file

The source templates for CSharp are located on my netbook at: “/usr/local/src/monodevelop-2.4/src/addins/CSharpBinding/templates”. The Makefile references the template files in this directory. I had to add two template files to the directory and to the Makefile and the file CSharpBinding.add.xml. Then I did a make within the directory /usr/local/src/monodevelop-2.4/src/addins/CSharpBinding and then a “sudo make install” and finally got my WinForm project and file template available in MonoDevelop.

Continue reading ‘Monodevelop: Howto add a WinForm project and file template’ »