Monday, August 8, 2011

Emacs lisp functions for word lookup using web services

2011-08-08 Mon 19:47

Without any commentary about Xah Lee besides this preemptory caveat that there is alot of commentary about him, there are some useful functions from his website http://xahlee.org/emacs/emacs\_lookup\_ref.html. The two used here are both lookups based on the word under the cursor for either a definition or wikipedia.

In the original definition of his function lookup-word-definition the web service is hard-coded. In preparation for making the particular web service configurable we need to know what might be available and a sense of the API. Xah Lee also had a list of online dictionaries (http://xahlee.org/PageTwo\_dir/Vocabulary\_dir/dictionary\_tools.html) along with an example for the word 'curlicue'.

American Heritage Dictionary (AHD)
http://www.answers.com/main/ntquery?s=curlicue
AHD 2
http://education.yahoo.com/reference/dictionary/entry/curlicue
AHD 3
http://www.yourdictionary.com/curlicue
wiktionary
http://en.wiktionary.org/wiki/curlicue
AHD, Random House, …
http://dictionary.reference.com/browse/curlicue
Merriam Webster Collegiate
http://m-w.com/dictionary/curlicue
Longman
http://www.ldoceonline.com/search/?q=curlicue
Compact Oxford English Dictionary
http://www.askoxford.com/concise\_oed/curlicue
Oxford Advanced Learner's Dictionary
http://www.oxfordadvancedlearnersdictionary.com/dictionary/curlicue
Open Source Dictionaries
http://www.dict.org/bin/Dict?Form=Dict2&Database=*&Query=curlicue
Google dictionary
http://www.google.com/dictionary?q=curlicue
  • "Google Dictionary is no longer available."

First we declare a new variable, tcb/lookup-word-definition-dictquery, that points to the dictionary and prepares the query under the assumption that the word to be found is the very last part of the string.

(defcustom tcb/lookup-word-definition-dictquery
  "http://m-w.com/dictionary/"
  "Dictionary and query API used in lookup-word-definition."
)

Now we define the function itself using the new variable.

(defun lookup-word-definition ()
  "Look up the current word's definition in a browser.
If a region is active (a phrase), lookup that phrase."
 (interactive)
 (let (myword myurl)
   (setq myword
         (if (and transient-mark-mode mark-active)
             (buffer-substring-no-properties (region-beginning) (region-end))
           (thing-at-point 'symbol)))

  (setq myword (replace-regexp-in-string " " "%20" myword))
  (setq myurl (concat tcb/lookup-word-definition-dictquery myword))

  (browse-url myurl)
  ;; (w3m-browse-url myurl) ;; if you want to browse using w3m
   ))

Another useful function is a wikipedia lookup.

(defun lookup-wikipedia ()
  "Look up the word under cursor in Wikipedia.
If there is a text selection (a phrase), use that

This command switches you to your browser."
 (interactive)
 (let (myword myurl)
   (setq myword
         (if (and transient-mark-mode mark-active)
             (buffer-substring-no-properties (region-beginning) (region-end))
           (thing-at-point 'symbol)))

  (setq myword (replace-regexp-in-string " " "_" myword))
  (setq myurl (concat "http://en.wikipedia.org/wiki/" myword))
  (browse-url myurl)
   ))

--
R|Burt〉

Friday, July 15, 2011

Testing org-googlecl after host replacement

For the last 18 months the home computer network, and especially my own machine, have deteriorated to agonizing usability. In these past few days I have enlivened the systems and things are running well. This particular post is a test of the blogging capability from emacs orgmode that is made possible by the wonderful package org-googlecl and googlecl.


--
R|Burt〉

Saturday, March 12, 2011

Access to URL has been blocked over 3G because of an account filter

2011-03-11 FRI 11:56

If I ever get the message "Access to URL has been blocked" surfing the web over 3G, I'll call customer service to ask if the phone number has filters applied. Here is the short story that leads to this conclusion.

We have a Samsung Captivate smartphone running the Android v2.1 operating system. Browsing the internet worked over both wireless and the 3G data network. Then came a day when 3G browsing no longer worked but wireless did. Neither research nor 'random walks through solution space' (as a friend is wont to say) yielded a solution so we went to the AT&T store for help. Even though they had not heard of this problem they were helpful and attempted some resolution to no avail.

After 20 minutes of failed attempts they still did not give up but rather brainstormed and checked assumptions. One such assumption was that the phone account itself had the proper permissions to browse the web over 3G. Since this capability worked before and we had not requested it to be disabled, it didn't seem likely that this was a problem. However, a call to customer service revealed that the phone line was indeed filtered in a way to block data, including web access, over 3G. This configuration was incorrect and never requested, but a plausible explanation is that when we requested data blocking for our daughter's line my wife's line was inadvertently blocked as well.

So, if you are getting the "Access to URL has been blocked" message, see if the line is somehow filtered.

Troubleshooting Notes

Here are some troubleshooting observations and actions we tried that failed.

  • All internet activity was successful when connected to a wireless network.
  • Some internet activity was successful when not connected to wireless but going through 3G
    • Examples are weather, local news
    • These activities had a phone application associated with them
  • Reset browser settings
  • Put into flight mode for a few minutes then return to normal mode
  • Remove battery then put it back
  • Use a different browser

--
R|Burt〉

Wednesday, January 19, 2011

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.

If the task is a bit more complex will do well to use another standard Unix tool with regular expression capability (such as sed). For example, if we have files with a date in the name (e.g. 20101210) and want to change the date (e.g. to 20110119), then here is solution.

for i in *20101210*; do j=`echo $i | sed s/20101210/20110119/`; mv $i $j; done

Still simple.