Monday, December 31, 2012

Selenium - Get current date

<tr>
        <td>storeEval</td>
        <td>var d=new Date(); d.getDate()+'-'+((d.getMonth()+1))
+'-'+d.getFullYear();</td>
        <td>date2</td>
</tr>
<tr>
        <td>echo</td>
        <td>${date2}</td>
        <td></td>
</tr>

Rails solved - Capistrano change repository

  • Remove deploy/shared/cached-copy
  • (remove .ssh/known_hosts) <- optional
  • ssh git@xxx.unfuddle.com
  • (config.rb add:  default_run_options[:pty] = true) <- optional
Reference: https://help.github.com/articles/deploying-with-capistrano

Known Hosts bug

If you are not using agent forwarding, the first time you deploy may fail due to Capistrano not prompting with this message:

# The authenticity of host 'github.com (207.97.227.239)' can't be established.
# RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
# Are you sure you want to continue connecting (yes/no)?
To fix this, ssh into your server as the user you will deploy with, run ssh git@github.com and confirm the prompt.

Sunday, December 30, 2012

Git tips - create an empty commit

git commit --allow-empty -m '[empty] initial commit'

Git tips - search a string on all revisions


git rev-list --all | (
while read revision; do

git grep -F 'Your search string' $revision

done

)

Tuesday, December 25, 2012

Cloud server vs VPS

http://forums.eukhost.com/f45/cloud-server-vs-vps-virtual-private-server-11356/#.UNkQBpNevKw

2010

Cloud hosting offers many advantages over normal VPS or Semi-Dedicated server hosting services due to the number of servers that are being used for a single cluster, and if you or your business rely greatly on your website, Cloud hosting is the best suitable option for you. The enhanced architecture powering Cloud hosting solution utilize groups of high specification servers, network attached storage devices to reliably serve every web page, and image of a website. Inside each storage device, drives are replicated to each other in a RAID configuration to create a first level of redundancy.

With Virtual Private server, you will not get guaranteed resources that you will pay for, which means other user of the VPS node could squeeze in on your allotted resources but this is not case with Cloud server, you will get the guaranteed amount of resources you are paying for and it's always available when you need them. In addition to all these features, you will also get the ability to customize the resources of Cloud server anytime. VPS is not at all reliable when compared to Cloud server because VPS is based on software virtualization platform. Each platform of servers have their merits and demerits but here there are no demerits of Cloud server, so now it depends on you whether to choose VPS or Cloud server after understanding the needs and the service that you are looking.

http://www.vps.net/blog/2012/08/20/vps-vs-cloud-server/

Cloud Servers have three primary advantages over a traditional VPS.

Near limitless flexibility with resource sizes.
On the fly resource upgrades, sometimes without even requiring a reboot.
Significantly better redundancy
Centralized redundant storage


VPS - not quite reliable on stability

Today, our web hosting on VPS is down. Called the technical support for
the reason saying that VPS down is common.

Mac shortcut symbols


  Command/Apple Key (like Control on a PC)
Also written as Cmd
  Option (like Alt on a PC)
  Shift
  Control (Control-click = Right-click)
  Tab
  Return
  Enter (on Number Pad)
  Eject
  Escape
  Page Up
  Page Down
  Home
  End
  Arrow Keys
  Delete Left (like Backspace on a PC)
  Delete Right (also called Forward Delete)
reference: http://www.danrodney.com/mac/index.html

Monday, December 24, 2012

Ruby - Notes on using Yardoc

List Options
$> yard help doc

Add additional tags:


>$ yardoc --tag data_source:"Data Source"
where data_source is the tag in comment.  e.g.  # @datasource The data is gathered by client collection.
"Data Source" is the string that appears on the generated document.

OR

Create a .yardopts file in project root, add the line --tag data_source:"Data Source"
Then >$yardoc

https://rubydoc.tenderapp.com/kb/getting-started-with-rubydocinfo/setting-up-a-yardopts-file





Thursday, December 20, 2012

Ruby yardoc - Remove view source from generated document

