Tuesday, January 15, 2013

Short hint for all those who use vim and pathogen

Today, after updating my wokspace to latest version I encounter below error during vim running:
Error detected while processing function pathogen#runtime_append_all_bundles:
line    1:
E121: Undefined variable: source_path
E116: Invalid arguments for function string(source_path).') to pathogen#incubate('.string(source_path.'/{}').')')
E116: Invalid arguments for function 4_warn
Press ENTER or type command to continue
Quick look on pathogen runtime_append_all_bundles function and I found:
call s:warn('Change pathogen#runtime_append_all_bundles('.string(a:1).') to pathogen#incubate('.string(a:1.'/{}').')')
So simply replacing:
call pathogen#runtime_append_all_bundles()
with:
call pathogen#incubate()
in $HOME/.vimrc fix the problem.

Sunday, November 18, 2012

Sqlite3 gem not supported on Heroku

When I tried to deploy second part of RoR tutorial to Heroku I get this error:
       An error occurred while installing sqlite3 (1.3.5), and Bundler cannot continue.
       Make sure that `gem install sqlite3 -v '1.3.5'` succeeds before bundling.
 !
 !     Failed to install gems via Bundler.
 !
 !     Detected sqlite3 gem which is not supported on Heroku.
 !     http://devcenter.heroku.com/articles/how-do-i-use-sqlite3-for-development
 !
 !     Heroku push rejected, failed to compile Ruby/rails app

To git@heroku.com:thawing-beyond-7283.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:thawing-beyond-7283.git'
I searched a little bit about this error and find this stackoverflow post. But when I look more carefully on the Gemfile syntax I found a mistake. I used simply:
gem 'sqlite3', '1.3.5'
But I should have:
group :development do
  gem 'sqlite3', '1.3.5'
end
group :production do
  gem 'pg', '0.12.2'
end
As RoR tutorial states.

Prepare for Ruby on Rails on Debian wheezy

I start to learn Ruby on Rails. As always when you learn new programming language toolchain is required. In this tutorial I will try to go through toolchain preparation for my Debian wheezy. Of course I based on Vim as my editor of choice. Second requirement will be using some parts of toolchain in latest greatest version.

As a beginner point for learning Ruby on Rails I choose this tutorial. I will try to use their methods of setting environment adding my comments where it is needed. Also will resolve Debian and Vim specific issues. So let's begin.

After quick look at RoR tutorial I have to switch to this site for installation for Ubuntu 12.04 LTS. But instructions don't work as expected for my Debian. So after quick:
sudo apt-get install git curl
I realized that I need proxy for curl and not only temporary but permanent. I added below line to my $HOME/.curlrc:
proxy=proxy.server.com:8080
After that I was able to download and install stable version of rvm:
curl -L get.rvm.io | bash -s stable
Next I sourced configuration:
source ~/.rvm/scripts/rvm
Output which I get was:
pietrushnic@lothlann:~/src/node$ rvm requirements
Requirements for Linux "Debian GNU/Linux wheezy/sid"

NOTE: 'ruby' represents Matz's Ruby Interpreter (MRI) (1.8.X, 1.9.X)
             This is the *original* / standard Ruby Language Interpreter
      'ree'  represents Ruby Enterprise Edition
      'rbx'  represents Rubinius

