off by one

Categories: pedro | technical:hack

[Add new subcategory] [Edit] [Delete]

Super cool idea -- using servers to heat homes:

Why not heat your home and water with a rack of servers?. From clickolinko.

[Edit me!]

resizing windows in ubuntu:

Like many hackers I'm constantly looking at or moving around tons of different terminal windows, which often need to be resized. Compiz in Ubuntu includes the Grid plugin, which at first I thought was super annoying, what with its automatically resizing my windows for no apparent reason. But then I set some hotkeys that make my life easy. Basically, using the modifier <Ctrl><Alt><Shift> and the keys A,Q,W,E,D,C,X,Z and S, I can stuff a window into various quadrants or halves of the screen. It's REALLY handy for lining up two vertical terminals side by side on today's widescreen monitors.

But the other day, I was using a crufty old P4 with an ancient video card do I had to fall back to GNOME. Boy, did I miss grid. But in googling around, I found out that in addition to ALT-leftbutton_drag to move windows, there's also ALT-middlebutton_drag to resize windows. I thought, "that's dumb"... but then I tried it and it's pretty awesome, especially when moving windows from a bigger monitor to a smaller monitor when grid or maximize gets confused. A little middle-button alt dragging and things are just right.

I actually have a whole set of left-hand chording shortcuts for window management that I'll post about at some point later. It makes window management for multiple terminals and desktops super easy.

[Edit me!]

hey, I should do^H^H^H^H see if someone has done that:

So you're diving through folders, looking for some files or data. Of course you're using Nautilus since you're running GNU/Linux and Gnome*. You get to your file, "ah ha, you found it" only to realize that you really wish you had a command line to slice and dice the file. What you'd love is to be able to just "open a terminal here". I just had that experience, and like usual (thanks to the long tail), someone else has already done this. If you're using Ubuntu (or possibly Debian) you can simply 'apt-get install nautilus-open-terminal'. Enjoy!

* No offense implied to anyone else, I'm just being silly.

[Edit me!]

Sometimes I can be a little too sensitive...:

Case-sensitivity is a given in most *NIX and programming environments. But in your editors and tools, case sensitivity is a double-edged sword. Sometimes it's nice to have case-insensitive search so you can find every matching sequence, but just as often I end up getting "too many hits". And doing find and replace insensitively can be really annoying. If only there was a smarter way to manage case!

There is. vim has a neat feature called "smartcase" that searches insensitively if you use all lower-case, but searches case-sensitively if you include any capital letters in your search. So,

/foo

... would find "foo", "Foo", "fOO", etc., but

/Foo

... would only match on "Foo".

To enable smartcase, you also need to enable case-insensitivity. You can put this in your .vimrc:

set ignorecase " Do case insensitive matching

set smartcase " I'm sensitive, but not too sensitive.

However, if you want to do this on a case by case basis, you can do this in vim at runtime with :set ignorecase and :set smartcase. (:set nosmartcase and :set noignorecase will undo the option.) Happy hacking!

[Edit me!]

Storing Research Data -- SQLite vs. The Other Guys :

I generally have a real aversion to using a full-on SQL implementation like MySQL or Postgres when it's not really necessary... and I typically think it's unnecessary until something forces me to change my mind. When I started writing small projects in Perl, I used to use Berkeley DB key-value pairs — lately I've used Python Pickles for similar purposes. It's simple and quick, which is nice, but it basically forces you to roll your own code.

Lately, everyone's been getting on the SQLite bandwagon, and it's pretty awesome. I've moved to using SQLite as my first choice when storing anything beyond flat text data. It has nice portability characteristics (unlike your homemade solution), simple backup and export formats. And, being able to make queries on the data is great for me, since these days most of my data are experimental results, etc.

But another good reason for using an external, portable data sink became obvious when I started to visualize and analyze my data using R. R has the RSQLite package, which made importing data into R for plotting and analysis a breeze. (Or as much of a breeze as anything is in R.) The thing is, roll-your-own formats may be perfectly "good enough" for isolated projects, but the minute you start wanting to use a different tool to view the data, having it already be in a format that is easily accessible is a major win. And if you're like me, you won't always know that in two months you're going to want to use the data in some completely different way. So I feel like I got that capability for "free" just because I decided to store my data in a more structured and portable way.

