Skip to content

Instantly share code, notes, and snippets.

View TwP's full-sized avatar
🛰️
Spacing Out

Tim Pease TwP

🛰️
Spacing Out
View GitHub Profile
class Module
# call-seq:
# logger_name #=> string
#
# Returns a predictable logger name for the current module or class. If
# used within an anonymous class, the first non-anonymous class name will
# be used as the logger name. If used within a meta-class, the name of the
# actual class will be used as the logger name. If used within an
# anonymous module, the string 'anonymous' will be returned.
---
filter:
- textile
- outline
---
<toc />
h1. Foo
h2. Bar
class Logging::Appenders::TimestampRollingFile < Logging::Appenders::RollingFile
def initialize( name, opts = {} )
super
@date_fmt = '%Y%m%d'
@logname_fmt.sub!(%r/\.%d/, '.%s')
end
def roll_files
class Webby::Resources::Page < Webby::Resources::Resource
alias :_initialize :initialize
def initialize( fn, meta_data = nil )
_initialize(fn, meta_data)
# put your initialization code here
end
end
module WikiTrail
def wiki_trail( *args )
links = args.flatten.map do |name|
"> #{link_to_page_unless_current name} <"
end
links.join(" ")
end
end
Config.new {
_'the description of the next variable'
foo 42
_'the description of bar'
bar {
_'the description of baz'
baz 3.14159
}
}
# LAME
if a > b
foo = a
else
foo = b
end
# SWEET
foo = if a > b
a
module PortfolioHelper
def portfolio_prev_next
items = @pages.find(:all,
:in_directory => "/portfolio",
:sort_by => "title")
portfolio = @pages.find(:title => "Portfolio")
current = @pages.find(:title => @page.title,
:in_directory => "/portfolio")
index = items.index(current)
# require 'monkey-proof'
#
# class Foo
# def foo() puts 'foo'; end
# end
# monkey_proof Foo
#
# class Foo
# include Enumerable
# end
# These are some functions that are useful for dealing with git branches
# ----------------------------------------------------------------------
# This function returns the name of the current git branch
function gitb {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
# This function updates the current branch with the latest changes from the