Decaffeinating your own tea

Lately, we’ve been enjoying loose-leaf teas a lot. On our trip to Taiwan last December we picked up some Oolong and Black teas in loose-leaf form. Then we picked up a simple, $15 plastic tea pot with an infuser. You can fill up the pot with hot water multiple times, and each time the taste will develop as the leaves unfurl. It’s really a great way to drink tea.

But what about decaffeinated tea? No problem. Here’s an article that addresses this question. From the article:

Caffeine is highly water soluble, and nearly 80% of the total caffeine content of the tea leaves will be extracted within the first 30 seconds of steeping. If you wish to “decaffeinate” your own tea, the process is simple. Pour boiling water over the tea leaves, and allow a maximum of a 30 second rinse. Empty this water off, and pour fresh boiling water over the rinsed leaves to brew for the prescribed time.


Related Posts

Tags:
Posted in solutions on August 15th, 2008 | No Comments »


Standing is beneficial

According to this ABC News article:

Standing burns 17 percent more calories than sitting; so give up your seat on the bus or stand when you’re on the phone. In a study, overweight people spent about 2½ more hours a day in their chairs than leaner people did.


Related Posts

Tags:
Posted in corpore sano on July 21st, 2008 | No Comments »

xclip and vim

logo

To overly simplify, X Windows has two basic selections, the primary selection (when you select text), and the clipboard selection (when you select the “Copy” menu item or press Ctrl-C). The primary selection is super handy, because you just have to highlight the desired text to “copy” it, and then you press both mouse buttons simultaneously to “paste” it. Very handy! In fact, when I am in X, I never even bother with the clipboard selection.

The problem is that sometimes I use a program in Wine that is not aware of the primary selection. When I want to copy text from the program to a vi window, for instance, it is a whole fiasco. It used to be that I used "*p in vim. But now I mostly use vi since it is smaller and loads faster. That means I can’t use those handy copy and paste functions, since all the GUI functions were separated out to the vim executable (in ArchLinux anyway).

Here is what I currently have to do. First I have to start OpenOffice, open a new Writer document, paste the text with Ctrl-V, select it all with Ctrl-A, and then go to my vi document to paste it with the mouse. Then I close OpenOffice. What a hassle!

The solution

There is a small, handy utility called xclip that helps for cases like this. From it’s sourceforge page:

xclip is a command line interface to the X11 clipboard. It can also be used for copying files, as an alternative to sftp/scp, thus avoiding password prompts when X11 forwarding has already been setup.

To paste into vi, you just use:

:r!xclip -o -sel clip

Better yet, create a mapping so that you just have to press one key (F7, for instance) to paste from the clipboard. This great little vim recipe explains how.


Related Posts

Tags:
Posted in solutions on July 7th, 2008 | 1 Comment »

Recording sound clips from movies

logo

What if, hypothetically, there is a clip on youtube that you’d really like to have on your iPod? Because you posted the content and lost your original source files, obviously. Or, say, there is a music video on youtube for a song you love (that you wrote and produced), but to your great disappointment, you lost your original master copies.

Never fear! Firefox, mplayer, and lame to the rescue!

First, get the video

The first order of business is to get a copy of the video. As often as really good youtube content disappears, this is a handy trick. Get the VideoDownloader plugin for Firefox. It helps you to grab .flv files for flash videos on youtube or Google video.

Install the plugin, restart your browser as instructed, and navigate back to the youtube page with the content you need. Use the new toolbar item you have and download the video to your home directory.

Extract the audio portion

If all you care about is the audio portion, then you’ll need to create a .wav file from the .flv file. No problem. That’s what mplayer is for.

Use the following command:

mplayer -vo null -ao pcm:file=output.wav video.flv

Now you’ll have a large “output.wav” file.

Clean up your audio file

At this point, you may want to clean it up a bit to slice the section you are interested in. Or perhaps there are some inappropriate words that you want to filter out by applying an effect of some sort. No problem: use Audacity.

