Skip to content

Instantly share code, notes, and snippets.

View asime's full-sized avatar

Arin Sime asime

View GitHub Profile
@asime
asime / 35.ru
Created October 18, 2015 23:56
React.render(<ActivityFeed newActivity=message />, @react('ActivityFeed'))
@asime
asime / 34.ru
Created October 18, 2015 23:55
<%= react_component('ActivityFeed' ) %>
@asime
asime / 33.ru
Created October 18, 2015 23:54
def have_already_answered_the_question?(question)
question.participant_answers.where(participant_id: self.id).count >= 1
end
def answer_question(question, answer)
participant_answers.build(answer: answer)
save()
answer.correct?
end
@asime
asime / 32.ru
Created October 18, 2015 23:54
def handle_question_answer(auth_key, answer_id)
ActiveRecord::Base.connection_pool.with_connection
participant = Participant.find_by(authorization_password: auth_key)
answer = Answer.find(answer_id)
allowed_to_answer_question = ( answer.question.id == current_question.id )
if allowed_to_answer_question && !participant.have_already_answered_the_question?(answer.question)
participant.answer_question(current_question, answer)
end
end
@asime
asime / 31.ru
Created October 18, 2015 23:54
rails g model ParticipantAnswer participant:references answer:references
rake db:migrate
@asime
asime / 30.ru
Created October 18, 2015 23:54
def subscribe_to_client_events
PubnubSingleton.client.subscribe(
channel: client_channel,
auth_key: auth_key,
callback: handle_client_events
)
end
def handle_client_events
lambda do |envelope|
@asime
asime / 29.ru
Created October 18, 2015 23:53
<%= react_component('QuestionDisplay') %>
@asime
asime / 28.ru
Created October 18, 2015 23:52
subscribeToServerChannel: ->
@pubnub.subscribe(
channel: @server_channel
message: @serverCallback
connect: ->
)
serverCallback: (message, env, ch, timer, magic_ch) =>
switch(message.event)
@asime
asime / 27.ru
Created October 18, 2015 23:51
def format(format_name)
format = if format_name == :title_with_answers
h = { title: title }
h[:answers] = answers.to_a.collect{|answer| {id: answer.id, title: answer.title }}
h
else
raise 'Unknown format'
end
format
end
@asime
asime / 26.ru
Created October 18, 2015 23:51
def start!
self.current_question_index = 0
send_current_question()
schedule_switch_to_next_question!(30)
save()
end
def schedule_switch_to_next_question!(secondes)
Rufus::Scheduler.singleton.in "#{secondes}s" do
ActiveRecord::Base.connection_pool.with_connection do