суббота, 31 декабря 2011 г.

Projects of 2011

Knowledge area of the year:
  • ASP.NET MVC
  • Linux
  • Video
Most valuable projects:
  1. add audio stream selection to nginx's mp4 streaming plugin - c, linux
  2. asp.net mvc project for restaurant booking - asp.net mvc, jquery, entity code-first
  3. DVR (video server) - slackware linux based, mono, linux-live, gsoap, integrate usb device with libhid
  4. asp.net mvc project as web UI for face recognition service - asp.net mvc, jquery
  5. winforms application - UI for people psychology compatibility service. - winforms, bltoolkit, sqlite, custom controls, custom design applied.
  6. ffmpeg scripts: for video conversion to stream for iOS devices, to add watermark, to add overlays
  7. media-player-classic fork that can view customers video format

пятница, 18 ноября 2011 г.

bash howto's 3


#This will remove leading spaces...
echo " 1233 test " | sed 's/^ *//g'
#This will remove trailing spaces...
echo " test 543453 " | sed 's/ *$//g'


#Make the following XML file available under http://127.0.0.1:5555/
(printf "HTTP/1.1 200 OK\\r\\nContent-Type: text/xml\\r\\n"; \
printf "Content-Length: $(cat "response.xml"|wc -c)\\r\\n\\r\\n"; \
cat response.xml") | nc -l -p 5555 >/dev/zero 2>&1 &

воскресенье, 6 ноября 2011 г.

nginx mp4 streaming with audio stream selection

Tips:
compile nginx with nginx_mod_h254_streaming-2.2.7 module
nginx module debug tips:
-add to nginx.conf
worker_processes 1;
daemon off;
master_process off;
error_log /tmp/were/i/want/see/error.log debug;
-to improove rebuild time modify Makefile in nginx sources
change "rm -rf Makefile objs"
to "rm -rf objs/addon/src/* objs/nginx"

the magic is in mp4_reader.c

вторник, 18 октября 2011 г.

Как установить monodevelop на slackware 13.37

1. установить slapt-get
http://software.jaos.org/slackpacks/13.37/slapt-get/slapt-get-0.10.2l-i386-1.tgz
2. настроить прокси для slapt-get
для этого установить переменные окружения
export http_proxy=http://user:password@host:port
export ftp_proxy=http://user:password@host:port
3. Добавить репозитории для slapt-get
SOURCE=http://repository.slacky.eu/slackware-13.37/:OFFICIAL
SOURCE=http://download.salixos.org/i486/13.37/:PREFERRED
3. Обновить данные из репозиториев
slapt-get --update
4. Убедиться, что monodevelop есть в списке пакетов:
slapt-get --available | grep monodevelop
5. Установить
slapt-get -i monodevelop-2.8-i686-1sl


пятница, 23 сентября 2011 г.

bash howto's 2

#extract from tar.xz
tar -xpJf archive.tar.xz

#setup environment variable
export VAR_NAME="value"
#somewhere use it
VAR_NAME=${VAR_NAME:-"default value"}
echo "$VAR_NAME"

#Запуск команд от имени системных пользователей
#Иногда требуется запустить некую команду, программу или просто проверить права #доступа от имени системных пользователей nobody, apache, и т.д. Простой запуск через
#su - nobody
#Даёт
#This account is currently not available.
#Это происходит из-за того, что у этих пользователей в качестве шела указан /sbin/nologin. #Можно воспользоваться параметром -s для указания другого шела:
su - nobody -s /bin/sh
#И получить нужный результат.

#how to list all disk drives ?
fdisk -l

#Copy a directory (and subdirectories) without .svn files.
rsync -a --exclude=.svn source destination

#Copy directory structure (without files)
find /where/to/search -type d | cpio -pvdm /where/to/copy

#find string in files
grep -lir "qwe"
grep -lir "mod.*" ./log*
find ./ -name log* -exec grep -l qwe {} \;

#bash filename extraction
FILENAME="/some/path/my.file.ext"
echo "Path: ${FILENAME%/*}"
echo "Filename: ${FILENAME##*/}"
echo "Extension: ${FILENAME##*.}"
BASENAME=${FILENAME##*/}
echo "Filename w/o extension: ${BASENAME%.*}"

#find the ten biggest files on your file system linux command
du -a /var | sort -n -r | head -n 10

#Show disk usage under Linux for folder
du -h -s /some/folder/path/*

# delete empty lines
sed "/^$/d" input
# remove spaces
sed 's/ //g'
# remove newline chars
sed 's/\n//g'

# search and replace
sed "s/searchpattern/replacepattern/" input

# find commandline options using sed and grep
URL=$(echo $@ | sed 's:\ :\n:g' | grep "url" | sed 's:\-\-url=::')

#Random string
openssl rand -base64 30

#Returns a list of the number of connections by IP.
netstat -an | grep :80 | awk '{print $5}' | cut -f1 -d":" | sort | uniq -c | sort -n
#Print out a list of open connections on your box and sorts them by according to IP address
netstat -atun | awk '{print $5}' | cut -d: -f1 | sed -e '/^$/d' |sort | uniq -c | sort -n
#Print the number of established and listening connections to your server on port 80 per each IP address
netstat -plan|grep :80|grep -E "(EST|LIST)"|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1

#Get Public IP and copy it to Clipboard
#!/bin/bash
MYIP=`curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.\.]*\).*/\1/g'`
echo $MYIP | pbcopy
/usr/local/bin/growlnotify 'IP address copied' -m "Address was: $MYIP"

#backup
sudo su
cd /
tar cvpjf /tmp/backup.tar.bz2 --exclude=/proc --exclude=/tmp --exclude=/dev --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys /

#http://www.catonmat.net/blog/sed-one-liners-explained-part-one/
#http://sed.sourceforge.net/sedfaq4.html
#http://sed.sourceforge.net/sed1line.txt
#http://tdistler.com/2009/04/17/sed-regular-expression-find-lines-not-matching-a-string
#Substitute (find and replace) only the last occurrence of "foo" with "bar".
sed 's/\(.*\)foo/\1bar/'
#Substitute all occurrences of "foo" with "bar" on all lines that DO NOT contain "baz".
sed '/baz/!s/foo/bar/g'
#Substitute all occurrences of "foo" with "bar" on all lines that contain "baz".
sed '/baz/s/foo/bar/g'

#extract language
cat $F | grep "Stream" | sed "s/ //g" | cut -f 1 -d ":" | sed "/.*(.*).*/!s/.*/und/g" | sed "s/^.*(\(.*\))$/\1/"

#echo full path to command
echo $0
echo "$0" | sed "s|^./|$(pwd)/|"
which ffmpeg
which ffmpeg | sed "s|^./|$(pwd)/|"

#/usr/local/bin/get-ip-address
/sbin/ifconfig | grep "inet addr" | grep -v "127.0.0.1" | awk '{ print $2 }' | awk -F: '{ print $2 }'

четверг, 25 августа 2011 г.

Как рекурсивно поменять права только каталогам или только файлам

cd /home/some_dir
chmod -R 644 *
find . -type d -exec chmod 0755 {} ';'

#Эта команда рекурсивно пройдется по текущему (точка ".") каталогу и всем его подкаталогам и изменит права на 755 только у каталогов (-type d)
find . -type d -exec chmod 755 {} \;
#Похожим образом действуем и с файлами:
find . -type f -exec chmod 644 {} \;
#если необходимо применить действия только к определенным файлам, подходящим по маске, то действуем так:
find . -type f -name '*.htm*' -exec chmod 644 {} \;
#а если нужно применить команду только к файлам или каталогам определенного владельца, то -
fiind . -type d -user fileowner -exec chmod 0755 {} \;

четверг, 18 августа 2011 г.

bash howto's

first line:
#!/bin/bash

#input parameters count:
$#

#script parameters:
$0 - self name, $1 ... $9 - input params

#check that file exist, the spaces near "[" and "]" are required :
if [ -e "streamcount.info" ]
then
echo 'file exist info'
fi

#get file extension:
SHORTFILENAME=$(basename $FULLFILENAME)
DEST_EXT=${SHORTFILENAME##*.}

#get temporary file name:
TFILE="/tmp/streaminfo.$RANDOM.$$.tmp"

#working directory:
$PWD

#redirect error stream to console and filter strings that contain word "Stream":
ffmpeg -i "$SRC" 2>&1 | grep "Stream"
#count strings with grep -c and put it into variable:
a=$( cat < $TFILE | grep -c "Audio:" )

#save command result as array with ( $( ) ):
s=( $( cat < $TFILE | grep "Audio:" | cut -f 2 -d "#" | cut -f 1 -d "(" ) )

#print array contents:
echo "stream numbers: ${s[@]:0}"

#use "for" construction:
for i in `seq 2 $a`;
do
index=$( echo "$i-1" | bc )
v="${s[index]}"
echo "$i. $v"
done

#extract float value:
x=$( echo "qwerty: 123.123123 !" | sed "s/.*[^0-9]\([0-9]\.[0-9]*\).*/\1/g" )

#float point operations:
echo "(256 / $x) / 10" | bc
for float result:
bc -l


# Checks for root privileges
if [ "$(whoami)" != 'root' ]
then
echo "You need to be root to execute uphosts. Exiting!"
exit 1
fi

# Checks required packages
ABORT=0
builtin type -P wget &>/dev/null || { echo -n "wget is missing."; ABORT=1; }
builtin type -P unzip &>/dev/null || { echo -n "unzip is missing."; ABORT=1; }
builtin type -P fromdos &>/dev/null || { echo -n "fromdos(tofrodos) is missing."; ABORT=1; }
builtin type -P grep &>/dev/null || { echo -n "grep is missing."; ABORT=1; }
if [ $ABORT != 0 ]
then
echo " Exiting!"
exit 2
fi

среда, 4 мая 2011 г.

startkde fail

After some compilation with slackware 13.37 kde start failed with message "Could not start ksmserver. Check your installation.".

Fix (link):
In /usr/bin/startkde, change the line similar to
LD_BIND_NOW=true /usr/lib/kde4/libexec/start_kdeinit_wrapper +kcminit_startup
by removing the LD_BIND_NOW=true clause, leaving just
/usr/lib/kde4/libexec/start_kdeinit_wrapper +kcminit_startup

четверг, 21 апреля 2011 г.

script for repository.slacky.eu download

#!/bin/sh
date +"%F %X %Z" >> .update
rm ./FILELIST.TXT
wget http://repository.slacky.eu/slackware-13.1/FILELIST.TXT
cat FILELIST.TXT | cut -d '.' -f2-20 -s | sed '/^$/d'| sed 's/^/slackware-13.1/' >./links.txt
wget --base="http://repository.slacky.eu/" -x --input-file=./links.txt -P pub -T 120 -t 3 -nc

вторник, 1 февраля 2011 г.

Parse OpenStreetMap data

Task:
Parse http://planet.openstreetmap.org/planet-110112.osm.bz2 and put data into DB
Technologies:
C#, SevenZipSharp, XML, XSD
Design:
Create data types with xsd.exe
Read data with SevenZipExtractor to WindowedStream (SharpDevelop ring buffer)
Mix DOM and SAX xml processing:
  • Read elements with XmlReader
  • Parse them with XmlSerializer
  • Put result in DB with BlToolkit