robfelty.com


Git tip – restoring “lost” commits

Posted in wordpress

Quarter note = 06222018 robfelty
Treble clef 4/4 Time
I ran into a git issue today where I thought I was ready to push a recent commit, and the push failed, saying that I was in the middle of a rebase. I don’t remember starting a rebase, but maybe I did. I tried git rebase –continue, but that didn’t work, so then I tried git rebase –abort. That fixed the issue about being in the middle of a rebase, but it also threw out my commit. It was a […] (Read more)

UNIX tip of the day: two file processing with AWK

Posted in wordpress

Quarter note = 01202018 robfelty
Treble clef 4/4 Time
I recently came across some AWK code from a work colleague that I did not understand at all awk -F'\t' -v OFS='\t' 'FNR==NR{a[$1]=$1;next};$1 in a{print $1,$2,$3}' file1 file2 I usually like to understand code instead of blindly copying and pasting, so I did a little research into what this was doing. Searching for “awk FNR NR” got me to this stackoverflow page: linux – What is “NR==FNR” in awk? And that led me in turn to this excellent article about […] (Read more)

UNIX tip of the day – trap EXIT

Posted in wordpress

Quarter note = 08102017 robfelty
Treble clef 4/4 Time
I was reading a shell script today and came across the trap command, which I was not aware of. Some googling led me to this article: How “Exit Traps” Can Make Your Bash Scripts Way MoreRobust And Reliable , which has a really nice explanation. Basically, trap acts sort of like a finally block in a try/catch pattern. Very useful for shutting down services, cleaning up temp files and such. I think that trap is specific to BASH, so you […] (Read more)

UNIX tip of the day – grep -P is slow

Posted in perl, regex, UNIX

Quarter note = 09282016 robfelty
Treble clef 4/4 Time
Unless you really need some advanced regular expressions only supported by PCRE, using POSIX regular expressions with grep is usually an order of magnitude faster – that’s because the default engine with grep uses finite automata, as opposed to a backtracking algorithm which PCRE uses ( the main featuress you gain from the backtracking algorithm are lookahead/lookbehind and backreferences) Here’s a small example $ time grep -E 'post:content.*facebook' a_bunch_of_files* | wc -l 1643 real 0m2.643s user 0m1.304s sys 0m1.306s $ […] (Read more)

Improving my coding efficiency in vim

Posted in javascript, php

Quarter note = 04142016 robfelty
Treble clef 4/4 Time
I have been using Vim for most editing for about 12 years now. I think I tried it for the first time in about 2003, and quickly gave up. Then in 2004 my roommate at the time convinced me to give it another try, and I quickly got hooked. I wrote my dissertation completely in vim. I have been coding in vim since then. I frequently find myself accidentally typing hjkl in non-vim editors. I feel I am pretty efficient […] (Read more)