Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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.

#!/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 / 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
@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 / nodename.rb
Created May 2, 2014 21:57
Add Chef node name to the IP address during knife-ssh commands
# Tested with:
# * Ruby 2.0
# * Chef 11.6.2
require 'chef/knife'
require 'chef/knife/ssh'
module Nodename
def self.prepended(base)
@chuckg
chuckg / include_recipe_helper.rb
Last active October 19, 2017 07:33 — forked from hartmantis/spec_helper.rb
ChefSpec/RSpec 3 stubs for testing a recipe in isolation
# Updated for rspec 3.0:
module IncludeRecipeHelper
def enable_stubbed_include_recipe
# Don't worry about external cookbook dependencies
allow_any_instance_of(Chef::Cookbook::Metadata).to receive(:depends)
# Test each recipe in isolation, regardless of includes
@included_recipes = []
allow_any_instance_of(Chef::RunContext).to receive(:loaded_recipe?).and_return(false)
allow_any_instance_of(Chef::Recipe).to receive(:include_recipe) do |recipe, included_recipe|
@chuckg
chuckg / instructions.md
Last active August 29, 2015 14:17
Install OSX command line tools (sudo password required)
  • Open AppleScript
  • Paste the xcode-select-install.osa script into the edit.
  • Save the file as xcode-select-install.app, select "Application" from the "File Format" option.

It's important the app is saved with exact name specified or it won't be able to skip the accessibility confirmation when run.

Seeing LSOpenURLsWithRole() failed with error -10810 for the file /var/tmp/xcode-select-install.app? Run: command "chmod +x xcode-select-install.app/Contents/MacOS/applet"