[ snippets and notes ]

convert a video to standard avi format

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

extract audio from video using ffmpeg

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

add time to bash prompt

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

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


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

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

linux disable paste on middle mouse button

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

sudo withno password for a user

in the last line of /etc/sudoers
user ALL=(ALL) NOPASSWD: ALL

compiling in ubuntu

/usr/bin/ld: cannot find crt1.o: No such file or directory

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

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
stdbuf -i0 -o0 -e0 command
To do it for line (faster)
stdbuf -oL -eL command
from stackoverflow

when gdb fails to set an exception raise event …

And says
breakpoint.c:5997: internal-error: print_one_breakpoint_location: Assertion `b->loc == NULL || b->loc->next == NULL' failed.
use function breakpoint on __cxa_throw
break __cxa_throw

gdb for everyone in ubuntu

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

or

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

Error : /bin/rm: Argument list too long

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

get part of file using tail and head


#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 

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

ping all hosts in a ipv4 C network

Sends pings to 1-254 addresses simultaneously

#!/bin/bash
if [ "$1" == "" ]; then
echo "$ping all hosts in a ipv4 C network0 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:

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

little shellscript to sync two folders automatically


#!/bin/bash
if [ "$(which inotifywait)" == "" ]; then
echo "inotify-tools package needed, please install it."
exit
fi
if [ "$1" == "" ] || [ "$2" == "" ]; then
echo "help: $0 source_folder destination_folder";
exit
fi
source=$1
destination=$2
while inotifywait -r -e modify,create,delete "$source"; do
rsync -avz "$source" "$destination"
done

linux touchscreen rotation


# for asus T101ha is right , device 13
normal)
xinput set-prop 13 "Coordinate Transformation Matrix" 1 0 0 0 1 0 0 0 1
;;
inverted)
xinput set-prop 13 "Coordinate Transformation Matrix" -1 0 1 0 -1 1 0 0 1
;;
left)
xinput set-prop 13 "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1
;;
right)
xinput set-prop 13 "Coordinate Transformation Matrix" 0 1 0 -1 0 1 0 0 1

get windows license key

Using admin CMD:

wmic path SoftwareLicensingService get OA3xOriginalProductKey