Tuesday, 16 August 2011

Fluid google template

I'm using the Picture Window template but wanted a fluid (stretchy) design so that folk with wide screens don't need to see my lines of computer program wrapped in a terribly hard to read fashion.

I was able to find notes on adapting this template with custom CSS.

body {
padding-left: 50px;
padding-right: 50px;
}

html body .content-outer {
max-width: 1600px;
}


which does the trick nicely

pdf and zip in google blogger

Google blogger allows only .png, .jpeg and .gif files to be uploaded as part of a blog post.

As my blog is somewhat technical, I want to be able to offer a zip file from time to time, containing sources I mention.

A first thought would be to rename the .zip to .png and tell the user to rename it after download, but even better is to have a chimera file which is both a .zip and a .png at the same time! The png could display the instruction to rename the file to .zip

I can then upload this .png file to google blogger which will display telling folk to download and rename to .zip

I've done this for a pdf in my blog post here where the thumbnail png brings up a large-png. If the large-png is saved to disk and renamed to .pdf, the pdf from which the thumbnail was taken is displayed.

This works because .png and .gif files have their magic at the beginning of the file, and .zip files and .pdf files have their magic at the end of the file. (The magic is the part of the file that is first read by the file viewer to work out how to treat the file).

Thus there is no deception. The chimera file is truly a .png file, and is truly a .zip file.

This example file here contains the instructions:
(right-click and save link/target as .zip not .png)
Be careful to save the link-target (the original and full sized image) and not the thumbnail.

Importing a threaded MBOX into google blogger

My first blog used wordpress. I worked out some script to export the wordpress database as a threaded-mbox and for a while ran my blog as a web interface to a citadel imap folder.

Circumstances moved me to google blogger and I didn't want to lose my old posts or comments.

So I wrote a sed script to convert a threaded mbox into google blogger format.

it's pretty complete. If you want to know how it words, just read ths source, man!

#! /usr/bin/sed -f

/^Content-[Tt]ype: /{
  # keep reading till new From
  :-body
  N
  /\nFrom - /!b-body
}

/^Content-[tT]ype: multipart\/alternative/{
  # Are we a comment (convert to text) or a post
  x;/\n *<category.*#comment.*>/!{x;b-get-html};x

  :-get-text
  /\nContent-Transfer-Encoding: quoted-printable/{
    s/=0D=0A/\n/g
    s/=20/ /g
    s/=\n//g
    s/=3D/=/g
  }

  s/^.*\nContent-type: text\/plain/Content-Type: text\/plain/i
  :-chop
  /^\n/b-chopped
  s/^[^\n]*\n//;
  b-chop
  :-chopped
  s/\n--[^\n]*\nContent-type.*//i
  s/^\n\n*//

  s/^/  <content type="html">\n/i;
  s/$/\n  <\/content>/i;

  H

  s/^.*/From - /

  :-get-html
  x
  s|$|\n  <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/blogger/2008/kind#post'/>|
  x

  /\nContent-Transfer-Encoding: quoted-printable/{
    s/=0D=0A/\n/g
    s/=20/ /g
    s/=\n//g
    s/=3D/=/g
  }

  s/^.*\nContent-type: text\/html/Content-Type: text\/html/i
  s/\n--[^\n]*\nContent-type.*//i

  :-got
}

/^Content-[tT]ype: text\/html/{
  # try to save the <title> instead of the subject line
  /<title>/{
    x
    s/$/\n/
    G
    s/\n\n.*<title>\([^<]*\)<\/title>.*/\n  <title>\1<\/title>/i
    # rid of the old title
    s/ *<title>[^<]*<\/title>\n//
    x
  }

  s/^.*\?<body\b[^>]*>[\n ]*//i
  s/[\n ]*<\/body>.*//i

  # Are we a comment (convert to text) or a post
  x;/\n *<category.*#comment.*>/!{x;b-convert-html};x

  :-convert-text
  s/<br\b[^>]*>/\n/gi
  s/<p\b>/\n/gi
  s/<[^>]*>//g
  s/&\#8320;/…/g
  s/^\n\n*//
  s/\n\n*/\n/g
  b-quote

  :-convert-html
  x
  s|$|\n  <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/blogger/2008/kind#post'/>|
  x

  :-quote
  s/&/\&amp;/g; s/"/\&quot;/g; s/</\&lt;/g; s/>/\&gt;/g

  s/^/  <content type="html">\n/i;
  s/$/\n  <\/content>/i;

  H

  s/^.*/From - /
}

/^From - /{
  s/.*//
  1!{
    s/$/<\/entry>\n/
    H
    x
    p
    x
  }
  s/.*/<entry>/
  h
  d
}

/^Message-ID:/{
  s/^[^:]*:[[:space:]]*<\?//
  s/>\?$//
  s/#/_/g
  s/&/\&amp;/g; s/"/\&quot;/g; s/</\&lt;/g; s/>/\&gt;/g
  s/^/  <id>/
  s/$/<\/id>/
  H
  d
}

/^References:/{
  s/^[^:]*:[[:space:]]*<\?//
  s/>.*$//
  s/&/\&amp;/g; s/"/\&quot;/g; s/</\&lt;/g; s/>/\&gt;/g
  s/^/  <thr:in-reply-to ref="/
  s/$/" type="text\/html"\/>/
  s|$|\n  <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/blogger/2008/kind#comment'/>|
  H
  d
}

