Skip to content

Instantly share code, notes, and snippets.

View overture8's full-sized avatar

Phil McClure overture8

  • Stora
  • Belfast, Northern Ireland
View GitHub Profile
@overture8
overture8 / unobtrusive_observe_form.js
Created October 7, 2009 12:15
Unobtrusively observe a form with prototype
var ObserveForm = Class.create({
initialize: function() {
this.form = $('form_id');
this.form.observe('submit', this.submitForm.bindAsEventListener(this));
this.data_area = $('display_area');
},
submitForm: function(event) {
event.stop();
this.form.request({
class Company < ActiveRecord::Base
# Sunspot/Solr search indexing
searchable do
string :name
text :profile
integer :media_type_id
integer :sector_type_id, :multiple => true do
sectors.map {|sector| sector.sector_type_id}
end
end
def search_results
search = Company.search do
keywords 'belfast marketing'
with(:sector_type_id).any_of [1, 2, 4, 8]
paginate :page => page_number, :per_page => 30
order_by :name, :asc
end
@results = search.results
end
<h2>Your results</h2>
<% unless @results.nil? %>
<table>
<tr>
<th>company</th>
<th>profile</th>
</tr>
<% for result_item in @results %>
<tr class="<%= cycle('odd', 'even') %>">
<td><%= result_item.name %></td>
common: &common
solr:
hostname: localhost
port: 8983
production:
<<: *common
solr:
path: /data/solr/myapp
// ***** Roast Theme
!base_color_1 = #2D1E1E
!base_color_2 = #4B3C37
!base_color_1_light = !base_color_1 + #212121
!base_color_1_lighter = !base_color_1 + #444444
!base_color_1_dark = !base_color_1 - #111111
!base_color_2_light = !base_color_2 + #212121
!base_color_2_lighter = !base_color_2 + #444444
// ***** Raindrop Theme
!base_color_1 = #1C1D21
!base_color_2 = #31353D
!base_color_1_light = !base_color_1 + #212121
!base_color_1_lighter = !base_color_1 + #444444
!base_color_1_dark = !base_color_1 - #111111
!base_color_2_light = !base_color_2 + #212121
!base_color_2_lighter = !base_color_2 + #444444
// ***** Ruby Theme
!base_color_1 = #212121
!base_color_2 = #660000
!base_color_1_light = !base_color_1 + #212121
!base_color_1_lighter = !base_color_1 + #444444
!base_color_1_dark = !base_color_1 - #111111
!base_color_2_light = !base_color_2 + #212121
!base_color_2_lighter = !base_color_2 + #444444
@overture8
overture8 / sort_mongomapper_embeddoc.rb
Created January 20, 2010 11:46
How to sort by a field in an EmbeddedDcouemt (MongoMapper)
post.comments.sort_by(&:created_at)
@overture8
overture8 / mongomapper_sort_desc.rb
Created January 20, 2010 11:47
Sort field in MongoMapper EmbeddedDocument (Descending)
post.comments.sort_by(&:created_at).reverse