1. Create a file like
.../your_project_directory/doc/my_template/default/method_details/setup.rb
2. $>yardoc -p ./doc/my_template

Ruby on Rails documentation

YARD
Yay! A Ruby Documentation Tool

http://yardoc.org/

http://rubydoc.info/docs/yard/file/docs/GettingStarted.md
http://rubydoc.info/docs/yard/file/docs/Tags.md#taglist

(rake doc:app hanged on processing one of the class)

Rails Solve : You have already activated ... , but your Gemfile requires ...

Solution 1:
Use gems version as in Gemfile.lock $> bundle exec ...

Solution 2:
1. Include e.g. gem "rake", [some_version] in Gemfile
2. Update Gemfile.lock by $> bundle update

Wednesday, December 19, 2012

Visio alternative on Mac

OminGraffle

http://www.omnigroup.com/products/omnigraffle/

And awesome stencils

http://www.graffletopia.com/

Very nice!


See also: draw.io

Mistake - Fix lost after deployment

In today's deployment, one of our previous adhoc fix was lost since I miss the merge from fix to development branch.  In order to avoid that from happening again, I will try to use a different branching approach:

Named development branches
This are development branches use for implementation of different features.  It can only contain code on story and merge from _production branch.  In this way, individual story can be deployed to production without including other stories.

master branch
This is the branch that merge named development branches for the features that's going to be release to staging/production server.  It can contains codes from all dev branches and _production branch.

_staging branch
This is the branch in sync with staging release, every deployment to staging server mush be on this branch.  Merges from master, dev and/or _production branches for deployment.

_production branch
This is the branch in sync with production release, every deployment to production server must be on this branch.  Merges from _staging branch for deployment.  Any urgent or adhoc fixes on production branches should be merged to at least master and _staging branch according.


Monday, December 17, 2012

Thursday, December 13, 2012

Coding convention as on ruby on rails development

As suggested by ruby on rails framework development:

Follow the Coding Conventions
Rails follows a simple set of coding style conventions.
  • Two spaces, no tabs (for indentation).
  • No trailing whitespace. Blank lines should not have any spaces.
  • Indent after private/protected.
  • Prefer &&/|| over and/or.
  • Prefer class << self over self.method for class methods.
  • Use MyClass.my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
  • Use a = b and not a=b.
  • Follow the conventions in the source you see used already.
  • The above are guidelines — please use your best judgment in using them.
reference: http://guides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions

Sunday, December 9, 2012

Solve - Modx friendly url not working

Problem:
    Modx config -> Friendly URL -> yes.
    http://localhost/home.html -> Page not found.

Solution:
enable mod_rewrite: 
    $> sudo a2enmod rewrite
    $> sudo service apache2 restart

/etc/apache2/sites-avaiable/default:
AllowOverride all                                   

ht.access -> .htaccess

Reference:
http://wiki.modxcms.com/index.php/Friendly_URLs_Guide
http://rtfm.modx.com/display/Evo1/Moving+Site

Solved - Configuration warning: 'GD and/or Zip PHP extensions not found' on MODX

$ sudo apt-get install php5-gd

reference:
http://www.cyberciti.biz/faq/ubuntu-linux-install-or-add-php-gd-support-to-apache/

Friday, December 7, 2012

Enable https on apache2

sudo a2enmod ssl
sudo a2ensite default-ssl

sudo service apache2 restart


Apache add virtual host on a new port

1. Create a site

$> cp /etc/apache2/sites-available/default /etc/apache2/sites-available/newsite

edit /etc/apache2/sites-available/newsite:

<VirtualHost *:8082>
        ServerAdmin ops@example.com

        DocumentRoot /home/yourname/www
...

2. Enable a site


$> ln -s /etc/apache2/sites-available/newsite /etc/apache2/site-enabled/newsite
or
$> sudo a2ensite newsite


3. Listen to the port

edit /etc/apache2/ports.conf

Listen 80
Listen 8082
NameVirtualHost *:80
NameVirtualHost *:8082

