Skip to content

Instantly share code, notes, and snippets.

require 'growl'
module Jekyll
class GrowlHook < Hook
safe false
sequence :pre, :post
def run(site, sequence)
case sequence
when :pre
# Not sure if we should throw an exception or not.
def self.sequences(*sequences)
if sequences.any? && (sequences - SEQUENCES.keys).empty?
@sequences = sequences
else
raise ArgumentError, "Invalid sequence"
end
@sequences || [:in]
end
# Revision 3:
#
# Just define the method, don't declare which sequences
# this hook will be executed in.
#
# More meaningful sequence names, following rails naming conventions
# for familiarty.
#
# pre -> before_process
# in -> before_render
require 'fileutils'
module Jekyll
class CleanHook < Hook
sequences :pre
def pre(site)
FileUtils.rm_r(site.dest, :force => true) if File.directory?(site.dest)
end
end
module Jekyll
# Specify a post's time in the YAML front matter. An in-hook
# guarantees we'll have all the post data before rendering the payload.
class TimeHook < Hook
safe true
sequences :in
def in(site)
site.posts.each do |post|
if post.data.has_key?('time')
class String
# Converts degrees, minutes and seconds to decimal degrees
#
# "52°12′17.0″N".to_degrees # => 52.2047222222222
# "27 28 05S".to_degrees # => -27.4680555555556
# "Invalid".to_degrees # => 0.0
#
# Returns Float
def to_degrees
self =~ /^(\d+)[^\d]+(\d+)[^\d]+([\d\.]+)[^NESW]*([NESW])/i
@tatey
tatey / transmitter_importer.rb
Created April 30, 2011 09:58
Import terrestrial transmitter data into an SQLite database for use in Antenna Mate (http://antennamate.com).
#!/usr/bin/env ruby
# Import terrestrial transmitter data into an SQLite database for use in
# Antenna Mate (http://antennamate.com).
#
# Supported Regions:
# Australia - http://www.acma.gov.au/scripts/nc.dll?WEB/STANDARD/1001/pc=PC_9150
# United States - http://www.fcc.gov/mb/video/tvq.html
#
# Usage:
require 'rake'
require 'erb'
UNLINKABLES = %w[Rakefile]
desc "install the dot files into user's home directory"
task :install do
replace_all = false
Dir['*'].each do |file|
next if UNLINKABLES.include? file
@tatey
tatey / gist:986559
Created May 23, 2011 11:14
Experimenting with liquid and fragmented content
Layout.new.tap do |layout|
layout.body <<-HTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
{{ content }}
</body>
</html>
@tatey
tatey / gist:1084561
Created July 15, 2011 12:00
Would be nice to be able to do this in Rails 2.3
class Citizen < ActiveRecord::Base
contextual :everyone do
validates_presence_of :last_name
validates_format_of :email, :with => /\w+/
end
contextual :admin do
validates_presence :first_name
end
end