Skip to content

Instantly share code, notes, and snippets.

@schnittchen
schnittchen / gist:a47e40760e804a5cc8b9
Created October 8, 2014 20:22
"Tunneling" an ssh agent connection through into an lxc container (for bootstrapping)
while :; do socat UNIX:$SSH_AUTH_SOCK EXEC:"lxc-attach -n $CONTAINER_NAME -- /usr/bin/socat STDIN UNIX-LISTEN\:/agent-sock"; done
# After entering the container the usual way using lxc-attach (from a separate host shell), set the SSH_AUTH_SOCK environment variable to "/agent-sock".
# Needs socat both on the host and in the container.
@schnittchen
schnittchen / groovy_bostbuild_script.groovy
Created July 22, 2014 22:02
Hacked jenkins integration for slack
// Install the "Groovy Postbuild" plugin and use this as postbuild script:
def message = "${manager.build.result}" + ': ' + manager.build.getDisplayName() + ' ' + manager.build.getAbsoluteUrl()
def command = ['sh', '-c', 'echo "' + message + '" | curl --data-binary @- "https://YOURSLACKDOMAIN/services/hooks/slackbot?token=YOUR_SLACKBOT_INTEFGRATION_TOKEN&channel=URL_ENCODED_CHANNEL_NAME"' ]
command.execute()
@schnittchen
schnittchen / spec_helper_snippet.rb
Last active December 15, 2015 00:28
Make view specs fail when image_tag is used for a non-existing asset
config.before(:each) do
if self.class.metadata[:type] == :view
view.singleton_class.send :alias_method, :original_image_tag, :image_tag
view.singleton_class.send :define_method, :image_tag do |path, options = {}|
normalized_path = path_to_image(path.to_s)
asset_paths = Sprockets::Helpers::RailsHelper::AssetPaths.new(nil) # hack: easy access to is_uri?
unless asset_paths.is_uri?(normalized_path)
normalized_path = normalized_path[asset_prefix.length+1..-1]
unless Rails.application.assets.find_asset(normalized_path) or path.respond_to?(:stubbed?)
@schnittchen
schnittchen / routes.rb
Created March 3, 2013 21:06
Routing constraints tied to your app without breaking reloading in development mode
# Sometimes Constraints need to interact with controllers (fex. in order not to query the database twice), then I like
# to put them inside the controller. If you load controllers from your routes.rb (more precisely, when routes.rb is loaded),
# these won't reload in development mode.
# If your constraints live somewhere else (say, /app/constraints), it's basically all the same.
# This demonstrates an easy workaround by wrapping the fetching of constraints in a block:
class ConstraintWrapper
# Helps to load constraints from inside controllers without breaking
# development environment reloading
# in m/m_q.rb
module M
module MQ
end
end
# in m/m2.rb
module M
@schnittchen
schnittchen / comments
Created November 5, 2012 10:02
Using backup gem in rails project with separate Gemfile
Note: the full file names are config/backup/Gemfile and config/deploy.rb, which gist.github.com can't handle ;-)
Of course, you will need a backup config file, preferrably in config/backup/config.rb, and you need to trigger the backup from cron (check out the whenever gem if you want that behaviour bundled with your rails app).
In both files, you need to take the locations of stuff (rails root, backup config file) into consideration.
@schnittchen
schnittchen / include_constants.rb
Created October 13, 2012 15:53
A Ruby quirk with include. Quite annoying.
module A
module B
end
module Wrapper
module C
end
end
#Cite:
#When this module is included in another, Ruby calls append_features in this