Skip to content

Instantly share code, notes, and snippets.

View remi's full-sized avatar
👋

Rémi Prévost remi

👋
View GitHub Profile

Keybase proof

I hereby claim:

  • I am remiprev on github.
  • I am remi (https://keybase.io/remi) on keybase.
  • I have a public key whose fingerprint is 0EB8 6575 1221 3709 D835 08F6 2601 D146 D7E8 4CB5

To claim this, I am signing this object:

@remi
remi / memoizable.rb
Created February 25, 2015 18:23
Define memoized methods with style
#!/usr/bin/env ruby
module Memoizable
# This would be `extend ActiveSupport::Concern` in Rails
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def define_memoized(method)
@remi
remi / schema_dumper.rb
Created October 2, 2014 20:05
Remove the useless and harmful ActiveRecord::SchemaDumper vertical alignment
# Remove the useless and harmful ActiveRecord::SchemaDumper vertical alignment
module ActiveRecord
class SchemaDumper
def table_with_sane_alignment(table, main_stream)
# Call the original method to populate our custom stream
stream = StringIO.new
table_without_sane_alignment(table, stream)
# Rewind the stream and remove useless whitespace
content = stream.tap(&:rewind).read.gsub(/(?<!^)(?<!\s)[ ]{2,}/, ' ')
@remi
remi / gist:308c690da9483adaaddf
Last active August 29, 2015 14:06
Update Bash on OS X without setting it as default shell
$ brew update
$ brew install bash
$ sudo mv /bin/bash /bin/bash-what-the-hell-man
$ sudo ln -s `brew --prefix`/bin/bash /bin/bash
@remi
remi / gist:dbed458d7eb0ebdcfc25
Created August 26, 2014 12:55
Debug Rails mailer views
# config/routes.rb
get 'mailer_test', to: 'application#mailer_test'
# app/controllers/application_controller.rb
def mailer_test
render text: UserMailer.welcome_email(User.first).body.to_s
end

Keybase proof

I hereby claim:

  • I am remiprev on github.
  • I am remi (https://keybase.io/remi) on keybase.
  • I have a public key whose fingerprint is D902 6B81 9AE6 EA3E E4A4 AA02 F64F 552E 0DB2 83C4

To claim this, I am signing this object:

@remi
remi / current_year_benchmark.rb
Created April 1, 2014 17:55
The fastest way to get the current year in Ruby
#!/usr/bin/env ruby
require 'benchmark'
require 'date'
Benchmark.bm do |x|
x.report('Time.now') { 100_000.times { Time.now.year } }
x.report('Date.today') { 100_000.times { Date.today.year } }
end
@remi
remi / migrate.rake
Created December 5, 2013 13:13
`db:migrate:data` task
# Migrate data from two ActiveRecord databases.
# Works with ActiveRecord 3 and above.
#
# Written by Rémi Prévost
# Based on the work of Rama McIntosh & Mike Castleman
#
# This task is released under this BSD license:
#
# Copyright (c) 2008, Matson Systems, Inc.
# Copyright (c) 2010, Roasted Vermicelli LLC.
@remi
remi / rack_date.rb
Created November 27, 2013 12:58
Testing Rack::Date with RSpec and Rack::MockRequest
require "rack"
class Rack::Date
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
headers.merge! 'Date' => Time.now.httpdate
@remi
remi / README.md
Created October 3, 2013 19:04
ImageOptim + ImageAlpha via commandline

Installation

Install binaries

Most of them are available through Homebrew.

$ brew install advancecomp gifsicle jhead jpegoptim jpeg optipng pngcrush