Archive for the 'tips' Category

Firefox 3 Thumb Button brings up Save As dialog

Thursday, October 2nd, 2008

This has been driving me nuts since I have upgraded to Firefox 3.0.1 on my laptop like a month ago. I’m still running Gutsy on that thing, and only the beta version (which crashes a lot) is in the repositories. So I pretty much did the same thing as back when FF 2.0 came out and I was running dapper. I snagged the statically linked linux binary from the website, dumped it into /opt/firefox and un-installed the old version. It works fine with a single exception - my thumb button was acting weird as hell.

This requires some explaining. I’m using Logitech VX Revolution wireless mouse and the btnx to detect and remap all the additional buttons on the mouse. I configured it so that the back and forward thumb buttons are set to emulate the Alt+ left arrow key and Alt+ right arrow key. These are of course Firefox shortcuts for Back and Forward controls.

To tell you the truth, I actually forgot how to press the back and forward buttons on the FF chrome. I just never do it. At home I am using MS Sidewinder mouse which also has convenient thumb buttons. I always use them while browsing because it is just so much faster than anything else. Faster than keyboard shortcuts because when I’m browsing one of my hands is usually holding the mouse. So thumb buttons are perfect for quick flicking back and forward between pages and I miss them when I’m forced to use a mouse which doesn’t have them.

Ever since I started using FF 3.0.1 on my laptop the back thumb button started doing something weird. In addition to sending the browser the “Back” signal it would also invoke the “Save As” dialog. Yes, it would just pop up in the middle of the screen. Attempting to use the dialog would be futile however. I tried to actually save whatever it was asking me to save several times, but Firefox never actually produced any files as a result of using this particular dialog.

It was nothing more than a constant annoyance. Every time I tried to go back a page, I would have to cancel this dialog. It was actually more annoying than clicking the buttons manually, or taking my hand off the mouse do do the Alt+ Left Arrow thing. Since then I have reconfigured btnx dozens of times, and kept searching Google for a possible solution. No luck. Eventually I figured out this had to be some Firefox setting and started digging in about:config.

Through bunch of trial and error tests, and good amount of luck I finally managed to identify the culprit. If you have this problem, all you have to do is to set:

middlemouse.contentLoadURL = false

From mozilla knowledge base:

Background:

This preference determines how to handle middle clicks in the content area. It was split off from middlemouse.paste, which now handles middle clicks in text fields only.

Possible values and their effects:

True: Load the contents of the clipboard as a URL. (Default for Linux/Unix.)

False: Handle middle-clicks normally. (Default for all but Linux/Unix.)

I actually never, ever use this feature because 90% of the time the thing in my clipboard is not a loadable URL. Besides, since I switch between platforms a lot, I generally don’t get used to platform specific features like that.

I have no clue why this particular setting kept picking up the Back Thumb button as some sort of “Save As” invocation. Note that this was not happening in FF 2.x, so go figure. Setting it to false solved the issue for me. I can browse like a normal person again.

Hopefully this post will help some other poor soul frustrated by this issue. )

Vim Tips

Wednesday, October 1st, 2008

Hey kids! Guess what time it is? It’s time for some Vim Tips!

What? Don’t make that face! Vim is awesome! Don’t give me that “B-b-but mistur Luke, we don’t use vim!” That won’t work with me again! You know damn well you should be using it. What is your lame excuse today? Is it “vim is to hard”? Suck it up you babies. Real men and women use vi and that’s that! There is only one excuse that I’m willing to accept, and that excuse is “I use Emacs”. So, how many of you whining babies use emacs? One person? Ok, you are excused - you can go sit over there. Your exercise is to write an elisp macro to do something interesting.

The rest of you, STFU and listen. No, I don’t care you use Eclipse on a daily basis. Just get the viPlugin and you will have the combined power of Vi and Eclipse at your fingertips. How awesome is that. No, don’t shrug - it’s fucking awesome, and you are gonna like it, right now! There, that’s better.

Ok, question from the back row. Yes, you - the guy with the stupid face. You use word? You know what - get the fuck out! Just get out and never come back. Actually, on the second thought wait. Sit your ass down and try the ViEmu thing. I tested it a while ago and it was pretty cool. Unfortunately it tad expensive and I could not justify purchasing it since I only use Word when I’m forced to. Still, it might work for you.

