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
def self.search(options = {}) | |
length_criteria = (options[:length] == 'all' or options[:length].blank?) ? '' : 'and LENGTH(name) = ' + options[:length] + ' ' | |
registered_criteria = options[:order] == 'views DESC' ? "and registered = false " : '' | |
viewable_criteria = "and viewable_at < '" + Time.now.utc.to_s(:db) + "' " | |
category_criteria = options[:category] != 'all' ? 'and category = "' + options[:category].downcase + '" ' : '' | |
public_criteria = options[:public_only] ? 'and public = true ' : '' | |
paginate :per_page => DOM_PER_PAGE, :page => options[:page], |
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
## Favorite.rb | |
class Favorite < ActiveRecord::Base | |
belongs_to :user | |
attr_accessible :name | |
validates_presence_of :name | |
validates_presence_of :user | |
validates_format_of :name, :with => /\A[a-z]+\Z/ | |
before_create :ensure_unique_for_this_user |
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
## Factory | |
Factory.define :promo, :class => Promotion do |promo| | |
promo.code "cm" | |
promo.quantity 100 | |
promo.remaining 100 | |
promo.description "for chris and mike" | |
end | |
## Spec |
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
The Javascript: | |
function stripeResponseHandler(status, response) { | |
if (response.error) { | |
$("#stripe_error").html(response.error.message); | |
$('input[type=submit]').attr('disabled', false) | |
} else { | |
$("#subscription_stripe_card_token").val(response.id); | |
$("#new_subscription").get(0).submit(); | |
} |
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
$.ajax({ | |
url : "http://words.bighugelabs.com/api/2/youapikey/" + word + "/json?callback=?", | |
dataType : 'json', | |
complete : function(jqXHR, textStatus) { | |
if (textStatus == 'parsererror') { | |
// Did not find any synonyms | |
alert("404 error because no synonyms exist for this word"); | |
} | |
}, | |
success : function(data) { |
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
POPULATION_SIZE = 50 | |
NUM_BITS = 64 | |
GENERATIONS = 1000 | |
SAMPLE_SIZE = 100 | |
CROSSOVER_PROBABILITY = 0.7 | |
MUTATION_RATE = 0.001 | |
class Chromosome | |
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
POPULATION_SIZE = 24 | |
NUM_BITS = 64 | |
NUM_GENERATIONS = 1000 | |
CROSSOVER_RATE = 0.7 | |
MUTATION_RATE = 0.001 | |
class Chromosome | |
attr_accessor :genes |
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
experiments = 1000 | |
visitors = 250 | |
conversion_rate = 0.3 | |
expected_conversions = visitors * conversion_rate | |
expected_sd = sqrt( visitors * conversion_rate * ( 1 - conversion_rate ) ) | |
sd_for_axis_range = 4.5 | |
axis_divisions = 5 | |
results = vector() |
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
setClass( | |
Class = "Distribution", | |
representation = representation( | |
name = "character", | |
participants = "numeric", | |
conversions = "numeric", | |
sample_proportion = "numeric", | |
se = "numeric", | |
color = "character", | |
x = "vector", |
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
namespace :lint do | |
task run: :environment do | |
js_dir = "#{Rails.root}/app/assets/javascripts" | |
Dir.chdir(js_dir) | |
# No directories and no application.js | |
files = Dir.glob('*').delete_if{ |f| File.directory?(f) || f == 'application.js' } | |
files.each do |file| | |
puts file | |
OlderNewer