Skip to content

Instantly share code, notes, and snippets.

class Array
# This method reads from the DATA section of this file, which
# in Ruby is marked by __END__. It takes each line and pushes
# it into the calling array, yields the code block and writes
# the array, one element per line, to the end of the file,
# starting at the beginning of the DATA block. Idea stolen
# from O'Reilly's Perl Cookbook.
def tie()
DATA.each_line { |line| self.push(line.chomp) }
yield
#!/usr/bin/env ruby -wKU
# Ruby Quiz #207: Quine
# This week's quiz is to create a quine[1], that is: a program which
# receives no input and produces a copy of its own source code as its
# only output.
# [1]: http://en.wikipedia.org/wiki/Quine_(computing)
# Dana Merrick
# 5/29/2009
@dmerrick
dmerrick / ethers.rb
Created June 8, 2009 18:22
For Morgan: parses an ethers file to generate a dhcpd.conf file.
#!/usr/bin/env ruby -wKU
# This program scans your ethers file to generate a valid dhcpd.conf file
# (or at least a segment of one). In addition, it will read your hosts file
# to see if there are any known aliases it can add. It then prints the
# formatted results to standard out.
#
# Author:: Dana Merrick (mailto:letterkills+ethers@gmail.com)
# Copyright:: Copyright (c) 2009 Dana Merrick
# License:: Released under the MIT license
@dmerrick
dmerrick / another_file
Created June 9, 2009 21:53
For Morgan: Example git sessions.
Im adding another file to this gist
@dmerrick
dmerrick / sql_insert.rb
Created July 13, 2009 15:24
Morgan wanted to see how Ruby could generate a SQL insert.
# given: arg = { 'col1':'foobar',
# 'col2':'fubar',
# 'col3':'fuck'}
#
# generate:
# INSERT INTO table (col1, col2, col3) VALUES("foobar","fubar","fuck")
#
input = { :col1 => "foobar", :col2 => "fubar", :col3 => "fuck" }
#!/usr/bin/env ruby -wKU
# grab goove salad playlist from twitter
# (avoids using Soma.fm to keep costs low)
require 'rss/2.0'
require 'open-uri'
# thank you http://rubyrss.com!
# the groovesalad twitter feed
# set up message details for growl
if new_balance != old_balance
title = "Mint.com Updated"
# TODO: Test me!
details = "New balance is: #{new_balance} (#{new_balance - old_balance})"
else
title = "Mint.com Refreshed"
details = "Click here for more info."
end
@dmerrick
dmerrick / antiafk-s.scpt
Created July 18, 2009 16:35
The short version of my anti-afk bot. Tweak to taste.
-- Anti AFK Bot
-- Warrior edition
-- 12/1/08
-- This program will keep you from AFKing in a WoW battleground.
-- (c) Dana Merrick 2008
-- Released under the MIT License.
log "Starting program"
#!/usr/bin/env ruby -wKU
# TODO: use the awesome Array#abbrev method
#require 'abbrev' if RUBY_VERSION.to_f <= 1.9
hosts = ["fubar", "foobar"] # hosts you're setting mappings to
aliases = [] # datastructure to hold mappings
# build the datastructure
# starting with "fu" => "fubar", "fub" => "fubar", etc.
#!/bin/bash
# Updates all of the git repos in the current dir.
for dir in `find . -depth 2 -name .git | sed -e 's!^..\(.*\)/.*$!\1!;'`;
do echo "Updating $dir..."; cd $dir; git pull; cd ..;
done