Archive for the 'Programming' Category

download simpleviewer images

nFlickrViewer Demo  - www.chaimjaskoll.com
How to download images in a gallery where a simpleviewer is used as a flashviewer in front:

U=http://www.simpleviewergallery-somewhere-host.NETNET/gallery ; 
for a in `wget -q -O- $U/gallery.xml | egrep -o "filename>[^<]+" | cut -d\> -f2 ` ; do wget $U/images/$a ; done

If you’re new here, you may want to subscribe to my RSS feed.
Thanks for visiting!

mount WebDav in Ubuntu/Linux from FireFox

Gallery_mount_with_webDavOn a standard photo Gallery, you can select to mount Gallery on your desktop with a WebDAV client. I searched for an easy solution to mount webdav from the browser but was not able to find any scripts doing so with only one click. See the first picture to see how you find the link on a Gallery 2.0.

Here is the simple script: (Read more for an advanced script)

#!/bin/sh
 
DAVURL=`cat "$1" | grep ":url" | egrep -o "http[^< \"]+"`
DIR=`echo $DAVURL | egrep -o "[a-zA-Z0-9\.]" |xargs | sed s/\ //gi`
MOUNTPATH="/media/webdav.$DIR"
 
gksu -- mkdir $MOUNTPATH
gksu -- mount.davfs -onoaskauth $DAVURL $MOUNTPOINT
nautilus $MOUNTPOINT

Continue reading ‘mount WebDav in Ubuntu/Linux from FireFox’

How to download over 6000 Free True Type fonts?

A small script to download over 6000 free TrueType Fonts from a webpage.
This script should be for learning purpose only. Removing XX makes you guilty!
Continue reading ‘How to download over 6000 Free True Type fonts?’

Send each directory over ssh to their own gzipped tar file (.tar.gz)

Find directories in the directory you are standing in:
-maxdepth 1 -type d

Exclude the first ‘.’ :
-mindepth 1

Remove the ./ part from the list:
sed s@^.\/@@gi

Tar-gzip the directory with compression 1 for faster network transfer:
tar -cv $a | gzip -1

Send the file to the dd program:
ssh -l user server "dd of=/path/to/$a.tar.gz"

Wrapping it into a small example script:

for a in `find . -mindepth 1 -maxdepth 1 -type d | sed s@^.\/@@gi`; do 
(tar cv $a | gzip -1) | ssh -l user server "dd of=/path/to/$a.tar.gz" ;
done

I suggest you install a ssh-key before doing this, or you will have to type the user password for each directory. This script does not support spaces in directory names.

The script below handle directories with space in them, just like “Document and Settings”.
I print each file (%p) with a colon at the end. The seperator used by the for-loop is also the colon which is defined by the IFS variable.

IFS=":"
for a in `find . -mindepth 1 -maxdepth 1 -type d -printf '%p:' | sed s@^\".\/@\"@gi`; do
(tar cv $a | gzip -1) | ssh -l username servername "dd of='/outputdir/$a.tar.gz'" ;
done
unset IFS

Boot the ubuntu-live cd, making the network start.
livecd$ ssh-agent
livecd$ ssh -l username server -A
server$ ssh-add

root@ubuntu:/media# dd if=/dev/sda2 | ssh -l username hostname "dd of=/path/to/save/my_backup_sda2.ntfs.disk"
The authenticity of host 'hostname (192.168.1.1)' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hostname,192.168.1.1' (RSA) to the list of known hosts.
username@hostname's password:
38957625+0 records in
38957625+0 records out
19946304000 bytes (20 GB) copied, 2541 s, 7,8 MB/s
37811184+2292882 records in
38957625+0 records out
19946304000 bytes (20 GB) copied, 2532.89 s, 7.9 MB/s
root@ubuntu:/media#

Scripted download of AVG definitions with BASH


Here is a oneliner of how to download avg definitions. For the full version updates, just change free.avg.com to www.avg.com on the oneliner.

wget -q -O - http://free.avg.com/download-update | grep "http://[^\"]*\.bin" -o | xargs wget

Here is a small script to download updates:

cd /path_for_updates/avg/free
for a in `wget -q -O - http://free.avg.com/download-update | grep "http://[^\"]*\.bin" -o`
do
        f=`basename $a`
        test -r $f || wget $a
done
cd /path_for_updates/avg/full
for a in `wget -q -O - http://www.avg.com/download-update | grep "http://[^\"]*\.bin" -o`
do
        f=`basename $a`
        test -r $f || wget $a
done

Here is a improved downloader for AVG:

