FreedomCoder-utility_belt 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/History.txt +5 -0
  2. data/Manifest.txt +7 -0
  3. data/README +372 -0
  4. data/bin/amazon +16 -0
  5. data/bin/google +7 -0
  6. data/bin/pastie +7 -0
  7. data/bin/twitt +15 -0
  8. data/html/andreas00.css +449 -0
  9. data/html/authorship.html +86 -0
  10. data/html/bg.gif +0 -0
  11. data/html/front.jpg +0 -0
  12. data/html/index.html +81 -0
  13. data/html/menubg.gif +0 -0
  14. data/html/menubg2.gif +0 -0
  15. data/html/test.jpg +0 -0
  16. data/html/usage.html +298 -0
  17. data/lib/utility_belt.rb +22 -0
  18. data/lib/utility_belt/amazon_upload_shortcut.rb +25 -0
  19. data/lib/utility_belt/clipboard.rb +70 -0
  20. data/lib/utility_belt/command_history.rb +110 -0
  21. data/lib/utility_belt/convertable_to_file.rb +34 -0
  22. data/lib/utility_belt/equipper.rb +71 -0
  23. data/lib/utility_belt/google.rb +34 -0
  24. data/lib/utility_belt/hash_math.rb +13 -0
  25. data/lib/utility_belt/interactive_editor.rb +78 -0
  26. data/lib/utility_belt/irb_options.rb +3 -0
  27. data/lib/utility_belt/irb_verbosity_control.rb +30 -0
  28. data/lib/utility_belt/is_an.rb +4 -0
  29. data/lib/utility_belt/language_greps.rb +28 -0
  30. data/lib/utility_belt/not.rb +15 -0
  31. data/lib/utility_belt/pastie.rb +35 -0
  32. data/lib/utility_belt/pipe.rb +24 -0
  33. data/lib/utility_belt/rails_finder_shortcut.rb +18 -0
  34. data/lib/utility_belt/rails_verbosity_control.rb +8 -0
  35. data/lib/utility_belt/string_to_proc.rb +72 -0
  36. data/lib/utility_belt/symbol_to_proc.rb +30 -0
  37. data/lib/utility_belt/twitty.rb +58 -0
  38. data/lib/utility_belt/wirble.rb +83 -0
  39. data/lib/utility_belt/with.rb +21 -0
  40. data/spec/convertable_to_file_spec.rb +31 -0
  41. data/spec/equipper_spec.rb +70 -0
  42. data/spec/hash_math_spec.rb +17 -0
  43. data/spec/interactive_editor_spec.rb +146 -0
  44. data/spec/language_greps_spec.rb +9 -0
  45. data/spec/pastie_spec.rb +92 -0
  46. data/spec/pipe_spec.rb +30 -0
  47. data/spec/spec_helper.rb +8 -0
  48. data/spec/string_to_proc_spec.rb +41 -0
  49. data/spec/utility_belt_spec.rb +4 -0
  50. data/utility-belt.gemspec +38 -0
  51. metadata +145 -0
