Run This: seeing is believing!

Add a button to let your readers run snippets of code directly from your blog and see the results interactively.

Right now, supported languages are:
Ada, Assembler, AWK, Bash, bc, Brainf**k, C, C#, C++, CLIPS, Clojure, COBOL, Common Lisp, D, Erlang, Factor, Forth, Fortran, Go, Groovy, Haskell, Icon, Intercal, Java, JavaScript, Lua, Nemerle, Nice, Nimrod, Ocaml, Oz, Pascal, Perl, PHP, Pike, Prolog, Python, Python3, R, Ruby, Scala, Scheme, Smalltalk, Tcl, Unlambda, Visual Basic, Whitespace.

Demos

Python example

print [x*x for x in range(0,9)]

C example

#include <stdio.h>

int main (int argc, char** argv) {
  printf("Hello, World!");
  return 0;
}

Lua example

function add(n, acc)
  acc = acc or 0
  if n == 0 then
    return acc
  end
  return add(n-1, 1+acc)
end

print(add(1000000))

Scheme example

(define dx .0001)
    (define (deriv f)
       (define (f-prime x)
         (/ (- (f (+ x dx)) (f x))
            dx))
       f-prime)

(define (square x) (* x x))

(define square-deriv (deriv square)) ;; x -> 2*x

(display (square-deriv 7))

Haskell example

fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

main = print $ fibs !! 10

Haskell example with input

import System.IO

quicksort []     = []
quicksort (x:xs) = quicksort [y | y <- xs, y < x] ++ [x] ++ quicksort [y | y <- xs, y >= x]

main = print . quicksort =<< getLine

Factor example

USING: io sequences unicode.case ;
{ "tomato" "orange" "banana" } [ >upper print ] each

How do I use it ?

If you use Wordpress, simply install the plugin. Otherwise:

  1. Download run_this.zip and unzip it into your blog folder structure
  2. Add the following to your HTML (make sure the paths are correct):
    <link rel="stylesheet" type="text/css" href="run_this/run_this.css" />
    <script type="text/javascript" src="run_this/jquery-1.3.2.js"></script>
    <script type="text/javascript" src="run_this/flensed/deploy/flXHR.js"></script>
    <script type="text/javascript" src="run_this/run_this.js"></script>
    
  3. Finally, add a "run-this" class and a lang attribute (ada, assembler, awk, bash, bc, brainf**k, c, c#, cpp, c99, clips, clojure, cobol, clisp, d, erlang, factor, forth, fortran, go, groovy, haskell, icon, intercal, java, rhino, javascript, lua, nemerle, nice, nimrod, ocaml, oz, pascal, perl, php, pike, prolog, python, python3, r, ruby, scala, scheme, smalltalk, tcl, unlambda, vbasic, whitespace) to the snippets you want to execute:

    <pre lang="python" class="run-this">
    def double(n):
      return 2*n
    </pre>
    
  4. save to your website folder (and edit run_this.js accordingly)
  5. (optional) change the CSS file to suit your taste

Get in touch : runthis.plugin(o)gmail.com

Run This uses Ideone API © by Sphere Research Labs