mutt

Mutt Tip: Safe Delete

27 Mar 2008, posted on mutt

Update (Mar 27, 2008): I discovered that the previous version of these macros did not not work with collapsed threads. I’ve updated the code and now it should work under all cases.

In its default configuration, mutt behaves as man’s best friend and does what it is told without any further question. Press the “D” key and down the drain goes your email. No way out.

To solve this problem, edit your .muttrc file and add the following:

## Safe deletion macros apply for all folders, EXCEPT the 'deleted' folder.
## "Y" is set to 'unsafe delete' (useful over slow imap links).
## Also note the slight difference between 'index' and 'pager' for thread
## delete. The "\ni" will cause mutt to briefly switch to pager mode and
## back to index, causing the thread to uncollapse. It's a trick but as
## a trick goes, it works really well (for me, at least) :)

bind  index   y   delete-message
bind  pager   y   delete-message

folder-hook . 'macro index d  <copy-message>=deleted\ny<delete-message>  "Safe Delete"'
folder-hook . 'macro pager d  <copy-message>=deleted\ny<delete-message>  "Safe Delete"'
folder-hook . 'macro index \ed \ni<tag-thread><copy-message>=deleted\ny<delete-message> "Safe delete Thread"'
folder-hook . 'macro pager \ed <tag-thread><copy-message>=deleted\ny<delete-message>    "Safe delete Thread"'

## Really erase if we're using the 'deleted' mail folder.

folder-hook 'deleted' 'macro index d   <delete-message> "Delete Message"'
folder-hook 'deleted' 'macro index \ed <delete-thread>  "Delete Thread"'
folder-hook 'deleted' 'macro pager d   <delete-message> "Delete Message"'
folder-hook 'deleted' 'macro pager d   <delete-message> "Delete Message"'

From this glorious moment on, pressing “D” will no longer delete messages, but rather move them to a mail folder called deleted. The same applies for Control-D, which moves entire threads to that folder.

If you want to permanently delete a message, bypassing all the chicanery described above, just use the “Y” key.


[Permalink] | [Digg Me] | [Add to del.icio.us] | [Submit to reddit] | [Submit to ma.gnolia.com] | [Submit to FURL]

This is a bit long, but a good example of how to lose customers for nothing.

After many years squatting on friends servers to host some of my pages and backups, I decided it was time to give them a break and pay a professional hosting company. I took some advice, read some reviews and decided to go with Dreamhost. Their employee-owned model, feature set and overall coolness made them very appealing to me.

I signed up and was really happy with Dreamhost. So happy in fact, that I decided to recommend their services to a friend. He signed up and called me saying “Hey, you just made $97!”. Puzzled, I asked why and he explained that Dreamhost had this referral program that would pay me $97 for bringing a new customer in! Already planning on a second year of hosting, I logged in and discovered that I had made $11.94, and not $97 as promised in the signup page. How strange…

A bit of investigation revealed that Dreamhost has, in fact, two “rewards” plans: Plan number one, where they pay you $97 for each person you refer, and plan number two, where they pay you 10% of everything your referral spends with Dreamhost. The “Earn $97” plan is promimently displayed on their webpage banners, and when you click on the link for further explanations, you’re directed to the “affiliate program” page that shows two options: “Option 1”, One time payments and “Option 2”. Recurring payments (the “10%” plan). Note that even here, the “Earn $97” plan is the first option shown in the page.

But still, what happened? It does not take a lot of math to realize than earning $97 now is better than earning 10% of what your friends spend with them, unless you prefer to wait eight years to make the same amount of money you could make now, or have friends who tend to go on a hosting service shopping spree. Dreamhost knows that too, and so, they silently opt you in for the 10% plan. There’s no warning when people put you as the referrer and you do not have a chance to fix it afterwards! Yes, I changed my “preference” to “Earn $97”, but that will only affect future referrals. Somewhere, deep in the jungle, a sales monkey was laughing and calling me a sucker.

Still believing that this could have been an easy to correct oversight on their part, I posted a message to “Customer Relations”. The answer was something along the lines of “Hello Marco, I’m really sorry that you feel this is unfair (bla…) If you want to make a suggestion, click on this URL (bla…) But we have one of the best referral programs out there (bla…) I’m sure others will prefer the 10% plan (bla…)”. Translation: We’re not going to do anything for you. I replied to that message and got another message from the “Dreamhost Sales Team” saying that they were “very sorry” that I feel that way about a “free service they offer” (ha, what about the customer who would not have signed up if I had not referred him?), that they do not think they’re being “unfair”, and that I’d have to use their “suggestion system” to get anything changed (oh, the nerve!)

Hello Dreamhost, wake up!!! Referral bonuses are not a freebie. You got yourself a new paying customer because I pointed that customer your way. Also, “Customer Relations” is there to do something! If they had said “OK, we’ll revert the situation if you apply this to one extra year of hosting”, I’d gladly call it a closed case. Unfortunately, this never crossed the Customer Rep’s mind, in a demonstration of complete pettiness and disregard for the satisfaction of your customers.

