I moved my blog to this address : http://damien.krotkine.com
I moved my blog to this address : http://damien.krotkine.com
I haven't been blogging a lot this year-and-half, and for various reasons. But the reason number one is that I've been very busy writing a Perl book from scratch, in French, with 3 other fellow French Perl Mongers.
The book is called Perl Moderne. That means "Modern Perl", but it has nothing to do with chromatic's book. The book was actually published long time ago, end October 2010. But it took us authors some time to recover :)
This book is written in French, for French speaking readers. Its goal is to present the Perl 5 language as it exists now, and tries to teach the reader how to start using it the right way, that is, the modern way. The book is not a bible, nor an encyclopedia of the historical language. Instead, it's a collection of the useful concepts that are used nowadays, and how to use them in the latest version of Perl and CPAN.
The reader can be a total newbie in Perl, but it has to have a previous development experience with an other language, for instance PHP, Ruby, Python, or Java. However, the book goes far beyond introducing the language. It allows the reader to become fluent with the Perl data structure, regexps, Moose OO and typing, POE, interacting with databases, files, DateTime, XML and configuration files, Web interactions, and more...
It's big in content (many subjects covered, and 450 pages !) but small in size, as it's an A5 format, so it fits easily in a bag, and it's not heavy :)
Historically, Pearson France, the press editor, posted a request on the French Perl Mongers mailing list, saying that they were looking for authors willing to write a new Perl Book in French.
I decided to not let this opportunity pass : it's very rare that French editors are interested by Perl, and willing to produce good quality books. After some struggling, I ended up setting up a team of 4 brave French Perl Mongers, that became 4 Perl book authors :
Sébastien Aperghis-Tramoni (SAPER on CPAN) : active French Perl Monger, he knows almost everything about CPAN modules. He wrote several modules himself, and maintains numerous others. He wrote several Perl articles in the GNU/Linux Magazine France. He is also the hidden admin of your Perl conferences, as he maintains Act, empowering a lot of Perl conferences
Philippe Bruhat (BOOK on CPAN) : well known Perl figure, active French Perl Monger, former president of them, founder and treasurer of the YAPC Europe Foundation. Received a White Camel Award in 2009, and maintains quite a few modules on CPAN. Also wrote articles in the GNU/Linux Magazine France.
Jérôme Quelin (JQUELIN on CPAN) : active French Perl Monger, knows a great deal about Tk, wrote Games::Risk among other things, and maintains a bunch of CPAN modules. He is also maintaining a lot of Perl packages at Mandriva and Mageia. Also wrote articles in the GNU/Linux Magazine France.
Damien Krotkine (DAMS on CPAN) : well that's me ! I'm an active French Perl Monger, using Perl for 11 years or so, I wrote a couple of Perl articles in the GNU/Linux Magazine France, have some modules on CPAN (among them Curses::Toolkit), and I'm now a proud core developer of Dancer, the new big thing.
Perl Moderne starts with a gentle (but concise) introduction to Perl, with many pointers to external resources, focusing on ease-of-use. For instance, we mention CPAN and cpanm very early. Then the real business starts with an explanation of the major programming concepts (data structures, OO, databases, formats, event programming and the intarweb).
We tried to provide a preferred way to do each thing, while mentioning alternatives. We didn't separated the language and CPAN. "Perl is the syntax, CPAN is the language"... So about half of the book describes how to solve a problem using this or that CPAN module. And I think it's great. It allowed us to teach Object Oriented programming with Moose, explain event programming with POE, etc.
I think it is very important that new Perl books get written, and very important that some are written natively in non-english. It fits better its purpose to the localized need (students, teachers, academic structures and way of thinking are different from one country to another). That also makes editors aware of the local Perl activity, and help spreads the words about the language in schools and universities, where native books are preferred to translations.
So, if you know any French speaking (or learning) geek or computer scientist, around you, please consider recommending them this book. It was crafted with care and love by Perl passionated ! :) You can point them to the dedicated website of Perl Moderne
Here is an english translation of the table of content :
01. Start with Perl
02. Install a Perl module
I. Language and data structures
03. Language
04. Data structures
05. Regular expressions
II. Modern object programming
06. Basic Perl objects
07. Moose
08. Typing system in Moose
09. Methods in Moose
III. Data manipulation
10. Files and directories
11. SQL databases
12. SQL abstraction, ORM, non-SQL databases
13. Dates and times
IV. Formats
14. XML
15. Data serialisation
16. Configuration files
V. Event programming
17. Introduction to POE
18. Practical POE
19. Distributed POE
VI. Web
20. HTML documents parsing
21. HTTP and the Web
22. LWP
23. Web browsing
24. WWW::Mechanize
Are you curious to see how to create a real app from scratch with Perl Dancer, using DBIX::Class ? Well, my Perl Dancer Advent Calendar article has been published saturday :
http://advent.perldancer.org/2010/11
Enjoy !
Disqus is great. It's a full featured cross-site comments free management system. I have an account on it, so I wanted to use disqus instead of the typepad comments system.
"Easy enough" I said to myself : there is a dedicated page to help you install Disqus in Typepad. This includes adding a new "Embed your own HTML" module in your blog content, and copy-pasting a Javacript snippet in it.
Alas, the Javascript snippet didn't work fine. I suspect that the Typepad code has changed since the Disqus install documentation has been written. Maybe the Javascript code of Typepad tries to block other scripts playing with the comment tags.
Anyway, here is a solution : I changed the code a bit, and wrapped it in an Javascript onload . I'm not saying it's the best solution, but it works for me... Here is the Javascript code snippet to be used instead of the one Disqus provides in the Typepad Install section. Of course, replace YOUR_DISQUS_LOGIN with, well, your disqus login...
<script type="text/javascript">
var my_func = function() {
var div = document.getElementById('all-comments');
var script = document.createElement('script');
script.type = 'text/javascript'; script.src = 'http://disqus.com/forums/YOUR_DISQUS_LOGIN/embed.js';
document.getElementsByTagName('body')[0].appendChild(script);
div.innerHTML = '' ;
div.id = 'disqus_thread';
};
var x = window.onload;
window.onload = function() {my_func(); if (x) x(); }
</script>
Let me know if it works for your Typepad blog.
Today Idiscovered an easy way to merge PDFs files using Perl.
In my current project, I have to automatically generate a technical documentation from my perl modules PODs. It's easy to create one PDF file for each modules, but then I need to merge them all in one.
The very easy to use CAM::PDF Perl module provides appendpdf.pl. However it can only merge 2 files together.
I've copied and modified it for my need, and renamed it mergepdf.pl
Download : mergepdf.pl
Usage : appendpdf.pl [options] file1.pdf file2.pdf ... fileN.pdf outfile.pdf
See the help for more options.
First of all, the needs :
The solution is of course SyntaxHighlighter, the well known tool by Alex Gorbatchev. This tool is used widely and some people have already written on including it in Movable Type, or even in Typepad.
But I thought I would write on it as well, because there are some subtleties, and both SyntaxHighlighter and Typepad evolved since these entries were created.
So, if you don't know this too yet, or are too lazy to check its description page, SyntaxHighlighter is a pure JavaScript + CSS tool that finds and renders content, from a specific standard HTML tag you specify.
# Some Perl code
my $var = 42;
my @array = map { reverse }
grep { length }
@strings;
sub my_function {
my ($a, $b) = @_;
return ($a * $b);
}
First of all, you don't want to download SyntaxHighlighter from it "official" google code home, because it's hosted by Google (sorry, just kidding) because only the version 1.5 is available there. What we want is version 2.0, which has more features, and includes a Perl syntax brush by default (so no need to get it from elsewhere).
Download SyntaxHighlighter from this page. I downloaded version 2.1.364 (local copy here in case the site is down)
Then create a directory (I created mine as syntaxhighlighter at the root), and upload the following files. This list is the bare minimum to have it working, but you can (you should) add more brushes to support more languages highlighting, and also upload the icons (the .png files). You could as well upload all the languages brushes. And you can also use a different theme (I'll try the Emacs one, as I'm an Emacs addict).
Make sure your upload works by trying to access one of the file (of course replace your real site host name) :
http://YOURSITE.COM/syntaxhighlighter/shCore.js
If you can see or download the file, it means the files are properly uploaded.
For SyntaxHighlighter to work, you need to include some Javascript and CSS to the pages that will contain things you want to highlight. The best is to include it on every pages, as the tool is smart enough to find and apply styling only on what you specify to be highlighted.
Now, how do you add CSS and Javascript to your TypePad blog? There are two cases :
All blog entries I've seen on this topic only handles the case of advanced design, because it's easier to do. But, people using advanced design don't need a tutorial to include SyntaxHighlighter on their blog, they are, you know, advanced enough to do it on their own... So I thought it would be more useful to describe how to do with a simple design.
With a simple design on TypePad, you don't have access to the templates of the pages, but luckily, you can add a module that allows you to add any HTML code in your page. So the idea is to this module to your design content, and add the needed javascript and CSS reference to it. Here is how you can do it.
The content of the module will be used to load SyntaxHighlighter. Here is what I input in the module :
<!-- Include required JS files -->
<script type="text/javascript" src="http://YOURSITE.com
/syntaxhighlighter/shCore.js"></script>
<!-- At least one brush, here we choose Perl.-->
<!-- You need to include a brush for every language you want to highlight -->
<script type="text/javascript" src="http://YOURSITE.com
/syntaxhighlighter/shBrushPerl.js"></script>
<!-- Include *at least* the core style and default theme -->
<!-- You can choose a different theme -->
<link href="http://YOURSITE.com/syntaxhighlighter/shCore.css" rel="stylesheet" type="text/css" />
<link href="http://YOURSITE.com/syntaxhighlighter/shThemeDefault.css" rel="stylesheet" type="text/css" />
<!-- Important options, and finally the main call -->
<script type="text/javascript">
SyntaxHighlighter.config.tagName = "code" // use <code> tags
SyntaxHighlighter.config.stripBrs = true // disregard trailing <br>
SyntaxHighlighter.all()
</script>
As you can see, there are 2 options set at the end. These options are to make SyntaxHighlighter more compatible with the TypePad graphical editor. By default, SyntaxHighlighter looks for <pre> tags. But these are rebuilt each time you modify an entry in the graphical editor. So one of the option is to be able to use <code> tags, that are left untouched by TypePad. Well, almost untouched, TypePad tends to add <br> tags at the end of line, which is why the seconde option is there.
Now that everything is setup, all there is to do to have a nice code example into TypePad is to create a new Post, write the text using the "Rich Text" view of the editor. Then when you want to include a code snippet, switch to the "HTML" view, and add this :
<code class="brush: perl"><br>
# Your code example goes here. For instance, some Perl :<br>
my %hash = { foo => 'bar' };<br>
</code>
Which will output on your blog page as :
# Your code example goes here. For instance, some Perl :
my %hash = { foo => 'bar' };
And inside the TypePad graphical editor, this is what you will see. Most of the Atom / RSS feeds client (like Google Reader) will also have it like this :
Which is in my opinion, not too bad !
So here it is : a nice, free and open source syntax highlighter in your TypePad posts, easily included, wich themes, colors, a lot of languages supported, and which degrades nicely for feeds readers. There is more customization possible, I suggest you go look at the SyntaxHighlighter documentation.
I have tried to make this post / tutorial as easy as I possible, but please let me know if you think I should clear ups things, or add more screenshots. If you try to do it on your TypePad account and it works, let me know in the comment. If it doesn't work, I'll try to help.
Recent Comments