Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Friday, August 1, 2008

Code is Poetry








On a recent visit to the Wordpress sight I was struck by their tag line "Code is poetry". I have been searching for some time for a phrase that would sum up how I feel about well crafted code; code that is easy to understand, read and generally feels 'just right'.


I am not completely convinced that code is poetry - but it comes pretty close.




Sunday, April 27, 2008

Blogging Code



Blogging Code


I quite often find myself blogging about program source code, that code is typically stored in source files which I then run through a pretty printer (something like source-highlight). Combining everyting together means some copy and pasting - not the most repeatable process and quite often the code and article evolve together - so I end up copying and pasting quite often.


So I came up with mashup. A small ruby program to process html files and handle include directives to do inline include of another file and for this purpose the results of a process


The following source was include with



<x:include value="source-highlight -o STDOUT ~/projects/mashup/mashup"/>

By running:



mashup blogging-code.html > blogging-code-publish.html


#!/usr/bin/ruby

ARGV.each do |arg|
contents = File.new(arg).read()

contents.sub!(/<s:include\s+value="([^"]*)"\s*\/>/) do |match|
replacement = File.new($1).read()
replacement.gsub!(/.*<body>/m, '')
replacement.gsub!(/<\/body>.*/m, '')
replacement
end

contents.sub!(/<x:include\s+value="([^"]*)"\s*\/>/) do |match|
replacement = `#{$1}`
replacement.gsub!(/.*<body>/m, '')
replacement.gsub!(/<\/body>.*/m, '')
replacement
end

puts contents
end