Open Audacity with your “output.wav” file and make any all changes you want to. The program is pretty straight-forward, although I’m not an expert audio editor, so it always takes me longer than I expect to get the results I’m looking for.

Package your new file

The last step is compress your “output.wav” file. Chances are you’re not interested in lugging around a huge 50MB file everywhere. You want an .mp3 or .ogg file that will be a tenth the size.

Here are the commands you’ll need to convert the .wav file. Use just one of them depending on the output you seek:

oggenc out.wav -o out.ogg
lame -b 128 out.wav out.mp3

That’s all!

You’ve successfully extracted the audio or music portion of an online video and converted it into an MP3, without using alsa tools! Not too hard, right?


Related Posts

Tags:
Posted in solutions on July 4th, 2008 | 1 Comment »

Review: Choose your own adventure

Mystery of the Maya (Choose Your Own Adventure, No. 5)

These were some of my favorite books as a kid. Recently a workmate made a reference to these books, and I started considering picking one up and reading it through. The one I bought is the one shown here, “Mystery of the Maya”.

What’s so great about these books?

These books are wonderful reading material for children.

  1. The books are educational, teaching them about new lands, peoples, and history.

  2. They encourage creativity. I remember one summer sitting down and making my own “Choose Your Own Adventure”. I still recall drawing a flowchart of the stories and how they fork and interrelate. What a tremendous project for a child to be engaged in!

  3. It requires introspection and exercises problem-solving skills. You have to weigh different options and facts, and make decisions that affect you (your character) and those around you.

All great reasons to get an 8-year old started on this series!


These days kids sit in front of television sets, spending 4+ hours a day with little or no mental stimulus. Books like these that stir up creativity and instill a love of reading in children are worth their weight in gold. If a few of these books get a child to see how much fun a book can be and the thrill of experiencing adventures through reading, it is well worth the $7 one of these gems costs.


Related Posts

Tags:
Posted in books on July 1st, 2008 | No Comments »

Showing battery life in awesome with Lua

logo

On my Asus EEE PC 701, I don’t have a lot of screen real estate (800×480 on a 7″ screen). Also, using the touchpad is not the most efficient method of controlling a window manager, since it requires more precision than I care to use. These factors make a tiling window manager — like awesome — ideal.

I’ve already written about some of my experiences with awesome and Lua, but it’s time to accept the bad with the good and move on. So let’s get my desktop configured the way I like.

My desktop

The only things I really need to show on my screen are a few tags (1-3), the taskbar, the layout indicator (although I’ll go months without using anything other than the “max” layout), and battery life on my laptop. I’ve given in to the default color scheme to make it easier for me to update my .awesomerc.lua, since I download the git HEAD on a weekly basis.

Here is a typical view of my streamlined desktop:

screen_thumb

Click here to view full-size

This layout allows me to navigate quickly from one window to another. Now whenever I use a non-tiling window manager, I get irritated by the time wasted on organizing windows on the screen. Shouldn’t the window manager do that? :)

Displaying battery power

Here is a little bash script that I have in my ~/bin directory to display the current battery life as a percentage.

#!/bin/bash

### BATTERY
REM=`awk '/remaining capacity/ { print $3 }' /proc/acpi/battery/BAT0/state`
LAST=`awk '/last full/ { print $4}' /proc/acpi/battery/BAT0/info`
#STATE=`awk '{print $2}' /proc/acpi/ac_adapter/AC0/state`
#if [ "$STATE" = "on-line" ]; then
  #BAT=$(echo $REM $LAST | awk '{printf "Bat: %.1f%%, AC", ($1/$2)*100'})
#else
  #PRESENT=`awk '/present rate/ { print $3}' /proc/acpi/battery/BAT0/state`
  #BAT=$(echo $REM $LAST $PRESENT | \
    #awk '{printf "Bat: %.1f%%", ($1/$2)*100}')
  #  awk '{printf "Bat: %.1f%%, %d min", ($1/$2)*100, ($1/$3)*60}')
#fi
PERCENT=$(echo $REM $LAST | awk '{printf "%d", ($1/$2)*100'})

echo "$PERCENT%"

