Skip to content

Instantly share code, notes, and snippets.

View milkfarm's full-sized avatar

tim milkfarm

View GitHub Profile
@milkfarm
milkfarm / aiven-last-backup.rb
Created February 8, 2019 00:13
Get time stamp of last backup for given Aiven service
#!/usr/bin/env ruby
# Binaries and Defaults
# -----------------------------------------------------------------------
#######################################################################
# Do not change anything below
#######################################################################
require 'optparse'
@milkfarm
milkfarm / epubversion.sh
Created August 27, 2017 18:59
Unzip epub file, then check for version number
#! /bin/bash
# =======================================================================
#
# Unzips epub file, then checks version number
#
# To invoke, type:
# $ epubversion.sh filename.epub
#
# =======================================================================
@milkfarm
milkfarm / epubopen.sh
Created August 27, 2017 18:58
Unzip epub file into a directory of the same base name
#! /bin/bash
# =======================================================================
#
# Unzips epub file into a directory with the same basename.
# If the directory exists, abort.
#
# To invoke, type:
# $ epubopen.sh filename.epub
#
@milkfarm
milkfarm / mysql.thor
Last active January 3, 2016 17:38
Thor task to dump and load mysql databases in a Rails project by using the credentials in config/database.yml.
require 'io/console'
class Mysql < Thor
desc 'create DATABASE', 'create mysql database'
method_option :debug, :type => :boolean, :default => false, :aliases => "-d", :desc => "Debug"
method_option :verbose, :type => :boolean, :default => true, :aliases => "-v", :desc => "Verbose"
method_option :env, :type => :string, :default => 'development', :aliases => "-e", :desc => "Environment must be either 'development' or 'production'"
def create(db = nil)
debug = options[:debug]
@milkfarm
milkfarm / config.thor
Last active January 3, 2016 17:38
Thor task to check config/config.yml against config/config.template.yml for missing keys.
class Config < Thor
PATH = 'config/config.yml'
desc 'get KEY', "get value of key in #{PATH}"
def get(key)
%w(development production).each do |env|
puts "#{env}:"
begin
value = get_config(key, env)
puts " #{key} => '#{get_config(key, env)}'"
@milkfarm
milkfarm / counter.js
Created February 27, 2012 20:11
Prototype UJS Character Counter: Twitter-style character counter with optional input field truncation
/* Counter Script
* Requires Prototype Library
* By: <stuff@milkfarmproductions.com>
* http://milkfarmproductions.com
* This work is licensed under the Creative Commons Attribution-Share Alike 3.0
* http://creativecommons.org/licenses/by-sa/3.0/us/
*
* Requirements:
* - A 'texter' input field, the field to be counted
* - A 'counter' input field with class equal to 'countClass' variable, the field to contain the count
@milkfarm
milkfarm / gist:198249
Created September 30, 2009 17:16
Name parser
# http://artofmission.com/articles/2009/5/31/parse-full-names-with-ruby
class Name < ActiveRecord::Base
def self.parse(name)
return false unless name.is_a?(String)
# First, split the name into an array
parts = name.split
@milkfarm
milkfarm / debug.rb
Created September 4, 2009 01:12
Method to dump variables in Ruby
def debug(msg, object)
print "# [debug] #{msg} "
begin
Marshal::dump(object)
raise if object.nil?
puts h(object.to_yaml)
rescue Exception => e # errors from Marshal or YAML
# Object couldn't be dumped, perhaps because of singleton methods -- this is the fallback
puts "--- #{object.inspect}"
end