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>
#!/bin/sh
set -x
sudo sed -i 's/wheezy/testing/g' /etc/apt/sources.list
sudo apt-get update
sudo apt-get dist-upgrade -y
sudo apt-get autoremove -y
sudo apt-get install -y build-essential ruby ruby-dev
sudo gem update --system
@chrisk
chrisk / gist:10630382
Created April 14, 2014 09:08
Patch for pgrep bug in /etc/init.d/dropbox
--- /etc/init.d/dropbox
+++ /etc/init.d/dropbox-fixed
@@ -26,7 +34,8 @@
status() {
for dbuser in $DROPBOX_USERS; do
- dbpid=`pgrep -u $dbuser dropbox`
+ HOMEDIR=`getent passwd $dbuser | cut -d: -f6`
+ dbpid=`ps -u $dbuser -o pid,cmd | grep "$HOMEDIR"/"$DAEMON"\$ | awk '{ print \$1 }'`
if [ -z $dbpid ] ; then
@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 / 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 / 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