28 May 2012

An Exercise: Contact Scraping or How to Get Hired with ZeroMail

I’m trying out ZeroMail and saw their job listing at zeromail.

Though I’m happily and gainfully employed, it looked like an interesting exercise. The challenge is (verbatim from website): (1) Download http://zeromail.com/static/download/emails.txt (2) Write a python program that extracts contact information from signatures in the emails (3) Send your solution to bart@zeromail.com or skype it to bartjellema

After an hour of tinkering with it on my own terms (my Ruby > my Python), I’m realizing it’s more complex than I initially expected.

I see it as a multipart process: (1) Strip junk characters and lines out of the data (2) Determine and locate signature blocks (3) Extract pertinent data from signature blocks (might resort to wordlists of given names)

I tried using easily identifiable information through regexes (ie looking for Australian and US format phone numbers). This yielded decent results on the numbers themselves and I’m considering using phone number’s (or email addresses’) line numbers as ‘hotspots’ that I can extract and further process.

If I spend more time on the process, I’ll post my results here.

27 May 2012

Todo.txt Count in RPrompt ZSH

I’ve been using Todo.txt for at least a year, both from the commandline and the Android app.

It’s great keeping a todo list in text files, synchronized across multiple devices via Dropbox, but there’s one nagging thing in my system.
That nagging issue is that Todo.txt doesn’t nag me enough about the issues in my todo list! So, I’m taking steps to resolve this by adding a function to my zshrc configuration.

I mapped out the basic command in the shell by combining todo’s ls, grep (to keep only lines starting with numbers), and then a wordcount by line.

The following function was taken from Wynnnetherland.com and modified since I installed todo.txt through Homebrew, and since I prefer a different command to count the items.

todo\_count(){ if $(which todo.sh &\> /dev/null) then num=$(echo $(todo.sh ls | grep "^[0-9]" | wc -l)) let todos=num if [$todos != 0] then echo "$todos" else echo "" fi else echo "" fi } function zle-line-init zle-keymap-select { RPS1="${${KEYMAP/vicmd/\>\>\> ○[$(todo\_count)]}/(main|viins)/± \<\<\<[$(todo\_count)]}" RPS2=$RPS1 zle reset-prompt }

The following is a diff of the difference showing the updated function [gist id=2817309]

Now my right hand prompt shows a nice count of incomplete todo items inside square brackets…like so: [gist id=2817339]

Update: My own syntax highlighting is escaping some of the characters, so here’s a gist of it [gist id=2817304]

24 May 2012

VIM Movement command of the Day

The movment letter of today for VIM is G Using ‘G’ moves to the end of the file (or more specifically to the final line of the file).

The complimentary command is ‘gg’, to jump to top of file!

VIM: The more I learn, the better it gets.

22 May 2012

Why I love Open-Source Software

Open-source software is wonderful. For example, I needed to batch convert 700 AutoCad files (DWG) into regular image files.

Step one: Find library to do this for me. Succeeded by finding cad2svg. Can’t run as its compiled in OSX, can’t recompile b/c it has unavailable proprietary blob. Read author’s blog & README. He states that it was developed in Red Hat Linux/ Fedora. Blog is dated ~ 2009.

Off I go to grab Fedora 12. Install in virtual machine, set up shared folder between host and vboxclient. Use script like find . -name \*.dwg -print0 | xargs -0 cad2svg - OUTPUT.svg

Then jump back into OSX to use a library from Cairo 2d image library, svg2png. This will convert them into png images.

Do some googling for correct imagemagick settings to invert the image, convert all non-white to black, and then convert to monochrome.

Spent a few minutes tweaking the settings, order of events, properly piping the output image from svg2png into imagemagick… and voila! Computer is currently chugging through all 700 conversions. Command to convert from svg to png (with tweaks) svg2png -w8000 '#{item}' | convert png:- -negate -fill black +opaque white 'svgs/#{output}.png' (Note: Piping these two commands saves writing temp file to hard drive) ImageMagic, svg2png, cad2svg (except proprietary blob) are great tools made even greater by their Unix philosophy (doing one thing well and using standard-in and stdout to chain together commands)

21 May 2012

5 Days of OSX

Well, it’s been 5 days since getting an OSX laptop (MBA) and it’s treating me pretty well.

