Skip to content

Instantly share code, notes, and snippets.

View danielpietzsch's full-sized avatar

Daniel Pietzsch danielpietzsch

View GitHub Profile
@watson
watson / application_controller.rb
Created October 29, 2010 17:13
A way to accept the same XML input as model.to_xml generates as output (see http://stackoverflow.com/questions/4052677/rails-nested-resources-input-vs-output-format-inconsistency for details)
class ApplicationController < ActionController::Base
private
def fix_nested_attribute_structure(data = nil, model = nil)
unless data
# guess data based on current controller
data = params[self.class.to_s.sub('Controller', '').singularize.underscore.to_sym]
end
unless model
# guess model based on current controller
# gzip html, css and js
AddOutputFilterByType DEFLATE text/html text/css application/x-javascript application/javascript
# far future expires headers
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "access plus 10 years"
</FilesMatch>
@dejan
dejan / code filter for haml
Created April 3, 2009 13:59
code filter for haml
module Haml
module Filters
module Code
include Base
def render(text)
text = Haml::Helpers.html_escape(text)
text = Haml::Helpers.preserve(text)
text
end
end
@JosephPecoraro
JosephPecoraro / shell-execution.rb
Last active September 10, 2023 10:12
Shell Execution in Ruby
# 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