Skip to content

Instantly share code, notes, and snippets.

View remi's full-sized avatar
👋

Rémi Prévost remi

👋
View GitHub Profile
@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

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 / 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
@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 / 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 / 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)
<?php
function RSS_populateItemTemplate( $item ) {
$content = $item->children('http://purl.org/rss/1.0/modules/content/')->encoded;
return array(
'content' => $content
);
}
<?php
/**
* This filter makes it easy to use the same WordPress theme and resources
* accross multiple WordPress MU blogs.
*/
function my_global_template_url( $url ) {
// Uncomment this to use Amazon S3
// return 'http://mybucket.s3.amazonaws.com';
diff --git a/svn-color.sh b/svn-color.sh
index ac9d15b..6c8c90e 100755
--- a/svn-color.sh
+++ b/svn-color.sh
@@ -12,14 +12,14 @@ function svn
test "$CMDLEN" = "${#CMD}"
if [ $? = 1 ] || [ ! -t 1 ]
then
- $(whereis svn) $CMD
+ $(which svn) $CMD
#!/bin/sh
# run this file with sudo and TextEdit will be open as if it was open by root
exec /Applications/TextEdit.app/Contents/MacOS/TextEdit