Conclusion: Dreamhost just lost a customer and supporter. My friend was shocked with the whole sleaziness of the situation and is considering cancelling service with them. Two unhappy customers going out the door, for less than $100 (that would have gone straight into paying for an extra year of hosting).

My congratulations to the Dreamhost Sales Team for a job well done.


[Permalink] | [Digg Me] | [Add to del.icio.us] | [Submit to reddit] | [Submit to ma.gnolia.com] | [Submit to FURL]

This is a quick guide to some not so obvious command-line options available in the Linux netstat(8) command. I hope you enjoy it.

1. Plain old netstat

Without any command-line arguments, “netstat” shows a list of network connections in your system, including TCP, UDP and UNIX socket connections.

If you want to speed up things a bit, use “-n” (numeric) to prevent network lookups and display IP and port numbers instead of names.

2. Seeing all connections with “netstat -a”

Just like the above, but shows all connections, including those in the LISTEN state. Good when you want to see all connections in one shot.

3. What I am listening to? “netstat -l”

Many people type “netstat -a | grep -i LISTEN”, but “netstat -l” will do the same: filter the output to show sockets in the LISTEN state only. Very useful to quickly see what is being “served” in your box. You can combine this with “-u” to only show UDP connections or “-p” to restrict the output to TCP connections only.

4. Who’s using that socket? “netstat -p”

With “-p”, netstat shows what program/pid is using a given socket. Very handy to find out who’s listening on a port or holding a connection open. A personal favorite of mine is “netstat -lput”, which displays all TCP and UDP sockets in the LISTEN state, plus the name and pid of the program listening on that socket.

5. Details, lots of details: “netstat -e”

If you really want to see what’s going on, add the “-e” command-line switch to your netstat command. It will cause “extra” information to be printed, such as the username, process name and pid, and the inode number of each of your sockets.

6. Dial “o” for obscure: “netstat -o”

The “-o” command-line option causes the TCP timers to be displayed next to the connection. If you’re not into TCP/IP, the extra information will not make sense. For those who are, you’ll be able to see your TCP timers in real-time, and follow the progress of things like the KeepAlive timer, for instance. For a real treat, use “watch netstat -to”, sit down and watch the blinkenlights.

7. Interface status with “netstat -i”

Shows the status of your interfaces. Very handy to make sure everything is going smooth on the hardware side of things. Keep an eye on the ERR, DRP and OVR counters, as they can indicate trouble (10/100 mismatch anyone?).

8. Continuous display: “netstat -c”

Makes netstat display output continuously. This command-line option can be used with any other form of netstat. I’d suggest using the “watch” command instead.

9. TCP/IP statistics: “netstat -s”

Shows statistics about your TCP/IP stack. Requires deeper knowledge of the protocols to make some sense of it, but can be used by anyone to impress (scare?) friends, relatives and prospect girlfriends.

10. Boooooring: “netstat -r”

Use “ip route” instead of “netstat -r” to look cool and hip, and say “netstat is sooo 1975” when somebody asks why you’re doing that.


[Permalink] | [Digg Me] | [Add to del.icio.us] | [Submit to reddit] | [Submit to ma.gnolia.com] | [Submit to FURL]

While strolling across digg, I found an entry on How to transform your caps-lock into a third Control key. It basically introduces a program, called waNOCAPS, that modifies some entries in the Windows registry to do its deed.

But, can you do that in Linux/X? The answer is yes, and you don’t even need to download a program, or poke into undocumented areas of your operating system.

Unlike Windows, all the infrastructure to remap the keyboard is already embedded in the X11 server. The program to modify key and button mapping in X11 is called “xmodmap”, and comes pre-installed. All you have to do is to open a terminal window and type:

xmodmap -e 'remove Lock = Caps_Lock'
xmodmap -e 'keysym Caps_Lock = Control_L'
xmodmap -e 'add Control = Control_L'

From this point on, your “Caps-Lock” key should behave just like another “Control” key.

But wait, what does that mean? THAT YOU WOULD HAVE TO HOLD SHIFT TO YELL ONLINE? Only if you want! You can remap the right Control key to be your new caps lock:

xmodmap -e 'remove Control = Control_R'
xmodmap -e 'keysym Control_R = Caps_Lock'
xmodmap -e 'add Lock = Caps_Lock'

If you prefer to leave the right Control key alone and use the right “Windows” key as your new Caps-Lock key, use the commands below instead:

xmodmap -e 'keysym Super_R = Caps_Lock'
xmodmap -e 'add Lock = Caps_Lock'

Needless to say, this will only work if your keyboard has a “Windows” key (a distant relative of the infamous “any” key) :)

Note that none of the changes above is permanent. The method to make them permanent will vary according to your distribution of Linux and how you invoke X11. In Ubuntu, for instance, all you have to do is to use “pico”, “nano”, “vi”, or your editor of choice to add the lines below to a file called “.profile” under your home directory (create the file, if necessary):

