Skip to content

Instantly share code, notes, and snippets.

View victor-github's full-sized avatar

Victor Olteanu victor-github

View GitHub Profile
@victor-github
victor-github / gist:4716110
Created February 5, 2013 17:36
an example of handlebars helper for iteration
<table class="table table-bordered">
{{#each_in_group this}}
{{view App.ShowNoteView noteBinding="this"}}
{{/each_in_group}}
</table>
//a helper for iteration
Handlebars.registerHelper('each_in_group', function(context, options) {
var date = options.contexts[0], //the argument
group = App.notesController.get('dates_notes')[date],
@victor-github
victor-github / Rakefile
Created January 4, 2013 18:45
RefineryCMS: make the default spec task include all extension specs. Add this to the bottom of your Rakefile. "bundle exec rake" will now execute all your specs
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
MyApp::Application.load_tasks
Rake.application.options.trace = true
$ RAILS_ENV=test bundle exec rake SPEC=vendor/extensions/events/app/controllers/refinery/events/events_controller.rb
/Users/bluestar007/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -S rspec vendor/extensions/events/app/controllers/refinery/events/events_controller.rb
/Users/bluestar007/projects/oconnor-davies/vendor/extensions/events/app/controllers/refinery/events/events_controller.rb:3:in `<module:Events>': uninitialized constant ApplicationController (NameError)
from /Users/bluestar007/projects/oconnor-davies/vendor/extensions/events/app/controllers/refinery/events/events_controller.rb:2:in `<module:Refinery>'
from /Users/bluestar007/projects/oconnor-davies/vendor/extensions/events/app/controllers/refinery/events/events_controller.rb:1:in `<top (required)>'
from /Users/bluestar007/.rvm/gems/ruby-1.9.3-p194@od/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load'
from /Users/bluestar007/.rvm/gems/ruby-1.9.3-p194@od/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `block in load_spec_f
@victor-github
victor-github / document.js
Created May 24, 2011 16:33
BackboneJS Associations - Document HasMany Categories
var Document = Backbone.Model.extend({
initialize: function() {
var categories = new App.Collections.Categories();
var self = this;
categories.url = function() {
return self.url() + '/categories';
};
self.set({
@victor-github
victor-github / convenienceBackbone.js
Created May 24, 2011 16:25
Convenience methods for Backbone.js
//gets value if field exists, and returns empty string otherwise
Backbone.Model.prototype.getValue = function(field) {
if (this.attributes[field] != undefined) {
return this.attributes[field];
}
else {
return '';
}
};
@victor-github
victor-github / evalStringObjects.js
Created May 24, 2011 16:23
Given a string of form field1.field2.field3..., parses it and returns "" if at any point the fields are not defined, or the value of the evaluation if all fields are defined
// usage: ifDefined("field1.field2.field3") - do not specify second argument
ifDefined: function(str_object, prev_eval) {
var i = str_object.indexOf('.');
if (i === -1) {
return true;
} else {
var first = str_object.substring(0,i),
last = str_object.substring(i+1),
j = last.indexOf('.'),
second = last;
@victor-github
victor-github / backbone.rails.js
Created May 7, 2011 21:26 — forked from trydionel/backbone.rails.js
Makes Backbone.js play nicely with default Rails setup
//
// Backbone.Rails.js
//
// Makes Backbone.js play nicely with the default Rails setup, i.e.,
// no need to set
// ActiveRecord::Base.include_root_in_json = false
// and build all of your models directly from `params` rather than
// `params[:model]`.
//
// Load this file after backbone.js and before your application JS.