Skip to content

Instantly share code, notes, and snippets.

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

Jean-Michel Garnier jmgarnier

💭
❤️🚲
View GitHub Profile
@keathley
keathley / dry_monad_usage.md
Last active March 14, 2024 15:16
A description of how to take advantage of the dry-monad gem.

How we're using dry-monad

Imagine that we have an application where user's have a location. We want to find the weather for their current location using an external service call. We want to provide this functionality in a json api. A basic implementation might look like this.

def create
 user = User.find(params[:id])
@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
@ngsmrk
ngsmrk / sidekiq_monitoring
Created August 11, 2014 11:51
Sidekiq queue checking via rails console
stats = Sidekiq::Stats.new
stats.queues
stats.enqueued
stats.processed
stats.failed
@jmgarnier
jmgarnier / fast_presenter_spec.rb
Created December 6, 2012 10:24
How to unit test a presenter using rails i18n and ActionView helpers *without* loading the spec_helper, hence keeping the tests fast?
require 'action_view/helpers/number_helper'
require 'rails-i18n'
class FastPresenter
include ActionView::Helpers::NumberHelper
def initialize(value)
@value = value
end
@funny-falcon
funny-falcon / falcon.patch
Created September 14, 2012 12:07
Performance patch for ruby-1.9.3-head (applies to p194 as well)
diff --git a/array.c b/array.c
index 64647c3..618d9e3 100644
--- a/array.c
+++ b/array.c
@@ -255,15 +255,24 @@ rb_ary_modify(VALUE ary)
rb_ary_modify_check(ary);
if (ARY_SHARED_P(ary)) {
long len = RARRAY_LEN(ary);
+ VALUE shared = ARY_SHARED(ary);
if (len <= RARRAY_EMBED_LEN_MAX) {