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 bash_escape(argument) | |
"$'" + argument.gsub("\\'", '\\\\\&').gsub("'", "\\\\'") + "'" | |
end | |
ruby_code = "puts 'something'" | |
command = "ruby -e #{bash_escape ruby_code}" | |
puts "ssh server #{bash_escape command}" # => ssh server $'ruby -e $\'puts \\\'something\\\'\'' |
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
# for some reason active record doesn't include a simple way to serialize to | |
# cache. this simple trick will take you far | |
# | |
# usage: | |
# | |
# user = User.find(id) | |
# | |
# key = user.to_cache | |
# | |
# user = User.from_cache(key) |
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
module ActiveRecord | |
# Allows embedding of ActiveRecord models. | |
# | |
# Embedding other ActiveRecord models is a composition of the two | |
# and leads to the following behaviour: | |
# | |
# - Nested attributes are accepted on the parent without the _attributes suffix | |
# - Mass assignment security allows the embedded attributes | |
# - Embedded models are destroyed with the parent when not appearing in an update again |
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
# Ways to execute a shell script in Ruby | |
# Example Script - Joseph Pecoraro | |
cmd = "echo 'hi'" # Sample string that can be used | |
# 1. Kernel#` - commonly called backticks - `cmd` | |
# This is like many other languages, including bash, PHP, and Perl | |
# Synchronous (blocking) | |
# Returns the output of the shell command | |
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111 |
NewerOlder