Frontwalker Sundsvall

Jag har glömt att berätta om att jag bytt jobb för jag arbetar numera för Frontwalker Sundsvall.

Företagets namn var tidigare det mer välkända.

Jag ska försöka att blogga lite mer nu då jag jobbar med riktigt rolig ny teknik på jobbet. Jobbar för tillfället med det senaste inom webb, Java och .NET. Får man ha så roligt på jobbet? Ja det får man om man har en bra arbetsgivare! Så håll utkik efter nya inlägg.

MySQL server has gone away

One day I suddenly got the ”MySQL server has gone away” error message in my web-application. No queries were running. The webpage (cron update) that generates the error is a heavy one with approx. 10 000 queries. I had never seen this error message before and the solutions to fix it seems to be different in each case. The way I solved the error was the following.

1) I ran ”mysqlcheck” in repair mode and it fixed problems with clients that were using or hadn’t closed tables properly.

2) I found this workaround.

3) Then I checked the mysql servers system variable wait_timeout with:
mysqladmin -u username -p variables

The value was 10 which were pretty low considering the default value which is 28800.

wait_timeout is the number of seconds the server waits for activity on a noninteractive connection before closing it. This timeout applies only to TCP/IP and Unix socket file connections, not to connections made using named pipes, or shared memory.

4) I searched and found the ”wait_timeout” value in the mysql config file /etc/my.cnf. I had set this value to 10 when I did some mysql performance optimization in the past. Then I raised this value to a higher number.

5) Restarted mysql and ran the webpage. Everything worked fine.

I still don’t know why this error occured that day. The server configuration worked good before the accident and I haven’t made any changes lately. Very strange!

CyanogenMod 7 på HTC Desire Z

Det stora kruxet med att roota sin Android-smartphone är det ofta går att göra på tusen olika sätt och att det måste stämma med ett stort antal parametrar så som versioner av mjukvara, vilken firmware man har, vad man installerat innan etc. Då man kör igång är det oftast en enda stor djungel och man far fram och tillbaka mellan olika forum och läser på, laddar hem filer och mixtrar. Man får nästan räkna med att det inte ska gå smärtfritt, men det är väl det man får leva med då hela förfarandet är ganska osupportat/på egen risk.

Nåväl, idag rootade jag min HTC Desire Z och installerade Cyanogenmod 7. Det tog lite tid mycket på grund av problem med det jag nämnt ovan. Eftersom jag hade den senaste officiella uppdateringen så var jag tvungen att först nedgradera mobilen till en tidigare version och detta framgick inte så bra i olika guider. Om du vill göra samma sak som mig så behöver du bara följa dessa guider i turordning. Skit i resten, de gör dig bara förvirrad.

1. Installera ADB (Android Debug Bridge) på din pc

2. Nedgradera firmware. (på svenska)

3. Fortsätt på officiella wikin med rootningen

4. Flasha Cyanogenmod

Efter detta är du klar. Med lite flyt så borde det inte ta längre tid än 1h och om man är erfaren/snabb så kan man nog göra det på en halvtimme. Kom ihåg att göra backup ;-)

Notering
Efter några veckors användning så kan jag konstatera att den största positiva skillnaden mot fabriks-ROM’en är batteritiden. Nu räcker en laddning minst två dagar medan jag tidigare behövde ladda telefonen dagligen. Övrigt noterbart är att telefonen känns mycket rappare.

Facebook connect breaks mobile websites

I’ve had a really frustrating problem on the mobile version of a website that I am working on. This error has taken me hours debugging and the problem and solution is really simple. I am using the header <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/> for scaling. However the page doesn’t scale to my Android phones window. The page width is wider then the screen and it looks really awful.

The problem was related to html-code from Facebook Connect that my site is using. This code snippet comes from Facebook so I really dont have any clue why it is needed and how it works. All I can say is that it breaks webpages using viewport in smartphones.

The problem is the following

<div id="fb-root"></div>

