Skip to content

Instantly share code, notes, and snippets.

View sporkd's full-sized avatar

Peter Gumeson sporkd

View GitHub Profile
@sporkd
sporkd / Puppetfile
Last active August 29, 2015 13:56
Working Boxen config for older MacBook Pro
#------ snip ------
# Includes many of our custom types and providers, as well as global
# config. Required.
github "boxen", "3.4.2"
# Core modules for a basic development environment. You can replace
# some/most of these if you want, but it's not recommended.
@sporkd
sporkd / nested_view.js
Created March 6, 2012 20:14
Backbone.js add nested view example
addNested: function(model) {
var view = new View.Nested({ model: model });
this.$("#nested-view").html(view.render().el);
// Then I can safely init stuff like chosen.js
view.$("select").chosen();
}
@sporkd
sporkd / question.rb
Created February 15, 2012 23:33
Using arel matches_any
class Question < ActiveRecord::Base
# UGLY
def self.starts_with(*strings)
# Big loop to build something like this...
where("wording LIKE ? OR wording LIKE ? OR wording LIKE ?", 'blah%', 'blaah%', 'blaaah%')
end
# PURDY
def self.starts_with(*strings)
strings = strings.map { |s| s+'%' }
@sporkd
sporkd / file-user.json
Created December 12, 2011 23:55 — forked from bensie/file-user.json
Sublime Settings
{
"color_scheme": "Packages/Color Scheme - Default/Cobalt.tmTheme",
"font_size": 13.0,
"ensure_newline_at_eof_on_save": true,
"tab_size": 2,
"draw_white_space": "all",
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true
}
@sporkd
sporkd / tempfile.rb
Created October 1, 2011 23:31
Save carrierwave attachment to tempfile
Tempfile.open("attachment", "#{Rails.root}/tmp") do |f|
f.binmode # my attachment is binary
f.write(model.attachment.file.read)
end
@sporkd
sporkd / backbone-rails.js
Created June 20, 2011 22:54
Alias Backbone.sync method to inject Rails specific parameters
_.extend(Backbone.Model.prototype, {
// By default, rails expects model params to be wrapped in a nested params hash
// https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/params_wrapper.rb
_paramsWrapper : function() {
return this.paramsWrapper;
}
});
// Alias Backbone.sync method to inject Rails specific
@sporkd
sporkd / ruby-debugger-install.sh
Created March 7, 2011 03:34
How to install ruby debugger on rvm
gem install ruby-debug19 -- --with-ruby-include=/Users/peter/.rvm/src/ruby-1.9.2-head/
@sporkd
sporkd / mongoid_nested_embeds_many.rb
Created January 23, 2011 08:51
Explains how mongoid embeds_many is breaking when nesting more than 1 level deep
class Author
include Mongoid::Document
field :name, :type => String
embeds_many :posts
end
class Post
include Mongoid::Document
field :title, :type => String
embedded_in :author
Attempt 1 (require comes first)
---------------------------------
### lib/html5-boilerplate.rb ###
require File.join(File.dirname(__FILE__), 'app', 'helpers', 'html5_boilerplate_helper')
Compass::Frameworks.register("html5-boilerplate", :path => "#{File.dirname(__FILE__)}/..")
Stack Trace:
/Users/peter/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': /Users/peter/.rvm/gems/ruby-1.9.2-head@html5/gems/html5-boilerplate-0.1.6/lib/html5-boilerplate.rb:1: syntax error, unexpected tCONSTANT, expecting $end (SyntaxError)
sudo aptitude update
sudo aptitude dist-upgrade
sudo aptitude install openssh-server
sudo aptitude install build-essential binutils-doc
sudo aptitude install autoconf flex bison
sudo aptitude install vim