Here are some initial impressions: Some of the coolest things: 1. Spotlight 2. Quicksilver (launcher app) 3. Quickcursor (vim geek app lets edit with vim everywhere… like this an email or blog post) Thanks to Conner’s Blog4. Touchpad is magnificent… crazy amount of multitouch gestures 5. System based on BSD Mach kernel… allowing all sorts of Unix-compliant goodness Along with that goes MacVim, iTerm2, growl, and all my unix commandline favs 6. Homebrew and MacPorts… both very good but not as well integrated as Debian’s apt-get and Arch’s pacman. Oh well, still waiting for slick Linux laptop with the hardware support of OSX…(not holding my breath)

What’s not so cool: 1. Learning new keyboard shortcuts 2. Fn key is a complete waste of space, need to remap it to be Ctrl (Did this with KeyReMap4Macbook: Note that the config can be tricky depending on other keyboard tweaks, but it’s now working) 3. Logitech mouse is a bit tweakier than under Linux & windows. (Update: MagicMouse looks pretty cool, esp with multitouchtool) 4. Terminal based VIM is SegFaulting with one of my addons (it allows me to blog from commandline for blog.xargs.io, my tech blog. Thankfully it works ok in MacVIM). Haven’t solved this yet but with it working for 99% of my tasks… the troubleshooting can wait for a rainy day. Maybe updating Mac’s pre-installed python…and recompiling VIM.

21 May 2012

Using ZSH's History Incremental Search with Vi-Mode

I switched to ZSH a few months back and am spending more and more time in commandline + VIM/MacVIM.

Once I added the tag to my dotfile to force vi-mode on the commandline I lost the ability to do incremental searches of my zsh history. So here’s the fix which saves lots of typing:

First, the regular keybind to allow Ctrl-R to enter history search backward mode: bindkey "^R" history-incremental-search-backward

To fix the fact that the prior keymap no longer works in vi-mode zsh, add this to a zsh config: bindkey -M viins '^R' history-incremental-search-backward bindkey -M vicmd '^R' history-incremental-search-backward

Now I can ^R with aplomb…

This is thanks to the explanation from JDeBP over on superuser.com.

20 May 2012

Useful VIM cheetsheet

New VIM command of the day: d/(searchterm) This will delete up until the search term.

Source of this wisdom: VIM Commands

20 May 2012

VIM Video by Bram

Watched this video today by the author of VIM: Bram MoolenaarVIM Video by Bram Moolenaar

It’s about 1.3 hours long and worth the watch.

A useful tip so far is the \*

Which uses your current word as a search term and incremental searches forward.

12 May 2012

Keeping Track of Config Files with Git and Dropbox

Dotfiles are all the rage right now on Github, and for a good reason. They’re the files that allow you to configure your Vim, Linux, Mac, etc. They’re simple textfiles written in a specific format for each given application. Being a textfile they’re easily added to a version control system like Git or Mercurial and changes can be tracked, commited, diffed, etc.

How does it work? Make a folder in your Dropbox folder and place config files there.

mkdir ~/Dropbox/dotfiles
mv ~/.vimrc ~/Dropbox/dotfiles/.
ln -s ~/Dropbox/dotfiles/\* ~/.

The first command creates the folder. The second command moves the .vimrc configuration file into that folder. The last command symbolically links all files/folders inside the dotfiles folder into the base of the home folder, ie /home/tevic/.

Add all those files into a git repository via a git init; git add .; git commit -m "Initial Commit with Vimrc". Now you can also use git for tracking changes on various branches.

I’ve been very happy with storing my vimrc, zshrc, ~/.config/zsh.d, ~/.vim/ configurations in Dropbox. Switching to a new computer or reconfiguring is no effort whatsoever.

12 May 2012

My current favorite VIMRC one-liner

Very handy for quickly swapping between prior file and current file in VIM:

Add the following to VIMRC: nnoremap <leader>, :b#<cr>

My current leader key is set to comma (,) so punching ,, switches between prior and current file, or back again.

Runner up for other good one liners: inoremap jk <esc> This one allows you to stay on the commandline and ESCAPE out of insert mode by using key combo ‘jk’!Note: I find this faster than a more common binding of ‘jj’ for this purpose. With jj the same finger needs to activate the key in quick succession. With j & k the right hand index and middle finger both activate at a similar time. Thus my preference goes to the slightly easier and faster option.

Source & Credit: Gary Bernhardt’s Dotfiles on Github (though escape sequence of jj swapped to j k)

PS - The only conflict I’ve had with j k being an ESC sequence is this blog post. In code and prose I haven’t run into problems.