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
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')
# 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 "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 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.
#
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 )
class ReentrantMutex < Mutex
def initialize
super
@locker = nil
end
alias :original_synchronize :synchronize
def synchronize
# Convert a string to a numeric value
class String
# Convert the string into a numeric value. If the string does not
# represent a valid Integer or Float, then the string itself is returned.
#
# "10".numeric #=> 10
# "1.0".numeric #=> 1.0
# "foo".numeric #=> "foo"
#
require 'servolux'
require 'thread'
q = Queue.new
ary = []
3.times do
piper = Servolux::Piper.new 'rw'
@TwP
TwP / .vimrc
Created October 23, 2009 18:08
function! AckSnippets(search)
let ft = &ft
if ft == 'objc' || ft == 'cpp' || ft == 'cs'
ft = 'c'
elseif ft == 'xhtml'
ft = 'html'
endif
let dirs = join(split(
\ globpath(g:snippets_dir, ft)."\n".