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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
# could get a speed up if we initialized to 1 instead of 0 | |
# but then we would have to compute all, no way to lazy compute. | |
# where ar we using the value? | |
def set_question_records_attempt_2(enterprise_id) | |
previous_enrollment_id = nil | |
previous_question_id = nil | |
attempt = 0 | |
QuestionRecord.where(enterprise_id: enterprise_id).where('enrollment_id is not null').order(:enrollment_id, :question_id, :created_at).each do |qr| |
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
# load all migrations | |
Dir[Rails.root.join('db/migrate/*.rb')].each { |f| require f } | |
#find the trove migrations classes | |
# and the corresponding file | |
# sort by file | |
# instantiate | |
# and invoke change | |
# rescuing from any exception. |
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
# Gemfile | |
# gem 'rack-mini-profiler' | |
# config/environment.rb | |
if Rails.env.development? | |
# profile all middleware | |
Qstream::Application.middleware.each do |mw| | |
begin | |
::Rack::MiniProfiler.profile_method(mw.klass, :call) {|app| "#{mw.klass} call"} |
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
class TimeoutError < StandardError | |
end | |
# used to prevent code running on the same object twice | |
def answer | |
begin | |
eq = EnrollmentQuestion.find_by_enrollment_id_and_question_id(@enrollment.id, @question.id) | |
Lock.new(eq,0).synchronize do | |
if @enrollment.is_valid_attempt?(@question) | |
... |