Next, we’ll need a way to read the output of a system call in Lua. I’ve added this function in my .awesomerc.lua:

function get_command_output (command)
    local c = io.popen(command)
    local output = {}
    i = 0
   return c:read("*line")
end

This code runs the command you pass in, and returns the first line of output. Now we can retrieve the battery life for display in an awesome widget. In the hook_timer function, which I’ve set to run every 10 seconds, you retrieve the output of the battery command and put it in the textbox, like so:

    function hook_timer ()
        -- For unix time_t lovers
        -- mytextbox:set("text", " " .. os.time() .. " time_t ")
        -- Otherwise use:
        -- mytextbox:set("text", " " .. os.date() .. " ")
        mytextbox:set("text", " " .. get_command_output("battery") .. " ")
    end

My .awesomerc.lua

My latest .awesomerc.lua is always located here. Since I’m keeping up with the git HEAD, I try to minimize the differences against the project configuration file, while at the same time making sure I have a customized environment that is fast and efficient.


Related Posts

Tags:
Posted in linux on June 26th, 2008 | No Comments »

A simple Javascript email obfuscator

The goal was simple. I needed a way to obfuscate links in web pages to prevent spammers from harvesting email addresses from pages and flooding me with advertisements for products and services I’m embarrassed to even read about. There are some pretty high-tech solutions out there, but I just wanted a simple solution to start with: easy to use, easy to maintain.

Set up your links

Any links that are going to be a “mailto:” email address you set up like this:

<p>Why don't you write me at <a class='email' priv='grfg@grfg.pbz'></a>?</p>

Note that we used the class email and set up a priv tag with the rot-encoded email address. I used test@test.com for the above example. If you are using vi, type the real email address, and then use the g? command and a motion to rot13 the text.

In the example above, since there is no text in the a element, the email address is used as the anchor text. The output on the screen looks as if this were the HTML:

<p>Why don't you write me at <a class='email' href='test@test.com'>test@test.com</a>?</p>

If you already have text specified for the a element, it will stay.

Next, set up the javascript

Here is the code you’ll put on your page. These functions can be stored in a .js file if you wish. Just make sure you call the decodeLinks function on page load.

<script type='text/javascript' language='javascript'>
/* rot functions from http://4umi.com/web/javascript/rot13.php */
function rot( t, u, v ) {  return String.fromCharCode( ( ( t - u + v ) % ( v * 2 ) ) + u ); }  
function rot13( s ) {  var b = [], c, i = s.length,   a = 'a'.charCodeAt(), z = a + 26,   A = 'A'.charCodeAt(), Z = A + 26;  while(i--) {   c = s.charCodeAt( i );   if( c>=a && c<z ) { b[i] = rot( c, a, 13 ); }   else if( c>=A && c<Z ) { b[i] = rot( c, A, 13 ); }   else { b[i] = s.charAt( i ); }  }  return b.join( '' ); }  
function rot5( s ) {  var b = [], c, i = s.length,   a = '0'.charCodeAt(), z = a + 10;  while(i--) {   c = s.charCodeAt( i );   if( c>=a && c<z ) { b[i] = rot( c, a, 5 ); }   else { b[i] = s.charAt( i ); }  }  return b.join( '' ); }  
function rot135( s ) {  return rot13( rot5( s ) ); }

/* one day when IE is up to speed, use getElementsByClassName instead... */
function decodeLinks() {
    var links = document.getElementsByTagName('a');
    var re = /\S/i;
    for (var i = 0; i < links.length; i++) {
        var link = links[i];
        if (link.className != 'email') continue;
        var pl = link.getAttribute('priv');
        var email = rot13(pl);
        link.href = 'mailto:' + email;
        if (link.innerHTML.match(re) == null) {
            link.innerHTML = email;
        }
    }
}

/* call on page load */
decodeLinks();
</script>

That’s it!

That’s all it takes to set up a simple Javascript email obfuscation system site-wide. It works on IE and Firefox seamlessly. If your needs get more complex, it’s simple enough to modify and use different decoding schemes.

