Skip to content

Instantly share code, notes, and snippets.

View benedikt's full-sized avatar

Benedikt Deicke benedikt

View GitHub Profile
var Sample = function() {
var iamHidden = "you can't see me!";
this.lookInside = function() {
return iamHidden;
};
};
describe("Sample", function() {
it("should be equal", function() {
@benedikt
benedikt / gesture.png
Created April 26, 2011 10:14
Both are equivalent
gesture.png
@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 / 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 / spec_helper.rb
Created April 24, 2012 11:50
Makes spork-rails reload everything nicely
Spork.each_run do
if Spork.using_spork?
ActionDispatch::Reloader.cleanup!
ActionDispatch::Reloader.prepare!
FactoryGirl.reload
end
# This line should only be necessary when you have support files
# that use a namespace which is defined somewhere in your application.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
@benedikt
benedikt / projects_controller_spec.rb
Created July 17, 2012 18:50
I wish this would just work...
require 'spec_helper'
describe ProjectsController do
let(:project) { double(:project) }
let(:projects) { [project] }
describe 'GET show' do
let(:params) { { :id => 1, :format => :json } }
\lstdefinelanguage{ECMAScript}
{morekeywords={break, else, new, var, case, finally, return, void, catch, for, switch, while, continue, function, this, with, default, if, throw, delete, in, try, do, instanceof, typeof,
abstract, enum, int, short, boolean, export, interface, static, byte, extends, long, super, char, final, native, synchronized, class, float, package, throws, const, goto, private, transient,
debugger, implements, protected, volatile, double, import, public},
sensitive,
morecomment=[l]//,
morecomment=[s]{/*}{*/},
morestring=[b]",
morestring=[b]',
}[keywords,comments,strings]
@benedikt
benedikt / gist:5859066
Last active December 18, 2015 23:08
Is this a mongoid bug or a feature?
Model.elem_match(:embedded => { :a => 1, :b => 2 })
# => #<Mongoid::Criteria
# selector: {"embedded"=>{"$elemMatch"=>{:a=>1, :b=>2}}}
# options: {}
# class: Model
# embedded: false>
Model.elem_match(:embedded => { :a => 1 }).elem_match(:embedded => { :b => 2 })
# => #<Mongoid::Criteria
# selector: {"embedded"=>{"$elemMatch"=>{:b=>2}}}
@benedikt
benedikt / array_each.rb
Created October 23, 2013 09:28
In Rubinius, the `Array#each` method does not enumerate elements that are added while enumerating. Is this intentional or a bug?
array = [1, 2]
array.each { |n| array << n * 2; break if n > 10 }
array
# ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
# => [1, 2, 2, 4, 4, 8, 8, 16, 16, 32]
# rubinius 2.1.1 (2.1.0 be67ed17 2013-10-18 JI) [x86_64-darwin12.5.0]
# => [1, 2, 2, 4]
@benedikt
benedikt / Howto.md
Last active January 4, 2016 06:09
Setting up AppSignal on Shelly Cloud

Setting up AppSignal on Shelly Cloud

To set up AppSignal on Shelly Cloud, you first have to add both the dotenv-rails and the appsignal gem to your Gemfile. Make sure that the dotenv-rails gem is the very first gem in your Gemfile as it will set up important environment variables as soon as it is required.

# Gemfile

source 'https://rubygems.org'

gem 'dotenv-rails'