Change it to this and the problem is solved

<div id=fb-root" style="display:none"></div>

Analyzing column sizes in csv files

I had this problem with a rather big csv file. I needed to find the maximum length of each column in the file. This could probably be solved rather easily with M$ Excel, but anyway it is much more fun to write a program. It is rather crude but works.—

Download the CSV-checker (executable)
Download source-code (visual studio 2005)

Command line syntax
CSV-checker.exe filepath delimeter

Program output

----------- FILE ANALYZED -----------
Column nr | Column name | Max length
-------------------------------------
1 | Columname | 2
2 | Columname | 37
3 | Columname | 3
4 | Columname | 44
-------------------------------------
Nr of columns: 4
Nr of rows: 2701
Nr of chars: 2117584

using System;
using System.Collections.Generic;
using System.Text;

namespace CSV_checker
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                // check arguments
                if (args.Length < 1)
                {
                    Console.WriteLine("Missing file argument");
                    Environment.Exit(-1);
                }
                else if (!System.IO.File.Exists(args[0]))
                {
                    Console.WriteLine("That file does not exist");
                    Environment.Exit(-1);
                }

                // set delimiter
                char delimiter = ';';
                if (args.Length > 1 && args[1] != "" && args[1].Length == 1)
                {
                    delimiter = char.Parse(args[1]);
                }

                // read file
                string[] lines = System.IO.File.ReadAllLines(@args[0]);
                int nrColumns = lines[0].Split(new char[] { delimiter }).Length;
                int[] maxColumns = new int[nrColumns];
                string[] columnNames = new string[nrColumns];
                long nrChars = 0;

                // analyze file
                for (int i = 0; i < lines.Length; i++)
                {
                    string[] parts = lines[i].Split(new char[] { ';' });
                    for (int j = 0; j < parts.Length; j++)
                    {
                        nrChars += parts.Length;
                        if (i == 0)
                        {
                            columnNames[j] = parts[j];
                        }
                        else if (parts[j].Length > maxColumns[j])
                        {
                            maxColumns[j] = parts[j].Length;
                        }
                    }
                }

                // Print results
                Console.WriteLine("----------- FILE ANALYZED -----------");
                Console.WriteLine("Column nr | Column name | Max length");
                Console.WriteLine("-------------------------------------");
                for (int i = 0; i < nrColumns; i++)
                {
                    Console.WriteLine(i + 1 + " | " + columnNames[i] + " | " + maxColumns[i]);
                }
                Console.WriteLine("-------------------------------------");
                Console.WriteLine("Nr of columns: " + nrColumns.ToString());
                Console.WriteLine("Nr of rows: " + lines.Length);
                Console.WriteLine("Nr of chars: " + nrChars);

                //Console.ReadLine();

            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.Message);
            }
        }
    }
}

Segmentation fault: 11 (core dumped) in php on Freebsd

Oh, I finally got time for some coding and server updates. Sadly but interestering I got this strange error after updating php5 (/usr/ports/lang/php5) to the latest in the Freebsd ports tree.

The error:
/usr/local> php -v
PHP Fatal error: PHP Startup: apc_shm_create: shmget(0, 31457280, 914) failed: Cannot allocate memory. It is possible that the chosen SHM segment size is higher than the operation system allows. Linux has usually a default limit of 32MB per segment. in Unknown on line 0
PHP Fatal error: PHP Startup: apc_shm_attach: shmat failed: in Unknown on line 0
Segmentation fault: 11 (core dumped)

The first problem was the ”PHP Fatal error” lines that has something to do with APC cache. This was solved by:
/usr/ports/www/pecl-APC> make config
Then I unticked the "IPC Enable IPC shm memory support (default: mmap)" line. Don't really know what it does....
/usr/ports/www/pecl-APC> make deinstall
/usr/ports/www/pecl-APC> make clean
/usr/ports/www/pecl-APC> make install clean

