Skip to content

Instantly share code, notes, and snippets.

module SomeModule
@foo = 1234
def self.some_method
@foo
end
end
class SomeClass
def bar
§ echo "
.
.
.
"
.
.
.
>>> def do_something():
... print 'here'
... for x in xrange(0, 8):
... yield x
...
>>> do_something()
<generator object do_something at 0x100428aa0>
>>> foo = do_something()
>>> foo
<generator object do_something at 0x100428b40>
class SomeThing(object):
def doathing(self):
pass
class OtherThing(SomeThing):
make_it_happen_capn(self):
doathing()
>> require 'some_class'
=> true
>> foo = SomeClass.new
=> #<SomeClass:0x100a23900>
>> foo.doit
SomeClass=> nil
I have two parsers: one looks at sys.argv while the other looks at some of the tokens the first slurped up. So from argparse's perspective, it does seem like there should just be one parser. I assert that isn't appropriate for my purposes, though:
The first parser is looking at general lay-of-the-land-type stuff: "username to use when calling that API", etc.
The second is looking at specific what-to-do stuff: "what you should do with that API."
I want the settings for the first part to be configurable in a couple different ways: config file, env vars, command-line arguments. For that, I really want my various "configuration getters" to live together. The "what to do" parser has no business in that domain, though; I want it at the top-level script where it can determine a dispatch to some library function. So I have two parsers.
All I'm trying to get argparse to do is "if you are displaying a usage message, display the message for the general script and also the one describing the various subparsers." sys.e
@ErinCall
ErinCall / gist:2872479
Created June 5, 2012 03:41
Do these look functionally equivalent
#python 2.7
with warnings.catch_warnings(record=False) as w:
soup = BeautifulStoneSoup("<b />")
self.assertEqual(u"<b/>", unicode(soup.b))
#python 2.5
warnings_manager = warnings.catch_warnings(record=True)
w = warnings_manager.__enter__()
try:
soup = BeautifulStoneSoup("<b />")
<script id="template-item" type="text/html">
<li class="template e2ma-get-new-template" data-id="${id}" data-name="${name}">
<span><img src="${image}" alt="${name}" title="${name}" /></span>
<p>${name}</p>
</li>
</script>
@ErinCall
ErinCall / gist:2026022
Created March 13, 2012 01:26
it makes a tiny difference!
# building separately...
$ java -jar scripts/build-mailing-create/tools/closure-compiler/compiler.jar --warning_level QUIET media/js/mailing-create/e2ma/e2ma.save.js --js_output_file e2ma.save.min.js
$ java -jar scripts/build-mailing-create/tools/closure-compiler/compiler.jar --warning_level QUIET media/js/mailing-create/e2ma/e2ma.js --js_output_file e2ma.min.js
$ cat e2ma.save.min.js e2ma.min.js >| all1.js
# building all-at-once...
$ java -jar scripts/build-mailing-create/tools/closure-compiler/compiler.jar --warning_level QUIET --js media/js/mailing-create/e2ma/e2ma.save.js --js media/js/mailing-create/e2ma/e2ma.js --js_output_file all2.js
@ErinCall
ErinCall / gist:1658586
Created January 22, 2012 20:03
I wrote a test that failed so hard it killed spork
/Users/andrew/.rvm/gems/ruby-1.9.2-p180@railstut/gems/spork-0.8.5/lib/spork/forker.rb:50: [BUG] pthread_mutex_lock: Invalid argument (EINVAL)
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.8.0]
-- control frame ----------
c:0012 p:---- s:0045 b:0045 l:000044 d:000044 CFUNC :raise
c:0011 p:0083 s:0041 b:0041 l:000770 d:000770 METHOD /Users/andrew/.rvm/gems/ruby-1.9.2-p180@railstut/gems/spork-0.8.5/lib/spork/forker.rb:50
c:0010 p:0055 s:0037 b:0037 l:000a10 d:000a10 METHOD /Users/andrew/.rvm/gems/ruby-1.9.2-p180@railstut/gems/spork-0.8.5/lib/spork/run_strategy/forking.rb:17
c:0009 p:0023 s:0031 b:0031 l:000030 d:000030 METHOD /Users/andrew/.rvm/gems/ruby-1.9.2-p180@railstut/gems/spork-0.8.5/lib/spork/server.rb:47
c:0008 p:0098 s:0025 b:0025 l:000024 d:000024 METHOD /Users/andrew/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/drb/drb.rb:1558
c:0007 p:0146 s:0021 b:0021 l:000020 d:000020 METHOD /Users/andrew/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/drb/drb.rb:1518