Skip to content

Instantly share code, notes, and snippets.

@pacoguzman
pacoguzman / application.js
Created November 4, 2011 09:49
ASPGEMS JS BestPractices - RelatedSelects
$('#candidate_form').relatedSelects({
onChangeLoad: '/candidate/profile/update_locations_select',
defaultOptionText: I18n.translate('general.choose_option'),
selects: {
'candidate_profile[country_id]' : {
loadingMessage: I18n.translate('general.loading_provinces')
},
'candidate_profile[province_id]': {
loadingMessage: I18n.translate('general.loading_locations')
},
.fan_box .full_widget {
border: solid 1px #94A3C4;
background: white;
}
.fan_box .connections_grid .grid_item {
float: left;
overflow: hidden;
padding: 0 5px 8px 0;
}
@pacoguzman
pacoguzman / application.js
Created July 27, 2011 17:22
focused() method in Prototype
Element.addMethods({
focused: function(element) {
return element === document.activeElement && ( element.type || element.href );
}
});
$(document).on('mouseleave', 'input.special', function(e, el){
if (!el.focused() || el.focused().length == 0) {
el.removeClassName("special-focus");
}
@pacoguzman
pacoguzman / DESIGN_DOCS
Created July 4, 2011 06:52
ElasticSearch and Couchdb River
# Create design documents with the filters
curl -vX PUT 'http://127.0.0.1:5984/couchdb_myapp_development/_design/Product' -d '{
"_id": "_design/Product",
"language": "javascript",
"filters": {
"product": "function(doc, req) { return doc['type'] == 'Product'; }"
}
}'
curl -vX PUT 'http://127.0.0.1:5984/couchdb_myapp_development/_design/Person' -d '{
@pacoguzman
pacoguzman / _multi_select.html
Created June 1, 2011 10:20
ASPGEMS JS BestPractices - MultiSelects
<select name="initiative[collaborator_ids][]" multiple="multiple" id="initiative_collaborator_ids" class="multiselect" style="display: none;">
<option value="5" selected="selected">usuario2@localmail.com</option>
<option value="7">fake_user1@domain.com</option>
<option value="8">fake_user2@domain.com</option>
<option value="9">fake_user3@domain.com</option>
<option value="10">fake_user4@domain.com</option>
<option value="11">fake_user5@domain.com</option>
<option value="12">fake_user6@domain.com</option>
<option value="13">fake_user7@domain.com</option>
<option value="14">fake_user8@domain.com</option>
@pacoguzman
pacoguzman / solr_instrumentation.rb
Created May 25, 2011 22:06
Add sunspot solr instrumentation to a rails 3 app
module Sunspot
module Rails
module SolrInstrumentation
extend ActiveSupport::Concern
included do
alias_method :request_without_as_instrumentation, :request
alias_method :request, :request_with_as_instrumentation
end
class DynamicInclusionValidator < ActiveModel::EachValidator
def check_validity!
raise ArgumentError, "A proc which result has the method include? is required as the " <<
":in option of the configuration hash" unless options[:in].respond_to?(:call)
end
def validate_each(record, attribute, value)
unless options[:in].bind(record).call.include?(value)
record.errors.add(attribute, :inclusion, options.except(:in).merge!(:value => value))
end
@pacoguzman
pacoguzman / rails_3_1_beta_1_changes.md
Created May 6, 2011 07:34 — forked from ryanb/rails_3_1_rc4_changes.md
The Changelogs for Rails 3.1 Beta 1

Railties 3.1 Beta 1

  • The -j option of the application generator accepts an arbitrary string. If passed "foo", the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest requires "foo" and "foo_ujs". As of this writing "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline. Default is "jquery". [fxn]

  • jQuery is no longer vendored, it is provided from now on by the jquery-rails gem. [fxn]

  • Prototype and Scriptaculous are no longer vendored, they are provided from now on by the prototype-rails gem. [fxn]

  • The scaffold controller will now produce SCSS file if Sass is available [Prem Sichanugrist]

@pacoguzman
pacoguzman / gist:762794
Created January 2, 2011 20:38 — forked from fletcherm/gist:757775
RSpec backtrace clean pattern
RSpec.configure do |config|
# RSpec automatically cleans stuff out of backtraces;
# sometimes this is annoying when trying to debug something e.g. a gem
config.backtrace_clean_patterns = [
/\/lib\d*\/ruby\//,
/bin\//,
/gems/,
/spec\/spec_helper\.rb/,
/lib\/rspec\/(core|expectations|matchers|mocks)/
]
@pacoguzman
pacoguzman / multi_single_select.js
Created December 11, 2010 11:28
Transform select multiple to a single select - Progressive Enhancement
// Convert a multi-select into a single_select which keeps track of choices in an external list with
// hidden fields. The hidden fields have the same field name as the multi select. list_class
// defaults to the select id + "_data" Chosen options are moved from the 'Add' option group to
// the 'Remove' option group, Each suffixed by the given 'title' or the string "Option". The select
// header is extracted from the select's label for - if it exists. Otherwise it just prints 'Options...'
//
// Example:
//
// $("select_multi").multiSingleSelect({list_class:'select_multi_data', title:'Option',
// remove: "Remove", add: "Add", prompt: "Options..."});