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 »


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 »

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 »

MySQL Character Set and Collation issues

logo

The solution to this error message is simple:

Illegal mix of collations (utf8_general_ci,IMPLICIT) and (latin1_swedish_ci,IMPLICIT) for operation =

Just run this:

alter database `databasename` character set utf8;

Related Posts

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

Irritating mysql dump error

logo

Are you getting this error?

> pacman -Q mysql
mysql 5.0.51-3
> mysqldump -T /dump -u root -p dbname
mysqldump: Got error: 1: Can't create/write to file '/dump/test.txt' (Errcode: 13) when executing 'SELECT INTO OUTFILE'

It doesn’t matter what you chown or chmod the directory to. It just won’t work. What does work? Use the /tmp directory. But don’t bother trying to set permissions identically on your own directory, or running as a different user, or checking permissions on the mysql binary, or verifying that you have the FILE permission granted on the user you are doing the dump with. Nope, it just doesn’t work. Just rewrite all your scripts to use /tmp.

Yeah, pretty irritating.


Related Posts

Tags:
Posted in solutions on April 13th, 2008 | No Comments »

Hooking up my Verbatim external hard drive

logo

Just today I bought a new Verbatim external hard drive for my Linux machine. It’s a nice, small 160GB USB 2.0 hard drive. Getting it set up on ArchLinux with autofs was super simple. When you access the drive, it automatically mounts, and unmounts after a couple seconds of no activity. It works great. Here’s how to do it.

Setting up udev

The first order of business is getting udev to recognize the device and assign it the same device file everytime. I wanted it to show up as /dev/verbatim. First of all, I needed to see how it’s identified by Linux. So I plugged in the device, ran dmesg, and determined the USB address:

scsi 6:0:0:0: Direct-Access     TOSHIBA  MK1637GSX             PQ: 0 ANSI: 2

Now I went into the sys filesystem to get the vendor and model information to help udev identify this device in the future. Using the USB address above — 6:0:0:0, I descended into the directory:

cd /sys/bus/scsi/devices/6:0:0:0
cat vendor
cat model

That gave me the values of “TOSHIBA” and “MK1637GSX”. Ok, so I could have gotten that from the dmesg output, but I wanted to make sure I was looking at the right fields.

Now I was ready to create my udev rule. I put the following in /etc/udev/rules.d/60-verbatim.rules:

BUS=="scsi", SYSFS{vendor}=="TOSHIBA", SYSFS{model}=="MK1637GSX", NAME="verbatim", GROUP="storage", MODE="0660"

Since my user wasn’t in the storage group I had to add him:

sudo gpasswd -a username storage

Alright! Now we have a stable device everytime we plug in the drive.

Setting up autofs

This part is simple. We just want the autofs daemon to pay attention every time the /dev/verbatim device shows up on the system, and handle auto-mounting and unmounting it as it is accessed.

I made sure the following line is in /etc/autofs/auto.master:

/media /etc/autofs/auto.media --timeout 2

Then I added the following line to /etc/autofs/auto.media (where 95 is the storage group id) to automount the device onto /media/verbatim:

verbatim -fstype=vfat,async,rw,gid=95,umask=002 :/dev/verbatim

Now, just restart the autofs daemon:

/etc/rc.d/autofs restart

All done!

That’s all it takes. Make sure the drive is unmounted, unplug it, plug it back in and take a look at your /media/verbatim directory. As you access it, you’ll see it’s automatically mounted (run mount). After a couple seconds of no activity, the drive will auto-unmount.

Was this helpful? Please let me know!


Related Posts

Tags:
Posted in solutions on April 11th, 2008 | No Comments »

Getting urxvt to launch URLs

logo

I’ve had this in my ~/.Xdefaults for a while, but it’s only recently with the latest perl package updates that it started to work. The first time it worked was a pleasant surprise! Whenever there is a URL looking piece of text in a rxvt-unicode window, it will launch it with Firefox in a new tab. Tremendous!

URxvt.perl-ext-common: default,matcher
URxvt.perl-ext: default,matcher
URxvt.urlLauncher: firefox
URxvt.matcher.button: 1
URxvt.matcher.pattern.1: \\bwww\\.[\\w-]+\\.[\\w./?&@#-]*[\\w/-]

Related Posts

Tags:
Posted in solutions on April 2nd, 2008 | No Comments »

Quick searches

logo

I just found about Firefox “Quick Searches”. Tremendous! This Lifehacker article details how to use them. I’ve already set up “w” for wikipedia searches, “i” for imdb searches, and can’t wait to add more as I see the need. It also means I’ve removed the “Search Engine” box in my toolbar for an even more minimalistic toolbar. Oh, and Ctrl-L gets you to the address bar, without needing F6.

The other thing I’ll have to look into more is yubnub.org


Related Posts

Tags:
Posted in solutions on March 21st, 2008 | No Comments »

sshfs: A simple Linux file-sharing solution

logo

What’s a quick, simple way to set up a file share between two Linux boxes? I looked into NFS shares, but that involves running extra daemons, and I don’t want to deal with the hassle of extra configuration files and daemons. I looked into SAMBA — OK, I didn’t; the thought grossed me out before I even gave it a chance.

Enter sshfs

According to the project website:

This is a filesystem client based on the SSH File Transfer Protocol. Since most SSH servers already support this protocol it is very easy to set up: i.e. on the server side there’s nothing to do. On the client side mounting the filesystem is as easy as logging into the server with ssh.

» Read the rest of this entry


Related Posts

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

« Previous Entries