• HTML textarea default value line breaks

    This one I struggled to find the right formula to get it working. The solution was so simple and basic that I wonder why I did not just try it before all the complicated approaches.

    I basically needed to have line breaks occurring in the default value of a textarea field inside a HTML form. That is between the <textarea>…</textarea> tags.

    My first approach was to simply add \n where I wanted a line break. I also tried all possible combinations of \r, \n, CR, LF, separate, together, quoted, escaped… you name it. Nothing worked.

    Googling around proved no good. Most people kept referring to the nl2br function in PHP, but this is not what I was trying to achieve. Besides this is all client code, pure HTML, no server side processing involved.

    I ended up at the W3 HTML specification and saw the light! A simple example copied from their site included the solution to all my struggles:

    <FORM action="http://somesite.com/prog/text-read" method="post">
       <P>
       <TEXTAREA name="thetext" rows="20" cols="80">
       First line of initial text.
       Second line of initial text.
       </TEXTAREA>
       <INPUT type="submit" value="Send"><INPUT type="reset">
       </P>
    </FORM>

    Notice how they simply added a line break in the actual HTML source. This is so simple that you may even not notice the subtle difference. Let me show you how I had my initial code:

    <form>
    <p>Some random paragraph</p>
    <textarea>First line \n Second line</textarea>
    <p>Some more randomness</p>
    </form>

    As normally white space in HTML is simply ignored I did not give a thought about the fact that a line break can be created in the default textarea value by simply…, yes, adding a line break when writing the source code.

  • Empty Trash from the terminal

    For some reason I can not recall I went into my Trash bin on Fedora. There was unsurprisingly a lot of trash!

    I decided to empty the Trash bin but it only succeeded partially. I had a DVD directory that did not want to be deleted. Looking closer at the message it was a permissions error. Not sure how though, since if I did not have permissions to delete the directory from the Trash bin, how on Earth could I have moved it into the Trash bin to start with…!

    Looking around my home directory in the terminal I could not locate the exact spot to manually remove the directory. As always Google came to assistance and brought up a nice forum topic about how to empty the Trash bin in Fedora from the terminal.

    The simplest way would be to run the following command as root:

    rm -rf  ~/.local/share/Trash/files/*

  • Simple SMS sending with AT commands

    Since I am analysing different SMS related questions because of a new project I am involved in, I thought the following page at Nokia was useful. It is a very simplistic overview on how to read and send SMS with your mobile phone hooked up to your machine.

    As said it only covers the most basic AT commands (Hayes) but should be enough to get you started if you desire.

  • Latitude & longitude weather API

    While looking for a free and decent weather service API to display localised weather forecasts on tudomo‘s property details pages, I came across another blog describing how to get the current weather by using the iGoogle weather gadget API.

    The examples provided were mainly to locate the weather in a certain known city. My situation was a bit different as I never know beforehand where the properties for sale on tudomo are located in the world. So what I needed was a weather service based on latitude and longitude solely. Then it would not matter where in the world a property was located as I would get the closest possible matching weather measurement.

    To accomplish this you need to change the original query to the following. Please note all the commas are needed to make it work.:

    http://www.google.com/ig/api?weather=,,,36575560,-04670219

    Which will output some XML as the following:

    <xml_api_reply version="1">

    <weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">

    <forecast_information>
    <city data=""/>
    <postal_code data=""/>
    <latitude_e6 data="36575560"/>
    <longitude_e6 data="-4670219"/>
    <forecast_date data="2009-05-11"/>
    <current_date_time data="2009-05-11 17:09:51 +0000"/>
    <unit_system data="US"/>
    </forecast_information>

    <current_conditions>
    <condition data="Partly Cloudy"/>
    <temp_f data="71"/>
    <temp_c data="21"/>
    <humidity data="Humidity: 62%"/>
    <icon data="/ig/images/weather/partly_cloudy.png"/>
    <wind_condition data="Wind: SW at 13 mph"/>
    </current_conditions>

    <forecast_conditions>
    <day_of_week data="Mon"/>
    <low data="53"/>
    <high data="75"/>
    <icon data="/ig/images/weather/sunny.png"/>
    <condition data="Clear"/>
    </forecast_conditions>

    <forecast_conditions>
    <day_of_week data="Tue"/>
    <low data="53"/>
    <high data="75"/>
    <icon data="/ig/images/weather/sunny.png"/>
    <condition data="Clear"/>
    </forecast_conditions>

    <forecast_conditions>
    <day_of_week data="Wed"/>
    <low data="53"/>
    <high data="75"/>
    <icon data="/ig/images/weather/sunny.png"/>
    <condition data="Clear"/>
    </forecast_conditions>

    <forecast_conditions>
    <day_of_week data="Thu"/>
    <low data="46"/>
    <high data="71"/>
    <icon data="/ig/images/weather/mostly_sunny.png"/>
    <condition data="Mostly Sunny"/>
    </forecast_conditions>
    </weather>
    </xml_api_reply>

    Now it is up to you to simply parse the XML and process it as you wish. Please note that this is untested as I did not end up using the iGoogle API but instead Wunderground‘s as I felt it was more dedicated for the purpose. The same example call with Wunderground’s weather API would be:

    http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=36.575560,-4.670219

    Note there is a slight difference on how the latitude and longitude values are included in the GET request between the two APIs.