Category Archives: Tips

Word-problem

Idag hade jag väldigt stora och konstiga problem med Word. Till synes slumpmässigt gav den mig ett felmeddelande om “slut på minnet” och att jag genast måste spara mitt arbete så att det inte gick förlorat. Med cirka 3 Gb internminne och 280 Gb hårddisk ledigt så var det ett lite lustigt felmeddelande.

Efter många om och men har jag nu kommit fram till följande när man felsöker dylika konstigheter i Word:
Steg 1: Radera normal.dot och starta utan några inställningar.
Steg 2: Skapa en ny användarprofil på datorn och starta Word i denna nya “rena” profil.

Steg 3: Bränn datorn på ett bål under en ritual för att fördriva de onda andarna ur datorn

Sån tur var löste det sig i steg nummer 2.

Share
Posted in Funderingar, Tips | Tagged , , | Leave a comment

Redigering av 2GB+ filer

2 GB är väl inte så farligt längre? Det var dock inte så roligt att försöka redigera en sådan på ett Windows-system. Man längtade till massor av trevliga kommando i Linux för att hantera mastodont-filen och till slut blev det gVim som fick rädda dagen.

Share
Posted in Tips | Tagged , | Leave a comment

Vårstädning i Facebook

Jag kände att jag behövde se över hur mycket storebror Facebook känner till om mig och mitt leverne. När jag gick in under sekretessinställningar och sedan redigerade information om applikationer och webbplatser blev jag nästan lite häpen. Där fanns en lång lång lista över applikationer som tydligen hade rätt att läsa vad de ville om mig. Många av dem kommer jag ihåg att jag vid något svagt tillfälle tackat ja till (vem vill inte vara “Friends Forever”?) men nästan lika många kände jag inte alls igen.

I brist på vår i den riktiga världen bestämde jag mig för att utropa en vårstädning på Internet istället. Sagt och gjort, jag har nu tagit bort så gott som alla applikationer som hade tillgång till min information ifrån Facebook. De flesta av dem var inaktiva men det känns ändå skönt att ha dem borta.

Hur många applikationer har ni själva? Kolla här:
http://www.facebook.com/settings/?tab=applications

http://www.facebook.com/settings/?tab=application
Share
Posted in Internet, Tips | Tagged , , , | Leave a comment

Base64-kodning för e-post

Ibland är lösningar lättare än man tror. Jag hade en bild som skulle kodas till Base64 för att vara del av ett e-postutskick.  Jag funderade först på om jag skulle skriva ett enkelt litet program för att konvertera bilder till Base64 samt skapa header-information som ska följa med bilden i e-postutskicket.

Den enkla lösningen var att istället för att skapa ett program så skickade jag bilden till mig själv med e-post. Sedan vara det bara att “visa källa” på e-postmeddelandet och klippa ut den färdig-kodade bilden inklusive header med mera! Perfekt och enkelt. Ibland gör man det lätt för sig.

Share
Posted in Tips | Tagged , , | Leave a comment

Microsoft Security Essentials

För alla som missat det skulle jag villa påminna om att Microsoft Security Essentials sedan en tid tillbaka finns tillgängligt att ladda ner för alla Windows-ägare även här i Sverige. Tidigare var tillgången begränsad till vissa världsdelar men nu är den alltså i alla fall tillgänglig här.

Jag har alltid varit emot anitvirusprogram och försökt undvika dem bäst det går. Idag kan man inte vara utan skydd med tanke på alla hot som kommer ifrån Internet. För en gångs skull tycker jag dock detta är ett program som bör vara del av operativsystemet (till skillnad mot webbläsare och annat lull-lull som Windows ofta fokuserar på). Vem kan bättre än Microsoft själva veta var och hur man bör skydda systemet? Jag hoppas bara att de satsar ordentligt på den här produkten så att den blir minst lika säker som konkurrenterna som har flera års försprång i antivirus-hantering.

Under ett par månader har jag kört Microsoft Security Essentials (MSE) på min hem-PC och det har fungerat utmärkt. Alla mina tidigare antivirusprogram har alltid gjort mycket oväsen av sig i form av uppdateringar eller att de varit i vägen när vissa program skulle köra. MSE är mycket tystare av sig och hittills verkar den fungera bra. Det återstår att se vid nästa virusutbrott om den hanterar detta på ett bra sätt!

Share
Posted in Tips | Tagged , , , | Leave a comment

Filhantering med Dropbox

Dropbox är verkligen en härlig molntjänst. Tack vare de olika gränssnitt man kan använda Dropbox genom, till exempel som en vanlig mapp på din dator (vilket operativsystem du än kör) eller genom det utmärkta webbgränssnittet.

Det bästa med Dropbox är att man kan komma åt sina filer bakom nästan vilken brandvägg eller begränsad serverdator som helst. Ofta är företagsnätverk blockerade för “udda” trafik och då kan det vara svårt att ladda upp eller ner filer man behöver i jobbet.

Skaffa ett eget Dropbox-konto och få 2 GB gratis utrymme!

Share
Posted in Tips | Tagged , , | Leave a comment

