public
Description: Some utility scripts (the stuff I keep in ~/bin)
Clone URL: git://github.com/foca/utility_scripts.git
Search Repo:
Initial scripts (railify, import, ssh)
foca (author)
Sun Mar 23 04:33:18 -0700 2008
commit  af63fa36c52bb32dc4dbd581edcd7a8f8c48e048
tree    28345698ae8d11e87024dca12df80bdb403b9c72
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
0
@@ -0,0 +1,76 @@
0
+#!/opt/local/bin/ruby
0
+
0
+%w( rubygems active_support optparse ostruct ).each {|l| require l}
0
+
0
+module Enumerable
0
+ def shuffle
0
+ sort_by { rand }
0
+ end
0
+end
0
+
0
+class PassGrid
0
+ ALPHANUMERIC = ('A'..'Z').to_a + (0..9).to_a.map(&:to_s)
0
+ EXTENDED = ALPHANUMERIC + %w( + - = _ ! / < > @ # $ % ^ & * \ ; : . , )
0
+
0
+ def initialize(width, height, extended_charset = false, label = nil)
0
+ @rows = []
0
+ @width, @height = width, height
0
+ @label = label
0
+ self.characters = extended_charset
0
+ populate
0
+ end
0
+
0
+ def print
0
+ print_label
0
+ @rows.each {|row| puts row.join(@height == 1 ? "" : " ") }
0
+ end
0
+
0
+ private
0
+ def print_label
0
+ return if @label.nil?
0
+ puts @label
0
+ puts "=" * (2 * @width - 1)
0
+ end
0
+ def populate
0
+ @height.times do
0
+ @rows << []
0
+ @width.times { @rows.last << characters.shuffle.last.gsub(/\s+/, "") }
0
+ end
0
+ end
0
+ def characters=(charset)
0
+ @charset = ALPHANUMERIC
0
+ return if charset.blank?
0
+
0
+ @charset += case charset
0
+ when String then charset.split("").uniq
0
+ when Enumerable then charset
0
+ else EXTENDED
0
+ end
0
+ end
0
+ def characters
0
+ @charset.map do |char|
0
+ rand(2).zero? ? char.downcase : char.upcase
0
+ end
0
+ end
0
+end
0
+
0
+if $0 == __FILE__
0
+ options = { :extended => false, :width => 10, :height => 10, :label => nil, :help => false }
0
+
0
+ opts = OptionParser.new do |opts|
0
+ opts.on("-e [CHARSET]", "--extended [CHARSET]", "Extended character set") {|c| options[:extended] = c || true }
0
+ opts.on("-w WIDTH", "--width WIDTH", /\d+/, "Width of the grid (default 10)") {|w| options[:width] = w.to_i }
0
+ opts.on("-h HEIGHT", "--height HEIGHT", /\d+/, "Height of the grid (default 10)") {|h| options[:height] = h.to_i }
0
+ opts.on("-l LABEL", "--label LABEL", "Label for the grid") {|l| options[:label] = l }
0
+ opts.on_tail("--help", "Show this usage statement") { raise }
0
+ end
0
+
0
+ begin
0
+ opts.parse!(ARGV)
0
+ rescue Exception => e
0
+ puts opts
0
+ exit
0
+ end
0
+
0
+ PassGrid.new(options[:width], options[:height], options[:extended], options[:label]).print
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
0
@@ -0,0 +1,113 @@
0
+#!/usr/bin/env ruby
0
+
0
+# Generate a rails app (using EDGE rails), set up a git repo for it, install GemsOnRails,
0
+# haml, rspec, and the rspec-haml-scaffold generator
0
+#
0
+# USAGE: $0 some_app_name
0
+
0
+RAILS_SVN_CHECKOUT = '/Users/foca/Rails/_rails'
0
+
0
+module Helpers
0
+ LINE = 80
0
+
0
+ def announcing(msg)
0
+ print msg
0
+ yield
0
+ print "." * (LINE - msg.size - 6)
0
+ puts "\e[32m[DONE]\e[0m"
0
+ end
0
+
0
+ def silent(command)
0
+ system "#{command} &> /dev/null"
0
+ end
0
+
0
+ def templates
0
+ { :gitignore => %w[config/database.yml tmp/* log/*.log db/*.sqlite3 db/schema.rb public/stylesheets/application.css] * "\n",
0
+ :routes => ["ActionController::Routing::Routes.draw do |map|", "end"] * "\n" }
0
+ end
0
+
0
+ def git(message)
0
+ silent "git add ."
0
+ silent "git commit -m '#{message}'"
0
+ end
0
+
0
+ def braid(repo, dir, type="svn")
0
+ silent "braid add #{repo} --type #{type} #{dir}"
0
+ silent "git merge braid/track"
0
+ end
0
+
0
+ def rake(task, args={})
0
+ args = args.inject("") do |list, (name, value)|
0
+ list << "#{name.to_s.upcase}=#{value}"
0
+ end
0
+ silent "rake #{task} #{args}"
0
+ end
0
+end
0
+
0
+if __FILE__ == $0
0
+ include Helpers
0
+
0
+ app_name = ARGV.first
0
+
0
+ announcing "Fetching EDGE rails" do
0
+ Dir.chdir(RAILS_SVN_CHECKOUT) { silent "svn update" }
0
+ end
0
+
0
+ announcing "Creating application layout" do
0
+ silent "ruby #{RAILS_SVN_CHECKOUT}/railties/bin/rails #{app_name}"
0
+ end
0
+
0
+ Dir.chdir(app_name) do
0
+ announcing "Setting up rails app" do
0
+ silent "rm README"
0
+ silent "rm public/index.html"
0
+ silent "rm log/*.log"
0
+ silent "rm public/images/rails.png"
0
+ silent "cp config/database.{,sample.}yml"
0
+ silent "rm -r test"
0
+ File.open("config/routes.rb", "w") {|f| f << templates[:routes] }
0
+ end
0
+
0
+ announcing "Creating databases" do
0
+ rake "db:create"
0
+ rake "db:create", :rails_env => "test"
0
+ end
0
+
0
+ announcing "Configuring git repo" do
0
+ silent "git init"
0
+ File.open(".gitignore", "w") {|f| f << templates[:gitignore] }
0
+ silent "touch {tmp,log}/.gitignore"
0
+ git "Basic rails app structure"
0
+ end
0
+
0
+ announcing "Freezing rails" do
0
+ braid "http://dev.rubyonrails.org/svn/rails/trunk", "vendor/rails"
0
+ end
0
+
0
+ announcing "Installing GemsOnrails" do
0
+ silent "gemsonrails"
0
+ git "Froze GemsOnRails plugin"
0
+ end
0
+
0
+ announcing "Installing haml" do
0
+ silent "haml --rails ."
0
+ rake "gems:freeze", :gem => "haml"
0
+ git "Froze haml gem and plugin"
0
+ end
0
+
0
+ announcing "Installing RSpec" do
0
+ braid "http://rspec.rubyforge.org/svn/trunk/rspec", "vendor/plugins/rspec"
0
+ braid "http://rspec.rubyforge.org/svn/trunk/rspec_on_rails", "vendor/plugins/rspec_on_rails"
0
+ end
0
+
0
+ announcing "Generating RSpec base files" do
0
+ silent "script/generate rspec"
0
+ git "Added RSpec base files"
0
+ end
0
+
0
+ announcing "Installing make_resourceful" do
0
+ braid "http://svn.hamptoncatlin.com/make_resourceful/trunk", "vendor/plugins/make_resourceful"
0
+ end
0
+ end
0
+
0
+end
0
ssh
...
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
0
@@ -0,0 +1,9 @@
0
+#!/bin/bash
0
+
0
+real_ssh=/opt/local/bin/ssh
0
+
0
+if [[ $(ssh-add -L | cut -d\ -f1) != "ssh-rsa" ]]; then
0
+ ssh-add
0
+fi
0
+
0
+$real_ssh $@

Comments

    No one has commented yet.