2014/09/19

Sed

Print only lines you want:
sed -n 41,43p file.txt
sed -n 42p file.txt

Tabs to spaces:
sed -i.bak -re 's/\t/    /g' file1

Print lines matching pattern:
sed -ne '/Failed: [^0]/p' results.txt

Delete a line matching pattern and the following 4 lines:
sed -e /pattern/,+4d file


Delete lines matching certain regex:

rg regex -l dir | xargs sed -i '' -E '/regex/d'

find dir -type f | xargs sed -i -E '/regex/d'

echo -e 'file1 \n file2' | xargs sed -i -E 's/regex1/regex2/g'
echo -e 'file1 \n file2' | xargs perl -p -i -e 's/regex1/regex2/g'

2014/08/13

Vim search non-ascii

/[^\x00-\x7F]

:highlight nonascii guibg=Red ctermbg=Red
:match nonascii /[^\x00-\x7F]/

2014/06/27

Convert mp3

Convert m4a to mp3


$ sudo apt-get install ffmpeg
$ vi m4a-mp3.sh

#!/bin/sh

for m4a in *.m4a; do
    mp3=`echo "$m4a" | sed -e 's/m4a$/mp3/'`
    if [ ! -e "$mp3" ]; then
        ffmpeg -i "$m4a" -acodec libmp3lame -ab 256k "$mp3"
        test -s "$mp3" && rm "$m4a"
    fi
done

$ chmod +x m4a-mp3.sh
$ ./m4a-mp3.sh

Convert flac to mp3


$ sudo apt-get install ffmpeg
$ vi flac-mp3.sh

#!/bin/bash

for a in ./*.flac; do
  ffmpeg -i "$a" -qscale:a 0 "${a[@]/%flac/mp3}"
done
 

$ chmod +x flac-mp3.sh
$ ./flac-mp3.sh 

Convert legacy ID3 tags 


$ sudo apt-get install python-mutagen
$ mid3iconv -e cp1251 ~/mp3/*

2014/06/20

jQuery delegate

$('body').delegate('*', 'focusin focusout', function(e){
    if ( e.type === 'focusin' ) {
        console.log('target: in ' + e.currentTarget.id);
    }
    else if ( e.type === 'focusout' ) {
        console.log('target: out ' + e.currentTarget.id);
    }
    e.stopPropagation();
    element.focus();
});

$('body').delegate('*'...) should be changed to $(document).delegate('body'...) - unproven
Then there should be $(document).undelegate('body'...)

2014/05/14

Fedora 20 install kde

# yum -y install @kde
# yum -y install dconf-editor
$ dconf write /org/gnome/shell/always-show-log-out true
[logout]