Utnyttja statistiken från din hemsida

Glöm inte att följa statistiken ifrån din hemsida. Vad letar dina besökare efter när de hittar din hemsida? Att använda ett bra statistikverktyg som Piwik eller Google Analytics kan öppna ett helt nytt sett för dig att se din egen hemsida.

Följ trender såsom var dina besökare kommer ifrån. Hur många besökare får du från den där bloggen eller forumet som du länkas ifrån. Det kan vara bra att veta då man kanske bör ägna mer tid åt att svara på kunders frågor på Internet och därmed lämna ett spår efter sig för nästa kund.

Ett mycket intressant sätt att använda statistik på är framförallt att hitta saker som dina besökare letar efter men som inte finns på din hemsida. Säg att ert företag lagt upp en “offert”-sida. Att se vilka besökare som når denna sida kan avslöja vad dina presumtiva kunder söker. Om du ser massor av sökord på “fastpris offert” (särskrivet i exempelvärldens underbara värld) så kanske detta bör framhävas på hemsidan om ni erbjuder denna tjänst.

Att ändra sidan efter de sökord där den passar är lite som att anpassa varorna i en butik efter vem som kommer och handlar. Kunden har alltid rätt, även på Internet!

Share
Posted in Internet, SEO, Tips | Tagged , , , | Leave a comment

How to avoid a page being cached

All web programmers have probably had trouble with browsers caching pages it ought not to. So what can we do about it? Well in good old HTTP 1.0 we had a nice header that simply said:

Pragma: no-cache

Easy huh? Yes. Probably to easy. If not browsers then sure some proxy server will dissobey that simple command and require that we explain it to them more thoroughly. This brings on the next HTTP-command:

Expires: -1

Acctually any invalid date format will do, the meaning should be interpreted as “this page have ceased to be” [mental image of John Cleese banging a parrot on the desk]. Only problem is still some missbehaving browsers and proxys interpret this as “well you might have written an erranous date, so we play nice and cache the page for you still”. Cue HTTP 1.1 and we have another header:

Cache-control: no-cache

Oh, remember this directive? Easy huh? Heard it before. Yes, it’s to easy to be true as well. The problem with this one is that some missbehaving reverse-proxys apparently fails to deliver these pages through the proxy in what seems to be their inability to forward it since they are not allowed to save it. At least in my case it was a reverse proxy that seemed to think very little of pages it wasn’t allowed to keep. We had to give it “Cache-control: private” in order for it to acctually pass the page on. The obvious problem with this is that it no longer prehibits the end user agent (as opposed to a in the middle proxy) to cache the page.

Now all available headers have failed in some way, add to this that someone using HTTP 1.0 might try and send a cache-control which will fail due to it not being part of 1.0 or in reverse someone using 1.1 sending Pragma header which might be ignored due to being replaced by cache-control in 1.1.

What is a programmer to do? Well, since proxys have made me not rely on normal HTTP headers the next step is into HTML and the http-equiv META tags. Let’s blast the browser with everything we have:

<meta http-equiv=”Expires” content=”-1″>
<meta http-equiv=”Pragma” content=”no-cache”>
<meta http-equiv=”Cache-Control” content=”no-cache”>

Now no proxy should ever interfere with our headers. The problem with cache-control and pragma remains so if you use HTTP 1.0 the former is ignored and in 1.1 the latter. If we include both we are safe, at least until they decide to probably change the whole thing in a future 1.2 version. We also send the expires tag which should make its way all the way to the browser without being cached. Hopefully at least one of these will be treated with respect by the browser, this is even partly recommended in an old KB-article from Microsoft. Still http-equiv is not as safe as real HTTP headers, it requires the browsers to support them. Some support them better than others (the article is old but still sends my head spinning in dissbelief).

Being dissillusioned by the current state of cache control (not the header, the subject) I ended up doing what probably most people are doing allready. Appending a random 10 character string to every call I ever make effectivly fooling the browser that this information might be improtant and making it update the page properly. Just append it to the back of every GET and include a random field in every POST.

http://www.fireflake.com/?cache=ds4R3HYh4

http://www.fireflake.com/?cache=BawqEw42cf

Not the same page. Obviously. Please don’t tell any browser developer this or they might include a “random cache of everything in the known universe”-feature in their next build.

Share
Posted in Internet, Programmering, Tips | Tagged , , , | 2 Comments

PHP Serialize vs Database normalization

I’ve recently started developing plugins for Wordpress in PHP. Being an old school Perl programmer PHP comes very easy and MySQL is still same old MySQL. PHP don’t have many advantages over Perl in general except one very good one: simplicity. I have always tried to write simple code, not simple in the sense that it doesn’t accomplish complex tasks rather in the sense that while being a huge and complex system it is still built with easy to understand blocks of code. With that being said, there are a few shortcuts I rather not take.

The reason I write this is that in all the PHP applications and PHP documentation I’ve come across regarding serialize() nobody ever mentions database normalization.

PHP Serialize

I found the serialize() function in PHP quite useful, it takes a datastructure and creates a string representation of that structure. This string can later be use with unserialize() to return it to the old structure. An example:

