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

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

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.

29 Apr 2012

Easier Directory Navigation

Source: http://stackoverflow.com/questions/3986760/cd-1-2-3-etc-in-z-shell

While looking for a zsh compatible way to replace AutoJump with a ZSH compatible option, I found the following: setopt autocd setopt AUTO\_PUSHD The first option allow moving into a new directory by directly typing it’s name without ‘cd DIRECTORY’.

The second option allows easier navigation using ‘dirs -v’ to check for recent directories or cd ~+<tab> for tab completion jumping :).

Another little way to save small repetitions!

As a side note: I’m quite sad not to have the flexibility of AutoJump in my repetoire with ZSH. It’s the only feature I find lacking compared to BASH. Hopefully it works better in ZSH in the near future, or hopefully I can look into why it doesn’t work and learn how to patch it.

28 Apr 2012

My Kingdom for a Good Fuzzy Finder

I’ve been working on my VIM configurations recently which involved cleaning out cruft from when I hadn’t transitioned to using Pathogen. While doing so I realized that I wanted to take the advice of DestroyAllSoftware.com and switch away from Nerdtree to something that doesn’t involve a context switch. CtrlP to the rescue! Slick addon that I’m happy to have in my arsenal. Plus, it didn’t necessitate installing and configuring VIM with Ruby 1.8.7 as Command-T did :).

25 Apr 2012

Converting to Arch Linux

It’s been about 4 months now since I switched my HP Tm2t to ArchLinux.  This came after using my laptop for work  with necessary proprietary programs on Windows and dual booting into Crunchbang Linux (Debian based). Well, I upgraded the work laptop to a Vaio workstation replacement i7 w/ nVidia dedicated GPU which freed up my Tm2t! In my excitement, I swapped out the 500GB spinning platter drive for a 60GB 3Gbps SSD, installed ArchBang Linux, and couldn’t be happier. ArchBang is based on the style and concept of Crunchbang Linux (Openbox Minimalism with high utility) but based on the packaging system and system structure of Arch Linux.  This 2-3 yr old laptop is very quick and a nice environment for evening Ruby programming & development. I replaced Openbox with XFCE because my minimalism doesn’t run quite that deep, installed RVM, Chromium, gmrun, configured keyboard shortcuts for Terminator, spacefm (slick file manager), and then spent the next few weeks working on final optimizations (feeling pretty good about the 3+ hours of battery life under Linux). Now if only my touchpad had the quality of a MacBook Pro under Linux (or even the quality of the touchpad under W7), the battery lasted 5+ hrs like W7, and a high resolution screen.  I’m on the lookout to upgrade from this laptop once a decent high resolution ultra portable comes out, preferably from Lenovo’s Thinkpad line.

20 Feb 2012

Fixing 'Disk Not Found' Error in Grub after apt-get upgrade

One of my development virtual machines went belly up after a recent system upgrade. After tinkering around at the grub> prompt to no avail, I booted a LiveCD, followed the instructions here: http://sazeit.com/articles/repair-or-reinstall-grub-with-boot-repair, and was up and running in minutes. Moral of the story; sometimes it’s more important to solve the problem than understand the underlying issues…not often, but sometimes :).

05 Oct 2011

Uggh - "Puppet hostname doesnt match server certificate"

Wow, this one stumped me for the better part of 12 hrs… So Puppet (the Ruby Gem) uses SSL certificates to authenticate to the Puppet Master.  I kept receiving the warning listed in the title of this post no matter how I altered my configs. Here’s the short version: Determine what Fully Qualified Domain Name is being used by the PuppetMaster to created the signing cert.  On my virtual platform this ended up being the hostname Add that hostname/FQDN and it’s IP address to your PuppetClient’s /etc/hosts like so: 173.999.999.999 &nbsp; &nbsp;hostname Now start up the PuppetMaster Server with the following command # puppetmasterd --verbose --no-daemonize Now invoke the puppet client like so: puppet agent --no-daemonize --verbose --server=HostnameOfServer Finally, now that we know it’s working well edit the /etc/puppet/puppet.conf on Puppet Client so that you have a server entry in the [main] section: [main] server=HostnameOfServer Tada!   Source of partial answer: Puppet hostname doesnt match server certificate - Server Fault.