Resque.info
Resque.queues
Resque.redis
Resque.size(queue_name)
# check out what's coming next in the queue
# Resque.peek(archive_queue)
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 'uglifier' | |
| File.open("outfile.min.js", "w") do |file| | |
| file.write Uglifier.compile(File.read("infile.js")) | |
| end | |
| # Or with a one liner from the Terminal | |
| ruby -e "require 'uglifier'; puts Uglifier.compile(File.read('infile.js'))" > outfile.min.js |
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 Age | |
| class << self | |
| def today | |
| Time.now.utc.to_date | |
| end | |
| # Formats the date as mm/dd/yyyy | |
| def formatted_bday(bday) |
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
| # Routing Concerns is an attempt to DRY up your config/routes.rb. | |
| # The basic idea is to define common sub-resources (like comments) | |
| # as concerns and include them in other resources/routes. | |
| # Here’s the obvious example: | |
| concern :commentable do | |
| resources :comments | |
| end | |
| concern :remarkable 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
| module Slugable | |
| module ClassMethods | |
| def find_by_slug(param) | |
| if to_return = where("lower(name) LIKE ?", "#{patternify(param)}") | |
| to_return.first | |
| else | |
| nil | |
| 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
| # config/rails_admin.rb | |
| config.excluded_models = Dir.glob(Rails.root.join('app/models/concerns/**.rb')).map {|p| 'Concerns::' + File.basename(p, '.rb').camelize } |
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 'resque' | |
| require 'resque_scheduler' | |
| require 'resque/server' | |
| require 'resque_scheduler/server' | |
| schedules = YAML.load_file(Rails.root.join('config', 'schedules.yml')) | |
| $redis = Resque.redis = Redis.current = Redis.new( url: ENV['REDIS_URI'] ) | |
| Resque.schedule = schedules |
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 EmailValidator < ActiveModel::EachValidator | |
| def validate_each(record, attribute, value) | |
| unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i | |
| record.errors[attribute] << (options[:message] || 'is not an email') | |
| end | |
| 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
| require 'digest/sha1' | |
| # | |
| # A wrapper for generating SHA1 hash value | |
| # Simply done by concatenating all values using the colon symbol for delimiter. | |
| # This algorithm is mostly used by payment gateways. | |
| # | |
| # Usage: | |
| # | |
| # SHA1Generator.digest('foo', 'bar', 'fizz', 'buzz') | |
| # => "e723e86a6000fc8462142eb4821672de107535c1" # 40 chars |
2.hours.ago # => Thu, 27 Aug 2015 14:39:36 AFT +04:30
1.day.from_now # => Fri, 28 Aug 2015 16:39:36 AFT +04:30
Time.zone.parse("2015-08-27T12:09:36Z") # => Thu, 27 Aug 2015 16:39:36 AFT +04:30
Time.current # => Thu, 27 Aug 2015 16:39:36 AFT +04:30
Time.current.utc.iso8601 # When suppliyng an API ("2015-08-27T12:09:36Z")
Time.strptime("2015-08-27T12:09:36Z", "%Y-%m-%dT%H:%M:%S%z").in_time_zone # If you can't use Time.zone.parse (Thu, 27 Aug 2015 16:39:36 AFT +04:30)
Date.current # If you really can't have a Time or DateTime for some reason (Thu, 27 Aug 2015)