Presenting Your Code
-
Upload
moto -
Category
Technology
-
view
456 -
download
0
description
Transcript of Presenting Your Code
![Page 1: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/1.jpg)
Presenting Your CodeIan Dees
http://texagon.blogspot.com
Hi, I'm Ian Dees, a software developer for a test equipment manufacturer near Portland, Ore.
Today, we're going to talk about freeing your source code from your text editor and getting it into your presentations.
![Page 2: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/2.jpg)
TextMate
Smultron
http://www.macromates.com
http://smultron.sf.net
The basic ideas will work on any platform, but the screenshots we're looking at today will primarily be from two popular text editors for the Mac.
![Page 3: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/3.jpg)
Let's say we're trying our hand at the great Computer Language Shootout with Ackermann's Function. Here's what one solution looks like inside our text editor.
![Page 4: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/4.jpg)
def ackermann(m, n) $memo ||= {}
$memo[[m, n]] = $memo[[m, n]] ? $memo[[m, n]] : 0 == m ? n + 1 : 0 < m && 0 == n ? ackermann(m - 1, 1) : ackermann(m - 1, ackermann(m, n - 1))end
1.upto(8) {|n| puts ackermann(3, n)}
But if we do a Select All in our text editor and then copy and paste into our presentation, we lose all the pretty syntax highlighting.
![Page 5: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/5.jpg)
We could just take a screenshot from our text editor and paste it into the presentation as a graphic. But that makes for large file sizes and blurry font sizes. And if we distribute our slides as PDFs, readers won't be able to cut and paste our text.
Also, it's a pretty manual process.
![Page 6: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/6.jpg)
1 ! ackermann.rb ! 2007-09-03 23:11 ! Ian Dees
def ackermann(m, n) $memo ||= {}
$memo[[m, n]] = $memo[[m, n]] ? $memo[[m, n]] : 0 == m ? n + 1 : 0 < m && 0 == n ? ackermann(m - 1, 1) : ackermann(m - 1, ackermann(m, n - 1))end
1.upto(8) {|n| puts ackermann(3, n)}
If you're using Smultron as your editor, you can print to a PDF and then drag the PDF file into your slide--assuming your slides have a white background.
![Page 7: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/7.jpg)
But I prefer a bit more flexibility. Let's look at HTML for a potential solution. We could just submit our code to Pastie, and then cut/paste the result into our presentation.
![Page 8: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/8.jpg)
<span class="r">def</span><span class="fu">ackermann</span>(m, n)
.r { color:#080; font-weight:bold }
.fu { color:#06B; font-weight:bold }
And since Pastie's stylesheets are pretty simple, we could even tweak the colors before we put the code into our presentation.
![Page 9: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/9.jpg)
http://www.ruby-lang.org
But there's another way that doesn't require a round trip to the Pastie servers every time you want to highlight your code.
First, get Ruby.
![Page 10: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/10.jpg)
gem install syntax
Then, install the Syntax gem.
![Page 11: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/11.jpg)
http://pastie.caboo.se/95056
Finally, grab the Ruby source code from this file and save it to your hard drive somewhere.
![Page 12: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/12.jpg)
⌘B
Now, you can configure your text editor to run the script. In Smultron, hit Cmd-B to bring up the Commands window. Create a new command, bind it to a keystroke if you like, and fill in its contents like this. You'll want to substitute the paths to where you keep your Ruby interpreter and where you saved the script, of course.
![Page 13: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/13.jpg)
Now, whenever you hit your chosen hotkey, Smultron generates the HTML and (if you've enabled it in the script) launches your browser for easy cutting and pasting.
![Page 14: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/14.jpg)
⌘⌥R
The process is similar in TextMate. Just hit Cmd-Option-R to bring up the Filter Through Command dialog, browse to where you saved the script, and select Show as HTML.
![Page 15: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/15.jpg)
When you press Execute, TextMate brings up a new window with highlighted code that remembers its colors...
![Page 16: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/16.jpg)
def ackermann(m, n) $memo ||= {}
$memo[[m, n]] = $memo[[m, n]] ? $memo[[m, n]] : 0 == m ? n + 1 : 0 < m && 0 == n ? ackermann(m - 1, 1) : ackermann(m - 1, ackermann(m, n - 1))end
1.upto(8) {|n| puts ackermann(3, n)}
...when you paste it into a slide, like this.
![Page 17: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/17.jpg)
def ackermann(m, n) $memo ||= {}
$memo[[m, n]] = $memo[[m, n]] ? $memo[[m, n]] : 0 == m ? n + 1 : 0 < m && 0 == n ? ackermann(m - 1, 1) : ackermann(m - 1, ackermann(m, n - 1))end
1.upto(8) {|n| puts ackermann(3, n)}
There will be a few minor differences, of course. Punctuation, class names, and constants might be colored a little differently between your text editor and the resulting HTML. But with a little tweaking, you can get pretty darn close.
![Page 18: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/18.jpg)
⌘⌃R
And in the specific case of TextMate, you can do even better than just "pretty darn close." Run the "TextMate >> Create HTML From Document" command, which is bound to Cmd-Ctrl-R (as opposed to Cmd-Opt-R) on my system. By default, that brings up the raw HTML tags in a new window, but you can configure TextMate to actually render the HTML instead.
![Page 19: Presenting Your Code](https://reader036.fdocuments.in/reader036/viewer/2022070303/54b869794a795970478b490c/html5/thumbnails/19.jpg)
Presenting Your CodeIan Dees
http://texagon.blogspot.com
And that's it. Thanks for your time.