bash >= 4.1 required
curl is required
git is required (>= 1.7 for ruby-head)
patch is required (for 1.8 rubies and some ruby-head's).

To install rbx and/or Ruby 1.9 head (MRI) (eg. 1.9.2-head),
then you must install and use rvm 1.8.7 first.

Additional Dependencies:
# For Ruby / Ruby HEAD (MRI, Rubinius, & REE), install the following:
  ruby: /usr/bin/apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config

# For JRuby, install the following:
  jruby: /usr/bin/apt-get install curl g++ openjdk-6-jre-headless
  jruby-head: /usr/bin/apt-get install ant openjdk-6-jdk

# For IronRuby, install the following:
  ironruby: /usr/bin/apt-get install curl mono-2.0-devel
I need Ruby so copy&paste line for it and:
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config
Next thing we need is Node.js because this code of JavaScript runtime is under active development (latest version is 0.8.14 and Debian provided for sid 0.6.19) we use its latest greatest version from git repository.
git clone https://github.com/joyent/node.git
Following by:
cd node;./configure;make;make test
In my configuration only one test failed test-tls-server-verify:
Running 'Allow both authed and unauthed connections with CA1'

assert.js:102
  throw new assert.AssertionError({
        ^
AssertionError: agent1 rejected, but should NOT have been
    at ChildProcess. (/home/pietrushnic/src/node/test/simple/test-tls-server-verify.js:217:14)
    at ChildProcess.EventEmitter.emit (events.js:96:17)
    at Process.ChildProcess._handle.onexit (child_process.js:698:12)
    at process._makeCallback (node.js:248:20)
This is known issue probably we have to wait for update of OpenSSL library in wheezy. Ignore this problem and install node.js:
sudo make install
Because of RoR tutorial requirements we install version 1.9.3:
rvm get head && rvm reload
rvm install 1.9.3
Next thing will be adding vim-ruby for our favorite editor Vim. I organize my dotfiles using git. I also use pathogen to control Vim plugins (as described here), so :
cd workspace
git submodule add https://github.com/tpope/vim-rails.git dotfiles/vim/bundle/vim-rails
git submodule init && git submodule update
git commit -m "vim-rails submodule added"
Finally we have ready to use Ruby on Rails development environment based on Vim. I suggest to take a look at this movie and after that dive into tutorial.

Tuesday, November 13, 2012

New background and not so big "coming back"

It's been a long time since I last wrote anything on the blog. Because I hear complains about the background causing my blog hard to read I decide to change it.

I have little break in my side project and noticed that most read posts are related to some technical workarounds and solutions for different problems I decide to write a series about gcc errors and some solutions for it. I know it may sound like some complete spam and trash for blog, but when I searched for some explanation and solution of this errors sometimes it was hard to find them, sometimes it was hard to match with my code and finally sometimes I was unable to understand what is going on. I want to share what I learned and even if it wouldn't help anyone I want to have this in one place.

Recently I returned to my long-neglected hobby - chess. I will also try to write something constructive in this topic. Last time I also think a lot about embedded stuff (trying to reverse my printer), android (writing little project helping my colleague) and many other things. So maybe I will write about this. To not be boring I will simply get my hands dirty.

Sunday, May 13, 2012

Mutt tutorial part 4 - html mails, address book and other useful features

How mutt can handle mails in html format ? Takling about html mail handling is talking about handling any type of Multipurpose Internet Mail Extensions. Mutt supports handling for all MIME types in one place for all programs. This place is .mailcap file. Googling a little bit I found below mailcap file configuration (kudos to Bart Nagel).
text/html; pandoc -f html -t markdown; copiousoutput; description=HTML Text; test=type pandoc >/dev/null
text/html; lynx -stdin -dump -force_html -width 70; copiousoutput; description=HTML Text; test=type lynx >/dev/null
text/html; w3m -dump -T text/html -cols 70; copiousoutput; description=HTML Text; test=type w3m >/dev/null
text/html; html2text -width 70; copiousoutput; description=HTML Text; test=type html2text >/dev/null
Of course we need to install all applications to make mailcap work correct:
sudo apt-get install pandoc lynx w3m html2text
To bring address book functionality to mutt we need abook application:
sudo apt-get install abook
Also few new line in $HOME/.muttrc will be needed:
# add alias file for addresses
set alias_file=~/.mutt/alias
source ~/.mutt/alias
# configure addressbook
set query_command= "abook --mutt-query '%s'"
macro index,pager A "<pipe-message>abook --add-email-quiet<return>" "add the sender address to abook"
Adding new address simply create entry in alias file. During adding new alias abook asks about alias name, e-mail address, personal name and confirmation for given data. Some this fields could be filled automatically by interaction between abook and mutt. Of course file $HOME/.mutt/alias have to exist before running mutt:
touch $HOME/.mutt/alias
To access saved aliases simply click <Tab> button in cc, to or bcc filed.
There is few more options that I found useful. To find it please go to my workspace scripts at github. Also if you have any issues with the configuration or comments please let me know by commenting below the post.

Mutt tutorial part 3 - sidebar, URLs in e-mails

Information in this post came from lunar linux page. Kudos to its author. In this post I want to discuss two topics: sidebar and how to open urls form inside mutt. Sidebar is mutt feature delivered in mutt-patched package in Debian. It cause to split standard mutt window in two parts. In first we can find list of folders defined in the $HOME/.muttrc file, second window is a known old window with the list of posts. Mutt window with sidebar looks like on the picture below:
To use side bar we need to install mutt-patched packed in Debian:
sudo apt-get install mutt-patched
To make side bar more accessible I use default settings from lunar linux page. Add below lines to $HOME/.muttrc:
set sidebar_width       = 30
set sidebar_visible     = yes
color sidebar_new yellow default
bind index CP sidebar-prev
bind index CN sidebar-next
bind index CO sidebar-open
bind pager CP sidebar-prev
bind pager CN sidebar-next
bind pager CO sidebar-open
First line sets width of side bar it depends on how long are your folder names. Second line makes sidebar by default visible. Third makes folders with new messages yellow. Other lines create shortcuts for navigating sidebar. Note that C is not Ctrl but uppercase 'c' key. Second topic I want to discuss is how to open urls from inside e-mails. To do this we can use tip from mutt site. As it said we need urlview application:
sudo apt-get install urlview
To correctly configure this tool you need to create $HOME/.urlview file. So:
vim $HOME/.urlview
In this file we define two things. First will be regular expression which match urls and second will be command line to run when regexp was matched. File looks like below:
REGEXP (((https?|ftp|gopher)://|(mailto|file|news):)[^’ <>"]+|(www|web|w3).[-a-z0-9.]+)[^’ .,;<>":]
COMMAND chromium %s
Chromuim is my browser of choice but you can use firefox, lynx or anything you want.

Mutt tutorial part 2 - secure login

This is second post of mutt tutorial series. As in the previous post for below information I need to thank Kousik for posts about gpg and using it with mutt. But probably the most important to simplify this method was Fau comment here. So going to the point of secure login for mutt we need gpg. First of all we need to install it by simply:
sudo apt-get install gpg
After that we generate our keys by:
gpg --gen-key
I choose all default answers. So first is key type: 'RSA and RSA'. Second - keysize: 2048. Third - time for key expiration: '0 = key does not expire'. After that you need to identify your key with some data. This data will be used to find your key so IMHO it should be short and simple but meaningful. At the end of this process you will be asked about pass phrase, which will be used to decrypt files encrypted with generated key. When you end with key generation you can encrypt file with passwords. Best way to do this is to write some script that will be sourced by mutt after decryption. For storing passwords I create directory in my $HOME:
mkdir $HOME/.passwd
Inside this directory I create text file with the script, which look like below:
vim $HOME/.passwd/mutt.txt
set my_isp1 = "password1"
set my_isp2 = "password2"
set my_isp3 = "password3"
This script of course mean to set value of variable name my_isp{1,2,3} to some password string. Remember to use 'my_' prefix because this is the way that user variables should be defined in mutt scripts. After writing this file we need to encrypt it.
gpg -e -o mutt.gpg mutt.txt
Now we should delete txt file. To use our newly created encrypted password script we need to add some lines to $HOME/.muttrc. So:
vim $HOME/.muttrc
Line that we need before sourcing encrypted scripts is declaration of variables in the script:
set my_isp1 = ""
set my_isp2 = ""
set my_isp3 = ""
After this line we can source and decrypt out file with the passwords:
source "gpg --textmode -d ~/.passwd/mutt.gpg |"
At the end wee need to replace all out plain text passwords (smtp_pass and imap_pass variables) with variables defined in out encrypted file. This settings will cause that mutt during start will run gpg to ask about password to decrypt password script file. In the next post I will discuss mutt with sidebar and how to open html files from inside mutt.