Skip to content

Instantly share code, notes, and snippets.

View jmgarnier's full-sized avatar
💭
❤️🚲

Jean-Michel Garnier jmgarnier

💭
❤️🚲
View GitHub Profile
@jmgarnier
jmgarnier / bootstrap.rb
Created January 4, 2013 19:31
bootstrap a Rails project
#!/usr/bin/env ruby
# encoding: utf-8
# This command will help a new developer to contribute, see github http://zachholman.com/talk/ruby-patterns
# GOTO line 61 for the script itself
# Just for fun, a micro RSpec framework to run and document bootstrap process ;)
module Kernel
def bootstrap(description = "project", &block)
examples = Bootstrap::Dsl.new.parse(description, block)
@jmgarnier
jmgarnier / prepare-commit-msg
Last active December 16, 2015 12:29
Tired of typing the ticket number at the beginning of each commit msg? Git hooks to the rescue! From your current git project, edit the .git/hooks/prepare-commit-msg
#!/bin/sh
project="VCORE-"
ticket=$(git symbolic-ref HEAD | awk -F- '/VCORE-(.*)-/ {print $2}')
if [ -n "$ticket" ]; then
TEMP=`mktemp /tmp/commitmsg-XXXXX`
(echo "$project$ticket - "; cat $1) > $TEMP
cat $TEMP > $1
fi
@jmgarnier
jmgarnier / import.rb
Last active December 17, 2015 16:59
Use Case: you need to extract Rails engines from your kitchen sink webapp.
#!/usr/bin/env ruby
# Copy this file to the destination project folder
# Example:
# noglob ./import.rb *role* ../../project_source
# => copying app/models/role.rb
# => copying spec/models/role_spec.rb
@jmgarnier
jmgarnier / custom_plan.rb
Created June 19, 2013 10:02
When you need to truncate the test DB before each test, Zeus won't do it automatically. You need a custom plan for that: Run zeus init and then copy paste the following code.
require 'zeus/rails'
class CustomPlan < Zeus::Rails
def truncate_db
require 'database_cleaner'
DatabaseCleaner.clean_with :truncation
end
def test
require 'cancan'
# Add a setting to the application to configure the ability
ActiveAdmin::Application.inheritable_setting :cancan_ability_class, "Ability"
module ActiveAdmin
class CanCanAdapter < AuthorizationAdapter
def authorized?(action, subject = nil)
@jmgarnier
jmgarnier / factory_girl_ar_instrumentation.rb
Created September 8, 2014 09:06
Use FactoryGirl AR instrumentation to track how much time is spent creating test data
# https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#activesupport-instrumentation
RSpec.configure do |config|
test_data_setup_time = 0
ActiveSupport::Notifications.subscribe("factory_girl.run_factory") do |name, start, finish, id, payload|
execution_time_in_seconds = finish - start
test_data_setup_time += execution_time_in_seconds
@jmgarnier
jmgarnier / explain_analyze_in_dev.rb
Last active August 29, 2015 14:21
Postgres "EXPLAIN ANALYZE" from Rails 3.2 console with syntax hightlighting
if Rails.env.development?
require 'active_record/connection_adapters/postgresql_adapter'
require 'pygments' # add `gem 'pygments.rb', require: false` to Gemfile
module ExplainAnalyze
@@use_explain_analyze = false
def explain_analyze
@@use_explain_analyze = true
@jmgarnier
jmgarnier / google_translate_nl_to_en.scpt
Created November 2, 2016 09:25
Automator Service for passing selected text (after selection the service from context menu) to google translate (works in Google Chrome, OS X 10.10 still up-to-date) on run
-- Automator Service for passing selected text (after selection the service from context menu) to google translate (works in Google Chrome, OS X 10.10 still up-to-date)
on run {input}
set inputText to input as string
tell application "Google Chrome"
activate
set theUrl to "http://translate.google.com#nl/en/" & inputText

Keybase proof

I hereby claim:

  • I am jmgarnier on github.
  • I am jmgarnier (https://keybase.io/jmgarnier) on keybase.
  • I have a public key ASA_JUA4A3aXm4LT0fYtZTZxfmqHvkNgQkD5x-myA6guvQo

To claim this, I am signing this object:

@jmgarnier
jmgarnier / wait_for_ajax_on_steroids.rb
Last active July 3, 2018 12:52
Ruby on Rails with React, Wait for ajax - 💪🏻version
module WaitForAjax
def click_ajax_link(link, timeout: Capybara.default_max_wait_time)
with_ajax(timeout: timeout) { click_on link }
end
def wait_for_ajax
wait_for_ajax_status(:inactive)
end
def wait_for_ajax_status(expected_status, wait_time = Capybara.default_max_wait_time)