Skip to content

Instantly share code, notes, and snippets.

@apolzon
apolzon / gist:2354749
Created April 10, 2012 21:35
olark configuration.js
= javascript_include_tag "external/olark.onready"
:javascript
$(document).ready(function(){
if (typeof(olark) !== "undefined") {
olark.identify('5955-991-10-7137');
olark("api.visitor.updateFullName", {fullName: "#{current_user.first_name} #{current_user.last_name}"});
olark("api.visitor.updateEmailAddress", {emailAddress: "#{current_user.email}"});
olark('api.chat.updateVisitorNickname', {snippet: "MY AWESOME CUSTOM NICK", hidesDefault: true});
}
});
@apolzon
apolzon / include_javascript.rb
Created March 28, 2012 19:09
include javascript rspec matcher
RSpec::Matchers.define :include_javascript do |expected|
match do |actual|
actual && actual.match(/<script src="\/javascripts\/#{expected}\.js.+ type="text\/javascript"><\/script>/)
end
failure_message_for_should do |actual|
"expected that javascript tag #{expected} would be present, but was not"
end
@apolzon
apolzon / template.html.haml
Created March 9, 2012 18:25
Form Helper fields_for bug
= f.fields_for :questions do |question_form|
- if question_form.object.needs_answer?
%li
= question_form.label :answer, question_form.object.decrypted_question
= question_form.password_field :answer
- question_form.object.encrypted_answer = SecurityQuestion::DIRTY_ANSWER
= question_form.hidden_field :encrypted_answer
@apolzon
apolzon / resque_profiler.rb
Created March 8, 2012 18:14
Resque Profiler
def time_queue_chomping(size = 10)
if Resque.redis.llen("queue:robot_events").to_i > 0
puts "no way jose, the queue is full of junk!"
return
end
Rails.application.config.logger.level = Logger::WARN
ActiveRecord::Base.logger = ::Logger.new(StringIO.new)
t0 = Time.now.to_i
size.times { Resque.push("robot_events", :class => "RobotEventHandler", :args => [{:occurred_at => DateTime.now, :mailer => Mailer.first.attributes, :action => "fetch_top_line_data", :status => "success", :duration => "5", :response_queue => "ROBOT_EVENTS"}]) }
printed = []
require 'active_record'
require 'active_record/base'
module ActiveRecord
module ConnectionAdapters
class Mysql2Adapter < AbstractAdapter
def pk_and_sequence_for(table) #:nodoc:
puts "!!!"
keys = []
result = execute("SHOW CREATE TABLE #{quote_table_name(table)}", 'SCHEMA')
@apolzon
apolzon / gist:1953217
Created March 1, 2012 21:04
Rspec how long does each example take
if ENV['PROFILE_LIKE_CRAZY']
config.before :each do
$start = Time.now
end
config.after :each do
p "#{example.description} spec ran in #{"%.2f" % (Time.now - $start)} seconds"
end
end
<SCRIPT>
$(function() {
$( "#datepicker" ).datepicker();
});
</SCRIPT>
<DIV class=demo>
<P>Date: <INPUT id=datepicker></P></DIV><!-- End demo -->
<DIV class=demo-description style="DISPLAY: none">
<P>The datepicker is tied to a standard form input field. Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay. Choose a date, click elsewhere on the page (blur the input), or hit the Esc key to close. If a date is chosen, feedback is shown as the input's value.</P></DIV><!-- End demo-description -->
puts "factory id: #{@user.id}"
User.destroy_all
puts "factory id after destroyall : #{Factory(:user).id}"
yields:
factory id: 942334689
factory id after destroyall : 942334690
require 'rubygems'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:quiet) do |t|
t.verbose = false
end
class User
include Mongoid::Document
references_many :sombreros, :inverse_of => :wearer, :class_name => "Hat"
end
class Hat
references_in :wearer, :inverse_of => :sombreros, :class_name => "User", :stored_as => :array
end
User.sombreros uses a Mongoid::Criterio with an @selector querying the user_id. It should query for the wearer_id.