Permalink
Browse files

Added some scripts

  • Loading branch information...
0 parents commit 80d1eee7d2e1f543e74fd645fba5e79c7084d7c3 @jferris committed Jan 14, 2010
Showing with 2,917 additions and 0 deletions.
  1. +2,484 −0 ack
  2. +25 −0 align_ascii_table
  3. +9 −0 clear_database
  4. +15 −0 cuc
  5. +21 −0 find-interacting-feature
  6. +3 −0 git-unmerged-next
  7. +72 −0 mvim
  8. +79 −0 ruby_spec
  9. +96 −0 ruby_test
  10. +73 −0 ruby_tu_rs
  11. +40 −0 schema
2,484 ack

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,25 @@
+#!/usr/bin/env ruby
+lines = STDIN.readlines
+leading_match = lines.first.match(/^\s+/)
+leading = leading_match ? leading_match[0] : ''
+lines_without_edges = lines.map { |line| line.strip.sub(/^\|/, '').sub(/\|$/, '') }
+lines_without_edges.reject! { |line| line.empty? }
+table = lines_without_edges.map { |line| line.split('|').map { |cell| cell.strip } }
+cell_count = table.first.size
+widths = (0...cell_count).map do |index|
+ table.inject(0) do |result, row|
+ size = row[index].size
+ size > result ? size : result
+ end
+end
+aligned_table = table.map do |row|
+ result = []
+ row.each_with_index do |cell, index|
+ result << cell.ljust(widths[index])
+ end
+ result
+end
+aligned_lines = aligned_table.map do |row|
+ leading + '| ' + row.join(" | ") + ' |'
+end
+puts aligned_lines.join("\n")
@@ -0,0 +1,9 @@
+#!/usr/bin/ruby
+
+ENV['RAILS_ENV'] ||= 'test'
+require 'config/environment'
+
+connection = ActiveRecord::Base.connection
+(connection.tables - %w(schema_migrations)).each do |table_name|
+ connection.execute("DELETE FROM #{table_name}")
+end
15 cuc
@@ -0,0 +1,15 @@
+#!/usr/bin/env ruby
+
+args = ARGV.map do |arg|
+ name, line = *arg.split(':')
+ line = ":#{line}" if line
+ "features/#{name}.feature#{line}"
+end
+
+script = if File.executable?('script/cucumber')
+ 'script/cucumber'
+ else
+ 'cucumber'
+ end
+
+exec(script, *args)
@@ -0,0 +1,21 @@
+#!/usr/bin/ruby
+
+unless failing_feature = ARGV[0]
+ puts "Usage: find-interacting-feature <feature_file>"
+ exit
+end
+
+other_features = Dir["features/**/*.feature"] - [failing_feature]
+
+interacting_feature = other_features.detect do |other_feature|
+ command = "./script/cucumber #{other_feature} #{failing_feature}"
+ puts "Running after #{other_feature}"
+ `#{command} 2>&1`
+ $? != 0
+end
+
+if interacting_feature
+ puts "Fails when run after #{interacting_feature}"
+else
+ puts "No interacting features found"
+end
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+git status | grep unmerged | sed "s/^.*unmerged: *//" | head -n 1
72 mvim
@@ -0,0 +1,72 @@
+#!/bin/sh
+#
+# This shell script passes all its arguments to the binary inside the
+# MacVim.app application bundle. If you make links to this script as view,
+# gvim, etc., then it will peek at the name used to call it and set options
+# appropriately.
+#
+# Based on a script by Wout Mertens and suggestions from Laurent Bihanic. This
+# version is the fault of Benji Fisher, 16 May 2005 (with modifications by Nico
+# Weber and Bjorn Winckler, Aug 13 2007).
+# First, check "All the Usual Suspects" for the location of the Vim.app bundle.
+# You can short-circuit this by setting the VIM_APP_DIR environment variable
+# or by un-commenting and editing the following line:
+# VIM_APP_DIR=/Applications
+
+if [ -z "$VIM_APP_DIR" ]
+then
+ myDir="`dirname "$0"`"
+ myAppDir="$myDir/../Applications"
+ for i in ~/Applications ~/Applications/vim $myDir $myDir/vim $myAppDir $myAppDir/vim /Applications /Applications/vim /Applications/Utilities /Applications/Utilities/vim; do
+ if [ -x "$i/MacVim.app" ]; then
+ VIM_APP_DIR="$i"
+ break
+ fi
+ done
+fi
+if [ -z "$VIM_APP_DIR" ]
+then
+ echo "Sorry, cannot find MacVim.app. Try setting the VIM_APP_DIR environment variable to the directory containing MacVim.app."
+ exit 1
+fi
+binary="$VIM_APP_DIR/MacVim.app/Contents/MacOS/Vim"
+
+# Next, peek at the name used to invoke this script, and set options
+# accordingly.
+
+name="`basename "$0"`"
+gui=
+opts=
+
+# GUI mode, implies forking
+case "$name" in m*|g*|rm*|rg*) gui=true ;; esac
+
+# Restricted mode
+case "$name" in r*) opts="$opts -Z";; esac
+
+# vimdiff, view, and ex mode
+case "$name" in
+ *vimdiff)
+ opts="$opts -dO"
+ ;;
+ *view)
+ opts="$opts -R"
+ ;;
+ *ex)
+ opts="$opts -e"
+ ;;
+esac
+
+# Last step: fire up vim.
+# The program should fork by default when started in GUI mode, but it does
+# not; we work around this when this script is invoked as "gvim" or "rgview"
+# etc., but not when it is invoked as "vim -g".
+if [ "$gui" ]; then
+ # Note: this isn't perfect, because any error output goes to the
+ # terminal instead of the console log.
+ # But if you use open instead, you will need to fully qualify the
+ # path names for any filenames you specify, which is hard.
+ exec "$binary" -g $opts ${1:+"$@"}
+else
+ exec "$binary" $opts ${1:+"$@"}
+fi
@@ -0,0 +1,79 @@
+#!/usr/bin/env ruby
+
+require 'fileutils'
+
+class SpecFinder
+ attr_reader :prefix
+ def initialize(prefix)
+ @prefix = prefix
+ end
+
+
+ def name_to_file(name, line = nil)
+ file = "#{prefix}/#{name}_spec.rb"
+ file << ":#{line}" if line
+ file
+ end
+
+ def file_to_name(file)
+ file.sub(%r{^#{Regexp.escape(prefix)}/}, '').sub(%r{_spec\.rb$}, '')
+ end
+
+ def spec_files
+ @spec_files ||= Dir["#{prefix}/**/*_spec.rb"]
+ end
+
+ def spec_names
+ @spec_names ||= spec_files.collect {|file| file_to_name(file) }
+ end
+
+ def run(specs)
+ if specs.empty?
+ if spec_files.empty?
+ puts "Nothing to do."
+ else
+ run(spec_files)
+ end
+ else
+ specs = specs.collect {|spec| force_spec_file(spec) }
+ command = command_to_run(specs)
+ puts command
+ exec command
+ end
+ end
+
+ def list
+ puts spec_names.sort.join("\n")
+ end
+
+ private
+
+ def force_spec_file(spec_and_line)
+ spec, line = spec_and_line.split(':')
+ if spec_files.include?(spec)
+ spec_and_line
+ elsif spec_names.include?(spec)
+ name_to_file(spec, line)
+ else
+ raise "No such spec: #{spec.inspect}"
+ end
+ end
+
+ def command_to_run(files)
+ files_string = files.join(" ")
+ "spec #{files_string}"
+ end
+end
+
+list = ARGV.delete('-l') || ARGV.delete('--list')
+prefix = ARGV.shift
+prefix = prefix ? "spec/#{prefix}" : 'spec'
+finder = SpecFinder.new(prefix)
+specs = ARGV.dup
+
+if list
+ finder.list
+else
+ finder.run(specs)
+end
+
@@ -0,0 +1,96 @@
+#!/usr/bin/env ruby
+
+require 'fileutils'
+
+class TestFinder
+
+ attr_reader :prefix
+
+ def initialize(prefix)
+ @prefix = prefix
+ end
+
+
+ def name_to_file(name)
+ "#{prefix}/#{name}_test.rb"
+ end
+
+ def file_to_name(file)
+ file.sub(%r{^#{Regexp.escape(prefix)}/}, '').sub(%r{_test\.rb$}, '')
+ end
+
+ def test_files
+ @test_files ||= Dir["#{prefix}/**/*_test.rb"]
+ end
+
+ def test_names
+ @test_names ||= test_files.collect {|file| file_to_name(file) }
+ end
+
+ def run(tests, pattern)
+ if tests.empty?
+ if test_files.empty?
+ puts "Nothing to do."
+ else
+ run(test_files)
+ end
+ else
+ tests = tests.collect {|test| force_test_file(test) }
+ command = command_to_run(tests, pattern)
+ puts command
+ exec command
+ end
+ end
+
+ def list
+ puts test_names.sort.join("\n")
+ end
+
+ private
+
+ def force_test_file(test)
+ if test_files.include?(test)
+ test
+ elsif test_names.include?(test)
+ name_to_file(test)
+ else
+ raise "No such test: #{test.inspect}"
+ end
+ end
+
+ def command_to_run(files, pattern)
+ files_string = files.inspect
+ require_string = 'require "#{f}"'
+ command_arguments = %w(-Itest -e)
+ command_arguments << "#{files_string}.each {|f| #{require_string} }"
+ if pattern != ''
+ command_arguments << '--' << '-n' << "/#{pattern}/"
+ end
+ exec('ruby', *command_arguments)
+ end
+end
+
+list = ARGV.delete('-l') || ARGV.delete('--list')
+prefix = ARGV.shift
+prefix = prefix ? "test/#{prefix}" : 'test'
+finder = TestFinder.new(prefix)
+args = ARGV.dup
+
+if list
+ finder.list
+else
+ pattern = []
+ tests = []
+
+ ARGV.each do |arg|
+ if pattern.size > 0 || arg =~ /^\//
+ pattern << arg.sub(/^\//, '')
+ else
+ tests << arg
+ end
+ end
+ pattern = pattern.join(' ')
+
+ finder.run(tests, pattern)
+end
+
Oops, something went wrong.

0 comments on commit 80d1eee

Please sign in to comment.