Anyways, this might be the first post of a series. I’m going to use it to drop little bits of vim lore that I want to remember for the future.

How do I use Vim input methodology for my text boxes in Firefox?

I think I mentioned it before but I use the It’s All Text! plugin. It puts a tiny little button next to all the textarea elements on the page. Pressing that button opens up the textarea contents in your editor of choice. For me that’s gVim but just about anything will do.

Hey, emacs guy - did you hear that? That one will be useful for you too. Write it down. MS Word guy, STFU! You don’t get to say anything!

There is another plugin out there called MozEx which seems to be doing something very similar. I haven’t tested it but it seems like it will also let you use vim for textareas.

I use It’s All Text! and my HTML doesn’t get highlighted

That’s because the plugin saves your buffer as a txt file. I got around this by simply forcing all text files to highlight as if they were HTML. It doesn’t really affect normal .txt files, but if you plug some HTML into one of them, it will look nice. If you want to do the same, just paste this into your .vimrc

au BufRead,BufNewFile *.txt setfiletype html

Luke, why is this post so long? How many words have you typed so far?

I don’t know, let me check…

g<Ctrl+g>

I typed 520 words so far. I’m like halfway done so stop whining. Anyway, this is how you do it. Select some text, then press g and then Ctrl+G and you will see bunch of useful information in the status line. For example, the number of words you have typed so far. Cool, eh? It’s especially useful if you are trying to meet some word count requirement. Which, I usually don’t do very often as you might have noticed. I start typing, and then stop when the post seems like it’s done.

Heh, I wonder how many times you typed the word “vim” in this post?

Again, not sure, but let me check…

:%s/vim //gin

I typed it exactly 7 times. Yep, it’s another nifty trick - you can use the good old regular expressions in a non-standard way. For example the n modifier will prevent the replacement taking place in the regex above. Instead vim will simply print out the number of matches on the status line.

Finally, last tip of the day:

How do I delete everything from the cursor up to but not including a specified character sequence?

A little specific, isn’t it? But it is useful when you want to delete a big chunk of text. I mean, yes there is always the good old dt command which deletes till the first occurence of a character that follows it. There is also d) which deletes the whole sentence and d} which deletes the whole paragraph but this let’s you be very, very specific. Here is how you do it:

d/char-sequence

That is, you press d (or c if you just want to switch to insert mode), then press ‘/’ to enter search mode, enter a character sequence, and hit return. This also works with other commands so you can also do:

v/char-sequence

That’s all I have for now. I hope you enjoyed this quick batch of Vim tips. And if you didn’t I don’t care. The emacs guy over there seems happy because he found out It’s All Text! plugin and the MS Word guy is crying cause I called him names. Eh…

There might be more of these. )

Enabling Polish Letters (Ogonki) in Vim

Tuesday, August 19th, 2008

This is one of these things that I always need to look up. I know this tip will probably have no relevance for 98.5% of my regular readers, but I wanted to put it here for future reference. Also, since I just spent like 20 minutes googling the solution perhaps this can be of service for people who run into the same issue.

Today was the first time since I last reinstalled Windows when I needed to type something in Polish inside Vim and I realized that my Alt-gr combinations are not working. In other words I could not type letters such as ł, ą, ę, ż, ź, ś, ć, ó and etc.. You’d be surprised how often these come up in an average sentence. Surprisingly enough, I had no such problem on Ubuntu where they worked just fine. Windows version however refused to cooperate.

I did a quick google search for “vim polish characters” and got basically nothing. Then I tried few search queries in Polish and still got little info. Then I realized I was approaching this wrong, and my issue was caused by two factors:

  1. Vim was not in a Unicode compliant mode
  2. The font I was using (Bitstream Vera Sans Mono) was not Unicode friendly

So I set out to fix this. How do we get Unicode characters to work properly in Vim on Windows? Easy, just paste the following snipped into your _vimrc:

if has("multi_byte")
     set encoding=utf-8
     setglobal fileencoding=utf-8
     set bomb
     set termencoding=iso-8859-15
     set fileencodings=ucs-bom,iso-8859-15,iso-8859-3,utf-8
