Skip to content

Instantly share code, notes, and snippets.

@hateradio
hateradio / html64.rb
Last active April 29, 2024 05:58
ruby image to base64 string
require 'base64'
# converts attached PNGs into base64 strings
# Eg
# <img src="my.png" /> to <img src="data:image/png;base64,..." />
class To64Html
def initialize(path)
@Hermanverschooten
Hermanverschooten / skip_asset_compilation.cap
Created August 10, 2014 14:41
Skip asset compilation in Capistrano 3 if no assets have changed since last deploy
namespace :deploy do
Rake::Task["deploy:compile_assets"].clear_actions
task :compile_assets => [:set_rails_env] do
run_locally do
if capture("git --no-pager diff #{fetch(:previous_revision)} #{fetch(:current_revision)} app/assets vendor/assets").empty?
info "Skipping assets compilation"
else
invoke 'deploy:assets:precompile'
invoke 'deploy:assets:backup_manifest'
end
@whatthewhat
whatthewhat / gist:cb6a62532a8a0984adbe
Created July 21, 2014 09:03
Find scheduled sidekiq job by id
require 'sidekiq/api'
Sidekiq::ScheduledSet.new.find_job("61374d5d51db323507376158")
# config/initializers/instrumentation.rb
# Subscribe to grape request and log with Rails.logger
ActiveSupport::Notifications.subscribe('grape.request') do |name, starts, ends, notification_id, payload|
Rails.logger.info '[API] %s %s (%.3f ms) -> %s %s%s' % [
payload[:request_method],
payload[:request_path],
(ends-starts)*1000,
(payload[:response_status] || "error"),
payload[:x_organization] ? "| X-Org: #{payload[:x_organization]}" : "",