Thursday, December 6, 2012

Setup Ubuntu for Modx Evolution - Part 3

http://wiki.modxcms.com/index.php/Installation_Guide

Ensure https supports:

sudo a2ensite default-ssl
sudo a2enmod ssl

Note: if site copied from original, make sure it's hosted on the same /home/cms/public_html or change paths accordingly.

Switch to utf8 in mysql on ubuntu - Update

[mysqld]
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_general_ci

[mysqld] default-character-set=utf8 (This line bugged and mysqld couldn't start!) [client] default-character-set=utf8

https://bugs.launchpad.net/ubuntu/+source/mysql-5.5/+bug/958120



Restart:

$> sudo service mysql restart

Switch to utf8 in mysql on ubuntu

http://blog.lesc.se/2011/06/switch-to-utf-8-charset-in-mysql-on.html


Switch to UTF-8 charset in Mysql on Ubuntu

When installing Mysql on Ubuntu the default character set is probably latin-1. Since Ubuntu uses UTF-8 for most other things this may be little strange. But it is easy to change.

The Mysql configuration file /etc/mysql/my.cnf has a magic line:
!includedir /etc/mysql/conf.d/

This will make it include settings on the subdirectory conf.d. It's not recommended to change the my.cnffile directly since it will cause problems when upgrading Ubuntu/Mysql to a new version.

Create a new file: /etc/mysql/conf.d/utf8_charset.cnf with the following contents:
[mysqld]  default-character-set=utf8    [client]  default-character-set=utf8

Restart mysql and you will have UTF-8 as character set:
$ mysql -u root -p -e "show variables like '%character%'"  +--------------------------+----------------------------+  | Variable_name            | Value                      |  +--------------------------+----------------------------+  | character_set_client     | utf8                       |  | character_set_connection | utf8                       |  | character_set_database   | utf8                       |  | character_set_filesystem | binary                     |  | character_set_results    | utf8                       |  | character_set_server     | utf8                       |  | character_set_system     | utf8                       |  | character_sets_dir       | /usr/share/mysql/charsets/ |  +--------------------------+----------------------------+ 


Setup Ubuntu for Modx Evolution - Part 2

Configurations:

Create user account:
$> sudo useradd -m  -s /bin/bash cms
$> sudo passwd cms

The user created will not be in the sudoers file.
-s : for setting the bash be the default shell.
-m: create /home/cms as user's home directory.
($> sudo userdel -r cms) to rollback


Migrate contents from current Modx CMS hosting on another server.
1. GZip tar and download the entire /public_html directory for old server.
2. Upload to /home/cms.
3. $> tar -zxvf public_html.tar.gz
4. Set apache document root to /home/cms/public_html
5. Restart apache: sudo service apache2 restart

6. Locate database config file: search database name within the files under /public_html
7. Config file: /manager/includes/config.inc.php

8. On the old server, export database by phpmyadmin>Export databases. -> localhost.sql
9. Copy localhost.sql to /home/cms
10. Restore database: $> mysql - u user_name -p database_name < file_name.sql




Project management - decide a story's point on task board

When it comes to review stories on task board and have to decide the
complexity points on every story, one approach is for every developer
and lead to think on their own without communicate with each other.
Then after everyone is ready, show the estimated points to all and
discuss the reason behind it. It would be quite a effective way.

Wednesday, December 5, 2012

Setup Ubuntu for Modx Evolution - Part 1

Procedures for setup Ubuntu and Modx Revolution:

Install Ubuntu Server 12.04

SSH: 
    Installation: sudo apt-get install openssh-server openssh-client
    Verify: ssh localhost

Apache2:
    Installation: sudo apt-get install apache2
    Verify: http://localhost or the IP
    Verify: sudo netstat -tap | grep mysql
    Location: /etc/apache2/

Mysql:
    Installation:
sudo apt-get install mysql-server
sudo apt-get install php5-mysql

    Verify: sudo netstat -tap | grep mysql

PHP5:
    Installation: sudo apt-get install php5 libapache2-mod-php5
    Restart Apache: sudo service apache2 restart
    Verify: <?php
                    phpinfo();
                ?>

Configurations:
edit /etc/apache2/sites-available/default, set the DocumentRoot there to /home/your_name/www

References:
http://www.cyberciti.biz/faq/ubuntu-linux-openssh-server-installation-and-configuration/
https://help.ubuntu.com/12.04/serverguide/index.html


Linux check version/distribution

$> lsb_release -a
or
$> cat /etc/*-release

postgresql psql console command reference

http://www.postgresql.org/docs/8.4/static/app-psql.html

postgresql psql show database, table, column

SHOW TABLE:
postgresql: \d
postgresql: SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';

SHOW DATABASES
postgresql: \l
postgresql: SELECT datname FROM pg_database;

SHOW COLUMNS
postgresql: \d table
postgresql: SELECT column_name FROM information_schema.columns WHERE table_name ='table';

DESCRIBE TABLE
postgresql: \d+ table
postgresql: SELECT column_name FROM information_schema.columns WHERE table_name ='table';

RENAME DATABASE
postgresql: alter database old_name rename to new_name;

Linux - list hardware configuration

lshw
sudo lshw

Monday, December 3, 2012

Rails migration by sql statement directly


Sometimes you need to do something in SQL not abstracted directly by migrations:
class MakeJoinUnique < ActiveRecord::Migration    
def up      
execute "ALTER TABLE `pages_linked_pages` ADD UNIQUE `page_id_linked_page_id` (`page_id`,`linked_page_id`)"    
end      
def down      
execute "ALTER TABLE `pages_linked_pages` DROP INDEX `page_id_linked_page_id`"    
end  
end

Saturday, December 1, 2012

Project - Enhancement on website to provide online application and facebook integration

On this story, we are going to enhance our current company website to support online application.  Within the application, we will correct client's personal information together with their Facebook authentication for further user information collection.

Requirements:
  1. Online application in a secured channel.
  2. Uploaded application and attached document needs to be secured.
  3. Collect Facebook authentication token.
  4. Access to submitted application from our internal staff in secure way.
What we are having now:
  1. The current website was design and created by a website design house.  Mainly static contents.
  2. We have an internal system which stores all client's sensitive information.
  3. We have register company domain and website is hosting on a shared hosting plan.  i.e. Many other outside domains are hosted together, sharing resources and IP.  This was fine at the moment since we only serves static information on our website.
  4. Website contents is managed by Modx.
  5. Design house will be responsible for creating new application form on our website.
  6. We will setup the environment for new website deployment and make sure the security of application data.
Considerations:
  1. Since our online application need to be secured, we needs https on application pages.
  2. Internal system should be separated from website for security concerns.
  3. Application data will be stored on hosting server database and file system.
  4. The application data on website should only be a temporary storage.  Once it's retrieved from our staff, it should be cleanup from website database.
  5. Application data should not be accessible by Design house personnel.  We should only provide minimal access for their deployment.  Once done, we should restrict their access.
  6. Access to application data on website should be granted only to IPs from office and internal system servers.
Things to do:
  1. Move web hosting to VPS so as to get a dedicated IP and server resource.
  2. Setup VPS and grant required access to design house for their deployment.
  3. Create access point on getting the Facebook authentication token and applications into our internal system.
Story daily:

  1. The original communication between us and design house was handle by another colleague who didn't say anything about online application security concerns.  No HTTPS was plan in the implementation.
  2. Raise security concern to product director.
  3. Agreed on we should make all application form secured.  Using HTTPS and SSL connections.
  4. Secure points: submission of form; Storage of application data on web server;  Secure retrieval of data from web server to our internal system.
  5. Coordinate with design house to make sure we are on the same picture and they know what they're going to do.
  6. Coordinate with developer on the way to get access Facebook token that will be stored on web site database.
  7. Apply VPS hosting plan.  Pay the bill, get access to VPS.
  8. Setup VPS for Modx deploy.
  9. ....