Skip to content

Instantly share code, notes, and snippets.

@chrisk
chrisk / markup.html
Last active July 2, 2020 19:58
FromHere.com rainbow countdown clock
<center id="timer-container">
<div id="times-up">
<div id="its-time">It's time!</div>
<div id="its-okay">(it's okay)</div>
</div>
<div id="timer">
<div id="days"></div>
<div id="hours"></div>
<div id="minutes"></div>
<div id="seconds"></div>
@chrisk
chrisk / crontab.erb
Created August 17, 2011 20:34
Example crontab generation in Capistrano
# This crontab is automatically generated on deploy
SHELL=/bin/bash
MAILTO=errors@example.com
RAILS_ENV=<%= stage %>
RAKE_CMD="<%= "#{bundle_path} rake --rakefile #{current_path}/Rakefile --trace" %>"
LOG_FILE="<%= "#{current_path}/log/cron.log" %>"
# Note: times are in the user's local time
<% if stage == :production && primary_server -%>
@chrisk
chrisk / mysql_db_and_table_size_queries.sql
Created January 19, 2012 02:58
MySQL queries to show the size of databases and tables reported by information_schema
-- Check the total size of each database
SELECT
tables.TABLE_SCHEMA AS database_name,
ROUND(SUM(tables.DATA_LENGTH + tables.INDEX_LENGTH) / POWER(2, 30), 3) AS database_size_in_gb
FROM information_schema.TABLES AS tables
GROUP BY tables.TABLE_SCHEMA
ORDER BY database_size_in_gb DESC;
-- List all tables larger than 1 GB
SELECT
@chrisk
chrisk / pivotal_tracker_info_rad.user.js
Created March 17, 2011 22:43
Greasemonkey script to adjust Pivotal Tracker for a big, vertical screen
// ==UserScript==
// @name Pivotal Tracker Info Radiator
// @namespace http://kampers.net
// @include https://www.pivotaltracker.com/projects/*
// ==/UserScript==
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
@chrisk
chrisk / remarkable_i18n_fix.rb
Created November 21, 2010 04:55
Workaround for Remarkable's deprecated I18n interpolation syntax
# The I18n gem included in Rails 2.3.10 deprecates the {{key}} interpolation
# syntax in favor of %{key}, but Remarkable still uses the deprecated syntax.
# This is fixed in https://github.com/remarkable/remarkable/commit/23177b7ddd,
# but not yet released in a gem that's still compatible with Rails 2 and RSpec 1.3.
change_string_values_to_new_syntax = lambda do |key, value|
case value
when String then value.gsub!(I18n::Backend::Base::DEPRECATED_INTERPOLATION_SYNTAX_PATTERN, '%{\2}')
when Hash then value.each_pair(&change_string_values_to_new_syntax)
end
@chrisk
chrisk / remove_old_submodules.rb
Created August 10, 2010 18:55
Rails initializer to remove old submodules
# Git doesn't remove submodules from your working tree when you pull. This Rails
# initializer will take care of it for you, so developers don't have to do
# anything.
paths = %w(vendor/gems/first_gem-1.0.0
vendor/gems/another_gem-1.0.0)
paths.each do |path|
dir = Rails.root.join(path)
if File.directory?(dir)
@chrisk
chrisk / cucumber_fakeweb_hook.rb
Created May 7, 2010 02:57
Using FakeWeb to stub out HTTP requests made by a server process from Cucumber's remote runners (Selenium, Mechanize, etc.)
# config/initializers/cucumber_fakeweb_hook.rb
# If this looks like a test server process, make its FakeWeb available to other
# processes via DRb. That way the test runner (which runs in a separate process)
# can dynamically register stubs for this server to use.
if Rails.env.cucumber? && defined?(PhusionPassenger)
require 'drb'
require 'fakeweb'
DRb.start_service("druby://localhost:30010", FakeWeb)
@chrisk
chrisk / gist:356034
Created April 5, 2010 04:49
Check an email address domain's validity using MX records
# Check an email address domain's validity using MX records
require 'resolv'
def known_email_domain?(email)
domain = email.match(/\@(.+)/)[1]
Resolv::DNS.open { |dns| dns.getresources(domain, Resolv::DNS::Resource::IN::MX) }.any?
end
@chrisk
chrisk / copy_pivotal_members.rb
Created February 1, 2010 09:40
Copy Pivotal Tracker members to all projects
#!/usr/bin/env ruby
# This script uses Pivotal Tracker's API to generate a list of unique members
# from all of your projects; it then iterates over each project, adding any of
# those members who are missing. That way, everyone has access to everything.
#
# It only acts on projects belonging to accounts called ACCOUNT_NAME below.
#
# By default, the script doesn't proceed with the modifications, so you can
# double-check the pending changes. Run it again with --no-dry-run to proceed.
@chrisk
chrisk / compact_progress_bar_formatter.rb
Last active September 4, 2015 06:04
CompactProgressBarFormatter for RSpec 1
# Originally by Nicholas A. Evans. See LICENSE.txt
#
# Note: includes modifications by Chris Kampmeier to use '=' for the progress
# bar mark and keep the cursor from hopping all around during the animation
#
# This version is compatible with RSpec 1.2.9 and ProgressBar 0.9.0
require 'spec/runner/formatter/base_text_formatter'
require 'progressbar'