Friday, August 17, 2012

Customize a new rake task in rails


Refer to lib/task/*.rake 
Arguments can be passed by using of ENV.
e.g.
desc "create csv of loan ledgers: LEDGERS_START_DATE=2011-07-01 LEDGERS_END_DATE=2011-12-31 rake adhoc:ledgers"
task :ledgers => :environment do
Adhocs.create_csv_of_loan_ledgers(ENV['LEDGERS_START_DATE'], ENV['LEDGERS_END_DATE'])
end

Explicitly trigger an exception notification in Rails

Sometimes you may want to handle an exception nicely and at the same time receive exception notification email.  Here's the way:

begin
...
rescue Exception => e
  ExceptionNotifier::Notifier.background_exception_notification(e).deliver
end

Thursday, August 16, 2012

Google Chrome Extensions

http://chromeextensionsdocs.appspot.com/docs.html

Setup SSL on Apache (Mac)


Referece:
Tested on Mac Lion.
STEP 1. CREATING A CERTIFICATE AUTHORITY

Open up Terminal and enter the following commands (don't type the $, that's the prompt):
$ cd ~/Documents
This changes to your Documents folder in your Home directory; next, enter:
$ mkdir certs
This create a new directory called certs; you can name to whatever makes sense to you, although non-spaced names are best.
$ /System/Library/OpenSSL/misc/CA.pl -newca
This runs the CA.pl script that is part of the system to create a new Certificate Authority in the certsdirectory. You will get the following output to the Terminal:
CA certificate filename (or enter to create) Making CA certificate ... Generating a 1024 bit RSA private key ..++++++.................................++++++ writing new private key to './demoCA/private/cakey.pem' Enter PEM pass phrase: (enter a new secure password) Verifying - Enter PEM pass phrase: (reenter the same password) ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave s  ome blank. For some fields there will be a default value, If you enter '.', the field will be left blank. 
As prompted, enter the information prompted for; the more meaningful you make it, the easier it is for people visiting your site to know that they aren't getting a bad connection:
----- Country Name (2 letter code) [AU]: State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (eg, YOUR name) []: sslthis.dyndns.org Email Address []
Once this step is completed, you will have a series of folders inside ~/Documents/certs that make up the necessary structure for a functioning Certificate Authority. Files/directories created so far are:
~/Documents/certs ~/Documents/certs/demoCA ~/Documents/certs/demoCA/cacert.pem ~/Documents/certs/demoCA/certs ~/Documents/certs/demoCA/crl ~/Documents/certs/demoCA/index.txt ~/Documents/certs/demoCA/newcerts ~/Documents/certs/demoCA/private ~/Documents/certs/demoCA/serial 
STEP 2. GENERATE A PRIVATE KEY FOR THE WEBSERVER

The next step will be to generate a private key for your webserver.In the ~/Documents/certs directory, enter the following in Terminal:
$ openssl genrsa -des3 -out webserver.key 1024
This will generate an encrypted, private key called webserver.key; use a meaningful name, no spaces. The output will be:
Generating RSA private key, 1024 bit long modulus ....................................++++++ .....................++++++ e is 65537 (0x10001) Enter pass phrase for webserver.key: (enter a new secure password) Verifying - Enter pass phrase for webserver.key: (reenter the same password) 
Next, you will have generate a non-password protected copy of the key for Apache so that it can start up without errors.
$ openssl rsa -in webserver.key -out webserver.nopass.key
This will generate a non-password protected copy of the private key you just generated.
Enter pass phrase for webserver.key: (enter the secure password created in step 2) writing RSA key
Files generated at this point:
~/Documents/certs/webserver.key ~/Documents/certs/webserver.nopass.key 
3. GENERATE A CERTIFICATE REQUEST

The next step will be to generate a certificate request for your webserver based on the private key generated in step two, in a format that can be signed by the Certificate Authority created in step one. In the ~/Documents/certs directory, enter the following in Terminal (Return key after each entry):
$ openssl req -config /System/Library/OpenSSL/openssl.cnf -new -key webserver.key -out newreq.pem -days 3650 
This will tell the system to generate a new certificate request newreq.pem with the default openssl.confconfiguration file and using webserver.key for a validity period of 10 years.
Enter pass phrase for webserver.key: (enter the secure password created in step 2) You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank. For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]: State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, comp  any) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (eg, YOUR name) []:sslthis.dyndns.org Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: leave blank An optional company name []: leave blank 
Files generated at this point
~/Documents/certs/newreq.pem 
STEP 4. SIGNING THE CERTIFICATE REQUEST

The next step will be to sign the certificate request newreq.pem with the Certificate Authority created in step one. In the ~/Documents/certs directory, enter the following in Terminal (Return key after each entry):
$ /System/Library/OpenSSL/misc/CA.pl -signreq 
This will tell the system to sign the 'newreq.pem' file created in step three.
Using configuration from /System/Library/OpenSSL/openssl.cnf Enter pass phrase for ./demoCA/private/cakey.pem: (enter the secure password created in step 1) Check that the request matches the signature Signature ok Certificate Details: Serial Number: 1 (0x1) Validity Not Before: Nov 29 04:00:05 2004 GMT Not After : Nov 27 04:00:05 2014 GMT Subject: countryName = as entered stateOrProvinceName = as entered localityName = as entered organizationName = as entered commonName = sslthis.dyndns.org emailAddress = as entered X509v3 extensions: X509v3 Basic Constrai  nts: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: D8:C4:76:37:6F:8C:FA:8E:62:95:2C:A3:2E:E9:CC:5C:24:E2:5B:DB X509v3 Authority Key Identifier: keyid:DB:12:B4:DB:77:03:D1:64:DA:87:8A:61:79:AA:38:17:E4:7E:6B:ED DirName: emailAddress= serial:00 Certificate is to be certified until Nov 27 04:00:05 2014 GMT (3650 days) Sign the certificate? [y/n]: (type y to confirm) 1 out of 1 certificate requests certified, commit? [y/n] (type y to confirm) Write out database with 1 new entries Data Base Updated Signed certificate is in newcert.pem 
Files generated at this point:
~/Documents/certs/newcert.pem 
After this is done, I moved all the files created (webserver.key, webserver.nopass.key, newreq.pem, newcert.pem) into a new subdirectory, sslthis.dyndns.org, for keeping things nice and neat.
$ ~/Documents/certs/sslthis.dyndns.org
STEP 5. BASIC SSL CONFIGURATION FILE
 
  • Edit /private/etc/apache2/httpd.conf, and uncomment the following line (it's line 473 in my installation):
    Include /private/etc/apache2/extra/httpd-ssl.conf
  • Edit /private/etc/apache2/extra/httpd-ssl.conf, and make sure that:
    • SSLCertificateFile points to newcert.pem
    • SSLCertificateKeyFile points to webserver.nopass.key
    • SSLCACertificateFile points to demoCA/cacert.pem
    • SSLCARevocationPath points to demoCA/crl
    Be sure to include the full pathnames for each entry. Optionally, you can edit DocumentRoot to your liking. I point it to /Library/WebServer/Documents-SSL, so I have two roots, one for http and one for https.
============================================

Points to note:
  • Use su to perform the setup.
  • Define virtual host port 80 on httpd.conf only.  Don't set port 443 on httpd.conf
  • Define virtual host port 443 on httpd-ssl.conf.
  • Use ">apachectl configtest" to check if the syntax is OK.
  • Location of conf files:
    • /private/etc/apache2/httpd.conf
    • /private/etc/apache2/extra/httpd-ssl.conf
============================================

The "Passenger" ruby gem: (Install in user login is ok, but has to be su for edit httpd.conf)
> gem install passenger
> passenger-install-apache2-module

Edit /private/etc/apache2/httpd.conf
Add the lines like below as instructed by the output of the above passenger install

   LoadModule passenger_module /Users/xxx/.rvm/gems/ree-1.8.7-2012.02@xxxxxx/gems/passenger-3.0.19/ext/apache2/mod_passenger.so
   PassengerRoot /Users/xxx/.rvm/gems/ree-1.8.7-2012.02@xxxxxx/gems/passenger-3.0.19
   PassengerRuby /Users/xxx/.rvm/wrappers/ree-1.8.7-2012.02@xxxxxx/ruby


Note that the rails will run in "production" environment when it's served by Apache.
============================================
E.g. in httpd-ssl.conf
<VirtualHost _default_:443>

#   General setup for the virtual host
#DocumentRoot "/Library/WebServer/Documents"
DocumentRoot "/Users/yourname/project/project_name/public"
ServerName www.example.com:443
ServerAdmin you@example.com
ErrorLog "/private/var/log/apache2/error_log"
TransferLog "/private/var/log/apache2/access_log"
============================================
Common commands:
$> apachectl stop
$> apachectl graceful
$> apachectl start
$> apachectl configtest

Life is really simple

Life is really simple, but we insist on making it complicated. - Confucius.
世上本无事,庸人自扰之

Choose a job you love

Choose a job you love and you will never have to work a day in your life. - Confucius

知之者不如好之者,好之者不如乐之者。- 孔子 《论语·雍也》

Wednesday, August 15, 2012

Article on web - How to create very reliable web services

Source: http://amix.dk/blog/post/19709


Over the years I have learnt a lot about creating reliable web services and I have scaled a startup from 0 to millions of users and billions of pages views. I want to share some tips with you that you apply to any language and any website.

The general strategy

I think creating scaleable and reliable services boils down to following:
  • Monitor everything: Have a clear picture of what's going on at any time. Have a log of how your past performance has been, have a log of errors, have a log of key metrics in your application, have visualization of every computer in your network, have visualization of response times etc. Using Google Analytics isn't enough, you need much more powerful tools.
  • Be proactive: Backups and anticipations of future load should be proactive. If your load is close to maxing out today then don't wait till your web site is down before you begin optimizations. Know everything about your systems so you can take an educated guess of how many more users you can handle. Think about which strategies you can apply if you want to scale 10x, 100x, 1000x of your current load.
    Snippet from Proactive vs. Reactive scaling.
  • Be notified when crashes happen: Getting SMS notifications is easy using a service like Pingdom or an open-source library like crash_hound.

The tools that you can use

In my toolset I use a lot of tools and I highly recommend them. There is no need to reinvent the wheel, unless necessary!

Realtime monitoring of anything

I read about statsd and Graphite in Keeping Instagram up with over a million new users in twelve hours.
After I read that blog post I was excited and I used a day to get statsd+Graphite up and running. Graphite is a bit complex to setup, but the investment was great and I must say that it changed my life! This setup lets you track anything in realtime without any performance penalty (since statsd uses non-blocking UDP communication). I track the average response times, number of errors, number of signups, number of sync commands, average response time pr. sync command etc. etc. I track these things across servers and across services.
This is especially useful when you do multiple deployments pr. day as you can quickly see if your latest deployment is introducing errors or performance issues.
Here's one of our Graphite dashboards:

Monitor performance and get notified when something crashes

Pingdom is quite useful as it can track performance from multiple locations in the world. It can also notify you on SMS when your website crashes. Pingdom is also public and lets your users track your uptime and performance (a very useful service for your users).
For more powerful stuff we use crash_hound which lets you program notifications! For example, I get a SMS if a worker queue is not being processed. Most of our notifications are setup using small scripts that are less than 10 lines of code.
How one of our Pingdom monitor pages look like:

Log every error

We have a central logger that logs every error and displays it in a central location. With each error we can see a request's environment. It's a must have tool for any web service since you can track errors and bugs much easier.
Here's how our central logger looks like:

I am sure there are some open-source tools that can do this as well (I did not find any that matched our style so we implemented our own).

SQL and request logger

We have a SQL logger that aggregates queries and shows which are run most times and which are the most expensive. We also have a request logger that shows the same things for requests.
These two tools are essential when you want to know which part of your codebase are worth optimizing.
I open-sourced request logger some time ago (it's very simple and quite hackish!)
Here's a screenshot of how it looks like:

Monitor your servers

Being hosted on Amazon AWS is a privilege since they provide a lot of great monitoring tools (such as CPU usage and alarms if your servers start to use more resources than necessary).
There are some open-source tools available as well. At Plurk we used Cacti and Nagios. Cacti and Nagios are complex and powerful tools, but definitely worth your time since they can give you a much better picture of your servers and services you are running.
Here is how some of Amazon's monitoring tools look like:

I hope you found my tips useful! I might open-source some of my tools such as the central logger or SQL monitor in the near future.
Stay tuned and as always: happy hacking!


Selenium IDE pause

<tr>
  <td>pause</td>
  <td>5000</td>
  <td></td>
</tr>

Selenium IDE input form random value


<tr>
    <td>storeEval</td>
    <td>javascript{Math.floor(Math.random()*11)}</td>
    <td>randomnumber</td>
</tr>
<tr>
    <td>echo</td>
    <td>id=client_short_name</td>
    <td>${randomnumber}</td>
</tr>

Monday, August 13, 2012

Use Selenium to extract web page contents that delays loading

$>gem install selenium-webdriver

require 'rubygems'
require 'selenium-webdriver'

driver = Selenium::WebDriver.for :firefox
driver.manage.timeouts.implicit_wait = 10 # seconds
driver.get "http://food.clickthecity.com/b/sn10f81/jollibee-paco"

phone_number = driver.find_element(:css, 'section#content section#heading div#main-info p span')
puts phone_number.text

driver.quit

Automated browser testing tools

Friday, August 10, 2012

Check Rails version within code

Rails.version

Ruby - Check where does a method defined

Use the "method" call. e.g. some_object.method(:some_method)

or

check its source location:

some_object.method(:some_method).source_location

Attach/add post parameters to form


Add/replace input tag(s) within the form:

function fn_copyFormInputs(sourceFormName, targetFormName, inputNames) {
    for(var i=0; i<inputNames.length; i++){
      $('#' + targetFormName + ' #' + inputNames[i]).remove();
      var value = $('#' + sourceFormName + ' #' + inputNames[i]).val();
      $('<input />').attr('type', 'hidden').attr('name', inputNames[i]).attr('id', inputNames[i]).attr('value', value).appendTo('#' + targetFormName);
    }}

Capture AJAX callbacks

$('#your_form').bind('ajax:error', function{ alert('Ajax failed!')} )

Get form input hash

var params = {}; $.each($('#your_form').serializeArray(), function(i, field) {params[field.name] = field.value;});

PDF Writer for ruby

Keywords: Ruby, Rails, Pdf, Prawn, Write, Generate

http://prawn.majesticseacreature.com/

Thursday, August 9, 2012

Setup Git server on Linux

  • Setup ssh login
    • ssh [your_name]@[server_name] mkdir .ssh
    • scp ~/.ssh/id_rsa.pub [your_name]@[server_name]:.ssh/authorized_keys
  • Install Git:
    • ssh [server_name]
    • sudo apt-get update
    • sudo apt-get install git-core
  • If a shared repository is need, create a git user:
    • sudo adduser git
    • ... cont on setup ssh login.
  • Add repository
    • Login as your_name or git
    • mkdir myrepo.git
    • cd myrepo.git
    • git --bare init
  • Setup development machine 
    • git remote add origin [server_name]:myrepo.git
    • git push origin master
  • Done

Saturday, July 28, 2012

Setup development environment on Ubuntu Desktop 12.04

Macvim/Gvim + Janus (+ ctags)
https://github.com/carlhuda/janus/

Setup procedures on fresh installed OS:

$ sudo apt-get install vim-gnome
$ sudo apt-get install git
$ sudo apt-get install rake
$ sudo apt-get install curl
$ sudo apt-get install ack
$ sudo apt-get install exuberant-ctags
$ curl -Lo- http://bit.ly/janus-bootstrap | bash

Thursday, July 19, 2012

Rename multiple files using regular expression

$> for i in *.avi; do j=`echo $i | sed 's/find/replace/g'`; mv "$i" "$j"; done

Wednesday, July 18, 2012

Ruby on Rails development notes, tips, practices

Development
  • Performance tuning tools:
    • New Relic
  • Useful tips:
    • Use rails console to counter check the SQL statements being executed.
Testing
  • Unit tests should be written in a way that adding new records in test fixtures shouldn't affect the previous test results.  
  • New test fixtures should be added in a way that they should link to existing fixture data so as to avoid breaking existing test cases.
Quality Assurance
  • Besides unit, functional and integration test within rails framework.  Create automated browser test using tools like "Selenium" over test/real data.
Maintenance
  • Avoid using unnecessary code reflection.  It's not good for performance and maintenance.



Tuesday, July 17, 2012

Selected web resources and news feeds





(to be cont.)

System design tips

General tips for develop web based system.
  • Action Audits - Keep track of user actions.  In Rails, system may log controller actions and corresponding params and response of every single request.
  • Bug/Error tracking - Every error triggered in system should be notified to developers.
  • Timestamps - Always keep creation, update and any other timestamps on every records in database.


(to be cont.)

General guidelines for team software development


Development Environment
  • Source control - e.g. Git (preferred choice) , Csv, Svn
    • May use internal server or public source controls (e.g. Github/ Unfuddle)
    • Team members should receive notification whenever there's new push/commit to the server repository.
  • Knowledge base - Wiki
    • Team members should try to contribute on:
      • Project documentations
      • Technical know-hows
  • Workflow control for agile development.  Some choices:
    • Simple and easy to use - Pivotal Tracker
    • More comprehensive one - Atlassian JIRA  
  • Continuous integration - Build and test server.  For example:
    • Jenkins - For Ruby on Rails developments
    • CuriseControl.NET - For .NET developments
  • Test Automation
    • Browser test - Selenium IDE
General Coding Practices
  • DRY - Don't repeat yourself.  Never copy and paste same (similar) block of code in multiple places within the project.  Instead, common functionalities should be "extracted" to a single access point like a helper function or by other means.
  • Coding conversions - Team members should follow a single set of coding conversion.
    • Try to keep each line under 120 to 150 chars.
  • Code with comments.
  • Should always keep the code clean and easy for maintenance.
  • Should keep small code source files.  Every source code file should in general not more than 500 or even 300 lines (excluding large blocks of comments).
  • Should keep small functions - not more than 30 to 50 lines.
  • Should keep functions as private/protected as possible.  Only expose a function to public whenever necessary.
  • Every single function/method should be unit tested.
  • Regular code coverage test.
  • Developers may keep a work diary to log everyday's work done.
Daily Collaboration Practices
  • Team members MUST complete test (unit, functional, integration test) and make sure there's no unexpected error before pushing code to repository.
  • The build server (e.g. Jenkins/CuriseControl.NET) should run complete test whenever there's code update on repository.  In this way, whoever broke any tests can be clearly identified.
  • If there's unexpected errors (except explicit NotImplementedError) reported by build server, whom pushed the related code should fix the errors ASAP.
  • Responsibilities - whenever a feature raised a issue/bug need to be fixed/enhanced, the team member(s) who contributed to that feature should be have the priority to follow the case.
  • Communications
    • Better communications between team members always save development time and avoid unnecessary bugs.
    • Always let other team members know what you're working on.
  • Pending or unfinished feature can be marked as "NotImplementedException" and let the corresponding test fail.  Then commit code to repository.
  • Any bug reported from QA Engineers should state as much details as possible including the environment and steps to reproduce a bug.
  • Code review
    • Team members should review each others' code.
    • For any problem spotted, one should inform the author of that code.  In addition, adding unit tests to indicate the problem may also helps.
    • It there's no QA team in the group.  Developer should write additional test cases for each other!  It's always better for a developer to find a bug before the end users!
  • All developers should stand by when a new release is deployed to production.
  • Business logic and any updates should be kept in a centralized repository such as work flow control or wiki.
  • Every developer should try their best to commit/push the work done on that day before leaving the office.
Source Control Usage Practices
  • New project feature should be developed on a separated branch.  Then merge back to master/main trunk when finished and tested.
  • Project releases should be tagged.

Sunday, July 15, 2012

The Passionate Programmer




Marketing

  • Both ends of the technology adoption curve might prove to be lucrative.
  • You can't compete on price.  In fact, you can't afford to compete on price.
  • Supply and demand.  Exploit market imbalances.
  • Don't just know how to program.  Now is the time to think about business domains you invest your time in.
  • Be the worst guy in every band you're in.
  • The people around you affect your own performance.  Choose your crowd wisely.
  • I haven't been given the opportunity...? Seize the opportunity!
  • Be a generalist.  Generalists are rare...and, therefore, precious.
  • Your skill should transcend technology platforms.
  • Be a specialist.  Too many of us seem to believe that specializing in something simply means not knowing about other things.
  • Don't invest on single technology or platform.  Vendor - centric views are typically myopic.
  • Passionate.  Work because you couldn't not work.
Investment
  • Learning.   Don't wait to be told.  Ask!
  • Learn the business you work for.   You can't creatively help a business until you know how it works.
  • Find a teacher.   It's ok to depend on someone.  Just make sure it's the right person.
  • Be a teacher.  To find out whether you really know something, try teach it to someone else.
  • Be a teacher.  Mentors tend not to get laid off.
  • Practice.  Practice at your limits.
  • Implementation.  If you want to feel you own a process, help implement it.
  • Stand on shoulder of Giant.  Mine existing code for insights.
  • Use existing code to reflect on your own capabilities.
Execution
  • It's now.  What can we do?  Right Now?
  • Mind reading.  The mind - reading trick, if done well, leads to people depending on you.
  • Daily report.  Have an accomplishment to report every day.
  • Don't forget whom you work for.  Your managers' successes are your successes.
  • Satisfaction.  Be ambitious, but don't wear it on your sleeve.
  • Get job well done today.  How much more fun could you make your job?
  • What's your value?  Ask, "Was I worth it today?"
  • Beware of being blinded by your won success.
  • Enjoy Maintenance.  Maintenance can be a place of freedom and creativity.
  • Concentrate on 8 working hours per day.  Projects are marathons, not sprints.
  • Learn from failure.  Every wrong note is but one step away from a right one.
  • Stressful times offer the best opportunities to build loyalty.
  • Say "No".  Saying "Yes" to avoid disappointment is just lying.
  • Don't panic.  Heroes never panic.
  • Say it, implement it, demonstrate it.  Status reports can help you market yourself.
Sales
  • Don't ignore feelings.  Performance appraisals are never objective.
  • Communication is important.  Your customers are afraid of you.
  • Communication and documentation.  You are what you can explain.
  • Show up.  Learn about your colleagues.
  • The right language to the right people.  Market your accomplishments in the language of your business.
  • Change the world.  Have a mission.  Make sure people know it.
  • Let people hear your voice.  
  • Have your own brand.  Your name is your name.
  • Google never forgets.
  • Publish your code.  Anyone can use Rails.  Few can say Rails contributor.
  • Be a master.
  • Relationships.  Fear gets between us and the pros.
Leading technologies
  • Outdated technologies.  Your shiny new skills are already obsolete.
  • You are not your job.
  • Endlessness.  Focus on doing, not on being done.
  • Create yourself a product roadmap.  
  • Notice the market.  Watch the alpha geeks.
  • Developer, review themselves.
  • Monkey catching trap.  Rigid values make you fragile.
  • Avoid waterfall career plannings.  
  • Daily improvement.  
  • Independent.  

Ubuntu server failover solution

Use ucarp.

Monday, July 9, 2012

Git daily usage cheat sheet


TaskCommand
Initialize a new git repository
git init
View local branchesgit branch
Create new local branchgit branch [new_branch_name]
Delete local branchgit branch -d [branch_name]
Switch to a branchgit checkout [branch_name]
Add files to gitgit add .
Undo all current changes.git checkout .
Commit changesgit commit -a -m "Log message"
Show git logsgit log
Push local to remotegit push origin [branch_name]
Pull from remotegit pull origin [branch_name]
Merge branchgit merge [from_branch]
Show diffgit diff
Show all branchesgit branch -a
Fix a tagged release
git checkout -b [tag_name]_fixes [tag_name]
OR (for getting a remote branch)
git checkout -b [new_local_branch] origin/[remote_branch]

e.g.

git checkout -b myfeature origin/myfeature
Create a new taggit tag [tag_name]
Push tags to remotegit push --tags
Overwrite existing taggit tag -f [tag_name]
Delete tag
git tag -d 12345
git push origin :refs/tags/12345
Merge individual commitsgit cherry-pick [commit_hash]
Stashing
git stash
git stash apply
git stash list
Create an empty repositorygit --bare init
Adding a remote repository
git remote add origin [server_name]:[directory_name]

Checkout a single file on another branch:
$ git checkout branch_name file_full_path

More on: http://gitref.org/index.html

Capistrano cheat sheet


Description Command
List cap details cap -T
backup database cap bullitt db:backup:adhoc
Deployment without migration cap bullitt deploy
Deployment with migrations cap bullitt deploy:migrations

Linux system full backup

$>tar --exclude /proc --exclude /mnt --exclude /tmp --exclude
/backupdata -jcvp -f /backupdata/system.tar.bz2 /

Add new drive to linux

Procedure:
  1. Locate the new device.  e.g. $> ls /dev/sdb
  2. Create partition.  $> fdisk /dev/sdb
    1. m - help
    2. n - new partition
    3. p - list partitions
    4. d - delete partition
  3. Reboot
  4. Format partition.  $> mkfs -t ext3 /dev/sdb1
  5. Edit /etc/fstab to mount on startup.  /dev/sdb1 /mnt/sdb1 ext3 defaults 1 2
  6. Done

Friday, June 22, 2012

Setup Ubuntu Server 12.04 on Lenovo S10 Thinkstation

Environment:
- Lenovo S10 Thinkstation
- Intel Matrix Storage RAID 1 : 500G HDD x 2
- Ubuntu Server 12.04 LTS

Problem:  During the installation, in the step for installing GRUB on master boot record.  It prompts for a dev like /dev/sda, /dev/sdb, ... and gave a default /dev/mapper.  What should be the right dev?

Solution:  /dev/mapper/isw_beajfgdjeh_LENOVO   
This volumn name should appear in the previous step.  So, keep this for GRUB.


Comment on Sep 28, 2012
Intel Matrix RAID is consider to be not stable for production use.  Use RAID controller instead for production.

Wednesday, March 28, 2012

Twitter bootstrap - UI

By nerds, for nerds.
Built at Twitter by @mdo and @fat, Bootstrap utilizes LESS CSS, is compiled via Node, and is managed through GitHub to help nerds do awesome stuff on the web.

Made for everyone.
Bootstrap was made to not only look and behave great in the latest desktop browsers (as well as IE7!), but in tablet and smartphone browsers via responsive CSS as well.

Packed with features.
A 12-column responsive grid, dozens of components, javascript plugins, typography, form controls, and even a web-based Customizer to make Bootstrap your own.

http://twitter.github.com/bootstrap/

Tuesday, February 28, 2012

Github - Source control


Free public repositories, collaborator management, issue tracking, wikis, downloads, code review, graphs and much more…

https://github.com/

Saturday, January 28, 2012

Phusion Passenger - Deployment

Easy and robust deployment of Ruby on Rails applications on Apache and Nginx Webservers.

http://www.modrails.com/