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
| namespace :db do | |
| task drop_tables: :environment do | |
| connection = ActiveRecord::Base.connection | |
| connection.tables.sort.each do |table_name| | |
| connection.execute("DROP TABLE #{table_name} CASCADE") | |
| puts "Dropped: #{table_name}" | |
| end | |
| end | |
| task truncate: :environment do |
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
| class Gravatar | |
| DEFAULTS = { | |
| default: :not_found, | |
| force_default: false, | |
| size: 100, | |
| secure: false | |
| }.freeze | |
| INSECURE_URL = "http://www.gravatar.com/avatar/%{hash}" | |
| SECURE_URL = "https://secure.gravatar.com/avatar/%{hash}" | |
| VALID_OPTIONS = :size, :default, :rating, :secure, :force_default |
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
| AJAX_LINK_SELECTOR = 'a[data-remote=true]' | |
| AJAX_BUTTON_SELECTOR = 'button[data-remote=true][type=button]' | |
| createArbitraryField = ($submit) -> | |
| $form = $submit.closest('form') | |
| $('<input />', type: 'hidden', name: $submit.attr('name'), value: $submit.val()).appendTo($form) | |
| destroyArbitraryField = ($submit) -> | |
| $form = $submit.closest('form') | |
| buttonName = $submit.attr('name') |
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
| # composed_of :duration, class_name: 'Duration', mapping: %w(duration to_i), constructor: :parse, converter: :parse | |
| class Duration | |
| SEPARATOR = ':' | |
| SECONDS = 0...60 | |
| MINUTES = 0...60 | |
| HOURS = 0...24 | |
| include Comparable |
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
| class User | |
| def full_name | |
| "#{first_name} #{last_name}" | |
| end | |
| def rfc5322 | |
| if full_name.present? | |
| %{"#{full_name}" <#{email}>} | |
| else | |
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
| # Requirements: | |
| # - jQuery | |
| # - UnderscoreJS | |
| # | |
| # Usage: | |
| # $('#element').idleTimeoutable() | |
| # $('#element').idleTimeoutable(after: 3000) # milliseconds | |
| # $('#element').idleTimeoutable(idleClass: 'inactive') | |
| TIMEOUT_STORE_KEY = 'idleTimeout' |
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
| class Age | |
| attr_reader :birthday | |
| def initialize(birthday) | |
| @birthday = birthday.to_date | |
| end | |
| def age | |
| today = Date.today | |
| result = today.year - birthday.year |
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
| namespace :log do | |
| desc 'Compresses the current application log for the environment' | |
| task :rotate do | |
| store_path = "#{Rails.root}/log" | |
| logfiles = Dir[File.join(store_path, '*.log')] | |
| logfiles.delete_if { |l| File.size(l).zero? } | |
| if logfiles.any? | |
| log_filenames = logfiles.map { |l| File.basename(l) }.join(' ') | |
| archive_filename = "logs_#{Time.now.strftime('%s')}.tgz" | |
| `cd #{store_path} && tar -zcvf #{archive_filename} #{log_filenames}` |
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
| class Array | |
| def find_by!(attributes) | |
| find_by(attributes) || fail('No element found') | |
| end | |
| def find_by(attributes) | |
| detect do |item| | |
| attributes.collect do |key, value| | |
| item.public_send(key) == value | |
| end.reduce(:&) |
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
| @ScrollRestorer = | |
| offset: | |
| top: null | |
| left: null | |
| store: -> | |
| $window = $(window) | |
| ScrollRestorer.offset.top = $window.scrollTop() | |
| ScrollRestorer.offset.left = $window.scrollLeft() |