RSS
 

Sending from multiple email addresses on iPhone

16 Mar

If you use multiple email addresses that all forward to the same email account, it’s easy to setup with the OSX desktop mail app.  All you have to do is enter your various email addresses into the account setup Address field, separated by commas.  When writing messages, you can select reply-to address from a drop-down.

On the iPhone, though, the Address field in the account setup brings up a limited character keyboard and the comma is not one of the characters that you can type.  This would seem to indicate that the iPhone doesn’t support multiple addresses without adding a separate account for each.

What you can do, though is type your addresses, separated by commas in the Description field and then copy/paste the whole thing into the Account field.  The craziest part is that it actually works!  Once you paste your email addresses, you will see a “From” field when composing emails.  Clicking this field will allow you to choose your reply address – the same as the Mail desktop app.

It’s a little strange and surprising that Apple prevents you from typing the comma into that field, yet manages to support multiple reply-to addresses anyway.  It probably has some security implications for any application that rely on a limited character keyboard for input validation.  Because originally there was no copy/paste on the iPhone, it would have been impossible to type illegal characters.  With copy/paste, though, you can circumvent that limitation.

 

Writing effective code comments

15 Mar

Many programmers, both good and bad, dislike writing comments.  When working on a team, lack of comments will eventually lead to lost productivity due to time spent tracing and re-learning.  The problem continues to get worse as revisions are made over the life-cycle of an application.  This can be especially true in larger teams where people come and go and/or work is outsourced.  However even if you’re the only programmer working on the code, it’s easy to forget why you did something months or years ago.

It’s my opinion that great programmers comment their code even if they’re the only person working on a project.  Not only does the small investment pay off later, it’s a simple habit that forces you to plan and proof-read your own work.  A poorly conceived function will become more apparent as you try to explain your thinking in the comments.  JavaDoc can be written before the code itself which helps to flesh out ideas before writing a lot of code.

Read the rest of this entry »

 
 

PHP behaves erratically when writing to files

05 Mar

This is such a dumb error  but I wanted to write it in case anybody else becomes mystified if a stable PHP application starts suddenly behaving erratically when writing to files.

The cause of this weird behavior could be that your server’s hard drive has run out of free space.   To check your server’s drive space on a Unix machine, you use the “df” command.  This will show you a percentage of used space.  If it’s in the high 90′s then obviously you need to clean out some files or upgrade the hardware.

This can cause a wide variety of very strange symptoms including:

  • Permission denied errors are thrown when opening, writing or closing files even though PHP has full permission granted
  • PHP stops appending to log files
  • PHP can create new files, but they are empty even though you are expecting PHP to write some data)
  • PHP can’t start new sessions, or doesn’t remember user’s session (because it can’t write session files)
  • Unknown error in Line 0.  (This actually occurs if you have an exception in your destructor, however this is a common place to close file handles so you might see this error)

Obviously the server is in an unreliable state so it’s likely to cause all kinds of weird and seemingly random behavior.  If you notice any other symptoms feel free to post a comment.

 
 

Install PDT Plugin in FlexBuilder 3

18 Feb

PDT Screenshot

Installing PDT (PHP Development Tools) Plugin for FlexBuilder allows you to work with PHP projects within the FlexBuilder environment.  This is useful if you are using AMFPHP, WebORB for PHP or some other PHP-based remote server.  There are similar instructions posted elsewhere, however I found that they have become outdated.  Because FlexBuilder 3 is based on an older release of Eclipse, you now have to specifically install older versions of the PDT files.

Note – If you are using a recent version of Eclipse with FlexBuilder plugin, or are using FlexBuilder 4 then you should not follow these instructions – instead install the most recent version of PDT.  These instructions are only necessary for FlexBuilder 3 Stand-Alone edition.

Installing PDT:

  1. Open FlexBuilder 3 menu Help->Software Updates->Find and Install
  2. Search for new feature to install
  3. Click “New Remote Site” and enter the following:
    • Name: PDT 1.x
    • URL: http://download.eclipse.org/tools/pdt/updates/
      (note is that this URL is to the old 1.x update site)
  4. After adding the site, click OK and select the following two Sites to include:
    • Europa Discovery Site
    • PDT 1.x
  5. Click “Finish” to begin searching for updates
  6. Once the results are displayed, un-check the box that says “Show latest version of a feature only”
  7. Expand PDT 1.x and select PDT SDK 1.0.3
    (important – do not select a higher version than 1.0.3)
  8. After you have selected PDT SDK, you may have required libraries missing.  You can try at this point clicking “Select Required” and they will be automatically selected from the Europa Discovery Site.  However, this sometimes causes FlexBuilder to lock up.  In which case, you have to force quit FlexBuilder, start the process over and manually select the required libraries which are:
    • Graphical Editors and Frameworks->Graphical Editing Framework 3.3.2
    • Java Development->Eclipse Java Development Tools 3.3.2
    • Models and Model Development->Eclipse Modeling Framework (EMF) Runtime + End-User Tools 2.3.2
    • Models and Model Development->XML Schema Infoset Model (XSD) Extender SDK 2.3.2
    • Web and JEE Development->Web Standard Tools (WST) Project 2.0.2
      (if any of these libraries are missing and do not appear, it probably means that you have already installed them)
  9. You should now be able to click “Finish” and agree to the license.  You can then restart the app and begin working with PHP project within FlexBuilder.

Configure Smarty (TPL) Template Editing

There is another project called smartypdt – however it doesn’t seem to be compatible with the older version of PDT – at least I couldn’t get it working.  Instead I simply configure TPL files to open using the PHP editor:

  1. Open the menu Window->Preferences
  2. Navigate in preferences to General->Content Types
  3. Expand the Text node and highlight “PHP Content Types”
  4. In the File associations list, add *.tpl

At this point you should be able to open a PHP folder and edit both PHP and TPL files.  If you configure your include path correctly, you should have code insight on your PHP classes and functions.

 
 

sqlite lpad and rpad functionality

12 Jan

sqlite is missing several basic database features compared to typical SQL servers and unfortunately padding is one of them.  For a most situations though, you can use a simple hack to get the same functionality.   This trick uses a combination of concatenation and substr:

-- the statement below is almost the same as
-- select lpad(mycolumn,'0',10) from mytable

select substr('0000000000' || mycolumn, -10, 10) from mytable

-- the statement below is almost the same as
-- select rpad(mycolumn,'0',10) from mytable

select substr(mycolumn || '0000000000', 1, 10) from mytable

The statement is fairly self-explanatory, but in case it doesn’t make sense we’re simply adding a big long string of characters to the original value and then truncating it down to the desired length.  The string used for concatenation has to be at least the same length that you are padding – 10 characters is used in this example (’0000000000′).

In most cases this workaround produces the same results as lpad/rpad except in the case where the length of your original value is greater than the length that you are padding.  In which case the original value would get truncated.  Usually when you are padding you know what the maximum length of the column anyway.

If you know of a more efficient technique, please post a comment.

 
No Comments

Posted in SQLite