@@ -0,0 +1,86 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
6
+ <meta name="description" content="Baddest Ruby gem evar." />
7
+ <meta name="keywords" content="ruby, giles bowkett, batman, utility belt, gem, attack of the killer tomatoes" />
8
+ <meta name="author" content="Giles Bowkett / Original design: Andreas Viklund - http://andreasviklund.com/" />
9
+ <link rel="stylesheet" type="text/css" href="andreas00.css" media="screen,projection" />
10
+ <title>Utility Belt: Authorship</title>
11
+ </head>
12
+
13
+ <body>
14
+ <div id="wrap">
15
+ <div id="header">
16
+ <h1><a href="http://utilitybelt.rubyforge.org">Utility Belt</a></h1>
17
+ <p><strong>IRB tools, tricks, and techniques</strong></p>
18
+ </div>
19
+
20
+ <div id="avmenu">
21
+ <h2 class="hide">Site menu:</h2>
22
+ <ul>
23
+ <li><a href="index.html">Overview</a></li>
24
+ <li><a href="usage.html">Usage</a></li>
25
+ <li><a href="authorship.html">Authorship</a></li>
26
+ <li><a href="http://rubyforge.org/projects/utilitybelt/">RubyForge Project</a></li>
27
+ </ul>
28
+ </div>
29
+
30
+ <div id="contentwide">
31
+ <h2>Copyright And Authorship</h2>
32
+ <h3>COMMUNITY EFFORT</h3>
33
+
34
+ <p>The majority of this code was written by other people and compiled, nicked, nabbed, herded, gathered, copied, or pilfered by me (Giles Bowkett). Check the links in the copyright notice for more detail. Thanks also to Bob Hutchison, Avdi Grimm, Marcus Derencius, Markus Prinz, Ben Bleything, Reginald Braithwaite-Lee, and Robert Berger for bug fixes, new features, documentation, and bug reports.</p>
35
+
36
+ <h3>LICENSE</h3>
37
+
38
+ <pre>
39
+ (The MIT License)
40
+
41
+ Copyright (c) 2006-2007 <a href="http://gilesbowkett.blogspot.com/" title="Giles Bowkett">Giles Bowkett</a>
42
+ Portions Copyright (c) 2006-2007 <a href="http://blog.bleything.net/2007/7/30/announcing-shell-style-history-for-irb-the-fixed-edition" title="bleything.blog(:stuff) Announcing Shell-Style History for irb, the fixed edition!">Ben Bleything</a>
43
+ Portions Copyright (c) 2006-2007 <a href="http://weblog.raganwald.com/2007/10/stringtoproc.html" title="String#to_proc">Reginald Braithwaite-Lee</a>
44
+ Portions Copyright (c) 2006-2007 <a href="http://gilesbowkett.blogspot.com/2007/10/use-vi-or-any-text-editor-from-within.html" title="Giles Bowkett: Use vi (Or Any Text Editor) From Within irb">Gregory Brown</a>
45
+ Portions Copyright (c) 2006-2007 <a href="http://weblog.jamisbuck.org/2007/1/8/watching-activerecord-do-it-s-thing" title="the { buckblogs :here : Watching ActiveRecord Do Its Thing}">Jamis Buck</a>
46
+ Portions Copyright (c) 2006-2007 <a href="http://clarkware.com/cgi/blosxom/2007/09/03" title="Mike Clark's Weblog">Mike Clark</a>
47
+ Portions Copyright (c) 2006-2007 <a href="http://blog.jayfields.com/2007/08/ruby-adding-not-method-for-readability.html" title="Jay Fields Thoughts: Ruby: Adding a "not" method for readability">Jay Fields</a>
48
+ Portions Copyright (c) 2005 <a href="http://api.rubyonrails.org/classes/Symbol.html" title="Class: Symbol">David Heinemeier Hansson</a>
49
+ Portions Copyright (c) 2006-2007 <a href="http://groups.google.com/group/ruby-talk-google/browse_thread/thread/9c1febbe05513dc0" title="shutting irb up - ruby-talk-google | Google Groups">Ara T. Howard</a>
50
+ Portions Copyright (c) 2006-2007 <a href="http://gilesbowkett.blogspot.com/2006/12/smalltalk-cleverness-in-rails-revisited.html" title="Giles Bowkett: Smalltalk Cleverness in Rails, Revisited">Pat Maddox</a>
51
+ Portions Copyright (c) 2006-2007 <a href="http://amazon.rubyforge.org/" title="AWS::S3 - Ruby Library for Amazon Simple Storage Service (S3)">Marcel Molina, Jr.</a>
52
+ Portions Copyright (c) 2006-2007 <a href="http://groups.google.com/group/ruby-talk-google/browse_thread/thread/9c1febbe05513dc0" title="shutting irb up - ruby-talk-google | Google Groups">Rick DeNatale</a>
53
+ Portions Copyright (c) 2006-2007 <a href="http://project.ioni.st/post/1334" title="Projectionist: A tumblelog">Projectionist</a> (Marcel Molina? Chad Fowler?)
54
+ Portions Copyright (c) 2006-2007 <a href="http://aspn.activestate.com/ASPN/Mail/Message/ruby-talk/3573982" title="Re: "with" statement :: ASPN Mail Archive :: ruby-talk">Dan Yoder</a>
55
+
56
+ Permission is hereby granted, free of charge, to any person obtaining
57
+ a copy of this software and associated documentation files (the
58
+ 'Software'), to deal in the Software without restriction, including
59
+ without limitation the rights to use, copy, modify, merge, publish,
60
+ distribute, sublicense, and/or sell copies of the Software, and to
61
+ permit persons to whom the Software is furnished to do so, subject to
62
+ the following conditions:
63
+
64
+ The above copyright notice and this permission notice shall be
65
+ included in all copies or substantial portions of the Software.
66
+
67
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
68
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
69
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
70
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
71
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
72
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
73
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</pre>
74
+
75
+ <h3>THE BATMAN GRAPHIC</h3>
76
+
77
+ <p>Is that cool or what? I have no idea where I found it. (If you're the creator, a thousand apologies. I just hella dig it.)</p>
78
+
79
+ </div>
80
+
81
+ <div id="footer">
82
+ <p>Copyright &copy; 2007 Giles Bowkett | Design by <a href="http://andreasviklund.com">Andreas Viklund</a>.</p>
83
+ </div>
84
+ </div>
85
+ </body>
86
+ </html>
data/html/bg.gif ADDED
Binary file
data/html/front.jpg ADDED
Binary file
data/html/index.html ADDED
@@ -0,0 +1,81 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
6
+ <meta name="description" content="Baddest Ruby gem evar." />
7
+ <meta name="keywords" content="ruby, giles bowkett, batman, utility belt, gem, attack of the killer tomatoes" />
8
+ <meta name="author" content="Giles Bowkett / Original design: Andreas Viklund - http://andreasviklund.com/" />
9
+ <link rel="stylesheet" type="text/css" href="andreas00.css" media="screen,projection" />
10
+ <title>Utility Belt</title>
11
+ </head>
12
+
13
+ <body>
14
+ <div id="wrap">
15
+ <div id="header">
16
+ <h1><a href="http://utilitybelt.rubyforge.org">Utility Belt</a></h1>
17
+ <p><strong>IRB tools, tricks, and techniques</strong></p>
18
+ </div>
19
+
20
+ <div id="avmenu">
21
+ <h2 class="hide">Site menu:</h2>
22
+ <ul>
23
+ <li><a href="index.html">Overview</a></li>
24
+ <li><a href="usage.html">Usage</a></li>
25
+ <li><a href="authorship.html">Authorship</a></li>
26
+ <li><a href="http://rubyforge.org/projects/utilitybelt/">RubyForge Project</a></li>
27
+ </ul>
28
+
29
+ </div>
30
+
31
+ <div id="contentwide">
32
+ <h2>Installation And Overview</h2>
33
+
34
+ <p>Utility Belt is a grab-bag of tricks, tools, techniques, trifles, and toys for IRB, including convenience methods, language patches, and useful extensions. It also includes a couple command-line widgets. Its primary inspirations were <a href="http://pablotron.org/software/wirble/" title="Pablotron: Wirble">an awesome gem called Wirble</a> and <a href="http://slash7.com/articles/2006/12/21/secrets-of-the-rails-console-ninjas" title="Slash7 with Amy Hoy - Secrets of the Rails Console Ninjas">a blog post by Amy Hoy called "Secrets Of The Rails Console Ninjas"</a>.</p>
35
+
36
+ <h3>INSTALL</h3>
37
+
38
+ <p>sudo gem install utility_belt</p>
39
+
40
+ <h3>FEATURES</h3>
41
+
42
+ <ul>
43
+ <li>Interactively edit IRB code in your preferred text editor</li>
44
+ <li>Read from and write to OS X clipboard</li>
45
+ <li>Post your code to Pastie with one command (OS X only)</li>
46
+ <li>Kick-ass Unix-style history buffer</li>
47
+ <li>Write command history to file or vi</li>
48
+ <li>Grep classes and methods for strings</li>
49
+ <li>Verbosity controls for regular IRB and Rails console</li>
50
+ <li>Finder shortcuts for Rails console</li>
51
+ <li>Upload shortcut for Amazon S3</li>
52
+ <li>Command-line Amazon S3 upload script</li>
53
+ <li>Command-line Google shortcut (OS X only)</li>
54
+ <li>Auto-indentation</li>
55
+ <li>_ special variable (like Unix shell var !!)</li>
56
+ <li>Extremely basic themes for Wirble syntax coloring</li>
57
+ <li>Pascal/JavaScript-style "with" statement</li>
58
+ <li>String#to_proc</li>
59
+ <li>Add and subtract Hashes with + and -</li>
60
+ <li>Grammatically-correct is_an? method - no more "is_a? Array" statements</li>
61
+ <li>One-character exit command</li>
62
+ </ul>
63
+
64
+ <h3>REQUIREMENTS</h3>
65
+
66
+ <ul>
67
+ <li>ReadLine</li>
68
+ <li>Wirble</li>
69
+ <li>Amazon S3</li>
70
+ <li>Platform</li>
71
+ <li>Some features require OS X</li>
72
+ </ul>
73
+
74
+ </div>
75
+
76
+ <div id="footer">
77
+ <p>Copyright &copy; 2007 Giles Bowkett | Design by <a href="http://andreasviklund.com">Andreas Viklund</a>.</p>
78
+ </div>
79
+ </div>
80
+ </body>
81
+ </html>
data/html/menubg.gif ADDED
Binary file
data/html/menubg2.gif ADDED
Binary file
data/html/test.jpg ADDED
Binary file
data/html/usage.html ADDED
@@ -0,0 +1,298 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
6
+ <meta name="description" content="Baddest Ruby gem evar." />
7
+ <meta name="keywords" content="ruby, giles bowkett, batman, utility belt, gem, attack of the killer tomatoes" />
8
+ <meta name="author" content="Giles Bowkett / Original design: Andreas Viklund - http://andreasviklund.com/" />
9
+ <link rel="stylesheet" type="text/css" href="andreas00.css" media="screen,projection" />
10
+ <title>Utility Belt: Usage</title>
11
+ </head>
12
+
13
+ <body>
14
+ <div id="wrap">
15
+ <div id="header">
16
+ <h1><a href="http://utilitybelt.rubyforge.org">Utility Belt</a></h1>
17
+ <p><strong>IRB tools, tricks, and techniques</strong></p>
18
+ </div>
19
+
20
+ <div id="avmenu">
21
+ <h2 class="hide">Site menu:</h2>
22
+ <ul>
23
+ <li><a href="index.html">Overview</a></li>
24
+ <li><a href="usage.html">Usage</a></li>
25
+ <li><a href="authorship.html">Authorship</a></li>
26
+ <li><a href="http://rubyforge.org/projects/utilitybelt/">RubyForge Project</a></li>
27
+ </ul>
28
+
29
+ </div>
30
+
31
+ <div id="contentwide">
32
+ <h2>Synopsis And Usage</h2>
33
+
34
+
35
+ <h3>SYNOPSIS</h3>
36
+
37
+ <p>Utility Belt gives you a ton of new options and techniques in IRB. (You may find yourself putting its language patches in actual projects as well.) The way to use Utility Belt is to edit, or create, your .irbrc file. This is analogous to a Unix .bashrc, .tcshrc, .profile, or similar file.</p>
38
+
39
+ <p>Windows users have a couple options. The easiest is to define an environment variable called IRBRC and set it to the full path of your irbrc (e.g. "C:\Documents and Settings\<username>\_irbrc"). Presto, .irbrc for Windows. You could also set your HOME-Variable to any directory you want and put your ".irbrc" in there. (It needs to be called ".irbrc", "_irbrc" won't work). Since Windows Explorer won't let you create a file with a dot in the beginning, use any text editor (Notepad will do just fine) and "Save As" to save it as ".irbrc". (The quotation marks make the magic happen.) We don't recommend this if you're also using MSYS or Cygwin, as they use the same variable for their own purposes.</p>
40
+
41
+ <p>Adding Utility Belt to your .irbrc is easy:</p>
42
+
43
+ <pre>require 'rubygems'
44
+ require 'utility_belt'</pre>
45
+
46
+ <p>To use the Amazon shortcuts, you also need to set some environment variables. See the section on S3 under "Usage" for more. Also, if your terminal has a light background, you'll need to enable the light-background syntax coloring theme - see the section on themes under "Usage" for more.</p>
47
+
48
+ <h3>USAGE</h3>
49
+
50
+ <p>Using each of Utility Belt's tools is different:</p>
51
+
52
+ <h4>Interactively edit IRB code in your preferred text editor</h4>
53
+
54
+ <p>If your preferred text editor is vi(m), emacs, or TextMate, there are built-in commands: vi, emacs, and mate, respectively. To use another editor, use this command:</p>
55
+
56
+ <pre>edit_interactively(:the_name_of_my_editor)</pre>
57
+
58
+ <p>or</p>
59
+
60
+ <pre>edit_interactively("the name of my editor")</pre>
61
+
62
+ <p>or</p>
63
+
64
+ <pre>edit_interactively("/the/path/to/my/editor")</pre>
65
+
66
+ <p>If you're wondering why the method name is so ridiculously long, <a href="http://gilesbowkett.blogspot.com/2007/12/utility-belt-vs-rails.html" title="Giles Bowkett: Utility Belt vs. Rails">there's a story there</a>.</p>
67
+
68
+ <h4>Read from and write to OS X clipboard</h4>
69
+
70
+ <p>To read:</p>
71
+
72
+ <pre>MacClipboard.read</pre>
73
+
74
+ <p>To write:</p>
75
+
76
+ <pre>MacClipboard.write("something")</pre>
77
+
78
+ <h4>Post your code to Pastie with one command (OS X only)</h4>
79
+
80
+ <p>First copy some code into your clipboard, or put it there with the MacClipboard.write() class method. Then use the command:</p>
81
+
82
+ <pre>pastie</pre>
83
+
84
+ <p>or the shortcut version:</p>
85
+
86
+ <pre>pst</pre>
87
+
88
+ <p>Note that this method currently auto-formats all code as Ruby. Support for other languages is possible but not implemented yet. Also, this code is OS X only because it uses the MacClipboard. (A platform-agnostic version without the clipboard aspect is certainly possible.)</p>
89
+
90
+ <h4>Unix-style history buffer</h4>
91
+
92
+ <p>Use "h" or "history" to view your command history, and "h! 123" to re-invoke command #123 in your buffer. "h!" with no args will run the last command.</p>
93
+
94
+ <h4>Write command history to file or vi</h4>
95
+
96
+ <p>To write your history to a file, use "history_write('/path/to/file')". To edit your history in vi, use "history_to_vi" or its shortcut alias "hvi".</p>
97
+
98
+ <h4>Grep classes and methods for strings</h4>
99
+
100
+ <p>Classes:</p>
101
+
102
+ <pre>&gt;&gt; grep_classes(&quot;ixnum&quot;)
103
+ #=&gt; [&quot;Fixnum&quot;]
104
+
105
+ &gt;&gt; grep_classes(&quot;num&quot;)
106
+ #=&gt; [&quot;Bignum&quot;, &quot;Fixnum&quot;, &quot;Numeric&quot;, &quot;REXML::SyncEnumerator&quot;]</pre>
107
+
108
+ <p>Methods:</p>
109
+
110
+ <pre>&gt;&gt; &quot;any arbitrary string&quot;.grep_methods(&quot;pretty&quot;)
111
+ #=&gt; [&quot;pretty_inspect&quot;, &quot;pretty_print_instance_variables&quot;,
112
+ &quot;pretty_print_inspect&quot;, &quot;pretty_print&quot;, &quot;pretty_print_cycle&quot;]
113
+
114
+ &gt;&gt; 32.grep_methods(&quot;*&quot;)
115
+ #=&gt; [&quot;*&quot;, &quot;**&quot;]</pre>
116
+
117
+ <p>At some point it'll probably be a good idea to add regex support for these methods. (Of course if I do that, I'll probably have to change the name from grep to ack.)</p>
118
+
119
+ <h4>Verbosity controls for regular IRB and Rails console</h4>
120
+
121
+ <p>regular IRB: "verbose" or "v" / "quiet" or "q"</p>
122
+
123
+ <p>Rails: "log" method turns verbosity on, there isn't actually any method for turning it off. (Might add one at some point.)</p>
124
+
125
+ <h4>Finder shortcuts for Rails console</h4>
126
+
127
+ <pre>user(:all) / user(1)</pre>
128
+
129
+ <p>instead of</p>
130
+
131
+ <pre>User.find(:all) / User.find(1)</pre>
132
+
133
+ <p>Supports arbitrarily complex finds.</p>
134
+
135
+ <h4>Upload shortcut for Amazon S3</h4>
136
+
137
+ <p>First, define your secret keys in your environment variables:</p>
138
+
139
+ <pre>export AMAZON_ACCESS_KEY_ID='foofoofoofoofoo'
140
+ export AMAZON_SECRET_ACCESS_KEY='barbarbarbarbar'</pre>
141
+
142
+ <p>(Obviously, replace those with actual values.)</p>
143
+
144
+ <p>Then, you can use</p>
145
+
146
+ <pre>aws_upload("bucket_name","filename")</pre>
147
+
148
+ <p>To easily upload public-access files. This method will automatically connect to Amazon S3 for you, if your keys are defined in your environment variables. It also writes the resulting Amazon URL to your clipboard, if you're on OS X, so you can easily share the file with others. Note that you have to create the initial buckets manually - see <a href="http://amazon.rubyforge.org" title="AWS::S3 - Ruby Library for Amazon Simple Storage Service (S3)">amazon.rubyforge.org</a> for details on that.</p>
149
+
150
+ <p>A good way to use this is actually to have a default bucket, and create a further method in your .irbrc file:</p>
151
+
152
+ <pre>def my_bucket_name(filename)
153
+ aws_upload("my_default_bucket",filename)
154
+ end</pre>
155
+
156
+ <h4>Command-line Amazon S3 upload script</h4>
157
+
158
+ <p>Utility Belt also includes <code>amazon</code>, a simple command-line uploader for S3. It requires that you set your Amazon environment variables (see above). The usage is:</p>
159
+
160
+ <pre>amazon -b my_bucket_name filename other_filename</pre>
161
+
162
+ <p>(For any arbitrary number of filenames.)</p>
163
+
164
+ <p>Anytime you want to upload a file to your default bucket on S3, for example, the "images" bucket for your blog - or the "mp3" bucket if you're running a blog like Projectionist - all you have to do is</p>
165
+
166
+ <pre>amazon -b blog_files some_file.name</pre>
167
+
168
+ <p>Or</p>
169
+
170
+ <pre>amazon --bucket blog_files some_file.name</pre>
171
+
172
+ <p>And you're good to go. Of course, if that were too many characters to type, you could always take it one step further with a shell script. For instance, in bash:</p>
173
+
174
+ <pre>alias b1="amazon --bucket my_main_bucket $1"
175
+ alias b2="amazon --bucket my_other_bucket $1"</pre>
176
+
177
+ <p>And then you would only have to type:</p>
178
+
179
+ <pre>b1 file.name</pre>
180
+
181
+ <p>And of course tab completion will handle all the typing of the file name, assuming you choose your file names deliberately ahead of time to make tab completion effective, in which case all you have to type is "b1 f[tab]" and bam.</p>
182
+
183
+ <h4>Command-line Google shortcut (OS X only)</h4>
184
+
185
+ <p>To pop open a new window in your default browser with Google search results for a given search term, do:</p>
186
+
187
+ <pre>google "any given term"</pre>
188
+
189
+ <p>For one-word terms, you can omit the quotes:</p>
190
+
191
+ <pre>google term</pre>
192
+
193
+ <p>If you already have the search term in your clipboard, you can just type:</p>
194
+
195
+ <pre>google</pre>
196
+
197
+ <p>(The last approach is useful for unusual command-line error messages.)</p>
198
+
199
+ <h4>Auto-indentation</h4>
200
+
201
+ <p>Just type as normally. This just enables built-in but underused functionality in IRB. (The IRB default auto-indentation isn't perfect, but it clobbers the living hell out of no indentation at all.)</p>
202
+
203
+ <h4>_ special variable (like Unix shell var !!)</h4>
204
+
205
+ <p>More activation of built-in but underused functionality in IRB. _ functions like !! in Unix, with one subtle difference. Instead of re-issuing the previous command in your history, it gives you the last result of evaluating a command. This means when you start a new IRB session, _ won't go to your history, it'll just give you nil, and it means that some commands can't be repeated exactly. Nine out of ten times, however, it's pretty much the same thing.</p>
206
+
207
+ <p>Note that when combined with the h! in the command history code, you basically have two synonyms for !! here. Neither one is an exact replica, but between the two of them, you should have what you need.</p>
208
+
209
+ <h4>Extremely basic themes for Wirble syntax coloring</h4>
210
+
211
+ <p>Utility Belt incorporates <a href="http://pablotron.org/software/wirble/" title="Pablotron: Wirble">Wirble</a> as a dependency. Wirble provides syntax coloring. Utility Belt allows you to choose between two syntax coloring themes: Wirble's default, and an alternate color set for terminals with light backgrounds. The default theme is enabled by default (duh), but if you have a terminal with a light background, you can enable the light-background theme just by putting the following line of code in your .irbrc:</p>
212
+
213
+ <pre>UtilityBelt::Themes.background(:light)</pre>
214
+
215
+ <p>To revert back to the default, just use this:</p>
216
+
217
+ <pre>UtilityBelt::Themes.background(:dark)</pre>
218
+
219
+ <p>To specify an entirely new syntax color scheme, see the source code for this gem or for Wirble.</p>
220
+
221
+ <h4>Pascal/JavaScript-style "with" statement</h4>
222
+
223
+ <p>I use this with RSpec's spec_helper. Instead of:</p>
224
+
225
+ <pre>Spec::Runner.configure do |config|
226
+ config.use_transactional_fixtures = true
227
+ config.use_instantiated_fixtures = false
228
+ config.fixture_path = RAILS_ROOT + '/spec/fixtures'
229
+ config.mock_with :flexmock
230
+ end</pre>
231
+
232
+ <p>I do this:</p>
233
+
234
+ <pre>Spec::Runner.configure do |config|
235
+ with(config) do
236
+ use_transactional_fixtures = true
237
+ use_instantiated_fixtures = false
238
+ fixture_path = RAILS_ROOT + '/spec/fixtures'
239
+ mock_with :flexmock
240
+ end
241
+ end</pre>
242
+
243
+ <p>Note however that this blew up once and I have no idea why. Caveat emptor, et cetera.</p>
244
+
245
+ <h4>String#to_proc</h4>
246
+
247
+ <p>Syntactic sugar for functional programming. (<a href="http://weblog.raganwald.com/2007/10/stringtoproc.html" title="String#to_proc">More detail here</a>.) Rails' Symbol#to_proc is also included.</p>
248
+
249
+ <pre>(1..3).map(&amp;&apos;*2&apos;) =&gt; [2, 4, 6]
250
+ (1..3).map(&amp;&apos;[-1, _, 0]&apos;) =&gt; [[-1, 1, 0], [-1, 2, 0], [-1, 3, 0]]
251
+ (1..3).map(&amp;&apos;x -&gt; y -&gt; x * y&apos;).map(&amp;&apos;[2]&apos;) =&gt; [2, 4, 6]
252
+ (1..5).select(&amp;&apos;&gt;2&apos;) =&gt; [3, 4, 5]
253
+ (1..3).map(&amp;&apos;x -&gt; y -&gt; x * y&apos;).map(&amp;&apos;.call(2)&apos;) =&gt; [2, 4, 6]
254
+ [5].map(&amp;&quot;(1.._).inject(&amp;&apos;*&apos;)&quot;) =&gt; [120]</pre>
255
+
256
+ <h4>Add and subtract Hashes with + and -</h4>
257
+
258
+ <pre>{:a =&gt; :b} + {:c =&gt; :d} = {:a =&gt; :b, :c =&gt; :d}
259
+ {:a =&gt; :b, :c =&gt; :d} - {:c =&gt; :d} = {:a =&gt; :b}
260
+ {:a =&gt; :b, :c =&gt; :d} - :c = {:a =&gt; :b}</pre>
261
+
262
+ <p>You could already do this with Arrays; now you can do it with Hashes as well. (I was kinda surprised the first time I tried to do this and realized I'd have to write it myself.)</p>
263
+
264
+
265
+ <h4>Grammatically-correct is_an? method - no more "is_a? Array" statements</h4>
266
+
267
+ <pre>&gt;&gt; [].is_an? Array
268
+ #=&gt; true</pre>
269
+
270
+ <p>Most people don't care, but personally, "is_a? Array" drives me completely insane.</p>
271
+
272
+ <h4>Object#not</h4>
273
+
274
+ <p>Replace this:</p>
275
+
276
+ <pre>if !response.incomplete? &amp;&amp; !response.invalid? &amp;&amp; response.total &gt; 0</pre>
277
+
278
+ <p>With this:</p>
279
+
280
+ <pre>if response.not.incomplete? &amp;&amp; response.not.invalid? &amp;&amp; response.total &gt; 0</pre>
281
+
282
+ <p>Syntactic sugar for boolean conditions. (<a href="http://blog.jayfields.com/2007/08/ruby-adding-not-method-for-readability.html" title="Jay Fields Thoughts: Ruby: Adding a "not" method for readability">More detail here</a>.)</p>
283
+
284
+ <h4>One-character exit command</h4>
285
+
286
+ <pre>x</pre>
287
+
288
+ <p>Because life is too short to type whole words.</p>
289
+
290
+
291
+ </div>
292
+
293
+ <div id="footer">
294
+ <p>Copyright &copy; 2007 Giles Bowkett | Design by <a href="http://andreasviklund.com">Andreas Viklund</a>.</p>
295
+ </div>
296
+ </div>
297
+ </body>
298
+ </html>