Coder Social home page Coder Social logo

seeing_is_believing's Introduction

Build Status

Seeing Is Believing

Evaluates a file, recording the results of each line of code. You can then use this to display output values like Bret Victor does with JavaScript in his talk Inventing on Principle. Except, obviously, his is like a million times better.

Also comes with a binary to show how it might be used.

For whatever reason, I can't embed videos, but here's a video showing it off.

Works in Ruby 1.9 and 2.0

Use The Binary

$ cat simple_example.rb
5.times do |i|
  i * 2
end


$ seeing_is_believing simple_example.rb
5.times do |i|  # => 5
    i * 2       # => 0, 2, 4, 6, 8
end             # => 5

Use The Lib

require 'seeing_is_believing'
believer = SeeingIsBelieving.new("[:a, :b, :c].each do |i|
                                    i.upcase
                                  end")

result = believer.call # => #<SIB::Result @results={1=>#<SIB:Line["[:a, :b, :c]"] no exception>, 2=>#<SIB:Line[":A", ":B", ":C"] no exception>, 3=>#<SIB:Line["[:a, :b, :c]"] no exception>}\n  @stdout=""\n  @stderr=""\n  @exitstatus=0\n  @bug_in_sib=nil>

result[2]            # => #<SIB:Line[":A", ":B", ":C"] no exception>
result[2][0]         # => ":A"
result[2][1]         # => ":B"
result[2][2]         # => ":C"
result[2].join(", ") # => ":A, :B, :C"

result.stdout    # => ""
result.stderr    # => ""
result.exception # => nil

Install

Currently requires Ruby 1.9 or 2.0 I don't have specific plans to make it available on 1.8, but it could happen.

$ gem install seeing_is_believing

Editor Integration

Emacs Integration

Add this function to your Emacs configuration:

(defun seeing-is-believing ()
  "Replace the current region (or the whole buffer, if none) with the output
of seeing_is_believing."
  (interactive)
  (let ((beg (if (region-active-p) (region-beginning) (point-min)))
        (end (if (region-active-p) (region-end) (point-max))))
    (shell-command-on-region beg end "seeing_is_believing" nil 'replace)))

You can now call seeing-is-believing to replace the current region or current buffer contents with the output of running it through seeing_is_believing.

Known Issues

  • BEGIN/END breaks things and I probably won't ever fix it, becuase it's annoying and its really meant for command-line scripts... but there is currently a spec for it
  • exit! ignores callbacks that SeeingIsBelieving uses to communicate the results back to the main app. If you call it, SeeingIsBelieving will blow up. We could "fix" this by overriding it, but I feel like that would violate the meaning of exit!, so basically, just don't call that method.
  • The code to find the data segment is naive, and could wind up interpolating results into a string or something

Shit that will probably never get done (or if it does, won't be until after 2.0)

  • How about if begin/rescue/end was able to record the result on the rescue section
  • What about recording the result of a line inside of a string interpolation, e.g. "a#{\n1\n}b" could record line 2 is 1 and line 3 is "a\n1\nb"
  • Be able to clean an invalid file (used to be able to do this, but parser can't identify comments in an invalid file the way that I'm currently using it, cuke is still there, marked as @not-implemented)
  • If given a file with a unicode character, but not set unicode, inform the user

License

       DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                   Version 2, December 2004

Copyright (C) 2012 Josh Cheek <[email protected]>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

 0. You just DO WHAT THE FUCK YOU WANT TO.

seeing_is_believing's People

Contributors

coreyhaines avatar dougbradbury avatar jaywengrow avatar joshcheek avatar kunalbhatt avatar pd avatar pszals avatar rewinfrey avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.