Skip to content

Instantly share code, notes, and snippets.

View jeffdeville's full-sized avatar

Jeff Deville jeffdeville

View GitHub Profile
$ bundle install
Updating git://github.com/jugend/amazon-ecs.git
fatal: '/Volumes/DATA/osx/jeff/.rvm/gems/ree-1.8.7-2010.02/cache/bundler/git/amazon-ecs-a0aa5ed40bb287c7b202ef607503f2ced5d0980c' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
An error has occurred in git. Cannot complete bundling.
Jeff-Devilles-MacBook-Pro:idea_collection jeffdeville$ rvm info
ree-1.8.7-2010.02:
system:
uname: "Darwin Jeff-Devilles-MacBook-Pro.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386"
shell: "bash"
version: "3.2.48(1)-release"
rvm:
version: "rvm 0.1.40 by Wayne E. Seguin ([email protected]) [http://rvm.beginrescueend.com/]"
class IdeaRatingIndexDto
attr_accessor :title, :url, :id
attr_writer :image
def image
@image || "/images/no_product_image.jpg"
end
def initialize(gift_idea)
@title = gift_idea.title
@url = gift_idea.url
if top_sellers.class.inspect == "Array"
asins = top_sellers.collect {|item| item.get('asin') }
elsif !top_sellers.nil?
asins = [top_sellers.get('asin')]
end
asins = asins || []
@jeffdeville
jeffdeville / gist:483086
Created July 20, 2010 15:18
YB BDD context
[TestFixture]
public abstract class Context
{
private Exception exception;
protected MockFactory factory;
protected AutoMockContainer container;
[TestFixtureSetUp]
public void initialize()
{
using System;
using Autofac;
using Autofac.Builder;
using Moq;
using System.Reflection;
using Autofac.Component.Activation;
using Autofac.Component;
using Autofac.Component.Scope;
namespace yellowbook.testing.common
scope :unrated_by, lambda {|user_id, limit|
# First, get a list of all of the products a user has already rated.
ids_to_exclude = Rating.only(:rateable_id).where(:user_id => user_id).collect{|r| r.rateable_id}
# I want to put the user in at a random point in the database to start rating products,
# to ensure that all products will have roughly the same number of ratings. Understanding the
# formula below isn't critical to understanding my problem.
total_idea_pool = GiftIdea.where(:sales_rank.lt => 1200).count - ids_to_exclude.size - limit
skip = total_idea_pool > 0 ? rand(total_idea_pool) : 0
The index I've created
db.gift_ideas.ensureIndex({"sales_rank":1, "rated_by":1, "random":1});
The query, in it's fast form, but that does not return gift_ideas as ordered by the random field
db.gift_ideas.find({"sales_rank":{$lt:1200}, "rated_by":{$nin:["100001450582916"]}, "random":{$gt:0.6071995101094684}}).limit(40)
The query, in it's dog-slow form, where I enforce the sorting
db.gift_ideas.find({"sales_rank":{$lt:1200}, "rated_by":{$nin:["100001450582916"]}, "random":{$gt:0.6071995101094684}}).limit(40).sort({"random":1})
Field Info for gift_ideas:
def dopplegangers()
raise StandardError.new("insufficient interests") unless interests.size >= MINIMUM_INTERESTS
usr_ints = interests.collect { |c| c.facebook_id }
matches = User.collection.find({
:facebook_id => {"$ne" => facebook_id}, #don't use current user
:access_token => {"$ne" => nil}, # access_token = activeuser
"interests.facebook_id" => {"$in" => usr_ints}}, # load all where at least 1 interest shared
{:fields => [:facebook_id, :interests]}).to_a
matches.each {|match| match[:score] = calculate_score(match) }
matches.sort{|x,y| y[:score] <=> x[:score]}
@jeffdeville
jeffdeville / heroku rake error
Created October 14, 2010 22:58
Error message I'm getting from heroku
/Volumes/osx/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/net/http.rb:586:in `connect': SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read finished A (OpenSSL::SSL::SSLError)
from /Volumes/osx/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/net/http.rb:586:in `connect'
from /Volumes/osx/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/net/http.rb:553:in `do_start'
from /Volumes/osx/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/net/http.rb:542:in `start'
from /Volumes/osx/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rest-client-1.6.1/lib/restclient/request.rb:166:in `transmit'
from /Volumes/osx/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rest-client-1.6.1/lib/restclient/request.rb:60:in `execute'
from /Volumes/osx/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rest-client-1.6.1/lib/restclient/request.rb:31:in `execute'
from /Volumes/osx/jeffdeville/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/gems/1.8/gems/rest-cli