how to embed runnable code snippets in a presentation

1,044 views
Skip to first unread message

Jabba Laci

unread,
Feb 2, 2014, 8:23:29 AM2/2/14
to golan...@googlegroups.com
Hi,

On YouTube I saw several presentations with embedded runnable Go code
snippets (e.g. http://www.youtube.com/watch?v=f6kdp27TYZs , see at
6:57). How to do it? Is it possible to do it with arbitrary languages?
I would be interested to do the same thing with Python too. I use
Linux.

Thanks,

Laszlo

Péter Szilágyi

unread,
Feb 3, 2014, 8:42:49 AM2/3/14
to Jabba Laci, golang-nuts
Hi,

  The Go presentations with embedded code are done using the Go present package [1]. It supports running code (i.e. playground) out of the box, but for Go only. Adding additional language support is quite easy, only about 10 lines of code, but you won't find help on this mailing list doing it :D (sorry, Gophers tend to stick to their toys :D). But if you'll search the mailing list archives, you'll find my post of about half a year ago with running Erlang inside Go present :P.

Cheers,
  Peter




--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jabba Laci

unread,
Feb 13, 2014, 11:34:09 AM2/13/14
to Péter Szilágyi, golang-nuts
On Mon, Feb 3, 2014 at 2:42 PM, Péter Szilágyi <pet...@gmail.com> wrote:
> Hi,
>
> The Go presentations with embedded code are done using the Go present
> package [1]. It supports running code (i.e. playground) out of the box, but
> for Go only. Adding additional language support is quite easy, only about 10
> lines of code, but you won't find help on this mailing list doing it :D
> (sorry, Gophers tend to stick to their toys :D). But if you'll search the
> mailing list archives, you'll find my post of about half a year ago with
> running Erlang inside Go present :P.
>
> Cheers,
> Peter
>
> [1] http://godoc.org/code.google.com/p/go.tools/present


Hi,

Thanks for the response. I'm using Go 1.1 and checked out `present`
today. It was hard to believe but `present` supports scripted
languages (the ones whose first line starts with a shebang) out of the
box! Awesome. It is implemented in the file
`code.google.com/p/go.tools/playground/socket/socket.go`. There is a
function called `shebang()` that checks the first line. However, I
found a bug in `shebang()`. The last line should be `return fs[0], fs`
instead of `return fs[0], fs[1:]`. (I reported the issue here:
http://code.google.com/p/go/issues/detail?id=7321).

Now, if you want to use Python code snippets, just write this in the
presentation (example):

* Hello Py
.play hello.py


Where the source of hello.py is:

#!/usr/bin/env python -u
# encoding: utf-8

from __future__ import print_function
from time import sleep

while True:
print("Hello, Py!")
sleep(1)

(The switch -u means unbuffered output. Without this you wouldn't see
any output while the `print` calls in the loop are buffered.)

Sorry for the Python post but I think there are lots of Pythonistas
who also use Go :) And thanks for the authors of `present` who thought
of script languages too.

Laszlo

kelle...@gmail.com

unread,
Jul 7, 2014, 2:21:17 PM7/7/14
to golan...@googlegroups.com, jabba...@gmail.com
Hi Peter,

thanks for your response. It seems you have a lot of experience using this tool. Are the slides sources from the fosdem 2014 available somewhere, so we could get a feeling...

Best regards

-- 
Eric

Dan Kortschak

unread,
Jul 8, 2014, 12:35:10 AM7/8/14
to kelle...@gmail.com, golan...@googlegroups.com, jabba...@gmail.com
There is a more recent batch of posts that show how to run compilable code (example was java), but python is trivial since shebanged code just runs. Have a look at this talk http://talks.golang.org/2013/go4python.slide
Reply all
Reply to author
Forward
0 new messages