But SQLite is targeted at a specific niche — projects that would benefit from SQL behaviors but don't need all the robustness and consistency guarantees of "enterprise" databases. While you get good performance (because SQLite works inside your code, rather than through RPCs), if you start wishing for read/write concurrency (say, importing new data and plotting other unrelated data at the same time) you may find yourself frustrated with SQLite's limitations. That's what happened to me. As I started to generate large numbers of plots, I wanted to be able to run multiple scripts (some of which generate plots, some of which update other tables) at the same time — SQLite can balk at this.

So, I switched to a more traditional SQL database, which itself was relatively painless because of the underlying SQL standard. (R has libraries for it as well — another good reason not to roll your own even if you don't need all that SQL provides.) And in turn, this highlighted another unexpected value for the more "enterprise" systems: caching. Re-running long queries just to tweak a plot is considerably quicker with the big server as opposed to SQLite.

None of this is new information — in fact, it's a pretty textbook tour of the hows and whys of data storage. But for me, it inspired a change of heart, thanks to the convenience factor. In the future, I'll probably start with a Big Dog SQL server for research projects (running on my personal laptop) because it avoids the papercuts encountered when my projects get to big for SQLite. But I'll stick to SQLite for simpler things, to avoid the dependencies created by the more enterprise approach.

[Edit me!]

Changing references from parens to brackets...:

In Word 2007 (at least) in order to change references from using parentheses to using square brackets requires editing XML! Boooo.

http://channel9.msdn.com/forums/Coffeehouse/240589-Word-2007-citations-should-be-simple-but-solved/

[Edit me!]

mairix rocks:

If you're like me, and if you're reading this there's at least a possibility you are, you don't keep your email at Gmail or in Thunderbird or Mail.app or wherever -- you keep it the way Ray Tomlinson intended -- on a server where you read it in plain text format. I use mutt with mboxes, but there are a lot of other possibilities. Anyway, after 10 or 20 (or more!) years of archiving your mail, it sometimes gets hard to find what you're looking for. Well, mairix is just the tool for you -- it incrementally indexes messages, and returns search results as a folder of messages for you to look in. It's free software, it's fast, and available in Ubuntu.

[Edit me!]

Throbbing You Blind:

So, I couldn't leave well enough alone. I was also too burned out on work to make progress, so I went back and revisited the N throbber, using the simpler technique (shrink at RGB, then index colors), and also added an alpha channel. I think it looks a lot better.

But I couldn't stop there -- I did what I probably should have done first -- I made a throbbing "F" for Firefox in the style of the N throbber. See yesterday's post for instructions to install it.

[Edit me!]

[Comments] (3) Highway Throbbery:

I've always wanted to get the old-timey Netscape "N" throbber working in Firefox, just for some of that retro feel. I found an old copy of the "N" throbber in my files and updated it for use with Firefox.

Here are some instructions for changing your throbber.

And here is an archive with the necessary files for that 90s feel. (Soul Asylum MP3s not included.)

The original throbber was 16 colors (EGA) and 30x30, but Firefox uses 16x16, 20x20, and 24x24 throbbers. Scaling the old dithered throbber looked awful, so I converted the GIF up to RGB, replaced the dithering with a solid color and made resized versions. However, the original GIF had an EGA palette, so converting the resized GIFs looked awful -- what I needed were more shades of the colors used in the image. With a limited palette, I could get several shades of each color within the 8-bit limit (DOOM used a similar trick). So, I stretched and blurred the RGB image and converted it back to 8-bit to make a reasonable indexed colormap (here are my source files). Then, I applied that map to my resized GIFs. Now you can party like its 1995!

[Edit me!]

firefox forwards and backwards navigation:

Thinkpad laptops have two special "forward" and "backward" keys above the typical left and right keys that are used for paging in applications like Firefox and other web browsers. Unfortunately, they don't work out of the box in Ubuntu like other buttons (like the volume knobs, suspend, etc.). I hate using Alt-Left/Right -- why make two keystrokes when I should be able to use one?

So I have been looking for a solution, but complicating this issue is that old solutions to this problem don't work in Firefox +v2.0, firefox extensions that advertise this ability are pre 2.0 as well, and Firefox remote tricks assigned to commands don't seem to work either (I think because of a vulnerability in Firefox remote? I'm not sure.)

Anyway, this site has a working howto, and it's really easy. The short version is to edit your ~/.Xmodmap to make back (keycode 234) and forwards (keycode 233) F19 and F20, and then edit browser.xul to use that instead of the Alt-Arrow combos. For Ubuntu anyway one thing different from the howto is that browser.xul is already unzipped in /usr/share/firefox/chrome/ ... etc, not in your homedir or .mozilla, etc. Just edit it and save it; you don't need to re-package chrome or whatever although you do need to restart Firefox. This material should get updated in the ThinkWiki and other sites... but I'm not going to do it.

Incidentally, the "back" and "forward" buttons on the new Microsoft Natural Ergonomic Keyboard 4000 use the same keycodes, so if you have one attached to your Thinkpad like me, this is a two-for-one deal.

Update: You can leave the old hotkeys in and just add the new ones to keep the old "alt-arrow" mapping and add the new thinkpad arrows if you want! Beaujolais!

[Edit me!]

cool screen tricks:

I used to do this one all the time, but recently forgot it. I had to look it back up again.

Anyway, when you're using screen (which is all the time, right?) and you wish that a particular screen was at a different index (like let's say when you're running some job that you don't want to start over) you can just reassign its index like this:

<escape>:number n

... where escape is probably control-a (aka C-a in screen lingo) and n is the numeric index you'd like the screen to be at.

Yes, it's just that simple!

Another cool screen trick that I'm going to throw in for FREE (if you call in the next 30 seconds) is nesting screens. There are two ways to do this:

1. Set a unique escape in each screen. You can do this by setting a new escape in one of the screens:

<escape>:escape ^Xx

... to set the escape to control-x in that screen. Then you can pick up the screen inside another screen and use the appropriate escape sequence in each screen context.

2. In this method, you don't change the escape sequences at all, but you just hit the sequence twice to "drill down" into a nested screen. So for example, if you have a screen within a screen, and within the nested screen you want to change to the next window, type:

<escape><escape>n

... where merely typing

<escape>n

... would just change the screen in the "top level" screen.

At these prices you can't say no!

[Edit me!]

cool vim trick:

You can split windows in vim and keep multiple files open. This isn't usually that interesting to me because I use screen for everything and memory usage isn't really an issue.

What *is* useful is that you can have two views into the same file -- so if you want to reference something way up top but you're working way down at the bottom, you can split your view. Here's how:

:sp (splits window) CTRL-W up (move up) CTRL-W down (move down) :q (closes this window)

You can find a lot more info and additional commands if you search for "vim split window" or somesuch.

Pretty rad!

[Edit me!]

T happy birthdays / encrypted Ubuntu:

Two birthdays to celebrate: One, The Tastytronic Diner is now in its 5th year. And two, Dumont the IO Tower Guardian, keeper of the clickolinko is now in his 7th year of operation. We figured out his birthday -- 950341551 (Sat, 12 Feb 2000 07:45:51 GMT) -- today after never having known it.

I also recently found Encrypted Filesystem HOWTO for Dapper which I'm using to build an encrypted backup server for flynn. It seems to work.

[Edit me!]

T cool vim trick:

So, I've seen vim configured to open and place the cursor in the last cursor position in that file before closing, and at first I thought it was annoying. Then I started to like it. Now I miss it. It was bittersweet though; I thought I would want it enabled in my .vimrc, but would I find myself getting annoyed by it? Intrigued, I went looking for an answer, and instead found that the command '" (that's a single quote followed by a ") jumps to that position -- essentially, when you close vim, it sets a mark for that position to the character " and, as we all know, ' is the "jump to" command. So now I don't have to have it as a default -- but any time I want it, it's there.

[Edit me!]

T .ssh/config:

Set ssh defaults for different hosts.

[Edit me!]

T gnome-terminal:

control-'-' and control-'+' increase and decrease the font size in the active window. Pretty cool!

I'm one of those people who thinks that it should probably be control-'=' so that I don't have to do control-shift-'='... but maybe that's just me. It seems a little pedantic to make people press shift.

[Edit me!]

T hot vim tip sandwich (au jus):

vim has a cool "delete-from-here-to" feature. In command mode, put your cursor where you want to start deleting. Then, type 'd/n', where n is a regex describing where you want to stop deleting. vim should show you where you are deleting to, either by highlighting, or by moving the cursor. When you're pleased with your regex, hit enter. Bam!

[Edit me!]

[Main]

Unless otherwise noted, all content licensed by Peter A. H. Peterson
under a Creative Commons License.