This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyController < ApplicationController | |
def action_xyz | |
if request.xhr? | |
set_cache_buster | |
end | |
render json: {what: 'ever'} | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
=begin | |
%> | |
This <a href="javascript:void(0);">will not be in the result HTML page.</a> | |
<% | |
=end | |
%> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :time_travel do | |
desc "Description of the lightning task" | |
task :lightning do |t| | |
# ... | |
end | |
desc "Description of the de_lorean task" | |
task :de_lorean do |t| | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
array = [...] | |
Benchmark.bm(7) do |x| | |
x.report("map") { array.map(&:upcase) } | |
x.report("map!") { array.map!(&:upcase) } | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convert_to_proc(&proc) | |
proc | |
end | |
hello = convert_to_proc { |name| puts "Hello #{name}" } | |
hello.call("Eric") # => "Hello Eric" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git config `push.default`: | |
– `nothing`: do nothing (make the user say what they mean) | |
– `matching`: push all local branches for which a remote branch of the same name exists | |
– `upstream`: push only the current branch, push it to its upstream, making push and pull symmetric | |
– `simple`: like upstream, but only if the branch names match (will become default in 2.0) | |
– `current`: push just the current branch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I use find -print0 and xargs -0 when the filenames contain characters used as delimitors, | |
# like space in this case | |
# | |
find '/tmp/temp results' -name '*.tmp' -print0 | xargs -0 -n 1 -J % rm '%' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############ | |
## 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. | |
#~~~~~~~~~~~~~~~~~~~~~ |