The second problem was the ”Segmentation fault: 11 (core dumped)” line which caused a core dump each time php ran (a php.core file is produced). This was a bit strange. To investigate why it crashes I used gdb on the core file. A core file contains the in-memory state of the program at the time it crashes.

/usr/local/lib/php> gdb /usr/local/bin/php php.core
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...(no debugging symbols found)...
Core was generated by `php'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /lib/libcrypt.so.4...(no debugging symbols found)...done.
Loaded symbols for /lib/libcrypt.so.4
Reading symbols from /usr/local/lib/libpcre.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libpcre.so.0
Reading symbols from /lib/libm.so.5...(no debugging symbols found)...done.
Loaded symbols for /lib/libm.so.5
Reading symbols from /usr/local/lib/libxml2.so.5...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libxml2.so.5
Reading symbols from /lib/libz.so.4...(no debugging symbols found)...done.
Loaded symbols for /lib/libz.so.4
Reading symbols from /usr/local/lib/libiconv.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libiconv.so.3
Reading symbols from /lib/libc.so.7...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.7
Reading symbols from /usr/local/lib/php/libs/curl.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/curl.so
Reading symbols from /usr/local/lib/libcurl.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libcurl.so.6
Reading symbols from /usr/lib/libssl.so.5...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libssl.so.5
Reading symbols from /lib/libcrypto.so.5...(no debugging symbols found)...done.
Loaded symbols for /lib/libcrypto.so.5
Reading symbols from /usr/local/lib/php/libs/iconv.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/iconv.so
Reading symbols from /usr/local/lib/php/libs/json.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/json.so
Reading symbols from /usr/local/lib/php/libs/exif.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/exif.so
Reading symbols from /usr/local/lib/php/libs/ftp.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/ftp.so
Reading symbols from /usr/local/lib/php/libs/openssl.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/openssl.so
Reading symbols from /usr/local/lib/php/libs/hash.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/hash.so
Reading symbols from /usr/local/lib/php/libs/bz2.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/bz2.so
Reading symbols from /usr/lib/libbz2.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libbz2.so.3
Reading symbols from /usr/local/lib/php/libs/mysql.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/mysql.so
Reading symbols from /usr/local/lib/php/libs/tokenizer.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/tokenizer.so
Reading symbols from /usr/local/lib/php/libs/simplexml.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/simplexml.so
Reading symbols from /usr/local/lib/php/libs/xml.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xml.so
Reading symbols from /usr/local/lib/php/libs/posix.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/posix.so
Reading symbols from /usr/local/lib/php/libs/dom.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/dom.so
Reading symbols from /usr/local/lib/php/libs/gd.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/gd.so
Reading symbols from /usr/local/lib/libt1.so.5...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libt1.so.5
Reading symbols from /usr/local/lib/libfreetype.so.9...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libfreetype.so.9
Reading symbols from /usr/local/lib/libX11.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libX11.so.6
Reading symbols from /usr/local/lib/libXpm.so.4...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libXpm.so.4
Reading symbols from /usr/local/lib/libpng.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libpng.so.6
Reading symbols from /usr/local/lib/libjpeg.so.11...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libjpeg.so.11
Reading symbols from /usr/local/lib/libxcb.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libxcb.so.2
Reading symbols from /usr/lib/librpcsvc.so.4...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/librpcsvc.so.4
Reading symbols from /usr/local/lib/libXau.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libXau.so.6
Reading symbols from /usr/local/lib/libXdmcp.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libXdmcp.so.6
Reading symbols from /usr/local/lib/libpthread-stubs.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libpthread-stubs.so.0
Reading symbols from /usr/local/lib/php/libs/xmlreader.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xmlreader.so
Reading symbols from /usr/local/lib/php/libs/xmlwriter.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xmlwriter.so
Reading symbols from /usr/local/lib/php/libs/sockets.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/sockets.so
Reading symbols from /usr/local/lib/php/libs/zlib.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/zlib.so
Reading symbols from /usr/local/lib/php/libs/session.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/session.so
Reading symbols from /usr/local/lib/php/libs/soap.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/soap.so
Reading symbols from /usr/local/lib/php/libs/xsl.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xsl.so
Reading symbols from /usr/local/lib/libexslt.so.8...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libexslt.so.8
Reading symbols from /usr/local/lib/libxslt.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libxslt.so.2
Reading symbols from /usr/local/lib/libgcrypt.so.17...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libgcrypt.so.17
Reading symbols from /usr/local/lib/libgpg-error.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libgpg-error.so.0
Reading symbols from /usr/local/lib/libintl.so.9...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libintl.so.9
Reading symbols from /usr/local/lib/php/libs/sqlite.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/sqlite.so
Reading symbols from /usr/local/lib/php/libs/pdo.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/pdo.so
Reading symbols from /usr/local/lib/php/libs/pdo_sqlite.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/pdo_sqlite.so
Reading symbols from /usr/local/lib/libsqlite3.so.8...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libsqlite3.so.8
Reading symbols from /lib/libthr.so.3...(no debugging symbols found)...done.
Loaded symbols for /lib/libthr.so.3
Reading symbols from /usr/local/lib/php/libs/xmlrpc.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/xmlrpc.so
Reading symbols from /usr/local/lib/php/libs/ctype.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/ctype.so
Reading symbols from /usr/local/lib/php/libs/fileinfo.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/fileinfo.so
Reading symbols from /usr/local/lib/php/libs/filter.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/filter.so
Reading symbols from /usr/local/lib/php/libs/imap.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/php/libs/imap.so
Reading symbols from /usr/local/lib/libc-client4.so.9...done.
Loaded symbols for /usr/local/lib/libc-client4.so.9
Reading symbols from /usr/lib/libpam.so.4...done.
Loaded symbols for /usr/lib/libpam.so.4
Reading symbols from /usr/local/lib/php/libs/mbstring.so...done.
Loaded symbols for /usr/local/lib/php/libs/mbstring.so
Reading symbols from /usr/local/lib/libonig.so.1...done.
Loaded symbols for /usr/local/lib/libonig.so.1
Reading symbols from /usr/local/lib/php/libs/sqlite3.so...done.
Loaded symbols for /usr/local/lib/php/libs/sqlite3.so
Reading symbols from /usr/local/lib/php/libs/zip.so...done.
Loaded symbols for /usr/local/lib/php/libs/zip.so
Reading symbols from /usr/local/lib/php/libs/apc.so...done.
Loaded symbols for /usr/local/lib/php/libs/apc.so
Reading symbols from /usr/lib/librt.so.1...done.
Loaded symbols for /usr/lib/librt.so.1
Reading symbols from /libexec/ld-elf.so.1...done.
Loaded symbols for /libexec/ld-elf.so.1
#0 0x0000000805de1f5d in apc_sma_init () from /usr/local/lib/php/libs/apc.so
[New Thread 0x801533120 (LWP 100263)]

Ok, I smell some fish here. Then i checked the ”stack backtrace” with bt.

(gdb) bt
#0 0x0000000804c7c8c0 in ?? ()
#1 0x00000008042e1bc4 in xsltUnregisterExtModuleFunction () from /usr/local/lib/libxslt.so.2
#2 0x00000008040adc97 in zm_shutdown_xsl () from /usr/local/lib/php/libs/xsl.so
#3 0x000000000055e2cf in module_destructor ()
#4 0x000000000056597a in zend_hash_apply_deleter ()
#5 0x0000000000565be8 in zend_hash_graceful_reverse_destroy ()
#6 0x00000000005596f7 in zend_shutdown ()
#7 0x00000000005045f5 in php_module_shutdown ()
#8 0x00000000005e505f in main ()
#9 0x00000000004189e5 in _start ()
#10 0x0000000800786000 in ?? ()

The problem was clearly related to one of my php-extensions /usr/local/lib/php/libs/xsl.so. Then I tried not to use this extension by uncomment it in /usr/local/etc/php/extensions.ini. However I got similiar error in another extension by doing that. There must be some other error that hasn’t with my extensions to do…

With some google fu I found this post which explains the problem. Some extensions are threaded while php5 isn’t by default. To make php threaded you have to configure it to be so. That’s fairly easy in Freebsd.

/usr/ports/lang/php5/make config
Tick the "LINKTHR Link thread lib (for threaded extensions)" option.
/usr/ports/lang/php5/make deinstall
/usr/ports/lang/php5/make clean
/usr/ports/lang/php5/make install clean

Then i restarted my apache server, typed ”php -m” and everything looked fine, not one single strange error message. Yieeehaa!!

En sak du inte visste om mig…

… är att jag lagt upp ett Youtube-klipp som har setts 211481 ggr. Helt sjukt är det! Filmen har jag spelat in då jag var i Thailand på semester. Tydligen så har den retat upp djurälskare över hela världen då tigrarna i tigertemplet inte behandlas särskilt bra. Bland annat så har ett filmteam velat köpa filmsnutten av mig till en film som de håller på att sätta samman. Här är filmen:

Varför skrivaren Epson Stylus D120 suger (och andra bläckstråleskrivare)

Okey, den är inte min men en familjemedlem har köpt denna skrivare BILLIGT så den verkar inom min intressesfär (dvs att jag får ta hand om den om det blir problem). Jag har krigat mot den ett tag och var från början bländad av dess läckra skinande utseende. Men här blev man verkligen lurad. Varför suger då dessa skrivare:

* Bläckpatronerna är dyrare än guld

* Bläckpatronerna är dyrare än skrivaren själv

* Bläckpatronerna tar slut snabbare än man hinner säga ”utskrift”

* Man måste ha komplett uppsättning patroner (alla färger) för att kunna skriva ut även om man bara ska skriva ut svartvitt

* Den kräver munstyckeskontroll för varje körning (som verkar sluka bläck även den)

* Den är långsam och bullrig

* Utskrifterna var väl sisådär också

* Kostnaden per utskrift blir hårresande

* Varje gång du slår på den så verkar bläcknivån sjunka trots att du inte skriver ut något.

* Drivrutinerna är skrattretande, okey ”köpa bläck” ska man, jag har fattat nu

Köper man en sådan här skrivare är man fullständigt lurad. Håll er undan från allt som har med Epson Stylus att göra. Skrivarbranschen riktad mot konsumenter är ett enda stort skämt. Om du nu ändå har en sådan här skrivare, mitt råd är att köpa bläck (refill) från ebay och fylla på själv istället för nya patroner som kostar skjortan. Mitt bästa råd är dock att slänga dessa skrivare på tippen. Köp inte!!! Det borde vara illegalt att sälja sånt här och Epson borde skämmas.

Köp istället en ny bra eller begagnad laserskrivare. Själv så kör jag med en gammal HP Laserjet 4000 samt en HP laserjet 4600dn som jag är otroligt nöjd med. Där räcker en laddning toner till 10 000 utskrifter. Det funkar även bra med refill på dessa så att de blir billiga att ladda om.

Fler som hatar epson stylus skrivare. Haha!

Aldrig mer bläck-skrivare för mig och inte för dig heller. Köp laserskrivare som är något dyrare men du tjänar på dessa i längden.

Windows Management Instrumentation could not initialize

My problem was that I could not start the ”Windows Management Instrumentation” service in Windows XP. The application I am working on uses WMI so I needed this to work. The error message in the eventlog said that it could not initialize.

This is what worked for me as a solution:
1. I deleted all files in %SystemRoot%\System32\Wbem\Repository
2. Started cmd.exe and ran the following commands
winmgmt /clearadap
winmgmt /kill
winmgmt /unregserver
winmgmt /regserver
winmgmt /resyncperf
3. Started the WMI service and it worked for me…