Skip to content

Instantly share code, notes, and snippets.

View mbobin's full-sized avatar
🔧
side effects

Marius Bobin mbobin

🔧
side effects
View GitHub Profile
@mbobin
mbobin / active_record_gem.rb
Last active July 11, 2017 12:32
ActiveRecord has_many through polymorphic bug
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
# Activate the gem you are reporting the issue against.
@mbobin
mbobin / active_record_extension.rb
Last active September 12, 2016 12:50 — forked from ozydingo/active_record_extension.rb
ActiveRecord left join
module ActiveRecordExtension
extend ActiveSupport::Concern
module ClassMethods
# Simple left join taking advantage of existing Rails & Arel code
def left_joins(*args)
inner_joins = self.unscoped.joins(*args).arel.join_sources
left_joins = inner_joins.map do |join|
Arel::Nodes::OuterJoin.new(join.left, join.right)
end
#!/usr/bin/env ruby
hits = []
checks = {
#'_spec\.rb$' => ['focus:[:space:]*true'],
'\.rb$' => ['binding\.pry', 'debugger', 'byebug', 'console\.log'],
'\.erb$' => ['binding\.pry', 'debugger', 'byebug', 'console\.log'],
'\.js$' => ['binding\.pry', 'debugger', 'byebug', 'console\.log'],
'\.coffee$' => ['binding\.pry', 'debugger', 'byebug', 'console\.log'],
{
"ensure_newline_at_eof_on_save": true,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"rulers":
[
80,
100,
140
@mbobin
mbobin / overlay.js
Last active July 24, 2016 23:29
bookmarklet - adds a black div as overlay
// add layer
javascript:(
function() {
var div = document.createElement('div');
var w = window.innerWidth;
var h = window.innerHeight;
div.setAttribute("class", "black-overlay");
div.setAttribute("style", "position: fixed; top: 0px; left:0px; width: "+w+"px; height: "+h+"px; background-color: rgba(0,0,0,0.3); pointer-events: none; z-index: 4294967296");
document.body.appendChild(div);
}