Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| p((_=[gets.split,[],"+-**/"])[0].map{|s|s=~/[\d\.]+/?_[1]<<s.to_f: _[2][s]?_[1]<<_[1].pop(2).inject(s):0}[0][0]) |
| # The new git-scm.com site includes man pages designed for pleasant viewing in a web browser: | |
| # | |
| # http://git-scm.com/docs | |
| # | |
| # The commands below can be used to configure git to open these pages when | |
| # using `git help -w <command>' from the command line. Just enter the config | |
| # commands in your shell to modify your ~/.gitconfig file. | |
| # Create a new browser command and configure help -w to use it. | |
| git config --global browser.gitscm.cmd "/bin/sh -c 'open http://git-scm.com/docs/\$(basename \$1 .html)' --" |
| # coding: utf-8 | |
| # | |
| # Encode any codepoint outside the ASCII printable range to an HTML character | |
| # reference (http://bit.ly/KNupLT). | |
| def encode(string) | |
| string.each_codepoint.inject("") do |buffer, cp| | |
| cp = "&#x#{cp.to_s(16)};" unless cp >= 0x20 && cp <= 0x7E | |
| buffer << cp | |
| end | |
| end |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| desc "A user's comment" do | |
| let(:user) { User.create! name: "John" } | |
| let(:comment) { user.comments.create! } | |
| it "delegates to user's name" do | |
| comment.name.should eq(user.name) | |
| end | |
| end |
| def Maybe(obj) | |
| return Maybe.new(Nothing.new) if obj.nil? | |
| return Maybe.new(obj) | |
| end | |
| class Nothing | |
| def method_missing(*args, &block) | |
| self | |
| end |