Evolving notes, images and sounds by Luis Apiolaza

Category: meta (Page 6 of 6)

On R, bloggers, politics, sex, alcohol and rock & roll

Yesterday morning at 7 am I was outside walking the dog before getting a taxi to go to the airport to catch a plane to travel from Christchurch to Blenheim (now I can breath after reading without a pause). It was raining cats and dogs while I was walking doggyo, thinking of a post idea for Quantum Forest; something that I could work on without a computer. Then I remembered that I told Tal Galili that I would ‘mention r-bloggers’ in a future post. Well, Tal, this is it.

Continue reading

A shoebox for data analysis

Recidivism. That’s my situation concerning this posting flotsam in/on/to the ether. I’ve tried before and, often, will change priorities after a few posts; I rationalize this process thinking that I’m cured and have moved on to real life.

This time may not be different but, simultaneously, it will be more focused: just a shoebox for the little pieces of code or ideas that I use when running analyses.

Publon: my simple publication Python script

After using PmWiki (PHP wiki software) for nearly five years to maintain my web site I was a bit tired of fiddling with it. I then rolled out the following very simple and crummy Python script. Besides a basic Python distribution it only requires Python Markdown and Pygments.

There are no external templates or any other niceties–although it deals with unicode–but it just works.

# coding: utf-8

import codecs, getopt, markdown, os, os.path, sys 

# Some important constants
base_path = '/Users/luis/Dropbox/website/'
site_path = 'http://apiolaza.net/'

