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 ReentrantMutex < Mutex
def initialize
super
@locker = nil
end
alias :original_synchronize :synchronize
def synchronize
module Kernel
# Settiing this global variable to +false+ will disable rubygems from
# being loaded at all.
$use_rubygems = true
# call-seq:
# require!( string )
# require!( string, gem_version )
# 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
# origin repository. The master branch is checked out, a git pull is performed,
# the original branch is checked out again, and then the changes from master
# are rebased back into the branch.
#
desc "Strip trailing whitespace from .rb .txt .rake and .yml files"
task :strip do
cmd = 'find . '
cmd << %w[rb txt rake yml].map {|str| "-name '*.#{str}'"}.join(' -o ')
cmd << %q{ | xargs sed -i 's/\s\+$//g'}
sh cmd
end
# This is a useful little pattern for working with gems without
# explicitly requiring rubygems in your code.
#
# The approach taken is to require a library and catch any LoadError
# that might get thrown. In the rescue clause we require rubygems.
#
# The require method is nice in that it will return true if the code
# was loaded, and it returns false if the code was _already_ loaded.
# If the require of rubygems returns true, we will retry our original
# require. It will either succeed this time (since we now have rubygems
desc 'add a new blog summary entry'
task :add_to_blog do
# Load up all files and populate the @pages DB
Webby.load_files
# Find the page that has the table of interest
page = Webby::Resources.pages.find('Page Title')
# 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
# require 'monkey-proof'
#
# class Foo
# def foo() puts 'foo'; end
# end
# monkey_proof Foo
#
# class Foo
# include Enumerable
# end
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)