endif

Explanation can be found in Vim Tip #246. The if statement is a safety precaution since your version of the editor may not be compiled with the multi_byte feature which is required for Unicode to work properly.

Next you need a unicode friendly font. Bitstream Vera Sans Mono did not have the right Glyphs. Neither did Lucida Sans Typwriter. However Lucida Console, Curier New and the Consolas font all worked just fine. I really can’t tell you which fonts will work and which wont. You should probably just type some interesting word like “Gżegżółka” into the editor and just try different fonts until you find the one you like. For example Bitstream Vera Sans looks like this:

Bitstream Vera Sans

On the other hand Consolas font looks like this:

Consolas

In my case I simply added the following line to _vimrc to change the font to Consolas:

set gfn=Consolas:h10:cANS

I hope that someone will find this helpful. I’m posting it under a Google friendly title in case someone else needs to figure this out they can easily find it here. For those of you who could care less about Polish characters, vim or unicode I apologize. It had to be done. Now we can return to our usual brand of craziness that you came here to read. P

My Firefox Extensions - Let Me Show You Them

Thursday, March 6th, 2008

Considering my stats, and the comment threads, I can safely say that majority of readers here use Firefox. So let’s share the best/favorite extensions out there. Here are the ones I use. You probably already know some of them, but some might be new to you - perhaps you will look through this list and find something cool that you didn’t eve know existed. I hope you share your cool choices in comments.

Adblock or Adblock Plus

Adblock is a must in this day and age. I use Adblock on my laptop and Adblock Plus on my desktop and I don’t see any real difference between the effectiveness of the two. Both have finely tuned filters built up over years of me manually killing every add banner I could find. So most sites I visit these days are add free. I usually white list some blogs which I want to support and which have unobtrusive adds though.

Adsense Notifier

This one will probably be of interest only to people who both own websites, and use Google Adsense. I simply like to be able to peek in the status-bar and know how little money this website is making each month. Thanks for clicking them add things guys!

CuteMenus Crystal SVG

This one is purely aesthetic. It adds nice Crystal SVG style icons to the rather bland Firefox menus (both pulldown and context). I usually run with the standard theme (just make the icons smaller) but this little extension makes it more lively. And there is a small usability boost here - these icons actually help you navigate by using visual cues instead of reading.

Dummy Lipsum

What do you do when you need to populate some web form with random text? Do you drum on they keyboard and type in “asdadffsdf sdf sf” or do you use some form of the Lorem Ipsum text which is typographically similar to English and has been used by typesetting industry for ages?

This extension allows me to generate a random Lorem Ipsum fragment by simply right clicking inside of a textarea or a textbox and choosing an option from the context menu. I use it constantly at work - very convenient.

Fasterfox

Allegedly it makes FF faster by doing all these about:config tweaks that people used to constantly blog about. I have been using it forever, but I never didn’t benchmarked it. I don’t know if it actually makes a difference anymore, but it doesn’t seem to be giving me any problems so meh..

Faviconize Tab

Let’s you reduce the size of selected tabs so that they only show the favicon. I use it all the time at work keeping my google reader, twitter, gmail and Terminally-Incoherent tabs nicely minimized in the corner.

Firebug

Absolutely necessary. I have no clue how people used to code Javascript stuff without it. It is extremely helpful and if you do any web design that requires you to mess around with client side code, definitely get this plugin. It saves lives.

Gmail Manager

Lets me know when I get a new email. Wordpress emails me whenever someone posts a comment here.Since I almost always have Firefox open when I’m on the computer and I’m not playing games, I get almost a live feed of what is going on here, and what you guys are saying. I don’t always have time to read and respond immediately but I know that something is up as soon as I glance in the right corner of FF. I use my Gmail account strictly for fun and socializing - so a blue email icon always lets’ me know there is some interesting email and/or blog comment to read.

Google Notebook

I use Google Notebook as sort of a permanent clipboard which persists between my desktop and laptop. I mostly use it for copying interesting quotes, URL’s or making quick todo notes. Not terribly useful but has slightly more functionality than some bookmark syncing strategy.

Greasemonkey

