Sunday, April 26, 2009

encrypting from the command line

This can be done from Linux, or any of the BSDs that have the openssl tool.

To encrypt

openssl enc -bf -in infile -out outfile.enc

enc is the encrypt command
-bf tells openssl to use the blowfish cipher
-in and -out are self-explanatory.
(I use the enc file extension to classify files that have been encrypted)

To decrypt:

openssl enc -f -bf -in infile.enc -out plainfile

-d add this flag to indicate that we are decrypting.

Note that you probably should choose a really passphrase.

Wednesday, April 22, 2009

vim: trailing spaces

Part of our coding standards is the absolute prejudice against trailing whitespace.

I often run the following vim regex to look for such creatures:

/\s\+$

Even better yet, add the following to your vimrc to show you where these pesky creatures live:

syntax match ToDo /\s\+$/


Note: I used ToDo out of personal taste. Some people might prefer to use Error. :)

PS. Related post: vim: How To Highlight Unwanted Spaces


vim: how to undo the undo

One of the first things you learn in vim is how to undo changes using u. (Duh!)

The quetion is, how do you undo the undo if you've accidentally pressed u?

Well the answer is:

:redo

or shortens to:

:red

(note, in case you haven't figured it out yet, the bits and pieces here are not earth shattering. Since nobody really even reads this blog, I really only use it for myself.)

Thursday, April 16, 2009

vim: seeking %

I use vim for my text editing needs. And I've recently been coding a lot in Python. Python, as you may well know, is a "{}"-less language. It depends on semantic whitespace to mark out blocks of code.

I find this to be very intuitive. But the one place I miss the braces is when I need to find the beginning (or end) of a block. Normally one can use the "%" command in vim to do this in C code. Alas no such luck for Python. (Remember the semantic whitespace? :)

(Note: I'm misusing the term "command" here. The more accurate description is cursor motion command, but that seems rather long. ;)

I found a little hack to get around this obstacle. Just make sure that Python blocks don't have empty lines in them. The aptly named "{" and "}" commands take you to the beginning and ending of a paragraph respectively. (Just make sure there are no empty lines.)

python global pre version 3

A snippet from the Python tutorial:

A special quirk of Python is that – if no global statement is in effect – assignments to names always go into the innermost scope. Assignments do not copy data — they just bind names to objects. The same is true for deletions: the statement del x removes the binding of x from the namespace referenced by the local scope. In fact, all operations that introduce new names use the local scope: in particular, import statements and function definitions bind the module or function name in the local scope. (The global statement can be used to indicate that particular variables live in the global scope.)

This may save a beginning Pythonista lots of subtle bugs later on. :)
nonlocal is a new language feature in version 3 that I will write about some time soon.

Wednesday, April 15, 2009

distroaddict: Qimo 4 Kids

Found a new Linux distro, Qimo 4 Kids. It claims to be appropriate for kids aged 3 and up. I've been thinking of coming up with a new distro, and this seems to be an underserved niche of the distro market. Stay tuned for a review of Qimo.

vim regex negative match

I know how to negate a single character match using the

[^x] - for a single character
[^a-z] - for a range of characters

I needed to be able to do a negative match (that is, match everything EXCEPT the regex pattern) for a project.

The easiest way I found that worked for my little problem was using the

:v/someregex/

command. This is similar to the :g// command except that it returns everything except the regex matches.

I think that you might also be able to use the negative lookahead regex pattern. I will save that for a future article.

Update: The negative look-ahead assertion articles is here!

Wednesday, April 8, 2009

gimp mini tip 1

I'm a learn as I go gimp user.

When fooling around with layers and transparencies once, I found on the web how to erase/unerase.

To erase simply use the "eraser" tool (duhhh).
To unerase, use the eraser tool while holding down ALT.

Simple!

simple webscraper in python

Found this on the python lists:

import os
site = 'website.com'
X = os.popen('lynx --dump %s' % site).readlines()


Obviously, you need lynx on your system. Links and elinks can probably be suitable replacements.

Coolness.

Sunday, April 5, 2009

hex editor for Linux

I needed a hex editor to search through a binary file. The best one I found was the Bless hex editor (http://home.gna.org/bless/).

I also tried tweak, hexcurse, vche and khexedit.

tweak, hexcurse and vche are good because they can be used on the console. Bless seems better than khexedit. Bless made it easy to view the binary data in different format, so that's what made it work for that particular use. I'm sure I can find a use for the other editors eventually, especially the console ones.

Looking for Linux books?

Wednesday, April 1, 2009

using links to download ftp files nonanonymously

How's that for a very specific tip?

Well I didn't want to emerge ftp in my gentoo installation and links was there. So I took it as a challenge to figure it out. I seem to remember being able to do that a long time ago. Found the answer here.

In short do this:

links ftp://username:passwd@hostname.sample/directory

In other words, it's not very secure. :) But sufficient for my internal network ftping needs...

Of course ncftp r0xx0r, so this is a very limited use tip.

opensuse 11.1

I love trying out new distros and it's been a while since I tried installing Suse. Back when I tried it, it was still called Suse. Now it's opensuse and they're at version 11.1.

Highlights include:

- KDE 4.1.3
- pretty fast graphics even using a software OpenGL implementation
- software installation is pretty slick (Yast is pretty good)
- (btw, pure_ftpd is a lot faster than vsftpd. not sure which is more secure, but I only use it internally anyway...)

Up next, PCBSD...

figuring out the MAC address

I needed to find out the MAC address on a Windoze XP box. On Linux, one simply types ifconfig. The equivalent ipconfig on WinXP did not do the trick.

Turns out you have to supply the /all as such:

ipconfig /all

Little things. (This IS the little tech tips blog after all. :p)
That raspberry goes out to a readership on none. ;)