wholemeal

Complete | Quality

Kill All Tabs in Eclipse

As a long time Vim user, I have the following config in my ~/.vimrc to ensure I never ever enter an evil tab character into my source code.

set   shiftwidth=2
set   tabstop=2
set   smarttab
set   et

For my Android projects, I’m starting to use Eclipse, and unfortunately eternally banishing all tabs in Eclipse is not such an easy task. Here’s where I’m at so far, YMMV and I’ll update this as I find more. It seems the tab boss is difficult to kill in this app.

  • Under Window -> Preferences -> General -> Editors -> Text Editors ensure Insert spaces for tabs is checked.
  • Under Window -> Preferences -> Java -> Code Style -> Formatter create a new profile based off the default, and under the Indentation tab set Tab policy to to Spaces only.

Secure Password Storage With Vim and GnuPG

There are a raft of tools out there for secure storage of passwords, but they will all come and go, Vim and GnuPG are forever.

Here’s the config:

augroup encrypted
    au!

    " First make sure nothing is written to ~/.viminfo while editing
    " an encrypted file.
    autocmd BufReadPre,FileReadPre      *.gpg set viminfo=
    " We don't want a swap file, as it writes unencrypted data to disk
    autocmd BufReadPre,FileReadPre      *.gpg set noswapfile
    " Switch to binary mode to read the encrypted file
    autocmd BufReadPre,FileReadPre      *.gpg set bin
    autocmd BufReadPre,FileReadPre      *.gpg let ch_save = &ch|set ch=2
    autocmd BufReadPost,FileReadPost    *.gpg '[,']!gpg --decrypt 2> /dev/null
    " Switch to normal mode for editing
    autocmd BufReadPost,FileReadPost    *.gpg set nobin
    autocmd BufReadPost,FileReadPost    *.gpg let &ch = ch_save|unlet ch_save
    autocmd BufReadPost,FileReadPost    *.gpg execute ":doautocmd BufReadPost " . expand("%:r")

    " Convert all text to encrypted text before writing
    autocmd BufWritePre,FileWritePre    *.gpg   '[,']!gpg --default-recipient-self -ae 2>/dev/null
    " Undo the encryption so we are back in the normal text, directly
    " after the file has been written.
    autocmd BufWritePost,FileWritePost  *.gpg   u

    " Fold entries by default
    autocmd BufReadPre,FileReadPre      *.gpg set foldmethod=expr
    autocmd BufReadPre,FileReadPre      *.gpg set foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':1
augroup END

Now, open a file, say super_secret_passwords.gpg and enter your passwords with a blank line between each set:

My Twitter account
malc : s3cr3t

My Facebook account
malc : s3cr3t

My LinkedIn account
malc : s3cr3t

When you write the file out, it will be encrypted with your GPG key. When you next open it, you’ll be prompted for your GPG private key passphrase to decrypt the file.

The line folding config will mean all the passwords will be hidden by default when you open the file, you can reveal the details using zo (or right arrow / l) with the cursor over the password title.

I like this system because as long as I have gpg and my private key available, I can extract any long lost password from my collection.

Building RedCloth With Bundler and GCC 4.6

Getting ready to work on a problem in Rails on an Ubuntu Oneiric (11.10) machine, I ran across the following problem running bundle install for Rails core:

$ bundle install
Updating git://github.com/rails/arel
Updating git://github.com/rails/journey
Fetching source index for http://rubygems.org/
Using rake (0.8.7) 
Installing RedCloth (4.2.7) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /home/malc/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb 
checking for main() in -lc... yes
creating Makefile

make
gcc -I. -I/home/malc/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/x86_64-linux -I/home/malc/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/home/malc/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1 -I.   -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long  -fPIC -O0 -Wall -Werror  -o redcloth_scan.o -c redcloth_scan.c
gcc -I. -I/home/malc/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/x86_64-linux -I/home/malc/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/home/malc/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1 -I.   -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long  -fPIC -O0 -Wall -Werror  -o redcloth_inline.o -c redcloth_inline.c
ragel/redcloth_inline.c.rl: In function ‘red_block’:
ragel/redcloth_inline.c.rl:99:9: error: variable ‘attr_regs’ set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors

make: *** [redcloth_inline.o] Error 1


Gem files will remain installed in /home/malc/.gem/ruby/1.9.1/gems/RedCloth-4.2.7 for inspection.
Results logged to /home/malc/.gem/ruby/1.9.1/gems/RedCloth-4.2.7/ext/redcloth_scan/gem_make.out
An error occured while installing RedCloth (4.2.7), and Bundler cannot continue.
Make sure that `gem install RedCloth -v '4.2.7'` succeeds before bundling.