I used to use it more in the past, but both Firefox and web applications that I used kinda caught up by now. So at the moment the only script I have in there right now is the one that removes music from MySpace pages. Not that I browse myspace more often that like 3 times a month, but when I do I don’t want to be assailed by a cacophony of sound.

IE Tab

Let’s me open IE in a FF tab. I used to use that a lot when my work required us to enter time in a crappy IE only online app. Fortunately we no longer use that POS system. I don’t get much more use of it these days but it’s not a bad thing to have.

Image Zoom

I actually don’t know why Firefox doesn’t have this functionality by default. It let’s you zoom images either using presets, by typing in pecentage/dimensions or gradually by using right-click+scroll combo.

It’s All Text

This one puts a little button in the corner of each text-area. If you click it, it opens a text editor of your choice (vim in my case) and populates it with the text from the box. Whenever you save in the text editor, it refreshes the textarea in the browser. So not only do you get to type in your favorite editor (vim key bindings) when you blog or comment. If the browser ever crashes for whatever reason , your text will still be in the opened text editor.

Check it out. I really like this one.

Linkification

Linkify is great - it will take any URL and convert it into a clickable link. It is one of those extensions that you tend to rely on without even realizing it. You only notice how much you were using it when it’s gone.

Live HTTP Headers

This is an extension that is nice to have, but you won’t use it very often. It lets you peek at the HTTP headers in real time. Since I installed it, there were maybe 4 times that I actually needed to use it. It’s probably worth having it just for shits and giggles.

PDF Download

Prevents Adobe from opening PDF files as a browser plugin and gives me a choice of whether I want to open it using the default reader, save it to disk or try to view HTML if possible. It’s a small thing but it really makes a difference when you deal with a lot of PDF files online.

Twitterfox

There are no good Twitter clients for Linux. I was searching for something like Snitter to run on Gutsy. I failed. Instead I found Twitterfox which is the next best thing. It’s small, unobtrusive and just works - lettign me follow tweets as I work without obsessively looking at my Twitter hompeage.

That’s all I have for now. How about you guys? Do you have some cool extensions that I should know about, but I didn’t list them here? Let me know!

Using CPAN version of WWW::Mechanize with ActiveState Perl on Windows

Monday, February 25th, 2008

I end up doing this each time I reinstall windows, and every time I forget how I did it, so I figured I’ll archive the process here. Perhaps it will help some of you. And I know, someone will say why don’t you use the PPM repository. Let’s just say i don’t want to. I want to grab the latest WWW::Mechanize package from CPAN and run with it.

Why am I posting it now? Because I needed to reinstall windows once again on my desktop, and now I need to get my blackboard scrips to work again.

This is really a multi step process. I’ll assume you have perl installed already. If not, you can get Activestate Perl which works pretty well on windows. Just grab the MSI package, install it and all the useful tools including perl, cpan and ppm will land in your path. From there follow these 3 easy steps:

Step 1: Get nmake

You will need nmake - the windows version of the make utility to compile most of the CPAN packages. How do you get nmake? There are several ways to do it, but probably easiest one is to grab the Microsoft version of the tool from their knowledge base. Once you download it, dump it somewhere in your path. It doesn’t really matter where it is, but I stuck it in the bin directory of my Perl install.

Step 2: Get YAML from CPAN

You will need YAML to build WWW::Mechanize. What is YAML? Sort answer is: do you care? Long answer: look it up. All you need to know is that you need it. So run cpan from your console and type in:

install YAML

This should cause some streaming text on the screen as the package is fetched and compiled. If it fails, make sure nmake is in your path, and that it is named nmake.exe and not something else.

Step 3: Install WWW::Mechanize

Final step is the easy one - just fetch and install the WWW::Mechanize package using the traditional method:

install WWW::Mechanize

Make sure you do step 1 and 2 before you try this. If you have tried this before you installed YAML the build will fail for some reason. To avoid that, just quit cpan, and run it again. This will clear the local cache and will re-fetch the package for a clean build.

So, there you have it. I know it’s a bit of a dry and uninteresting post for Monday morning. But this is more of a reminder to myself than anything else. I never remember where to grab nmake or what is that other package without which nothing ever builds on windows. Hopefully some of you will find it helpful. )