« Wordpress Pages and Babysitting Rikuto Rikuto Plays Peekaboo »
Nick Ramsay on August 23rd, 2008

I’ve installed WP-Syntax, a great plugin for Wordpress that lets you add code snippets to your blog posts without losing all the formatting.

You can use all manner of languages and even include line numbers if you want. Here’s a snippet from one of my math worksheet makers written in Perl:

5
use List::Util shuffle;    # Use the Shuffle module
166
167
168
169
170
171
# define and populate the arrays
my @girlsnames = ('Erin','Anna','Joanne','Sally', 'Mary');    
my @boysnames = ('Adam','Ken','Tom','Paul','David', 'Sam'); 
 
@girlsnames = shuffle @girlsnames;    # shuffle the girls' array
@boysnames = shuffle @boysnames;    # shuffle the boys' array
377
378
$name1 = pop(@boysnames);    # assign last name in array to $name1;
$name2 = pop(@girlsnames);    # assign last name in array to $name2;

If you liked this post, please submit it to JapanSoc, StumbleUpon, or Digg, and if you haven't already, please subscribe to my RSS feed. Thanks!

RSS feed | Trackback URI

9 Responses »

Trackback responses »

Comments on this post »

Comment by Mike Subscribed to comments via email
2008-08-24 00:20:44

I actually don’t really understand this post. :( What’s a code snippet? Can you show an actual example of what this code really does?

Comment by Nick Ramsay
2008-08-24 00:26:18

Stop pulling my leg, Mike. It’s quite obvious what a “code snippet” is, and I’ve commented the actual code so you know what it does. I’m not falling for your trickery! ;)

 
 
Comment by Mike Subscribed to comments via email
2008-08-24 00:30:31

What is this “code snippet” language thingy that you speak of?

Comment by Nick Ramsay
2008-08-24 00:38:18

A definition for you:

A segment of a document. Typically, a snippet is a set of contiguous text about the size of a paragraph and is about a single topic.

And another:

“Snippet” is a programming term for a small region of re-usable source code or text.

Comment by Mike Subscribed to comments via email
2008-08-24 05:47:32

Thanks for the definitions. :)

(Comments wont nest below this level)
 
 
 
Comment by Mum
2008-08-24 23:24:26

Love the photo, Nick. Rikuto looks so cute.I also like the diary updates. I can keep an eye on what you are doing. Ha ha!

Comment by Nick Ramsay
2008-08-24 23:32:34

You mean the Twitter updates? If you join Twitter.com, you can get those sent directly to your mobile phone! Then you’ll know exactly what I’m doing that very minute! ;)

 
 
Comment by Tori Subscribed to comments via email
2008-08-26 04:16:52

I’m a little confused…

What you are saying is this plugin displays code snippets as text in a post, right?
(Because normally any code would not show as text)
This would be useful for showing others a bit of code used for x purpose.

Or are you saying something else entirely?

Comment by Nick Ramsay
2008-08-26 09:20:47

That is exactly what I’m saying, Tori. I’m glad someone understood! :)

 
 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line=""> in your comment.