Skip to content

Instantly share code, notes, and snippets.

Avatar

Michel Pigassou Dagnan

View GitHub Profile
@Dagnan
Dagnan / application.html.erb
Last active Nov 21, 2020 — forked from averyvery/application.rb
Inline CSS or JS in Rails 5
View application.html.erb
<!DOCTYPE html>
<html>
<head>
<%= inline_js 'application.js' %>
<%= inline_css 'application.css' %>
</head>
<body>
</body>
</html>
@Dagnan
Dagnan / time.rb
Created Jan 4, 2017
Monkey patching Rails 3.2 to write datetimes with precision
View time.rb
# config/initializers/time.rb
module ActiveRecord
module ConnectionAdapters
module Quoting
alias_method :old_quoted_date, :quoted_date
alias_method :old_quote, :quote
# In Rails 3.2 quoted_date does not have the column argument
def quoted_date(value, column = nil)
# Calls original method ; default in Rails 3.2
View gist:a81bac9c0b8e4784f93f
CONFIGURE_OPTS="--with-readline-dir=/usr/local/Cellar/readline/6.3.8/" rbenv install 2.1.5
@Dagnan
Dagnan / gist:de4f60bcdaa8dce08095
Last active Aug 29, 2015
Install Nokogiri on OSX 10.9.4
View gist:de4f60bcdaa8dce08095
# Xcode has been installed with the full version (don't forget to accept the licence)
# Ruby has been installed with rbenv
# Not needed for recent versions of Nokogiri
#brew install libxml2 libxslt
#brew link --force libxml2 libxslt
brew tap homebrew/dupes
brew install --force libiconv
brew link --force libiconv
View gist:9bee80c203db6e2f3e4d
require 'active_support/core_ext/object/try.rb'
trap("INT") { puts "Exiting..."; exit }
FILENAME = ARGV[0]
if FILENAME.nil? || FILENAME.empty?
puts 'Usage:'
puts 'ruby parse_gemfile.rb path-to-your-Gemfile'
exit
@Dagnan
Dagnan / gist:9250039
Created Feb 27, 2014
Nokogiri and LibXML fix
View gist:9250039
gem install nokogiri -- --with-xml2-include=/opt/boxen/homebrew/Cellar/libxml2/2.9.1/includlibxml2/ --with-xml2-lib=/opt/boxen/homebrew/Cellar/libxml2/2.9.1/lib/
@Dagnan
Dagnan / active_model_errors.rb
Created Oct 24, 2012
Building an API with better errors display with JSON. Must be places in config/initializers
View active_model_errors.rb
# -*- encoding : utf-8 -*-
ActiveModel::Errors.module_eval do
def as_json options = nil
@api_errors
end
def initialize(base)
@base = base
@messages = ActiveSupport::OrderedHash.new
@api_errors = []
@Dagnan
Dagnan / parse_gemfile.rb
Created Oct 9, 2012
Gemfile parser: outputs the same Gemfile with the version of each gem used in the current project. Does not handle version of gems from a git repo.
View parse_gemfile.rb
require 'active_support/core_ext/object/try.rb'
trap("INT") { puts "Exiting..."; exit }
FILENAME = ARGV[0]
if FILENAME.nil? || FILENAME.empty?
puts 'Usage:'
puts 'ruby parse_gemfile.rb path-to-your-Gemfile'
exit
@Dagnan
Dagnan / config.log
Created Aug 10, 2012
Postgres formula error
View config.log
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by PostgreSQL configure 9.1.4, which was
generated by GNU Autoconf 2.63. Invocation command line was
$ ./configure --disable-debug --prefix=/usr/local/Cellar/postgresql/9.1.4 --datadir=/usr/local/Cellar/postgresql/9.1.4/share/postgresql --docdir=/usr/local/Cellar/postgresql/9.1.4/share/doc/postgresql --enable-thread-safety --with-bonjour --with-gssapi --with-krb5 --with-openssl --with-libxml --with-libxslt --with-ossp-uuid --with-python --with-perl ARCHFLAGS='-arch x86_64'
## --------- ##
## Platform. ##
View gist:498196
class CommandLineApp < BasicApp
def open_url(url)
if RUBY_PLATFORM =~ /darwin/
`open #{url}`
elsif RUBY_PLATFORM =~ /linux/ && `which xdg-open` != ""
`xdg-open #{url}`
elsif RUBY_PLATFORM =~ /mswin|mingw|bccwin|wince|em/
`start #{url}`
else
puts "Please open #{@authorize_url + request_token.token} in a web browser. "