Ask Your Question

Revision history [back]

One simple approach is to hide the code editor of the interact as described here to make the solution less obvious, but the code will still be in the page source.

A better way is to use the base64-encoding capabilities of the cell server. The permalink option of the "share" button produces a URL with the Sage code properly encoded. This GitHub gist describes a way to extract the original code from the encoded URL, which can then be displayed with eval().

The Python code in the gist doesn't ensure that the base64-string is a multiple of four, so you'll need to add =s as padding when needed. As an example, the permalink URL for plot(sin) is

http://sagecell.sagemath.org/?z=eJwryMkv0SjOzNMEABHuA1s=&lang=sage

The gist code splits the URL at = which is not quite right. If you just copy the z= portion of the URL up to the &, then you can display the plot in a SageCell using

eval( decompress(decode('eJwryMkv0SjOzNMEABHuA1s=')) )

You can also take the gist code as a starting point and directly encode and decode your original Sage code yourself.

One simple approach is to hide the code editor of the interact as described here to make the solution less obvious, but the code will still be in the page source.

A better way is to use the base64-encoding capabilities of the cell server. The permalink option of the "share" button produces a URL with the Sage code properly encoded. This GitHub gist describes a way to extract the original code from the encoded URL, which can then be displayed with eval().

The Python code in the gist doesn't ensure that the base64-string is a multiple of four, so you'll need to add =s as padding when needed. As an example, the permalink URL for plot(sin) is

http://sagecell.sagemath.org/?z=eJwryMkv0SjOzNMEABHuA1s=&lang=sage

The gist code splits the URL at = which is not quite right. If you just copy the z= portion of the URL up to the &, then you can display the plot in a SageCell using

from base64 import urlsafe_b64decode as decode  
from zlib import decompress
eval( decompress(decode('eJwryMkv0SjOzNMEABHuA1s=')) )

You can also take the gist code as a starting point and directly encode and decode your original Sage code yourself.

One simple approach is to hide the code editor of the interact as described here to make the solution less obvious, but the code will still be in the page source.

A better way is to use the base64-encoding capabilities of the cell server. The permalink option of the "share" button produces a URL with the Sage code properly encoded. This GitHub gist describes a way to extract the original code from the encoded URL, which can then be displayed with eval() or exec().

The Python code in the gist doesn't ensure that the base64-string is a multiple of four, so you'll need to add =s as padding when needed. As an example, the permalink URL for plot(sin) is

http://sagecell.sagemath.org/?z=eJwryMkv0SjOzNMEABHuA1s=&lang=sage

The gist code splits the URL at = which is not quite right. If you just copy the z= portion of the URL up to the &, then you can display the plot in a SageCell using

from base64 import urlsafe_b64decode as decode  
from zlib import decompress
eval( decompress(decode('eJwryMkv0SjOzNMEABHuA1s=')) )

For multiline Python code, use exec() instead of eval(). You may also need an explicit show() for output you want to display, but you generally need that inside an interact on the cell server already.

You can also take the gist code as a starting point and directly encode and decode your original Sage code yourself.