John Lai   [RSS Feed]

Archive for February, 2010

SVN Revert / Rollback

without comments

Revert an entire project to a previous version

  1. svn merge --dry-run -r73:68 http://my.repository.com/my/project/trunk
  2. svn merge -r73:68 http://my.repository.com/my/project/trunk
  3. svn commit -m "Reverted to revision 68."

Merge differences between a previous version and current version

svn merge -c -303 http://svn.example.com/repos/calc/trunk

svn commit -m ‘undoing changes’

Written by John Lai

February 23rd, 2010 at 10:49 am

Posted in Uncategorized

Tagged with

Program as little as possible

without comments

Some programmers are so detail oriented that they will try to cover as many scenarios as possible.  They will develop for today what they think will happen one or two months from now.  I use to be this kind of developer and boy do I regret it.

Businesses grow and requirements change.  As a result, the technology that drives businesses also change.  Change is difficult when systems are heavy, bloated and inflexible.   So don’t go adding potentially useful code unless you’ve got a damned good reason to do it.  In fact, don’t add new functionality/code unless 1) it’s in a contract or 2) your client asks you MORE THAN ONCE to do it.  Far too often I devoted much time to modules that were eventually scrapped because:

a) client changed his mind
b) at a later time, client requested a new feature that is closely related to an old feature, and thus, I rewrote 80% of the old feature  (I realised early one that rewriting 80% of two scripts is less work than 80% of ten scripts)

So keep your code lean and simple.  Do as little as possible so that when you inevitably refactor your work, you don’t have to throw out as much.

Written by John Lai

February 8th, 2010 at 2:37 pm

Posted in Uncategorized

Tagged with

Designers better at CSS development than programmers

with one comment

Getting a programmer to develop XHTML+CSS template can be frustrating.  Generally, they do not pay enough attention to what they deem as minor cosmetic issues that will drive everyone else crazy.

Examples:

  • They don’t pay enough attention to whether they are using the right shade of a particular colour.
  • They don’t pay enough attention to margins and spacing between elements
  • If designs don’t translate well into CSS + XHTML, they make little effort to “tweak” the template

From a programmer’s perspective, these are superficial details that do not impact functionality or performance.  But in the world of graphic design, superficiality is the name of the game.  Every pixel matters!

So that’s why when possible, graphic designers should not hand over CSS development to programmers.

Written by John Lai

February 7th, 2010 at 4:19 pm

Posted in Uncategorized

PHP Mail() with Postfix on Ubuntu

without comments

I set up my own LAMP VPS on linode.com.  Although linode provides a good guide on how to set up the LAMP environment, it doesn’t explain how to enable the PHP mail() function.  Additionally, it doesn’t explain how to prevent the server’s outgoing mail from ending up in the spam folder of popular web mail like Gmail, Yahoo and Hotmail.  I’ll explain my steps to getting PHP’s mail() function to work, without having to install a full blown mail server.  This means the bare minimum installation to get your PHP mail function to do the following:

- send out-going mail
- encrypt out-going mail
- reduce likelihood out-going mail ends up in spam folder

I’m not interested in hosting my own incoming mail box since I’ve got Google Apps to handle my mail (see linode guide for details).

Install Postfix

Postfix will be your mail server.  Install it by simply typing into shell:

sudo apt-get install postfix

Install TLS Encryption

You’d want to encrypt your outgoing mail.  Issue the following commands (this is an excerpt from ubuntu site):

touch smtpd.key
chmod 600 smtpd.key
openssl genrsa 1024 > smtpd.key
openssl req -new -key smtpd.key -x509 -days 3650 -out smtpd.crt # has prompts
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650 # has prompts
sudo mv smtpd.key /etc/ssl/private/
sudo mv smtpd.crt /etc/ssl/certs/
sudo mv cakey.pem /etc/ssl/private/
sudo mv cacert.pem /etc/ssl/certs/
sudo postconf -e 'smtp_tls_security_level = may'
sudo postconf -e 'smtpd_tls_security_level = may'
sudo postconf -e 'smtpd_tls_auth_only = no'
sudo postconf -e 'smtp_tls_note_starttls_offer = yes'
sudo postconf -e 'smtpd_tls_key_file = /etc/ssl/private/smtpd.key'
sudo postconf -e 'smtpd_tls_cert_file = /etc/ssl/certs/smtpd.crt'
sudo postconf -e 'smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem'
sudo postconf -e 'smtpd_tls_loglevel = 1'
sudo postconf -e 'smtpd_tls_received_header = yes'
sudo postconf -e 'smtpd_tls_session_cache_timeout = 3600s'
sudo postconf -e 'tls_random_source = dev:/dev/urandom'
sudo postconf -e 'myhostname = server1.example.com' # remember to change this to yours

In the last command, make sure you replace server1.example.com with your domain name.

If you have multiple domain names, add them to /etc/postfix/main.cf under

mydestination = domain1.com, domain2.com, domain3.com

Install SPF

Installing SPF will reduce the likelihood your emails go to recipient’s spam folder.

sudo apt-get install python-policyd-spf python-spf

Add this line to the end of /etc/postfix/main.cf

spf-policyd_time_limit = 3600s

Also add the following

smtpd_recipient_restrictions =
     ...
     permit_sasl_authenticated
     permit_mynetworks
     reject_unauth_destination
     check_policy_service unix:private/policy-spf
     ...

Where the triple dots denote the possible existence of other settings.

Now you should restart your postfix by typing

sudo /etc/init.d/postfix restart

Add the following TXT record in your DNS Manager to utilize SPF

v=spf1 a mx ~all

And that should be it.

Other useful resources:

Set up SPF Records

SPF, DKIM or SenderId?

Reverse DNS Lookup

Written by John Lai

February 3rd, 2010 at 2:10 pm