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.
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
If you use Wordpress, simply install the plugin. Otherwise:
<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>
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>
to your website folder (and edit run_this.js accordingly)
Get in touch : runthis.plugin(o)gmail.com
Run This uses Ideone API © by Sphere Research Labs