Skip to content

Instantly share code, notes, and snippets.

View msadouni's full-sized avatar

Matthieu Sadouni msadouni

View GitHub Profile
@nicolasblanco
nicolasblanco / gist:5684809
Last active December 17, 2015 22:49
The gems I use on almost all my projects (because today is Friday... if you know what I mean)

The gems I use on almost all my projects (because today is Friday... if you know what I mean)

  • kaminari

    Great pagination gem. I like writing my custom paginators as partials instead of Ruby classes.

  • rails_config

Even if there's "rails" in the name, this gem also works with other frameworks. Essential to have a global configuration object available everywhere in your app. I like the fact that it is environment-aware.

@gogogarrett
gogogarrett / artist_controller.rb
Last active December 17, 2015 03:38
Using Reform with a Workflow object to allow the controller to be simpler.
class ArtistsController < ApplicationController
def create
@form = create_new_form
workflow = Workflows::ArtistWorkflow.new(@form, params[:artist])
workflow.process do |obj|
return respond_with obj
end
render :new
@thbar
thbar / -Paranoid-BetterErrors-.md
Last active December 14, 2015 06:59
Slightly more paranoid better_errors activation.

Despite existing checks in the gem, I want to make sure it's not possible to activate better_errors at all in production (eg: erroneous RAILS_ENV configuration set to development, etc).

Here better_errors should be activated only if a .use_better_errors file is in place and if I'm on Mac OS X.

Not sure if this is necessary given the existing checks in the gem, but I suspect it cannot hurt either.

Next step: find a way to avoid putting them in the Gemfile completely.

@brunobord
brunobord / kill.js
Created January 30, 2013 23:21
Casper Script: restart Alwaysdata processes.
/**
* Casper script to restart Alwaysdata processes.
*
* Usage:
* $ casperjs kill.js email@example.com mysecretpassword
*/
var casper = require('casper').create();
casper.start("https://admin.alwaysdata.com/login/");
@bf4
bf4 / ruby_learning.md
Last active July 17, 2021 08:06
Some Ruby Learning Resources
@thbar
thbar / database.yml
Created January 22, 2013 08:09
Little sh script to enable git config for branch-specific databases with Rails.
<%
# http://mislav.uniqpath.com/rails/branching-the-database-along-with-your-code/
branch = `git symbolic-ref HEAD 2>/dev/null`.chomp.sub('refs/heads/', '')
suffix = `git config --bool branch.#{branch}.database`.chomp == 'true' ? "_#{branch}" : ""
%>
common: &common
adapter: mysql2
encoding: utf8
pool: 5
@ryanb
ryanb / issues_with_modules.md
Created November 29, 2012 22:38
Points on how modules can make code difficult to read.

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article &lt; ActiveRecord::Base
@kaelig
kaelig / README.md
Created November 28, 2012 11:10
HiDPI sprites with Compass
@mperham
mperham / after.rb
Created July 4, 2012 19:30
Thread-friendly shared connection
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
@bluemont
bluemont / url_validator.rb
Created June 25, 2012 04:27
ActiveModel URL Validator
class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
valid = begin
URI.parse(value).kind_of?(URI::HTTP)
rescue URI::InvalidURIError
false
end
unless valid
record.errors[attribute] << (options[:message] || "is an invalid URL")