2018/08/30

Perl code inside quotes

Run Perl code inside the quotes:

"Can't load ${\( $0 . 'hey' )}"

2018/06/01

Bash help

set -e : Exit immediately if a command exits with a non-zero status
set -u : Treat unset variables as an error when substituting

set -o pipefailNormally, pipelines only return a failure if the last command errors. In combination with set -e, this will make your script exit if any command in a pipeline errors.

2017/09/11

2017/06/12

Subclassing with overriding in Perl

package MyClass;

use strict;
use warnings;

use parent 'ParentClass';

sub new {
    my $class = shift;
    my %options = @_;
    my $self = $class->SUPER::new(@_);
    $self->{my_option} = 1 if $options{my_option};
    return $self;
}

sub my_option {
    my $self = shift;
    $self->{my_option} = shift if @_;
    return $self->{my_option};
}

sub overridden_sub {
    my $self = shift;
    my %args = @_;
    if ($self->{my_option}) {
        return do_my_logic_here();
    }
    return $self->SUPER::overridden_sub(@_);
}

2017/01/30

Vim Git trick

http://felixge.de/2013/08/08/vim-trick-open-current-line-on-github.html

~/.gitconfig:
[alias]
    url =! bash -c 'git config --get remote.origin.url | sed -E "s/.+:\\(.+\\)\\.git$/https:\\\\/\\\\/github\\\\.com\\\\/\\\\1/g"'

~/.vimrc:
nnoremap <leader>o :!echo `git url`/blob/`git rev-parse --abbrev-ref HEAD`/%\#L<C-R>=line('.')<CR> \| xargs open<CR><CR>

--

nnoremap <leader>o :!echo `sed -e 's,:,/,;s,git@,https://,;s,.git$,,' <(git ls-remote --get-url)`/blob/`cat .git/ORIG_HEAD`/%\#L<C-R>=line('.')<CR> \| xargs open<CR><CR>