Skip to content

Instantly share code, notes, and snippets.

View benedikt's full-sized avatar

Benedikt Deicke benedikt

View GitHub Profile
@benedikt
benedikt / gist:1977438
Created March 5, 2012 08:21
Protect all fields against mass assignment in a mongoid document by default
module Mongoid
module MassAssignmentSecurity
extend ActiveSupport::Concern
included do
attr_accessible nil
end
end
module Document
@benedikt
benedikt / active_model_serializers.rb
Created March 2, 2012 17:40
Makes mongoid and active_model_serializers play nicely together
# config/initializers/active_model_serializers.rb
Mongoid::Document.send(:include, ActiveModel::SerializerSupport)
Mongoid::Criteria.delegate(:active_model_serializer, :to => :to_a)
@benedikt
benedikt / pling.rb
Created October 24, 2011 11:48
Pling resque adapter
Pling.configure do |config|
config.gateways.use Pling::Gateway::C2DM, { :email => '', :password => '', :source => '' }
config.adapter = Pling::Adapter::Resque.new
end
Resque.before_first_fork do
Pling.gateways.initialize!
Pling.middlewares.initialize!
end
@benedikt
benedikt / rails.rb
Created July 30, 2011 13:16
Capistrano task to open a rails console on a remote server. Require this file in your deploy.rb and run "cap rails:console"
# encoding: UTF-8
Capistrano::Configuration.instance(:must_exist).load do
namespace :rails do
desc "Open the rails console on one of the remote servers"
task :console, :roles => :app do
hostname = find_servers_for_task(current_task).first
exec "ssh -l #{user} #{hostname} -t 'source ~/.profile && #{current_path}/script/rails c #{rails_env}'"
end
end
@benedikt
benedikt / gesture.png
Created April 26, 2011 10:14
Both are equivalent
gesture.png
var Sample = function() {
var iamHidden = "you can't see me!";
this.lookInside = function() {
return iamHidden;
};
};
describe("Sample", function() {
it("should be equal", function() {