This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| desc "imports the data from backup.sql" | |
| task :db_import => :environment do | |
| filenam = 'backup.sql' | |
| production = YAML.load(File.read(File.join(RAILS_ROOT, "config/database.yml")))['production'] | |
| db = production['database'] | |
| username = production['username'] | |
| password = production['password'] | |
| %x{mysql #{db} < #{filename} -u #{username} -p#{password}} | |
| puts "=====================================================" | |
| puts "Database imported successfully" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'yaml' | |
| require 'fileutils' | |
| desc "takes db backup and stores it to /var/backups/timestamp.sql with" | |
| task :db_backup => :environment do | |
| production = YAML.load(File.read(File.join(RAILS_ROOT, "config/database.yml")))['production'] | |
| db = production['database'] | |
| username = production['username'] | |
| password = production['password'] | |
| t = Time.now |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| new PeriodicalExecuter(function(){new Ajax.Request('/main/some_method', {asynchronous:true, evalScripts:true})}, 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'open-uri' | |
| class Some < ActiveRecord::Base | |
| # validates urls | |
| validates :url, :presence => true, :format => /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix, | |
| :uniqueness => true | |
| # validates email |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # using Iconv | |
| iv = Iconv.new("UTF-8//IGNORE", "UTF-8") | |
| content = iv.iconv(content) | |
| # using String.encode | |
| "string".encode(Encoding::UTF_8, :invalid => :replace, :undef => :replace, :replace => '') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module ApplicationHelper | |
| def page_links(pages) | |
| will_paginate(pages, :class => 'pagination', :inner_window => 2, :outer_window => 0, :renderer => BootstrapLinkRenderer, :previous_label => '«'.html_safe, :next_label => '»'.html_safe) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Simple configuration system | |
| # | |
| # The configuration is represented as a tree of keys. Examples: | |
| # | |
| # AppConfig['key'] | |
| # AppConfig['key','subkey'] | |
| # AppConfig['key.subkey'] | |
| # | |
| # An optional default value can be specified: | |
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1.9.3p194 :001 > a = 1,2,3,4,5,6,6 | |
| => [1, 2, 3, 4, 5, 6, 6] | |
| 1.9.3p194 :002 > a.methods.grep /groups/ | |
| => [:in_groups_of, :in_groups] | |
| 1.9.3p194 :003 > a.in_groups(2) | |
| => [[1, 2, 3, 4], [5, 6, 6, nil]] | |
| 1.9.3p194 :004 > a.in_groups_of(2) | |
| => [[1, 2], [3, 4], [5, 6], [6, nil]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| example action and view code: | |
| def index | |
| page = params[:page].to_i.zero? ? 1 : params[:page].to_i | |
| kids = current_day_care.kids(page) | |
| @kids = kids[:kids] | |
| unless kids[:total].to_i.zero? | |
| @kids_pages = (1..kids[:total]).to_a.paginate(:page => page, :per_page => Kid::PerPage) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # add the following JS code at the end of the ajax call. | |
| FB.XFBML.parse(); |
OlderNewer