[ snippets and notes ]

convert a video to standard avi format

1
ffmpeg -i input.mkv -vcodec mpeg4 -b 4000k -acodec mp2 -ab 320k output.avi

extract audio from video using ffmpeg

1
ffmpeg -i video.avi -q:a 0 -map a audio.mp3

add time to bash prompt

1
export PS1="\e[0;31m$(date +%H:%M:%S) ${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] "

create keys for a ssh session

from the client machine and user

1
2
3
4
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh-copy-id -i /home/user/.ssh/id_rsa.pub user@host
ssh user@host

bash, convert space delimited string into array

1
2
arr=($line)
echo ${arr[2]}

 

ccmake release with debug info

RelWithDebInfo

eclipse indexer does not find std::shared_ptr

Right click your project and click Properties
Under C/C++ General click “Preprocessor Include Paths, Macros”
Select the Providers tab
There should be an item in the list that says something like “GCC Built in Compiler Settings”. Select this entry.
Uncheck the “Use global provider…” option
Under the list there’s an box that says “Command to get compiler specs.” Append “-std=c++0x” to this.
Move the “GCC Built in Compiler Settings” provider at the top of the list using the ‘Move Up’ button on the right.
Click Apply and then OK.
Back in your Eclipse workspace, select the Project Menu, C/C++ Index, and click “Re-resolve unresolved includes.”

from stackoverflow

linux clean cache disk

1
sync ; sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'

linux disable paste on middle mouse button

1
2
# disable middle button
xmodmap -e "pointer = 1 0 3 4 5"

sudo withno password for a user

in the last line of /etc/sudoers

1
user ALL=(ALL) NOPASSWD: ALL

compiling in ubuntu

/usr/bin/ld: cannot find crt1.o: No such file or directory
1
sudo ln -s /usr/lib/x86_64-linux-gnu /usr/lib64

get parts of filenames with bash

A file named (for example) /etc/ntp.conf

1
2
3
4
5
6
7
8
9
10
11
sh#fname="etc/ntp.conf"
sh#echo ${fname%%.*}
/etc/ntp
sh#basename $fname
ntp.conf
sh#basename ${fname%%.*}
ntp
sh#dirname $fname
/etc
sh#echo ${fname##*.}
conf
echo ${fname%%.*} /etc/ntp
basename $fname ntp.conf
basename ${fname%%.*} ntp
dirname $fname /etc
echo ${fname##*.} conf

disable buffering in stdout for shell | pipes

To disable completely

1
stdbuf -i0 -o0 -e0 command

To do it for line (faster)

1
stdbuf -oL -eL command

from stackoverflow

when gdb fails to set an exception raise event …

And says

1
breakpoint.c:5997: internal-error: print_one_breakpoint_location: Assertion `b->loc == NULL || b->loc->next == NULL' failed.

use function breakpoint on __cxa_throw

1
break __cxa_throw

gdb for everyone in ubuntu

open /etc/sysctl.d/10-ptrace.conf and set kernel.yama.ptrace_scope = 0

or

1
# echo 0 > /proc/sys/kernel/yama/ptrace_scope

Error : /bin/rm: Argument list too long

Alternative:

1
find /path/to/files -name "*" | xargs rm

get part of file using tail and head

1
2
3
4
5
#start line
start=10
#how many lines to show
page=5
head -n $(($start + $page)) filename | tail -n $page

grep xml files with xpath

Use xgrep

1
echo 'hola'| xgrep -x '/root/value/text()'

ping all hosts in a ipv4 C network

Sends pings to 1-254 addresses simultaneusly

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash

if [ "$1" == "" ]; then
echo "$0 C network"
echo example: $0 192.168.1
exit
fi

function ping_to_server {
ip=$1
ping -c 2 $1 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "$ip alive";
fi
}

for a in $(seq 1 254); do
ping_to_server $1.$a &
done

example use:

1
2
3
4
5
6
alex@paco ~ $ bash ping.sh 192.168.1
alex@paco ~ $ 192.168.1.39 alive
192.168.1.1 alive
192.168.1.35 alive
192.168.1.250 alive
192.168.1.34 alive