$fruits = array (
"fruits"  => array("a" => "orange", "b" => "banana"),
"numbers" => array(1, 2, 3),
);

echo print_r($fruits);

The above code creates an array and prints the result. The output of the above will be:

Array
(
    [fruits] => Array
        (
            [a] => orange
            [b] => banana
        )

    [numbers] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )
)

Now if you use serialize on this object the following would happen:

$fruits = serialize($fruits);

echo print_r($fruits);

Output:

1a:2:{s:6:"fruits";a:2:{s:1:"a";s:6:"orange";s:1:"b";s:6:"banana";}s:7:"numbers";a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}}1Array

A long line of strange numbers, just what the programmer wanted! This data is perfect for transfering or saving the state of a data structure for later use. Calling unserialize() on the above string would return it to the same array that we first had.

Database Design

Most applications use a relational database for storing information. A relational database stores all data in tables of rows and columns (or relations of tuples and attributes if you use the original non-SQL names). To make a database work efficiently the design of those tables, rows and columns are pivotal. Any student of database design have probably been forced to read all of the different levels of database normalization. The normalization process, invented by Edgar F. Codd, involves searching for inefficient database design and correcting it.

The very first rule of database normalization called the first normal form (1NF) stipulates that “the table is a faithful representation of a relation and that it is free of repeating groups.” [wikipedia]. This means that there should be no duplicate rows and no column should contain multiple values.

Serialization meets 1NF

What happens if you insert the above serialized data into a column of a row in a database? Well put shortly you get a stored datastructure that can be easily accessed by your application by calling it with the keys for that particular row. The table would probably look something like this:

ArrayTable
key value
1 1a:2:{s:6:”fruits”;a:2:{s:1:”a”;s:6:”orange”;s:1:”b”;s:6:”banana”;}s:7:”numbers”;a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}}1Array
2 1a:2:{s:6:”fruits”;a:2:{s:1:”a”;s:6:”apples”;s:1:”b”;s:6:”banana”;}s:7:”numbers”;a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}}1Array

As long as you will never ever search for anything inside the value field this is all good and well (but still goes against my better teachings of database normalization). Take for example the problem of locating all stuctures containing apples or even worse something as simple as ordering the rows by fruit! The structure makes such “simple” tasks very hard.

The use of serialization to encode values into the database might be very tempting. It makes saving complex structures easy without having to worry about database design. Saving data in serialized form is however very inefficient from a database design standpoint, the data should have been stored in separate tables reflecting their internal structure.

As I said in the beginning simplicity is the highest virtue of programming for me, serialize is a simple neat solution for a small problem. What should be remembered though is that serialize is not a swizz army knife that should be used for all the database storage. If you ever think that you will need to search through or handle the information stored, do youself a favour and make it a proper table from the start. In the long run making those tables will be easier than later having to convert all those structures and complex code handling them.

Share
Posted in Funderingar, Programmering, Tips | Tagged , , , , , , , , | 6 Comments

WordPress as a simple CRM

I recently started a new business where I really want to focus on taking care of the customer needs, being proactive rather than reactive to them. As such I need a simple Customer Relations Management (CRM) tool to keep track of my promises and contacts. There are probably many simple CRM tools available but I decided to try out Wordpress as a CRM tool.

First I installed Wordpress on an internal server with no external connection. I set the firewall to block that server from traffic with the outside network and then I started to do my internal “company blog”. To structure things I decided to follow some simple rules:

  • I make one post for every type of contact (e-mail / phone / order etc) I do every day, if several contacts to the same company / person occurs the same day they still only get one.
  • Several types of contact to the same company / person will get multiple posts the same day
  • Categories are other authorities, companies and/or persons
  • Tags are techniques, events, frameworks etc.

On average I get three to four posts every day, usually covering a broad area. Some days there are big events which often are reflected in the blog/CRM by only having one post for that day. Amounts of posts per day is therefore irrelevant. I keep the posts very short, they are mainly thought of as references to other information like an e-mail or something else. If it was a phone conversation I usually take down a few simple sentances of what the discussion was about.

Three months later I now use this internal blog alot! It helps me keep track of events that I might have forgotten about. When I had a tax issue recently I could quickly click the “tax authority” category and see which days I had communicated with them and leave as a reference in my future communication.

One thing that also helps me is the simplicity of clicking a category to bring up all the communication with that customer. When someone calls I quickly click their category and all my previous conversations with them are recorded. It helps me quickly remember what we where talking about, just like a CRM should.

There are of course limitations, WordPress was never intended to be used this way. There are no way to search for inactive customers for example, should the need for this arise a plugin for WordPress could most certainly easily be developed. Furthermore you need to be very careful about where you install the software so you do not publish all your information on the Internet. I run my business alone but this setup would work very nice also with a few employees I would imagine. Everyone could be an author in the same blog and you can access what the other persons are working on should a customer call when they are out.

The simplicity of WordPress makes this a great choice for me!

Share
Posted in Affärer, Open Source, Tips | Tagged , , , , , | 4 Comments