if [ $DISPLAY ]
then
  # Add the 3 lines below to Convert caps-lock into Control
  xmodmap -e 'remove Lock = Caps_Lock'
  xmodmap -e 'keysym Caps_Lock = Control_L'
  xmodmap -e 'add Control = Control_L'

  # Add the 3 lines below to use the Right-Control as Caps-Lock
  xmodmap -e 'remove Control = Control_R'
  xmodmap -e 'keysym Control_R = Caps_Lock'
  xmodmap -e 'add Lock = Caps_Lock'

  # Or add the 3 lines below to use the right Windows key as Caps-Lock
  xmodmap -e 'keysym Super_R = Caps_Lock'
  xmodmap -e 'add Lock = Caps_Lock'
fi

Log out of your session and log back in. You should now be able to enjoy your new keyboard layout.


[Permalink] | [Digg Me] | [Add to del.icio.us] | [Submit to reddit] | [Submit to ma.gnolia.com] | [Submit to FURL]

This is a very brief HOWTO on how to capture Youtube and Google videos to your computer, saving them as AVI files encoded in the MPEG4 format, using only one command (actually, a few commands that you can cut & paste from this page).

Unlike most other articles around the net on this subject, this does not require the specialized plugins for Firefox or programs. All you need is a Linux workstation running any fairly recent Linux distro, and FFMpeg.

Step 1 — Make sure you have what you need

You need to be running Firefox. You’ll also need FFMpeg. To check if you have FFMpeg installed, just type “ffmpeg —version” at the shell prompt. You should see something like this:

$ ffmpeg --version
ffmpeg version CVS, build 3276800, Copyright (c) 2000-2004 Fabrice Bellard
(...) (many other lines removed)

If you don’t see the above, you’ll need to install ffmpeg. In Ubuntu and most other Debian variants, all you need is “apt-get install ffmpeg”. The installation procedure for other distributions of Linux will vary.

Step 2 — Locate and playback the content

Fire up Firefox and go to the website of your choice (usually Google Videos or Youtube). Select and play the movie you want. Allow the movie to end normally (this will guarantee that we have a fresh copy of the movie in the Firefox cache.)

Step 3 — Convert and save

Open command prompt and cut/paste the following into it:

ffmpeg -i "$(find ~/.mozilla -regex '.*Cache.*' -a -not -regex \
  '.*_CACHE_.*' -printf '%T+ %p\n' | \
  sort -n | awk '{ print $2 }' | xargs file | \
  grep -i "Video" | tail -1 | awk -F : '{ print $1 }')" \
  -vcodec msmpeg4v2 -b 200 -ab 64 -ar 22050 -s 320x240 \
  /tmp/video.avi

You should see something like:

Input #0, flv, from '/home/youruser/.mozilla/firefox/randomnumber/Cache/5D2BD385d01':
  Duration: N/A, bitrate: N/A
  Stream #0.0: Audio: mp3, 22050 Hz, mono
  Stream #0.1: Video: flv, yuv420p, 320x240, 1000.00 fps
Output #0, avi, to '/tmp/output3.avi':
  Stream #0.0: Video: msmpeg4v2, yuv420p, 320x240, 25.00 fps, q=2-31, 200 kb/s
  Stream #0.1: Audio: mp2, 22050 Hz, mono, 64 kb/s
Stream mapping:
  Stream #0.1 -> #0.0
  Stream #0.0 -> #0.1
Press [q] to stop encoding

And a frame counter. At this point, FFMpeg is converting your movie to mpeg4. This will take a while, depending on the speed of your computer and the length of the movie.

When the bash prompt returns, you’ll have your file encoded as “/tmp/video.avi”.

Troubleshooting and optimizations

Despite its intimidating look, the script above does something very simple: it locates Firefox’s cache directory and encodes the most recent file that looks like a “Macromedia Video” file. There’s not a lot of intelligence to it, and a few things can go wrong.

Remember that only the most recent file is encoded. Thus, if you watch one video and watch another, the first one will not be encoded. Worse yet, if you try to watch the first video again, it’s already in the cache, so it won’t be reloaded. As a result, it will never be the “newest file” in the cache again. To fix this, on Firefox, click on “Edit->Preferences->Privacy->Cache” and then click on the “Clear Cache Now” button. Reload the desired video and repeat the procedure.

Another problem is that there are a number of versions of ffmpeg floating around. Yours may have a slightly different syntax, so YMMV.

If you intend to run the program more than once, it may be a good idea to save it into a shell script. To do that, cut & paste the commands into a file called “/usr/local/bin/ffcap”. Then, turn on the executable bit on this file with:

 chmod 755 /usr/local/bin/ffcap

And you should be able to run all the shenanigans above just by type “ffcap” at the bash prompt.

You may also want to tweak the compression parameters or change the output codec. More compression means lower quality, but smaller resulting files. Check ffmpeg’s documentation for that.

If you’re using Gnome, you may want to change the output file from “/tmp/video.avi” to something like “~/Desktop/video.avi”. This will make the video appear on your Gnome desktop when processing is finished. If you save the commands into a script (see above), you may even create an icon in your desktop pointing to the script, so capturing videos is only a click away.


[Permalink] | [Digg Me] | [Add to del.icio.us] | [Submit to reddit] | [Submit to ma.gnolia.com] | [Submit to FURL]

[ 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 ] next ->>