Skip to content

Instantly share code, notes, and snippets.

@chuckg
chuckg / README.md
Last active December 20, 2024 10:09
Bootstrap an image for use as a Vagrant base box

Requirements

Prepare virtual machine

@chuckg
chuckg / 0_reuse_code.js
Created November 28, 2013 19:04
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
#!/usr/bin/env python
'''\
Usage: cookbookdiff COOKBOOK_NAME COOKBOOK_VER LOCAL_PATH [--nocolor]
Diff your LOCAL_PATH against what is on the chef server for a
given cookbook and version.
--nocolor: don't pipe output through 'colordiff' (in case you want to pipe to something else)
Examples:
cookbookdiff percona_toolkit 0.0.4 ~/chef-repo/cookbooks/percona_toolkit
@chuckg
chuckg / SPLUNK_RECIPES.md
Last active May 18, 2020 17:37
Splunk Storm recipes for Heroku logs.

Splunk Recipes for Heroku

A collection of Splunk recipes for Heroku logs. Instructions for setting up Splunk Storm with Heroku can be found here. For the vast majority of these recipes you'll need to have enabled the Heroku labs feature, log-runtime-metrics, for your application.

@chuckg
chuckg / mechanize_download_adapter.rb
Last active February 22, 2016 08:23
A Paperclip adapter to allow attachments to be set using a Mechanize::Download object; the default Paperclip::FileAdapter is incompatible with unlinked Tempfiles which Mechanize returns.
require 'paperclip'
module Paperclip
# Mechanize unlinks its Tempfiles immediately after creating them and some
# Paperclip functionality relies on an actual file available in the
# filesystem; not just a reference.
class MechanizeDownloadAdapter < AbstractAdapter
def initialize(target)
@target = target
cache_current_values
@chuckg
chuckg / uri_parser.rb
Created May 2, 2013 23:38
Parse URL to see if it's an image
class UriParser
def self.uri_is_image?(uri)
case File.extname(uri.path)
when '.jpg', '.png', '.gif'
return true
else
return false
end
end
end
@chuckg
chuckg / errors_request_spec.rb
Last active December 16, 2015 14:29
Testing exceptions with Rack. Couldn't get it to work in conjunction with :driver => :selenium level tests, but it runs fine when run individually. Not 100% sure the tests are necessary given the tests around routes/controllers.
require 'request_spec_helper'
describe "Errors" do
context "test", driver: :rack_test do
include Rack::Test::Methods
def app
app = Rack::Builder.new do
run Rewarder::Application
end.to_app
require 'rack/test'
describe SampleMiddleware do
include Rack::Test::Methods
let(:inner_app) do
lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['All good!'] }
end
let(:app) { SampleMiddleware.new(inner_app) }
@chuckg
chuckg / capypbara_utilities.rb
Created March 21, 2013 21:21
Capybara `sleep()` is sinful. Instead, block until your element appears!!
def wait_until_element_exists(element)
wait_until { page.find(element).visible? }
return unless block_given?
within element do
yield
end
rescue Capybara::TimeoutError
flunk "Expected '#{element}' to be present."
end
@chuckg
chuckg / binary_tree_equality.rb
Last active December 14, 2015 13:19
Binary tree value equality.
require 'tree'
require 'rspec'
# 2
# / \
# 1 4
# /
# 3
#
#