This file contains 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
# File 'config/initializers/settings.rb' | |
settings = YAML::load(ERB.new(IO.read(Rails.root + "config/settings.yml.erb")).result) | |
settings.merge(settings[Rails.env] || {}) | |
::Settings = settings |
This file contains 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 Object | |
def as_fiber(*method_names) | |
method_names.each do |method_name| | |
alias_method "fiberless_#{method_name}", method_name | |
module_eval <<-eos | |
def #{method_name}(*args) | |
Fiber.new do | |
fiberless_#{method_name}(*args) | |
end.resume |
This file contains 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 "erb" | |
require "ostruct" | |
vars = OpenStruct.new( :name => "David", :state => "Awesome" ) | |
# Either update OpenStruct with get_binding() | |
class OpenStruct | |
def get_binding | |
return binding() | |
end |
This file contains 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
#!/usr/bin/ruby | |
require 's3' | |
service = S3::Service.new( | |
:access_key_id => 'XXXXXXXX', | |
:secret_access_key => 'XXXXXXXX' | |
) | |
bucket = service.buckets.find('bucket-to-delete') |
This file contains 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
# Usage: | |
# rake db | |
desc "Start Postgresql" | |
task :db do | |
exec "postgres -D /usr/local/var/postgres" | |
end |
This file contains 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
$.serialAjax = (options...) -> | |
window.serialAjaxPromise ||= $.Deferred().resolve().promise() | |
window.serialAjaxPromise = | |
window.serialAjaxPromise.then -> $.ajax(options...) | |
This file contains 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 PngQuantProcessor < ::Tilt::Template | |
def prepare | |
# noop | |
end | |
def evaluate(scope, locals, &block) | |
IO.popen("pngquant -", "rb+") do |process| | |
process.write(data) | |
process.close_write | |
process.read |
This file contains 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
# Important to tell Sprockets this is a binary type, else you'll get UTF-8 byte sequence errors | |
Rails.application.assets.register_mime_type 'image/png', '.png' | |
# Register our processor as a post-processor for every PNG file | |
Rails.application.assets.register_postprocessor 'image/png', PngQuantProcessor |
This file contains 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
# Important to tell Sprockets this is a binary type, else you'll get UTF-8 byte sequence errors | |
Rails.application.assets.register_mime_type 'image/png', '.png' | |
Rails.application.assets.register_postprocessor 'image/png', :png_compressor do |context, data| | |
IO.popen("pngquant -", "rb+") do |process| | |
process.write(data) | |
process.close_write | |
process.read | |
end | |
end |
This file contains 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
Rails.application.assets.register_mime_type 'image/png', '.quant' | |
Rails.application.assets.register_engine '.quant', PngQuantProcessor |
OlderNewer