# Basic inside-code template, making
# script self-contained
def inline_template():
    template = u'''
    <!DOCTYPE html>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name='author' content='Luis A. Apiolaza' />
        <meta name='keywords' content='<!--tags-->' />
        <link rel='stylesheet' href='http://apiolaza.net/css/mANDo.css' type='text/css' />
        <link rel='stylesheet' href='http://apiolaza.net/css/pygments.css' type='text/css' />
        <div id='container'>
            <div id='page-header'>
            <h1><a href='http://apiolaza.net/'>Sketchbook</a></h1>
                <div id='page-menu'>
                <li><a href='http://apiolaza.net/ego-sum.html' title='Ego sum qui sum'>about</a></li>
                <li><a href='http://apiolaza.net/asreml-r/' title='asreml-r cookbook'>asreml-r</a></li>
                <li><a href='http://quantumforest.com/' title='Quantum Forest blog'>blog</a></li>
                <li><a href='http://apiolaza.net/code/' title='software'>code</a></li>
                <li><a href='http://apiolaza.net/colophon.html' title='Gory technical details'>colophon</a></li>
                <li><a href='http://apiolaza.net/publications.html'>publications</a></li>
                <li><a href='http://apiolaza.net/writings/'>writings</a></li>
            <div id='page-meta'>
                <p>This page was updated on <!--date--> (NZST) and is tagged 
            <div id='page-body'>
            <div id='footer'>
                <p>All bits sowed, harvested and baked in Christchurch, New 
                Zealand—43º31'S, 172º32'E—by <a href='http://apiolaza.net'>Luis 
                Apiolaza</a> with 
                <a href='http://creativecommons.org/licenses/by-nc-sa/3.0/nz/'>some rights reserved</a>.
                A longer blurb and gory technical details can be found in the 
                <a href='http://apiolaza.net/colophon.html'>colophon</a>.</p>

# In case of using external template file
def read_template(filename = 'page-template.html'):
        f = codecs.open(filename, mode = 'r', encoding = 'utf-8')
    except IOError:
        print 'Template file not found'
    text = f.read()

# Obtains body and meta values from single page
def process_page(text):
    # Instance of class Markdown with two extensions
    md = markdown.Markdown(extensions = ['meta', 'codehilite', 'footnotes'])
    body = md.convert(text)
    meta = md.Meta
    return([body, meta])

# Combines body, meta information and template
def build_page(body, meta, template):    
    for key in meta.keys():
        lookfor = '<!--' + key + '-->'
        template = template.replace(lookfor, meta[key][0])

    template = template.replace('<!--body-->', body)

# Creates location bar
def location(filename, base_path, site_path):
    full_name = os.path.abspath(filename)
    base_length = len(base_path)
    nav = u'<p>Document tree: <a href="' + site_path + u'">home</a>'

    if full_name.find(base_path) >=0:
        rel_path = full_name[base_length:-5] + 'html'
        rel_path_parts = rel_path.rsplit('/')
        print 'File is not in site folder'

    for i in range(len(rel_path_parts)):
        nav = nav + u' « ' + u'<a href="' + \
              (site_path + u'/'.join(rel_path_parts[:1+i])) + \
              u'">' + rel_path_parts[i] + u'</a>'

    nav = nav + '</p>'

# Writes page encoded as utf8
def write_page(page, name):
    (root, ext) = os.path.splitext(name)
    newname = root + '.html'
    f = codecs.open(newname, 'w', encoding = 'utf8')

# Help function
def usage():
    print 'Usage:'
    print 'python publon.py -d file.markdown (draft default) OR'
    print 'python publon.py -p file.markdown (publish)'

# Dictionary defining Castilian replacements
castilian = {u'á': '&aacute;', u'é': '&eacute;', u'í': '&iacute;',
             u'ó': '&oacute;', u'ú': '&uacute;', u'ñ': '&ntilde', 
             u'¿': '&iquest;', u'¡': '&iexcl;', u'ü': '&uuml;'}

# Convert castilian code to html entities
def convert_castilian(text, dictionary):
    for key in dictionary:
        text = text.replace(key, dictionary[key])


if __name__ == '__main__':
    # Processing command line options and arguments
        opts, args = getopt.getopt(sys.argv[1:], 'dp', ['draft', 'publish'])
    except  getopt.GetoptError, err:
        print 'Error detected: ', err

    # Reading file
    filename = args[0]
        f = codecs.open(filename, mode = 'r', encoding = 'utf-8')
    except IOError:
        print 'Markdown file not found'

    text = f.read()
    html, meta = process_page(text)
    template = inline_template()
    navbar = location(filename, base_path, site_path)
    meta[u'navbar'] = [navbar]
    page = build_page(html, meta, template)
    write_page(page, filename)

And that’s it.

Two hundred and counting

This is post two-hundred for this blog that started on Monday 14 July 2003. There have been gaps both on time of publication and a few missing items in the blog database. The latter explains that the permalink of this post actually contains the string http://uncronopio.org/quantum/article/203/. There was also a change of blogging system (in March 2004) from Greymatter to Textpattern.

Apart from the obvious decimal system significance, this post also marks the arrival of my new 15” Macbook Pro. After a good wait the guys from the IT department installed the extra RAM (to 1GB), setup Parallels virtualization with Windows XP (where I plan to install SAS and ASReml next week), and put the typical stuff for a university computer (MS Office and Endnote in their native mac versions).

Windows XP feels quite responsive under virtualizationand I already preordered Parallels (which is still in Beta) for USD 40. Next week I will comment on my experience installing and running SAS and ASReml.

Geotagging memory lane

Google Maps continues to include some higher resolution images (if not maps) for some parts of the planet. I was able to find the place where I used to live in Santiago at the level of buildings and houses. And here is where I used to study Just have a look at the centre of the pictures.

Distances between Christchurch places where I have lived at some point of my life (obtained using Geobyte’s city distance tool):

  • Hobart, Australia: 2442 km.
  • Palmerston North, New Zealand: 431 km.
  • Valdivia, Chile: 8647 km.
  • Mendoza, Argentina: 9487 km.
  • Valera, Venezuela: 12876 km.
  • Los Teques, Venezuela: 13255 km.
  • Santiago, Chile: 9351 km.
  • Concepcion, Chile: 8930 km.

It should be relatively easy to tag the images with every conceivable story that one is blogging about, although a bit time consuming. However, for most places I write about, imagery resolution is too broad for anything useful. I am sure it is just a matter of waiting a couple of years to sort out this issue.

Newer posts »

© 2024 Palimpsest

Theme by Anders NorenUp ↑