This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # bump.rb - Perform a project version bump | |
| # * If a .gemspec file is present, use it to determine the current project version | |
| # * Scans for the first line that contains .version and a 1.2.3-ish part | |
| # * If no gemspec is present, use the highest tagged version | |
| # * The expected tag format is '1.2.3' | |
| # * Depending on the command line options 'major', 'minor', 'build' it will | |
| # bump the 1st, 2nd, 4th digit of the version. No option implies a 'release', | |
| # which bumps the 3rd digit. Example: 1.2.3 -> 1.2.4 is a release. | |
| # * Overwrites the current gemspec with the new one if a gemspec was found |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # eachfile.rb - Execute a command for each file | |
| def help | |
| puts <<-HELP | |
| Syntax: #{$0} [option] "COMMAND" File1 [File2] .. [FileN] | |
| The command is executed for each of the specified files. | |
| FILE in the command is substituted with the name of each file. | |
| If there is no FILE in command, the filename is given as parameter instead. | |
| When no files are provided, all files in the current directory are used. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'net/ssh/gateway' | |
| s1 = {:host=>'foo', :user => 'foobar', :options => {:password => 'barfoo', :port => 2221}} | |
| s2 = {:host=>'bar', :user => 'foobar', :options => {:password => 'barfoo', :port => 2222}} | |
| s3 = {:host=>'baz', :user => 'foobar', :options => {:password => 'barfoo', :port => 2223}} | |
| s4 = {:host=>'moo', :user => 'foobar', :options => {:password => 'barfoo', :port => 2224}} | |
| gw = Net::SSH::Gateway.new(s[:host], s[:user], s[:options) | |
| gw_port = gw.open(s2[:host], s2[:port]) | |
| gw2 = Net::SSH::Gateway.new(s2[:host], s2[:user], s[:options].merge({:port => gw_port})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| s1 = {:host=>'foo', :user => 'foobar'} | |
| s2 = {:host=>'bar', :user => 'foobar'} | |
| s3 = {:host=>'baz', :user => 'foobar'} | |
| s4 = {:host=>'moo', :user => 'foobar', :options => {:password => 'barfoo'}} | |
| def gate(s, s2, opts={}) | |
| gw = Net::SSH::Gateway.new(s[:host], s[:user], {:port => 22}.merge(opts)) | |
| gw_port = gw.open(s2[:host], s2[:port]) | |
| yield(gw_port) | |
| ensure |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # cleanpath - Cleanup your $PATH! | |
| # | |
| # Reads the current $PATH and outputs a version without duplicate entries. | |
| # It is useful as a last line in ~/.profile: | |
| # export PATH=`/path/to/cleanpath` | |
| path = ENV['PATH'] | |
| clean_path = path.split(":").uniq.join(":") | |
| puts clean_path | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # Usage: s2b.sh branchname | |
| # Easily switch between branches and their databases for Rails projects. | |
| # Checks out given branch and copies the branch's database.yml to the active database.yml | |
| # Outputs a small list of databases being used. | |
| # Make sure you have set up your branch's database.yml in #{RAILS_ROOT}/config/database.#{branchname}.yml | |
| git checkout $1 && cp config/database.$1.yml config/database.yml | |
| databases=`grep --colour=auto database config/database.yml | grep -v ^# | sed s/database\:// | tr -d '\012' | sed -E s/^\ +\|\ +$// | sed -E s/\ +/,\ /g` | |
| echo "Using databases: $databases" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # BuildGems | |
| # Created by Wes Oldenbeuving, copyright 2009, licensed under MIT LICENSE. | |
| # | |
| # For a git project, build the gems for all gem tag releases. | |
| # The assumptions made are the following: | |
| # - Version tags have the format 'N.N', 'N.N.N', etc... Only digits and dots. | |
| # - There is a 'rake gem' task that builds the gem for the checked out version | |
| # - Gems are located in pkg/*.gem | |
| # - You want to copy all created gems to ~/gems/ after creating them. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'rubygems' | |
| require 'active_support' | |
| class John | |
| end | |
| j_c = John.class_eval do | |
| def hi | |
| 'hi' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # Command of the day | |
| # Picks a random executable from your path until it finds one with a manpage. | |
| # Use this to learn about some of the really obscure yet really useful scripts that are already on your system. | |
| files = ENV["PATH"].split(":").uniq.compact.map { |path| | |
| Dir.glob(File.join(path,'*')).select {|file| File.file?(file) && File.executable?(file)} | |
| }.flatten.compact.uniq | |
| cotd = File.basename(files[rand(files.size)]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # Random alphanumeric password generator | |
| # Takes one parameter, which is the password length | |
| # Forces the minimum length to be 10 or more | |
| # | |
| CHARS = (0..9).to_a + ('a'..'z').to_a + ('A'..'Z').to_a | |
| class << CHARS | |
| def rand | |
| self[Kernel.rand(size)] | |
| end |