Skip to content

Instantly share code, notes, and snippets.

View ebouchut's full-sized avatar

Eric Bouchut ebouchut

View GitHub Profile
@ebouchut
ebouchut / activemodel_activerecord_generate_error_message
Created November 21, 2014 14:29
ActiveModel ActiveRecord generate error message
class User # class User < ActiveRecord::Base
include ActiveModel::Model #
attr_accessor :name, :age
validates :name, presence: true
validates :age, presence: true,
numericality: { only_integer: true, greater_than: 0 }
end
@ebouchut
ebouchut / guard
Created November 24, 2014 10:27
Guard workaround to symlinks pointing to parent directories (another option is https://github.com/guard/listen/releases/tag/v2.8.1)
############
## Problem
############
bundle exec guard
...
(This may be due to symlinks pointing to parent directories).
Duplicate: /some/where/ebouchut/www/netadge/bo/rubymine/trunk/doc/simplecov
@ebouchut
ebouchut / resize_image_increase_canvas_size
Last active August 29, 2015 14:16
Resize and increase the canvas size of an image to 225x100 using imagemagick
# I want to resize an image from 600x128 to 225x100 while keeping its aspect ratio.
# Resizing the width to 225 while keeping the aspect ratio makes one dimension (height)
# smaller (225x48) than what I want to obtain (225x100).
# The workaround is to resize first,
# then increase the canvas of the other dimension (height)
# to obtain the desired size (225x100) then center the image in the canvas.
#~~~~~~~~~~~~~~~~~~~~~
tar cvzf ~/backup/project.tar.gz --dereference --exclude-vcs --exclude=/target/ project
@ebouchut
ebouchut / gist:83274db70170e363b444
Created July 20, 2015 15:49
Send a file to a URL using curl
curl $URL --data @$FILE -vv -L -H "Content-Type:application/json"
# curl $URL --trace-ascii - --data @$FILE -L -H "Content-Type:application/json"
# Remove comment that spans a whole line (like this one)
# and comments at the end of a line like the following
: echo "Hello" # comment at the end of a line
sed -e 's/#.*$//g' -e '/^[ \t]*$/d' file
@ebouchut
ebouchut / Comment a section of HTML+ERB
Last active September 3, 2015 09:48
Comment a section of HTML+ERB
<%
=begin
%>
This <a href="javascript:void(0);">will not be in the result HTML page.</a>
<%
=end
%>
@ebouchut
ebouchut / PrintStackTraceInAString
Created November 14, 2011 13:54
Print a StackTrace in a String
StringWriter writer = new StringWriter();
e.printStackTrace(
new PrintStream(
new WriterOutputStream(
new PrintWriter(writer)
)
)
);
@ebouchut
ebouchut / gist:1510447
Created December 22, 2011 14:18
(Sass/maven) Unable to launch rake using jruby-rake-plugin
java -jar ~/.m2/repository/org/jruby/jruby-complete/1.6.5/jruby-complete-1.6.5.jar -S gem env
@ebouchut
ebouchut / gist:1815764
Created February 13, 2012 10:13
Select a tags without a title attribute using CSS
a:not([title])