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
| # Applies to Rails 2.3 | |
| # Since Rails doesn't load classes unless it needs them, you must read the models from the folder. Here is the code | |
| Dir[Rails.root.to_s + '/app/models/**/*.rb'].each do |file| | |
| begin | |
| require file | |
| rescue | |
| end | |
| end | |
| Object.subclasses_of(ActiveRecord::Base).each do |model| |
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
| Object.find(:all, :conditions => ["created_at >= ? and created_at < ?", "#{DateTime.now.strftime("%Y-%m-%d")}", "#{(DateTime.now + 1).strftime("%Y-%m-%d")}"]) |
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 String | |
| def chunk_by_words(char_count) | |
| words = self.split | |
| s1_len = 0 | |
| word_count = 0 | |
| i = 0 | |
| while (i <= words.count-1) | |
| s1_len += words[i].length | |
| word_count += 1 | |
| i+=1 |
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 Attachment < ActiveRecord::Base | |
| belongs_to :attachable, :polymorphic => true | |
| mount_uploader :item, AttachmentUploader | |
| # background the storage of files to AWS and processing | |
| # makes for fast uploads! | |
| store_in_background :item | |
| attr_accessible :item | |
| before_save :update_attachment_attributes |
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
| if Rails.env.staging? || Rails.env.production? | |
| begin | |
| redis_config = YAML.load_file(Rails.root + 'config/redis.yml')[Rails.env] | |
| Sidekiq.configure_server do |config| | |
| config.redis = { :url => "redis://#{redis_config['host']}:#{redis_config['port']}", :namespace => 'nin' } | |
| end | |
| # When in Unicorn, this block needs to go in unicorn's `after_fork` callback: | |
| Sidekiq.configure_client do |config| |
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
| # find any jobs that chronologically overlap an array of job_assignments | |
| # ex: find any jobs that overlap an interpreter's existing jobs via the job_assignments | |
| def self.overlapping(job_assignments) | |
| jobs_table = Job.arel_table | |
| query = Job.scoped | |
| job_assignments.each do |ja| | |
| query = query.where((jobs_table[:start_datetime].in(ja.scheduled_start..ja.estimated_end)). | |
| or(jobs_table[:end_datetime].in(ja.scheduled_start..ja.estimated_end))) | |
| end | |
| query |
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
| # Let's say you have a join between Address and Job | |
| # You want to use a scope on Job to limit the jobs that have to be joined otherwise you would join all jobs. | |
| # So you try this | |
| Address.joins('INNER JOIN jobs ON jobs.id = addresses.addressable_id AND addresses.addressable_type = "Job" AND ' \ | |
| 'addresses.address_type = "physical"').where(Job.in_the_future) | |
| # What you get is an error like so | |
| # Job Load (1.1ms) SELECT `jobs`.* FROM `jobs` WHERE (start_datetime > '2014-04-28 16:06:12') | |
| # (pry) output error: #<TypeError: Cannot visit ActiveRecord::Relation::ActiveRecord_Relation_Job> |
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
| // job quote make the following assumptions: | |
| // 1 hr job during the week (normal/standard rate) | |
| // travel costs are included | |
| // includes interp minimum job hours (some interps have a requirement for two hours) | |
| // does not include tax | |
| { "job_quote": { "min_cost": "$20", "max_cost": "$65" } | |
| "interpreters": | |
| [ | |
| { "cityState": "Austin, TX 78758", "latitude": 123.456, "longitude": 123.456, "hourlyRate": "$45" }, | |
| { "cityState": "San Antonio, TX 77577", "latitude": 456.789, "longitude": 456.789, "hourlyRate": "$65" }, |
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
| loglevel notice | |
| logfile "" | |
| dir vendor/redis/db/ |
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
| en: | |
| helpers: | |
| submit: | |
| offer: | |
| create: "Make Offer" | |
| bid: | |
| create: "Place Bid" | |
| activerecord: | |
| errors: | |
| models: |