/^Subject:/{
  s/^[^:]*:[[:space:]]*//
  s/&/\&amp;/g; s/"/\&quot;/g; s/</\&lt;/g; s/>/\&gt;/g
  s/^/  <title>/
  s/$/<\/title>/
  H
  d
}

/^From:/{
  s/^[^:]*:[[:space:]]*//
  s/^"*//
  s/".*//
  s/&/\&amp;/g; s/"/\&quot;/g; s/</\&lt;/g; s/>/\&gt;/g
  s/^/  <author><name>/
  s/$/<\/name><\/author>/
  H
  d
}

/^Date:/{
  s/^[^:]*:[[:space:]]*<\?//
  s/\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\(...\)\(..\).*/\4-\3-\2T\5.000\6:\7/
  s/Dec/12/i
  s/Nov/11/i
  s/Oct/10/i
  s/Sep/09/i
  s/Aug/08/i
  s/Jul/07/i
  s/Jun/06/i
  s/May/05/i
  s/Apr/04/i
  s/Mar/03/i
  s/Feb/02/i
  s/Jan/01/i
  s/&/\&amp;/g; s/"/\&quot;/g; s/</\&lt;/g; s/>/\&gt;/g
  s/^/  <published>/
  s/$/<\/published>/
  H
  s/published/updated/g
  H
  d
}

${
#  a</content></entry></feed>
}


The hard part is that google will sometimes drop posts or comments without explaining why (even after claiming to have imported 20 comments it may be that only 17 are available after import) so it took a lot of trail and error.

On comment seemed to be dropped because it contained this text:

13. Use with the GNU Affero General Public License.

And to prove it, I was able to post that a s a comment to a google blog, but if I exported and imported the blog the comment would be dropped.

Thursday, 4 August 2011

Fast and Quiet - new heatsink

My computer is faster with a new heatsink.

3 of the fixing brackets on the old one had snapped and the computer would shutdown from overheating before it booted. It must have also been thermal-trottling before because now it is 2-3 times faster and SILENT instead of a noisy wind tunnel.

Anne bought this Zalman heat sink from CCL online after an online vendor failed to ship the official HP part after a week.



Socket LGA1366, LGA1156, 478, LGA775, AM3, AM2+, AM2, 754, 939, 940 compatible, Mfg Code: CNPS10X-Performa

Wednesday, 20 July 2011

Vanish decades of newbie make pain

I've just cured years of makefile hell with this single line:

   SHELL:=bash -c 'exec $(SHELL) "$${@//\\$$'\''\012'\''/$$'\''\012'\''}"' --

It means that make recipes that use \ at the end of a line for multi-line recipes will now have the \ stripped off - at last you can have PROPER multi-line recipes!!!


Previously, if you had normal looking multi-line shell clauses in your make recipe, you had to do something like this:

    if blah ; \
    then update-file ; \
    else create-file ; \
    fi


Which is a bit of a hack, and is actually treated as a single line shell statement with semi-colons.

And that is fair enough unless you have a multi-line sed statement as part of your recipe - which is easy to do by accident if you are using literate programming (http://new.fangled.org) with auto-syntax-quoting as one chunk is included into another. (Auto-syntax quoting is when your shell chunk included in a makefile has the $ converted to $$ automatically [something the banking industry has been doing for years])

Because make will start a new shell command every time it finds a newline in the command string (even if you hide it in a mid-line shell variable) there is no way that a backslash-newline can occur except when the human deliberately escapes it.

The single-line SHELL re-definition of mine uses bash to replace backslash-newline with newline and then passes the command to your regular shell.

And I get extra points for using exec


Now my literate programming tools can automatically and nestedly invoke sed in a bash context and then that bash in a make context with automatic quoting and have it all work nicely!

(As long as the makefile author inserts that sticking plaster at the top of the makefile)

And the newbie who uses this can use backslash-newline in a makefile in the proper intuitive way.

    if blah \
    then update-file \
    else create-file \
    fi


Thursday, 30 June 2011

How to draw a Union Jack

The flag of the United Kingdom, the Union Jack, is a superposition of the flags of Saint George (for England), Saint Andrew (for Scotland) and Saint Patrick (for Ireland). This superposition is quite intricate, and often drawn incorrectly.

J. D. A. Wiseman shows how it is done.

Friday, 10 June 2011

Big brother's cousin over the seas

..Binney believes that the agency now stores copies of all e-mails transmitted in America... the N.S.A. has built enormous electronic-storage facilities in Texas and Utah. Binney says that an N.S.A. e-mail database can be searched ... in the manner of Google. ... “General Hayden reassured everyone that the N.S.A. didn’t put out dragnets, and that was true. It had no need—it was getting every fish in the sea.”
The lesson? Beware when those in authority speak in metaphors.

To me the "dictionary selection after the manner of google" is a dragnet, and to most people it's the sort of thing they were worried about, so when an authority denies a specific behaviour by means of a metaphor, try to see what is being hidden and thus perhaps admitted to.

Drake, a former senior executive at the National Security Agency, faces some of the gravest charges that can be brought against an American citizen.