Skip to content

Instantly share code, notes, and snippets.

class Airmigo
include DataMapper::Resource
property :id, Serial
belongs_to :from, :class_name => 'User'
belongs_to :to, :class_name => 'User'
before :save do
Airmigo.first_or_create(:conditions => { :from => to, :to => from })
############### Named filter issues.
#
# 1) The table aliases for explicit joins are hacky. Obviously this is an easy fix, but we should
# talk about the best alternative. In this example, the resulting alias should not be "posts_blogs".
#
# => Agreed, although I can't think of anything really clever at the moment...
Post.filter do
join(Blog, :left, :posts_blogs) do
unless ENV['RAILS_ROOT']
ENV['RAILS_ROOT'] = Dir.pwd
end
STDERR.puts("Loading Rails environment...")
require File.join(ENV['RAILS_ROOT'], 'config', 'environment')
groups = CharacteristicGroup.filter do
with(:name).in(['Gender', 'Age', 'Lifestage', 'Internal QA'])
end
# s.query.keywords = params[:q] unless params[:q].blank?
# s.query.order_by(params[:order_by], params[:direction] || 'asc') if params[:order_by] && params[:order_by] != 'distance'
# s.query.order_by('content_score', 'desc') unless params[:order_by] && params[:order_by] == 'distance'
s.build do |query|
query.keywords(params[:q]) unless params[:q].blank?
query.order_by(params[:order_by], params[:direction] || 'asc') if params[:order_by] && params[:order_by] != 'distance'
query.order_by('content_score', 'desc') unless params[:order_by] && params[:order_by] == 'distance'
end
#
# Silently fail instead of raising an exception when an error occurs while writing to Solr.
# NOTE: does not fail for reads; you should catch those exceptions, for example in a rescue_from statement.
#
# To configure, add this to an initializer:
# Sunspot.session = SilentFailSessionProxy.new
#
# This is for Sunspot 0.18 and would need to be changed a little bit for Sunspot 1.0.
#
class SilentFailSessionProxy
CREATE TABLE stats (
column_name text,
column_value int,
test_id uuid,
score int,
height int,
PRIMARY KEY (column_name, column_value, test_id)
);
-- Now let's say we have a logical row with score=20, height=150
@outoftime
outoftime / index.html
Last active September 16, 2015 22:55 — forked from anonymous/index.html
JS Bin // source http://jsbin.com/renuhideco
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
@outoftime
outoftime / index.html
Last active September 20, 2015 18:07 — forked from anonymous/index.html
JS Bin // source http://jsbin.com/nopezo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
This is my first website! Hello, world!
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>