Wednesday, September 15, 2010

Could Richard Riley have solved my problem?

2010-09-08 Wed 18:55

Today on the orgmode mailing list Richard Riley posted a function that works with the Google command line tools (http://code.google.com/p/googlecl/) to create Blogger entries directly from my favorite emacs mode, orgmode. I have been looking for just such a solution to make blogging more transparent, and lo it is here. This post is the first test of the method, and it works. (Of course, I'm writing this before actually testing it, but since the new function evaluated without error then it must be right! ;-)

To be sure, there were quite a few steps to get to this point. Here was the recipe.

  1. Sign up for a gmail account at http://gmail.google.com
    • While I already had a Google account for Blogger, the username (email address for my local service provider) seemed to be causing problems while authenticating (OAUTH) with googlecl.
  2. Install python-gdata version 1.2.4 or higher
    sudo apt-get install python-gdata
    
  3. Download googlecl Debian package (googlecl_0.9.10-1_all.deb) from http://code.google.com/p/googlecl/downloads/list
  4. Install googlecl
    sudo dpkg --install googlecl_0.9.10-1_all.deb 
    
  5. Call the blogger service to initiate authentication
    google blogger list
    
    • Enter the gmail account (e.g. myname@gmail.com) at the prompt "Please specify user"
    • Grant authorization in a browser
      • The browser may automatically launch with the URL
      • If not, then the link is provided in the terminal
    • Press return in the terminal
      • If there are error messages, then something probably went wrong :-)
      • If a list of blog entries appears then authentication is accomplished
  6. Send this blog post from orgmode

At present org-googlecl is a project at http://github.com/rileyrg/org-googlecl. Thank you Richard.

Tuesday, September 14, 2010

Getting org-googlecl

2010-09-14 Tue 21:14

