Wednesday, May 25, 2011

jQuery Mobile Page transition without Ajax

Disable all
Add $.mobile.ajaxLinksEnabled = false;
*The order loading javascripts have to be jquery > disable code > jquery mobile .
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6b1.js"></script>
<script type="text/javascript">
$(document).bind("mobileinit", function(){
  $.mobile.ajaxLinksEnabled = false;
});
</script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>

Disable specific link
add rel="external" attribute into a tag.
<a link="#" rel="external">Link Text</a> 

jQuery Mobile How to submit a form without Ajax

Disable all
Add $.mobile.ajaxFormsEnabled = false;
*The order loading javascripts have to be jquery > disable code > jquery mobile .
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6b1.js"></script>
<script type="text/javascript">
$(document).bind("mobileinit", function(){
   $.mobile.ajaxFormsEnabled = false;
});
</script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>

Disable specific form
add data-ajax="false" attribute into form tag.
<form data-ajax="false">
.
.
</form> 

Friday, May 20, 2011

How to fix Chrome Mac crashes immediately after launch

STEP1: Move to 'Application' folder
STEP2: Right click 'Google Chrome' and choose 'Show Package Contents'
STEP3: Move to 'Contents' folder and delete or move Info.plist and boot Chrome.
And Chrome will launch and fix crash !

If Chrome works fine, restore Info.plist

How to backup MySQL with Rails and backup

'backup' is a RubyGem which allows you to configure and perform backups in a simple manner using an elegant Ruby DSL (for UNIX-like OS: Linux, Mac OSX)

Backup to various strage(Amazon S3,Dropbox and so on) compressed and notice by mail or Twitter.

In this article I'll show you the way to backup database with Rails.

Supported Databases
  • MySQL
  • PostgreSQL
  • MongoDB
  • Redis
Datails:Databases

Supported Strage
  • Amazon S3
  • Rackspace Cloud Files
  • Dropbox
  • Remote server(FTP SFTP SCP RSync)
Details:Storages

Ruby version
  • Ruby 1.9.2
  • Ruby 1.8.7
  • Ruby Enterprise Edition 1.8.7

Installing
gem install backup

Crating configure file
backup gem is not only for Rails, so it creates configure file in ~/Backup/config.rb.
It is out of Rails app dir, so generate with '--path' option and create in rails_app_dir/config directory.

Move to Rails app dir and hit the command.
backup generate --path='config/' --databases='mysql' --storages='ftp' --compressors='gzip'
*Options
--databases:database type (MySQL、PostgreSQL)
--storages:strage (Amazon S3、FTP)
--compressors:compressor type
Details:Generator

And config/config.rb will be generated.

Edit 'config.rb'
Using Backup With Rails
#
# Backup
# Generated Template
#
# For more information:
#
# View the Git repository at https://github.com/meskyanichi/backup
# View the Wiki/Documentation at https://github.com/meskyanichi/backup/wiki
# View the issue log at https://github.com/meskyanichi/backup/issues
#
# When you're finished configuring this configuration file,
# you can run it from the command line by issuing the following command:
#
# $ backup -t my_backup [-c ]

#Set database name,password refer to 'database.yml'
database_yml = File.expand_path('../config/database.yml',  __FILE__)
RAILS_ENV    = ENV['RAILS_ENV'] || 'development'
require 'yaml'
config = YAML.load_file(database_yml)

Backup::Model.new(:my_backup, 'My Backup') do
  database MySQL do |db|
    db.name               = config[RAILS_ENV]["database"]
    db.username           = config[RAILS_ENV]["username"]
    db.password           = config[RAILS_ENV]["password"]
    db.host               = "localhost"
    db.port               = 3306
    db.socket             = "/tmp/mysql.sock"
    db.skip_tables        = []
  end
 #Refer to Databases if want to use other database.

 store_with FTP do |server|
   server.username = 'my_username'
   server.password = 'my_password'
   server.ip       = '123.45.678.90'
   server.port     = 21
   server.path     = '~/backups/'
   server.keep     = 5 #number of backups
 end
 #Refer to Storages if want to use other strage.

  compress_with Gzip do |compression|
    compression.best = true
    compression.fast = false
  end

end

configure 'schedule.rb' for whenever gem
whenever is a ruby gem which allow you to set up cron easier.

Backup daily at 5:00 am.
every 1.days, :at=>'05:00' do
command "backup perform --trigger my_backup --config_file 'rails_app/current/config'"
end
*Options
--trigger the name which wrote in 'config.rb' Backup::Model.new(:my_backup, 'My Backup') do ...
--config_file path to 'config.rb'


 After deploy to your production server, 'backup' will automatically backup your database at the time which you set on 'schedule.rb'.

Monday, May 16, 2011

How to create create RSpec helper and share.

Create RSpec helper method and share in all specs if you need.
*RSpec ver 1.3x

Create helper
module UserHelpers
  def user_helper_method
     #do something
  end
end

describe User
  include UserHelpers
  .
  .
  .
end
Share in all specs
RSpec.configure do |config|
  config.include(UserHelpers)
end