Archive for the ‘tips’ Category

“tidify” a json in vim

Tuesday, February 17th, 2009

If you have to edit json files from vim, you may want to make them more readable, here is how you can do this:

start by installing the JSON::XS perl module from the CPAN

sudo cpan JSON::XS

then, edit your .vimrc and add the following

map <leader>jt  <Esc>:%!json_xs -f json -t json-pretty<CR>

now while editing a json file, you can hit ,jt (or whatever your is set to) and tidify a json.

vim and git

Friday, December 5th, 2008

idea from http://use.perl.org/~Ovid/journal/37966 (ovid is full of really good ideas for vim):

to get a quick git diff in my vim session, put this in your .vimrc


map ,gh   :call SourceDiff() " gh for git history

function! SourceDiff()
    let filename = bufname("%")
    let command = 'git log -5 --pretty=format:"%h - (%ar) %an - %s" "'.filename.'"'
    let result   = split( system(command), "\n" )

    if empty(result)
        echomsg("No past revisions for " . filename)
        return
    endif

    " get the list of files
    let revision = PickFromList('revision', result)

    if strlen(revision)
        let items = split(revision, " ")
         execute '!git diff ' . items[0] . ' -- "' . filename .'" | less'
    endif
endfunction

the output will look like

Choose a revision:
1: ea0bb4d - (3 days ago) franck cuny - fix new_freq
2: a896ac7 - (5 weeks ago) franck cuny - fix typo
3: c9bc5fd - (5 weeks ago) franck cuny - update test
4: e9de4be - (5 weeks ago) franck cuny - change the way we rewrite and check an existing url
5: 3df1fd6 - (7 weeks ago) franck cuny - put id category

You choose the revision you want to check the diff against, and you got a (colorless) diff in your vim buffer.

$PERL5LIB and zsh

Tuesday, October 7th, 2008

in my .zsh.d/S80_perl

 
# Perl
BASE_PATH=~/code/work/rtgi
for perl_lib in $(ls $BASE_PATH); do
    if [ -f $BASE_PATH/$perl_lib/Makefile.PL ]; then
        PERL5LIB=${PERL5LIB:+$PERL5LIB:}$BASE_PATH/$perl_lib/lib
 
    fi
done
export PERL5LIB

Customize your mysql prompt

Friday, August 8th, 2008

To customize your mysql prompt, create a .my.cnf file in your $HOME then add the following:

[mysql]
prompt="\\u [\\d] >"

It will look like this:

username [dabatases_name] >

Upgrading to perl 5.10

Monday, June 30th, 2008

Get the list of your installed 5.8 modules:

perl -MExtUtils::Installed -e'print join("\n", new ExtUtils::Installed->modules)' > module.list

then install Perl 5.10:

wget http://www.cpan.org/src/perl-5.10.0.tar.gz
tar xzf perl-5.10.0.tar.gz
cd perl-5.10.0
sh Configure -de -Dprefix=/opt/perl -Duserelocatableinc
make && make test
sudo make install
/opt/perl/bin/perl -e 'use feature qw(say); say "hi"'

and then re-install your modules

cpan `cat module.list`