A few days ago I wrote about how to set up googlecl in order to use Richard Riley's wonderful addition to emacs called org-googlecl. Tragically I did not even hint at how to get it. This post gives that hint, but assumes that git is already installed on the system and that the user knows how to configure emacs to use code in non-standard locations.

  1. Change to the directory for the installation (e.g. ~/prj)
    cd ~/prj
    
  2. Clone the repository
    git clone http://github.com/rileyrg/org-googlecl.git
    
  3. Add the new directory (~/prj/org-googlecl) to the emacs path by putting something like the following in a configuration file
    (add-to-list 'load-path "~/prj/org-googlecl")
    
  4. Load the library in emacs
    (load-library "org-googlecl")
    
  5. Set the configuration items for the blog
    (setq googlecl-blogname "Natural Log of X")
    (setq googlecl-username "<GoogleUserName@gmail.com>")
    
  6. After writing an entry in orgmode, publish the entry (defined by the outline level) to the blog
    M-x org-googlecl-blog RET
    
  7. Keep current with org-googlecl by updating the source
    cd ~/prj/org-googlecl
    git pull
    

Sunday, September 12, 2010

Rearranging output file from a PGM image conversion.

2010-09-12 Sun 11:44

convert ex-e_g.jpg[32x32+8+5] \
 -colorspace gray \
 -transpose \
 -compress none \
 -depth 8 PGM:- |\
  tail -n +4 |\
  tr -s ' \012' '\012' |\
  pr -T -s -32 -l32 \
  > ex-e_g_crop32x32.txt 

The convert command is from ImageMagick. The [32x32+0+0] crops as the image is read. The -colorspace Gray ensures that the image will be grayscale. The -compress none signals to use plain ASCII rather than a binary format. PGM output (to STDOUT) from 0 to 255 is ensured with -depth 8 PGM:-. The PGM header is removed with tail -n +4 and a single column of numbers is generated with the tr command.

The workhorse for the reformat is the pr tool which prepares file for printing. The -a puts columns across which is necessary for this flow to obtain the proper orientation. (This could have also been done with the -transpose switch to convert.) The -T ensures that no headers or footers are used, and that no page breaks are inserted. The -s switch puts tabs between values. The number of columns is specified with -32 and the number of lines with -l32.

Take note that initial tests without the -s command yielded files where the numbers were incorrect. This seems to have been due to something related to the width being too narrow, but the -s set the width to 512. The pr command does have the --width switch, but it is currently unclear how to calculate the exact width needed for the particular crop size.

Friday, September 10, 2010

How do I rename multiple files efficiently using only the bash shell?

2010-09-10 Fri 17:36

As a concrete example, let us consider the problem that we often have uploading pictures to certain sites (e.g. ebay). The photos from our camera all have .JPG extension. However, when we attempt to locate those pictures from some web sites, no photos are found. This is because something in the chain of events only lower case extensions, such as .jpg, are allowed.

The task is to change all files in a directory (e.g. /DATA01/Pictures/EBAY/2010-09-10) from upper case (.JPG) to lower case (.jpg) extensions.

cd /DATA01/Pictures/EBAY/2010-09-10
for i in *.JPG; do mv "$i" "${i/.JPG}".jpg; done

Simple.

There are certainly other ways, but this is good enough for now.

Weather for emacs and orgmode

On 09 Sep 2010 Julien Danjou provided a way to access the Google weather API from emacs. Additionally, the weather can easily be integrated into an orgmode agenda.

cd ~/Projects/git/
git clone git://git.naquadah.org/google-weather-el.git

Then we set up emacs in the following way

(add-to-list 'load-path "~/Projects/git/google-weather-el")
(require 'google-weather)
(require 'org-google-weather)

To add the weather to the agenda, put a call to org-google-weather with the city (e.g. "Webster, NY") or postal code (e.g. "14580") in an org file that is used by the agenda. Multiple weather locations can be included and the #+CATEGORY option can be used to distinguish them in the agenda.

#+CATEGORY: Webster, NY
%%(org-google-weather "Webster, NY")
#+CATEGORY: Washington, DC
%%(org-google-weather "Washington, DC")

The Google weather API is apparently very well undocumented (http://blog.programmableweb.com/2010/02/08/googles-secret-weather-api/), but the following call will retrieve an XML response.

http://www.google.com/ig/api?weather=14580

Other APIs that might be of interest are stock quotes

http://www.google.com/ig/api?stock=YHOO

movie listings

http://www.google.com/ig/api?movies=14580

and a news feed

http://www.google.com/ig/api?news

Neat stuff.

Thursday, September 9, 2010

Testing a new function from RR

2010-09-09 Thu 06:18

In terminal

cd ~/Projects/git/
git clone http://github.com/rileyrg/org-googlecl.git

In emacs

M-x load-file ~/Projects/git/org-googlecl/org-googlecl.el
M-x set-variable RET org-googlecl-blogname RET "Natural Log of X"
M-x set-variable RET org-googlecl-username RET "<well, you know>"

Write this entry in orgmode using emacs then call

M-x org-googlecl-blog

Wednesday, September 8, 2010

Could Richard Riley have solved my problem?

2010-09-08 Wed 18:55

Today on the orgmode mailing list Richard Riley posted a function that works with the Google command line tools (http://code.google.com/p/googlecl/) to create Blogger entries directly from my favorite emacs mode, orgmode. (See Getting org-googlecl for more information.) I have been looking for just such a solution to make blogging more transparent, and lo it is here. This post is the first test of the method, and it works. (Of course, I'm writing this before actually testing it, but since the new function evaluated without error then it must be right! ;-)

To be sure, there were quite a few steps to get to this point. Here was the recipe.

  1. Sign up for a gmail account at http://gmail.google.com
    • While I already had a Google account for Blogger, the username (email address for my local service provider) seemed to be causing problems while authenticating (OAUTH) with googlecl.
  2. Install python-gdata version 1.2.4 or higher
    sudo apt-get install python-gdata
    
  3. Download googlecl Debian package (googlecl_0.9.10-1_all.deb) from http://code.google.com/p/googlecl/downloads/list
  4. Install googlecl
    sudo dpkg --install googlecl_0.9.10-1_all.deb 
    
  5. Call the blogger service to initiate authentication
    google blogger list
    
    • Enter the gmail account (e.g. myname@gmail.com) at the prompt "Please specify user"
    • Grant authorization in a browser
      • The browser may automatically launch with the URL
      • If not, then the link is provided in the terminal
    • Press return in the terminal
      • If there are error messages, then something probably went wrong :-)
      • If a list of blog entries appears then authentication is accomplished
  6. Send this blog post from orgmode