2014/12/26

Diff commands

diff -u <(./cmd1) <(./cmd2)

Find files without some content:
diff -u <(ag -l) <(ag -l content) | grep "^-\b"

To install ag:
https://github.com/ggreer/the_silver_searcher

Get the filepaths out of a diff:
ag '^\+\+\+' diff | cut -d' ' -f2 | sed -re 's,^b/,,'
ag '^\+\+\+' diff | cut -d' ' -f2 | sed -e 's,^b/,,' | sed -e '/\/dev\/null/d'

2014/12/16

Alt-tab in KDE4

System Settings -> Desktop -> Desktop Effects -> All Effects -> Flip Switch (tick and apply)

2014/12/09

Vim Tabular plugin

0. Links:
http://vimcasts.org/episodes/aligning-text-with-tabular-vim/
https://github.com/godlygeek/tabular
https://github.com/tpope/vim-pathogen

1. Install pathogen:
mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

2. Configure pathogen:
vi .vimrc:
execute pathogen#infect()

Now any plugins you wish to install can be extracted to a subdirectory under ~/.vim/bundle, and they will be added to the 'runtimepath'. Observe:
cd ~/.vim/bundle && \
git clone git://github.com/tpope/vim-sensible.git

3. Install tabular:
cd ~/.vim/bundle
git clone git://github.com/godlygeek/tabular.git

4. Configure help:
vim
:Helptags

5. Read help:
vim
:help tabular

6. Use:
<select lines>
:Tab /=
:Tab /\.

2014/12/04

X session

Start clean X session:
$ xinit /usr/bin/xterm -- :1

Keyboard keys

Extra keyboard keys
Console:
# showkey --keycodes

GUI:
$ xev | grep -A2 --line-buffered '^KeyRelease' | sed -n '/keycode /s/^.*keycode \([0-9]*\).* (.*, \(.*\)).*$/\1 \2/p'

2014/12/01

Grub

vi /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg

2014/11/19

How many hours ago was the file changed?

FILE="/path/to/file"
CURRENT_DATE=$(date +%s)
PREVIOUS_DATE=$(date -d "$(ls -ld $FILE | awk '{print $6,$7,$8}')" "+%s")
DELTA=$(( CURRENT_DATE - PREVIOUS_DATE ))
DELTA_HOURS=$(echo "scale=2; $DELTA / 3600" | bc)
echo $DELTA_HOURS hours ago

2014/11/04

List broken link(s)

Also catches cyclic links:
find /path/to/search -type l -exec test ! -e {} \; -print

Does not catch cyclic links:
find /path/to/search -xtype l

Deprecated:
find /path/to/search -L -type l 2>/dev/null | xargs ls -l

2014/10/24

Try::Tiny::Retry

#!/usr/bin/env perl

use Try::Tiny::Retry;

my $current = 1;
sub get_next {
    return $current++;
}

retry {
    print get_next() . "\n" and die;
}
catch {
    print "catched\n";
}
finally {
    print "finally\n";
}

2014/10/23

ssh proxy

$ ssh -D 8080 myssh.server.com
Firefox: SOCKS proxy: 127.0.0.1 8080
http://whatismyip.com

Traffic goes like this:
local:8080 -> myssh.server.com -> internet -> myssh.server.com -> local:8080

2014/10/09

Skype statuses

Perl вдалося зробити те, чого не вдалося Java (незважаючи на неспівмірну наявність коштів та кадрів): священний Грааль "напиши раз ─ запускай де завгодно" (write once ─ run anywhere)

Найбільшою перевагою Perl є його спільнота


Always code as if the guy who ends up maintaining your code

will be a violent psychopath who knows where you live

cd /usr/ports && make srach

make: don't know how to make srach. Stop

If you feel the urge to shoot yourself in the foot by using multiple inheritance, Perl is not going to stop you

В умовах сучасного аутсорсу, на запитання "Які патерни ООП Ви знаєте?" слід відповідати:
- Костилювання, Інкостиляція та Полікостилізм


The only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle

In my opinion, it is embarrassing that humans spend so much time in school learning to execute algorithms that, quite literally, require no intelligence







Bash server

Server:
while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; } | nc -l 8080; done

Client:
nc localhost 8080

2014/09/26

Update bash

yum localinstall https://kojipkgs.fedoraproject.org//packages/bash/4.2.47/2.fc19/i686/bash-4.2.47-2.fc19.i686.rpm

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]

2014/04/25

Fedora: rpmfusion

su
rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm

2014/04/18

Refresh your page automatically

<meta http-equiv="refresh" content="nSeconds;URL">

Maximum z-index

var a = document.body.getElementsByTagName("*"); var zmax = 0; for(q in a){ try{ if(jQuery(a[q]).css("z-index") !== "auto" && zmax < jQuery(a[q]).css("z-index")){ zmax = jQuery(a[q]).css("z-index"); } }catch(e){ } } console.log(zmax);

2014/03/07

Resize images

Preserve ratio:
convert 1.png -resize 250x250 2.png

Don't preserve ratio:
convert 1.png -resize 250x250\! 2.png

2014/03/05

Manage yum repos

List repos:
# yum repolist

Disable/enable repo:
# yum-config-manager --disable/--enable local

Add remote repo:
# yum-config-manager --add-repo http://www.example.com/example.repo

Add local repo:
# vi /etc/yum.repos.d/local.repo
[local]
name=Local Repo
baseurl=file:///home/michael/Downloads
gpgcheck=0
enabled=1
# yum-config-manager --disable local
# yum install createrepo
# createrepo -v /home/michael/Downloads
# yum-config-manager --enable local

----------------------------------------------------

[ERROR]

# yum update
...
           Installing: kernel-devel-3.14.22-100.fc19.i686 (updates)
               kernel-devel-uname-r = 3.14.22-100.fc19.i686
 You could try using --skip-broken to work around the problem
** Found 1 pre-existing rpmdb problem(s), 'yum check' output follows:
kde-settings-kdm-19-28.fc19.noarch is a duplicate with kde-settings-kdm-19-23.fc19.noarch

# yum info kde-settings-kdm-19-28.fc19.noarch
...
Repo        : installed
From repo   : updates

# yum info kde-settings-kdm-19-23.fc19.noarch
...
Repo        : installed
From repo   : koji-override-0

# yum remove kde-settings-kdm-19-23.fc19.noarch
...
Running transaction
/var/tmp/rpm-tmp.uMYK1k: line 1: fg: no job control
error: %preun(kde-settings-kdm-19-23.fc19.noarch) scriptlet failed, exit status 1
Error in PREUN scriptlet in rpm package kde-settings-kdm-19-23.fc19.noarch
  Verifying  : kde-settings-kdm-19-23.fc19.noarch                                                                                
Failed:
  kde-settings-kdm.noarch 0:19-23.fc19                                                                                                     Complete!

[SOLVED]

# rpm -e --nopreun kde-settings-kdm-19-23.fc19.noarch

# package-cleanup --dupes
Loaded plugins: auto-update-debuginfo, langpacks, refresh-packagekit

2014/03/04

2014/02/27

BCDD

New development methodology:
BCDD - Burndown chart driven development

2014/02/05

Java is not working

/usr/java/jre1.7.0_45/bin/jcontrol
Security -> Medium -> Apply
Advanced -> Mixed code -> Disable -> Apply
Ok
Restart browser

2014/02/03

Firefox plugins

Adblock Plus (must-have)
Firebug (must-have)
iMacros (automation)
NoSquint (page zoom)
Status-4-Evar (green loader)

2014/01/31