# Gemfile
group :development, :test do
gem 'rspec-rails', '~> 3.0.0'
gem 'factory_girl_rails'
gem 'capybara'
This file contains 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 'underscore' | |
# Given an array of elements ELEM and a matching KEY value, | |
# will build the apprpriate projection to generate sortable | |
# weights for a mongo aggregator. | |
# | |
# ELEM: An array of values upon which to match against KEY | |
# KEY: The document field key to match against | |
# I: Default 0, index into array at which to begin | |
# |
This file contains 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
# update application.rb | |
# config.middleware.insert_before(ActionDispatch::Static, TracePoint::Middleware) | |
class TracePoint | |
class Middleware | |
def initialize(app) | |
@app = app | |
end | |
def call(env) |
This file contains 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 "json" | |
require "digest" | |
require "logger" | |
class SlowQueryLogger | |
def initialize(output = nil, opts = {}) | |
# will log any query slower than 500 ms | |
@threshold = opts.fetch(:threshold, "500").to_i | |
@logger = Logger.new(output || STDOUT) |
This file contains 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
#Model | |
expect(@user).to have(1).error_on(:username) # Checks whether there is an error in username | |
expect(@user.errors[:username]).to include("can't be blank") # check for the error message | |
#Rendering | |
expect(response).to render_template(:index) | |
#Redirecting | |
expect(response).to redirect_to(movies_path) |
This file contains 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
# UPDATE: Ruby 2.0.0 https://docs.ruby-lang.org/en/2.0.0/Kernel.html#method-i-__dir__ | |
# $ ruby -v | |
# ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18] | |
# $ pwd | |
# /Users/dev/Documents/Github/Gists/awesome/ | |
# $ echo "puts __dir__" > how-to-get-the-directory-of-the-current-file-using-ruby-2-0-0.rb | |
# $ cat how-to-get-the-directory-of-the-current-file-using-ruby-2-0-0.rb | |
# puts __dir__ | |
# $ ruby how-to-get-the-directory-of-the-current-file-using-ruby-2-0-0.rb |
A lot of important government documents are created and saved in Microsoft Word (*.docx). But Microsoft Word is a proprietary format, and it's not really useful for presenting documents on the web. So, I wanted to find a way to convert a .docx file into markdown.
On a mac you can use homebrew by running the command brew install pandoc
.
Sidekiq jobs can be enqueued or scheduled. Enqueued means that they are gonna be picked up as soon as possible, scheduled jobs will be enqueued at some specific time.
When using ActiveJobs, Rails will return a job_id
after sending the job to ActiveJobs
job = UserMailer.send_invite(params).deliver_later
This file contains 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
=Navigating= | |
visit('/projects') | |
visit(post_comments_path(post)) | |
=Clicking links and buttons= | |
click_link('id-of-link') | |
click_link('Link Text') | |
click_button('Save') | |
click('Link Text') # Click either a link or a button | |
click('Button Value') |
OlderNewer