cd /downloadpath/
for a in `(wget -q -O - "http://www.avg.com/download?prd=ibw"; wget -q -O - "http://www.avg.com/download?prd=afe"; wget -q -O - "http://free.avg.com/download?prd=afe"; wget -q -O - "http://www.avg.com/download?prd=ibw") | egrep "http://[^\"]*\.(bin|exe|sh|deb|gz|rpm|rar|iso|zip)" -o| sort | uniq`
do
        echo $a
        f=`basename $a`
        test -r $f || wget $a
done

Download a NRK nett-tv MMS stream

NRK on the goThis will print the stream url of the actual stream when you want to download the video of http://www1.nrk.no/nett-tv/klipp/450753

wget `wget --header "Cookie: NetTV2.0Speed=NetTV2.0Speed=10000" http://www1.nrk.no/nett-tv/klipp/450753 -q -O- | grep -i Filename | cut -d\" -f4` -O- -q | grep "ref href" | cut -d\" -f2 | head -n 1

Or make a small bash script called: nrk-nett-tv.sh:

#!/bin/sh
a=`wget --header "Cookie: NetTV2.0Speed=NetTV2.0Speed=10000" $1 -q -O- | grep -i Filename | cut -d\" -f4`
b=`wget $a -O- -q | grep "ref href" | cut -d\" -f2 | head -n 1`
c=`echo $b | sed s@/@-@gi | sed s/mms:--//gi`
echo $b
echo $c

Run the script with the url in your browser. Like this: nrk-nett-tv.sh http://www1.nrk.no/nett-tv/klipp/450753

After that, just use VLC to download it.

Maildrop: Generate accept-rule for your friends email address

I wanted to create a nice rule in my SPAM-filter, accepting emails from my friends.
I filter my mails after spam flagging, by making maildrop do the delivery to each mailbox on my system.
I have a copy of all my outgoing emails on my imap server in Maildir format. The folder is called Sent. I’m going to create a filter for maildrop which will accept mails from any of the email addresses I’ve sendt email to.

The command below is run in /@PathTo@/vpopmail/domains/@Domain.Name@/@MailboxName@/Maildir/.Sent/cur

fgrep -h "To: " * | grep -v "Reply-To: " | grep "^To: " | sed s/To:\ //gi | sed 's/\,/\
/gi' | cut -d\< -f2  |cut -d\> -f1 | grep "@" | sed s/\ //gi |sort | uniq | xargs | sed 's/\ /\/ \|\| \/\^From: /gi'

Continue reading ‘Maildrop: Generate accept-rule for your friends email address’

Linux: Copy file and directory permissions

How do you copy permissions recursively from one directory to another if you forgot to do ‘cp -rp’ when copying.

 

 

Continue reading ‘Linux: Copy file and directory permissions’

Copy/link files with spaces in the filename

$ cat filelist.txt
/full/path/to/img_1529 (Modified).jpg
/full/path/to/img_1593 (Modified).jpg
/full/path/to/img_1582 (Modified (3)).jpg
/full/path/to/img_1546 (Modified).jpg
/full/path/to/img_1612 (Modified).jpg
/full/path/to/img_1663.jpg
/full/path/to/img_1670 (Modified (2)).jpg
/full/path/to/img_1713.jpg
/full/path/to/img_1552.jpg
/full/path/to/img_1538 (Modified).jpg
 
$ cat filelist.txt | xargs -d\\n -n1 -I'{}' cp -p "{}" /tmp/

Find (new) images that does not exist in the f-spot database.

Here is a small script which will give some ideas of how it can be done:

 
# Backup your f-spot db-file to /tmp/
cp ~/.gnome2/f-spot/photos.db /tmp/
 
# Run a sql to find the photos matching my photo uri+2008, and 'DSC*.jpg'.
# split the list that sqlite3 generates. I just want the photo name, so that's my 10'th field.
# Uppercase every filename and sort it, then put it into a file.
sqlite3 ~/.gnome2/f-spot/photos.db 'select uri from photos where uri like "file:///home/%/Photos/2008/%DSC%.jpg"' | cut -d/ -f10 | tr 'a-z' 'A-Z' | sort > /tmp/gotFromFspot.list
 
# Go to the directory where you have your camera files. (ps: You should not have photos from 2008 in this directory.
cd /media/PHONE CARD/DCIM/100MSDCF/
 
# find all files and put them into another list.. 'CardFileList.list'
ls -1 | sort > /tmp/CardFileList.list
# Diff the file lists. We only care about the ones that does not exist in gotFromFspot.
diff /tmp/gotFromFspot.list /tmp/CardFileList.list | grep ">" | sed s/> //gi >/tmp/ResultList.list
 
mkdir /tmp/NewImagesTmpDestination
# Loop every file and copy the new, not existing in the f-spot photo db to /tmp/d/
for tmpvariable in `cat /tmp/ResultList.list'; do  cp $tmpvariable /tmp/NewImagesTmpDestination ; done