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
| CREATE TABLE `ladder` ( | |
| `i` int(1) unsigned NOT NULL, | |
| PRIMARY KEY (`i`) | |
| ) ENGINE=InnoDB DEFAULT CHARSET=latin1; | |
| INSERT INTO ladder (i) VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9); | |
| SELECT l1.i + l2.i * 10 + l3.i * 100 AS sequence | |
| FROM ladder l1 | |
| JOIN ladder l2 ON TRUE |
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 Question < ActiveRecord::Base | |
| default_scope order("seq ASC") | |
| # decrement seq / page # depending on position and page count | |
| def move_up! | |
| if self.first_on_page? | |
| move_to_previous_page! | |
| else | |
| decrement_seq! && self.survey.renumber_questions! | |
| end |
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
| /** | |
| * normalizeEvent | |
| * | |
| * Firefox does not implement offsetX, OffsetY, so we have to detect for this an | |
| * manually calculate it ourselves using the pageX, pageY less the event | |
| * target's left offset and right offset | |
| * | |
| * If using a browser that supports offsetX, OffsetY, just return the event, | |
| * don't need to do anything | |
| */ |
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
| require 'spec_helper' | |
| describe Question do | |
| it { should belong_to(:page) } | |
| it { should belong_to(:survey) } | |
| it { should have_many(:answers) } | |
| describe "default scope" do | |
| let(:first_question) { Question.create(seq: 1) } | |
| let(:second_question) { Question.create(seq: 2) } |
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
| require 'fileutils' | |
| require 'ostruct' | |
| require 'pony' | |
| require 'active_support' | |
| module MakeEmailable | |
| extend ActiveSupport::Concern | |
| included do | |
| attr_reader :sender, :receiver |
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
| require 'spec_helper' | |
| describe Track do | |
| describe "commenters" do | |
| let(:sleepy) { build(:user, fullname: 'Mr. Sleepy', email: 'sleepy@example.com', username: 'sleepy') } | |
| let(:dopey) { build(:user, fullname: 'Mr. Dopey', email: 'dopey@example.com', username: 'dopey') } | |
| let(:doc) { build(:user, fullname: 'Mr. Doc', email: 'doc@example.com', username: 'doc') } | |
| let(:sleepy_comment) { build(:comment, commenter: sleepy, content: "sleepy's comment") } | |
| let(:dopey_comment) { build(:comment, commenter: dopey, content: "dopey's comment") } | |
| let(:track) { build(:track) } |
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
| # simulation to calculate an answer to the question: | |
| # | |
| # "If you break a straight line randomly in two places, what is the probability that you can | |
| # form a triangle from the resulting three pieces?" | |
| # | |
| # usage: ruby ./triangles-sim.rb [trials] | |
| # sample output: | |
| # | |
| # $> ruby ./triangles-sim.rb 1000000 | |
| # |
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
| # simulation to calculate an answer to the question: | |
| # | |
| # "In a country in which people only want boys, every family continues to have children until they have a boy. If they | |
| # have a girl, they have another child. If they have a boy, they stop. What is the proportion of boys to girls in the | |
| # country?" | |
| # | |
| # !/usr/bin/env ruby | |
| # usage: ./family-sim.rb [trials] | |
| # | |
| # sample output: |
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
| require 'rubygems' | |
| require 'bundler' | |
| Bundler.require | |
| require './application' | |
| namespace :assets do | |
| desc 'compile assets' | |
| task :compile => [:compile_js, :compile_css] do | |
| end |
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
| module Mongoid | |
| module CounterCache | |
| extend ActiveSupport::Concern | |
| module ClassMethods | |
| # Use Case: | |
| # | |
| # keep a cached count of embedded collections in the parent collection(s) | |
| # | |
| # for example, if a Post embeds many Comments, and there have been 2 |