Thoughts? Ideas for improvement? Please let me know!


Related Posts

Tags:
Posted in solutions on June 24th, 2008 | No Comments »

Predicting the Weather

logo

Here are two interesting articles detailing various techniques for predicting the weather for the next couple days:

The first article states:

By being observant, forming hypotheses, and testing your predictions, you can fine-tune your weather predicting abilities beyond what any article could ever instruct.

Tags:
Posted in miscellanea on June 22nd, 2008 | No Comments »

Review: Alaska by James Michener

Alaska: A Novel

Coincident with a trip to Alaska, I picked up this eponymous book by James A. Michener. Previously I had heard his name before, but I was unfamiliar with his work. This book was a great introduction to this author. He is a popular author of some 40 titles.

His historical fiction is always well-researched and interesting — two of the most important characteristics of historical fiction. He blends fact and fiction so well that immediately after the Table of Contents, he spends a couple pages quickly informing you which characters, places, and events are real and which are fictional. Indeed, without this handy summary you would be hard-pressed to distinguish the two from his account. It was neat to visit a place in Alaska and see how things are done, and then that night read an accurate description in his book of the very same things.

Content

The scope of the book is impressive. Where do you start in addressing the history of the great land that is Alaska (”Great Land”, he explains, is the word from whence we derive “Alaska”)? He begins farther back than I would have guessed. The first chapter, entitled “The Clashing Terranes”, details the movements of the tectonic plates that scientists believe gave rise to the landmasses now defining Alaska. It details the appearance of the Aleutian chain as well as the Alaska range to the north.

Some of the details given in the book were disturbing, but alas! such is human history. For instance, the treatment of the Alaskan natives by the Russians is appalling. The following paragraph from the end of Chapter 5 provides an idea of what occurred:

When Vitus Bering’s men first stepped ashore on the Aleutians in 1741, the islands contained eighteen thousand, five hundred healthy men and women who had adapted masterfully to their treeless but sea-rich environment. When the Russians departed, the total population was less than twelve hundred. Ninety-four percent had been starved, drowned, forced into slavery, murdered, or otherwise disposed of in the Bering Sea. And even those few who survived … did so only by merging themselves into the victorious civilization.

The most gruesome story in the book, based on an actual historical incident, is in Chapter 4 (page 139 in my edition):

Utilizing three of the willing Russian traders, he had them choose at random twelve Aleut hunters, who were lined up one behind the other, with the man who had started the protest in front. When each Aleut was prodded forward so that he stood tightly wedged against the man in front, Innokenti cried: ‘We’ll show them what a good Russian musket can do,’ and he loaded his gun heavily, moved close to the head of the file, and took careful aim right at the heart of that first troublemaker…

Then, with icy rage he fired, and eight Aleuts, one after the other, dropped dead while the ninth fainted, for the bullet had ended against his ribs. The final three stood transfixed.

Stories like this fill one with immense disgust and remorse over the ugliness that characterizes so much of human history. Thankfully the book is filled with many more enjoyable stories of friendship and the wonder of the beautiful Alaskan country.

Summary

All in all, I enjoyed this book immensely. The last 100 pages — my edition has less than 900 — took me a while to complete, but I’m not convinced that was due to any fault of the author. Considering that I have not read any substantial work of fiction in years, I was impressed by this book’s ability to maintain my interest.

I highly recommend this book and am looking forward to reading more of Michener’s works in the future.


Related Posts

Tags:
Posted in books on June 21st, 2008 | No Comments »

Napping - how and why

logo

There’s a great graphic on The Boston Globe’s website called: How to Nap. From the article:

Research on pilots shows that a 26-minute “NASA” nap in flight (while the plane is manned by a copilot) enhanced performance by 34 percent and overall alertness by 54 percent. One Harvard study published this year showed that a 45-minute nap improves learning and memory.

My favorite part of the article was that a study last year showed that just thinking about taking a nap brought down blood pressure!


Related Posts

Tags:
Posted in corpore sano, miscellanea on June 17th, 2008 | No Comments »

« Previous Entries