[ 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<br />

extract audio from video using ffmpeg


1
ffmpeg -i video.avi -q:a 0 -map a audio.mp3<br />

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\] "<br />

create keys for a ssh session

from the client machine and user
1
2
3
4
5
<br />
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa<br />
cat ~/.ssh/id_rsa.pub &gt;&gt; ~/.ssh/authorized_keys<br />
ssh-copy-id -i /home/user/.ssh/id_rsa.pub user@host<br />
ssh user@host<br />

bash, convert space delimited string into array

1
2
3
<br />
arr=($line)<br />
echo ${arr[2]}<br />

 

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 &gt; /proc/sys/vm/drop_caches'

linux disable paste on middle mouse button

1
2
# disable middle button<br />
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
12
<br />
sh#fname="etc/ntp.conf"<br />
sh#echo ${fname%%.*}<br />
/etc/ntp<br />
sh#basename $fname<br />
ntp.conf<br />
sh#basename ${fname%%.*}<br />
ntp<br />
sh#dirname $fname<br />
/etc<br />
sh#echo ${fname##*.}<br />
conf<br />

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-&gt;loc == NULL || b-&gt;loc-&gt;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 &gt; /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
6
<br />
#start line<br />
start=10<br />
#how many lines to show<br />
page=5<br />
head -n $(($start + $page)) filename | tail -n $page<br />

grep xml files with xpath

Use xgrep 
1
2
<br />
echo 'hola'| xgrep -x '/root/value/text()'<br />

ping all hosts in a ipv4 C network

Sends pings to 1-254 addresses simultaneously


1
#!/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
}
1
 

1
for a in $(seq 1 254); do<br />   ping_to_server $1.$a &amp;<br />done<br />


example use:
1
2
3
4
5
6
7
<br />
alex@paco ~ $ bash ping.sh 192.168.1<br />
alex@paco ~ $ 192.168.1.39 alive<br />
192.168.1.1 alive<br />
192.168.1.35 alive<br />
192.168.1.250 alive<br />
192.168.1.34 alive<br />

1
<code>

little shellscript to sync two folders automatically


1
2
<br />
#!/bin/bash<br />
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

1
 

1
 

linux touchscreen rotation


1
2
3
4
5
6
7
8
9
10
11
12
13
<br />
    # for asus T101ha is right , device 13<br />
    normal)<br />
      xinput set-prop 13 "Coordinate Transformation Matrix" 1 0 0 0 1 0 0 0 1<br />
      ;;<br />
    inverted)<br />
      xinput set-prop 13 "Coordinate Transformation Matrix" -1 0 1 0 -1 1 0 0 1<br />
      ;;<br />
    left)<br />
      xinput set-prop 13 "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1<br />
      ;;<br />
    right)<br />
      xinput set-prop 13 "Coordinate Transformation Matrix" 0 1 0 -1 0 1 0 0 1

1
 
get windows license key

Using admin CMD:

wmic path SoftwareLicensingService get OA3xOriginalProductKey

 

1