Skip to content

Instantly share code, notes, and snippets.

module ActiveStorage
class Attached
def perform_attachment(attachables)
return yield unless record.class.respond_to?(:attachment_callbacks)
callbacks = record.class.attachment_callbacks[name.to_sym]
return yield unless callbacks
[callbacks[:before]].flatten.each { |cb| record.send(cb, self, [attachables].flatten) if cb }
yield
[callbacks[:after]].flatten.each { |cb| record.send(cb, self, [attachables].flatten) if cb }
end
set :assets_roles, :assets
after :compile_assets, :copy_manifest
task :copy_manifest do
on roles(:assets) do
within(shared_path) do
set(:manifest_path, capture(:ls, '-t', 'public/assets/.sprockets-*.json', '|', 'head', '-n1'))
set(:manifest_filename, fetch(:manifest_path).split('/').last)
download!(fetch(:manifest_path), "tmp/#{fetch(:manifest_filename)}")
@benwalsh
benwalsh / gist:0e3fa2276ffe2f03fef5
Created May 14, 2015 17:24
Capistrano for manifests
after "deploy:assets:precompile", "download_asset_manifest"
after "download_asset_manifest", "upload_asset_manifest"
desc "Download the compiled asset manifest .json file"
task :download_asset_manifest, roles: :admin do
set(:manifest_json, capture("ls #{ release_path }/public/assets/manifest*json").strip.split("/").last)
download "#{ release_path }/public/assets/#{ manifest_json }", "/tmp/#{ manifest_json }"
end
desc "Upload the asset manifest file"
Keats once bought a small pub in London and one day he was visited by Dr Watson, confrère of the famous Baker Street sleuth. Watson came late in the evening accompanied by a friend and the pair of them took to hard drinking in the back snug. When closing time came, Keats shouted out the usual slogans of urgent valediction such as 'Time now please!', 'Time gents!', 'The Licence gents!', 'Fresh air now gents!' and "Come now all together!' But Dr Watson and his friend took no notice. Eventually Keats put his head into the snug and roared 'Come on now gents, have yez no Holmes to go to!'
The two topers then left in that lofty vehicle, highdudgeon.
DUBLIN MADE ME
Dublin made me and no little town
With the country closing in on its streets
The cattle walking proudly on its pavements
The jobbers, the gombeenmen and the cheats
Devouring the fair-day between them
A public house to half a hundred men
And the teacher, the solicitor and the bank-clerk
@benwalsh
benwalsh / ads off kindle
Created July 5, 2013 00:50
Ads off Kindle
rm -rf /Volumes/Kindle/system/.assets/
touch /Volumes/Kindle/system/.assets
Bens-MacBook-Air:phorent benwalsh$ ps auxw | grep unicorn
root 9326 0.0 0.1 2482260 5724 ?? S 2:09PM 0:00.01 unicorn_rails master -p 81 -D
benwalsh 9358 0.0 0.0 2432768 592 s000 R+ 2:12PM 0:00.00 grep unicorn
root 9327 0.0 1.6 2561432 131228 ?? S 2:09PM 0:06.49 unicorn_rails worker[0] -p 81 -D
ActiveSupport::Inflector.inflections do |inflect|
inflect.singular 'BillingAddress', 'BillingAddress'
inflect.plural 'billing_address', 'billing_addresses'
inflect.singular 'billing_addresses', 'billing_address'
inflect.singular 'billing_address', 'billing_address'
end
@benwalsh
benwalsh / gist:5605606
Created May 18, 2013 20:01
startup shell script, ~/web.sh
rvmsudo passenger stop -p 81
rvmsudo passenger start -p 81 --user=username