This project transforms O'Reilly Atlas markup like this:
<pre data-executable="true" data-code-language="python"> import math for x in range(0, 1200, 30): l = 20 * math.sin(x/57.3) + 50 print " "*int(l/2) + "*"*int(l/2) </pre>
Into a browser plugin where you can run the code, like this:
import math for x in range(0, 1200, 30): l = 20 * math.sin(x/57.3) + 50 print " "*int(l/2) + "*"*int(l/2)
The plugin provides:
These will allow you to:
This project was hugely moved forward thanks to Geert Kapteijns awesome post Interactive Ruby in the browser for showing how to put JSREPL and JQ-CONSOLE together.
In addition to just running a program, some other use cases include:<pre data-executable="true" data-code-language="python"> def triangle(n): if n == 0: return [] elif n == 1: return [[1]] else: new_row = [1] result = triangle(n-1) last_row = result[-1] for i in range(len(last_row)-1): new_row.append(last_row[i] + last_row[i+1]) new_row += [1] result.append(new_row) return result def pascal(n): for row in triangle(n): print('{0:^120}'.format(row)) </pre>In this example, you hit "Run" and two functions get define. You can then run them on the console by typing
triangle(10)
to get back a python object, or do pascal(10)
to get a pretty printed version.
def triangle(n): if n == 0: return [] elif n == 1: return [[1]] else: new_row = [1] result = triangle(n-1) last_row = result[-1] for i in range(len(last_row)-1): new_row.append(last_row[i] + last_row[i+1]) new_row += [1] result.append(new_row) return result def pascal(n): for row in triangle(n): print('{0:^120}'.format(row))
<pre data-executable="true" data-code-language="python"> puts "Enter A" a = gets.chomp puts "Enter B" b = gets.chomp puts "The answer is " c = Integer(a) + Integer(b) puts c </pre>
puts "Enter A" a = gets.chomp puts "Enter B" b = gets.chomp puts "The answer is " c = Integer(a) + Integer(b) puts c