Monday, March 31, 2008

Linux Developer Gets Laid

The original news is from: http://www.bbspot.com/News/2000/9/linux_laid.html.
Philadelphia, PA - In news that is sure to excite the Linux community, long time Linux developer Todd Stanton got laid.

Happy Todd "I still have trouble believing it myself," said Todd. "I was doing some coding when my power supply blew. Instead of pulling out the spare like I usually would, I decided to head down to Best Buy to check out the new DVD releases. Nothing new was out, so I bought another copy of 'The Matrix' since the one I had was pretty worn out. Turns out the checkout girl was a Matrix fan too and well one thing led to another."

Word spread rapidly on message boards and on IRC. "It's pretty irresponsible of him and shows his lack of dedication to Linux and the open source movement," said Fred Simpson. "If others try to emulate this behavior then a lot of projects could get derailed."

Others like Gary Wilcox were glad to hear the news, "We're tired of all those Microsoft developers shoving their Win-Ho's in our face. Now we can tell them about Todd. Who's laughing now?"

Some developers are also excited that this may increase their chances of getting lucky, but most are being realistic. Walker Crandall said, "We thought we'd all be doing the hokey-pokey after Bill Fitzsimmons got some during the LinuxWorld Conference in 1999. We were fooling ourselves. Nobody got nothing."


Thursday, March 27, 2008

Adding more tics to gnuplot graphs


set xtic 10
set ytic 100

Tuesday, March 25, 2008

Amarok embedded album art : EmbedCover script

The latest version of Amarok (1.4.8) suffers from a side effect of a feature called "Dynamic Collection" (http://bugs.kde.org/show_bug.cgi?id=159663). This results in a initial dot "." to every file in the collection.

EmbedCover script for Amarok works great for embedding album arts directly in the mp3 file. But it will report "Song is not in your collection" if the file paths are incorrect in the database due to that bug.

I've provided a temporary fix in the script for that problem till the bug in Amarok gets fixed. The patched EmbedCover.rb is here:

  • file to patch: $HOME/.kde/share/apps/amarok/scripts/embedcover/


#!/usr/bin/env ruby
#
# amaroK Script for embedding album cover images in MP3 files.
#
# (c) 2005 Mark Kretschmann <markey@web.de>
# License: GNU General Public License V2

################################
# This is my patched version   #
# Perfectly working my ubuntu. #
# So, Good luck !!             #
################################


require 'md5'
require "uri"

MenuItemName = "EmbedCover Embed!"

def cleanup()
    `dcop amarok script removeCustomMenuItem #{MenuItemName}`
end


trap( "SIGTERM" ) { cleanup() }

`dcop amarok script addCustomMenuItem #{MenuItemName}`


loop do
    message = gets().chomp()
    command = /[A-Za-z]*/.match( message ).to_s()

    case command
        when "configure"
            msg  = '"EmbedCover does not have configuration options. Simply select a track in the '
            msg += 'playlist, then start EmbedCover from the context-menu (right mouse click)."'

            `dcop amarok playlist popupMessage "#{msg}"`

        when "customMenuClicked"
            if message.include?( MenuItemName )
                args = message.split()
                # Remove the command args
                3.times() { args.delete_at( 0 ) }

                # Iterate over all selected files
                args.each() do |arg|
                    uri = URI.parse( arg )
                    file = URI.unescape( uri.path() )

   dcopfile = file
   hds = `dcop amarok collection query "SELECT DISTINCT lastmountpoint FROM devices"`.split()

   for n in hds
    unless n == "/"
    g = /(^#{n})/.match(dcopfile)
     if n = g
     dcopfile = dcopfile.sub(/(^#{n})\//, './')
     break
     else
     end
    else
    end
   end

      dcopfile = dcopfile.sub(/^\//, './')
      file = dcopfile
      
      #`dcop amarok playlist popupMessage "#{file}"`

                    file.gsub!( /[']/, '\\\\\'' )  # Escape for SQL

                    puts( "Path: #{file}" )

                    backend = File.dirname( File.expand_path( __FILE__ ) ) + "/addimage2mp3.rb"

                    # Query is two parts, first ID, then name
                    artist_id = `dcop amarok collection query "SELECT DISTINCT artist FROM tags WHERE url = '#{file}'"`.chomp()
                    artist    = `dcop amarok collection query "SELECT DISTINCT artist.name FROM artist WHERE id = '#{artist_id}'"`.chomp()

                    album_id  = `dcop amarok collection query "SELECT DISTINCT album FROM tags WHERE url = '#{file}'"`.chomp()
                    album     = `dcop amarok collection query "SELECT DISTINCT album.name FROM album WHERE id = '#{album_id}'"`.chomp()

                    puts( "ArtistId : #{artist_id}" )
                    puts( "Artist   : #{artist}" )
                    puts( "AlbumId  : #{album_id}" )
                    puts( "Album    : #{album}" )

                    if artist_id.empty?() and album_id.empty?()
                        `dcop amarok playlist popupMessage "EmbedCover Error: This track is not in your Collection."`
                        next
                    end

                    md5sum = MD5.hexdigest( "#{artist.downcase()}#{album.downcase()}" )
                    imagefolder = "#{ENV['HOME']}/.kde/share/apps/amarok/albumcovers/large/"
                    image = "#{imagefolder}#{md5sum}"

                    puts( "Imagepath: #{image}" )

                    unless FileTest.exist?( image )
                        `dcop amarok playlist popupMessage "EmbedCover: No image found for this track."`
                        next
                    end

                    
      file = file.sub(/^\.\//, '/')
      #`dcop amarok playlist popupMessage "#{file}"`
      
      output = `ruby #{backend} "#{image}" "#{file}"`

                    if $?.success?()
                        `dcop amarok playlist popupMessage "image embedded SUCCESSFULLY !!!."`
                    else
                        reg = Regexp.new( "Error:.*", Regexp::MULTILINE )
                        errormsg = reg.match( output )

                        `dcop amarok playlist popupMessage "EmbedCover #{errormsg}"`
                    end
                end
            end
    end
end


X hangs on Ubuntu (gutsy) with latest Ati-fglrx driver

Symptoms:

  • X takes 100% cpu after a certain period of inactivity
  • mouse cursor moves, but doesn't respond to any clicks
  • ctrl+alt+shift+F1 occassionally works (not always)
I started having this problem after installing the latest ati-fglrx driver.
My fglrx output:

OpenGL vendor string: ATI Technologies Inc.
OpenGL renderer string: ATI MOBILITY RADEON X300
OpenGL version string: 2.1.7412 Release

Browsed a thousands of forum entries, tried a zillion of solutions. Finally this is what seemed to have fixed the problem for me:

vim /etc/default/acpi-support

# Should we save and restore state using the VESA BIOS Extensions?
SAVE_VBE_STATE=false

# Should we attempt to warm-boot the video hardware on resume?
POST_VIDEO=false

also check http://babilonline.blogspot.com/2008/03/unbuntu-ati-proprietary-fglrx-driver.html

BitThief - Download bittorrents without uploading anything ;-)

BitThief - "BitThief is a Java-based BitTorrent client designed to download from, but not upload to, BitTorrent networks. It is freeware and cross-platform. According to the BitThief homepage, it is intended as a proof of concept that there are weaknesses in the current BitTorrent protocol, which can be exploited by "cheating" BitTorrent clients (such as BitThief itself)." [wikipedia]

Download:
wget http://dcg.ethz.ch/projects/bitthief/dist/BitThief.jar
Run:
java -jar BitThief.jar                                                                           

;-)



Checking RoundCube webmails from console

I wrote this script to check "Today's" new email for the webmail account I have with NICTA, as obviously opening a new browser window, logging in and checking emails every hour was becoming a pain in the neck ... and ya, of course for the reason too, that konsole is more fun ;) ...


#!/bin/bash

read -s -p "enter password: " pass
echo

curl -s -k -c nicta.cookie -d "_action=login&_user=NICTA%2FXXX%2FYYY.ZZZ&_pass=$pass" 'https://webmail.nicta.com.au/' -L 2>&1 1>/dev/null

curl -s -k -b nicta.cookie -d "_action=login&_user=NICTA%2FXXX%2FYYY.ZZZ&_pass=$pass" "https://webmail.nicta.com.au/" -L -o - | grep "Today " | sed -e :a -e "s/Today/`date +%d:%m:%y`/g;s/ \;//g;s/<[^>]*>//g;/<;/N;//ba" | awk '{print $2}' rm nicta.cookie

** The script could be made more fancier, some IF/ELSE in the proper place should do the trick. I'll finish the script soon as I find some free time.

Checking Pennytel.com balance from console

    #!/bin/bash

    read -s -p "enter password: " pass
    echo
    curl -c /dev/null -d "username=888XXXX712&password=$pass" "https://www.pennytel.com/m/login.jsp" -L 2> /dev/null | grep Balance | sed -e :a -e 's/&nbsp\;//g;s/<[^>]*>//g;/<;/N;//ba' 


Sunday, March 23, 2008

Finding UUID on Ubuntu


** lsblk or ** ls -al /dev/disk/by-uuid/

Wednesday, March 19, 2008

AppleTV - airtunes from linux with amarok

1. Fix the "Shouter" plugin for Amarok in "/home/babil/.kde/share/apps/amarok/scripts/shouter/"

Playlist.py ::
if current > total : current = total
if float(total) == 0:
raise ShouterExceptions.amarok_not_playing_error

Globals.py ::
# coding=Latin-1

Bash ::
  • ln -s /usr/share/apps/amarok/scripts/common/Zeroconf.py /home/babil/.kde/share/apps/amarok/scripts/shouter/Zeroconf.py

  • ln -s /usr/share/apps/amarok/scripts/common/Publisher.py /home/babil/.kde/share/apps/amarok/scripts/shouter/Publisher.py

2. Run the "Shouter" plugin in Amarok "Tools/Script Manager"

3. Create a Playlist in nito with a entry like "http://192.168.0.5:8000/amarok" . Nito playlists are saved in "/Users/frontrow/Library/Application Support/nito/playlists"

4. Or run mplayer from ssh command line like this:

"/System/Library/CoreServices/Finder.app/Contents/PlugIns/nitoTV.frappliance/Contents/Resources/mplayer http://192.168.0.5:8000/amarok -autosync 30"


Tuesday, March 18, 2008

Unbuntu ATI proprietary fglrx driver logout/shutdown problem

I was annoyed to hell with this problem. It seems the problem was with atieventsd. Removing it from startup solves the problem:


update-rc.d -f atieventsd remove

atieventsd:: The ATI External Events Daemon atieventsd is a user-level application that monitors various system events such as ACPI or hotplug, then notifies the driver via the X extensions interface that the event has occurred.


Force filesystem check on Linux

a little hackery ...

tune2fs -c /dev/hda1 30 # setting the max check count
tune2fs -C /dev/hda1 31 # setting total check count so far


Force filesystem check on Ubuntu

sudo touch /forcefsck

Monday, March 17, 2008

Updating OpenOffice on Etch

Very strange !! clicking the menu entries openoffice wont run !!! Wait, there's one more trick ;-) You gotta make sure no other previous instances of "soffice" or "soffice.bin" was running.
  • killall soffice
... and voila, suddenly everything works !!!

Decreasing "swappiness" in Linux

  • cat /proc/sys/vm/swappiness
  • echo 15 > /proc/sys/vm/swappiness
  • vim /etc/sysctl.conf ... vm.swappiness=15

A few interesting linux distros

  • http://wiki.freespire.org/
  • http://www.mepis.org/
  • http://www.linux-xp.com/
  • http://www.blagblagblag.org/
  • http://wiki.linspire.org/
  • http://www.pclinuxos.com/

Sunday, March 16, 2008

Duplicate image remover script

Instructions:

  • Gererate dup.txt with this command: findimagedupes -f=mypic.dat > dup.txt
  • Go inside the directory where dup.txt is saved, run dupless.sh
  • The script will show you 2 images, select the one you want to remove, press "d"
  • Incase you want to recover deleted images, they are just moved to ".qiv_trash"
Prerequisites:

  • apt-get install qiv findimagedupes

#!/bin/bash

input="dup.txt"
c=0
t=`cat $input | wc -l`

while read line
do
ext=`echo "$line" | awk -F "." '{print $2}' | awk '{ print $1}' | sed 's/[[:blank:]]*$//g'`
#echo $ext
n1=`echo "$line" | awk -v ext="$ext" -F "$ext" '{print $1ext}'`
#echo $n1

ext=`echo "$line" | awk -F "." '{print $NF}'` | sed 's/[[:blank:]]*$//g'
#echo $ext
n2=`echo "$line" | awk -v ext="$ext" -F "$ext" '{print $2ext}' | sed 's/^ //g'`
#echo $n2
#exit

s1=`ls -al "$n1" | awk '{print $5}'`
s2=`ls -al "$n2" | awk '{print $5}'`

if [ $s2 -gt $s1 ]
then
tmp=$n2
n2=$n1
n1=$tmp
fi

if [ -e "$n1" ] && [ -e "$n2" ]
then
echo -en "$n1\t"
qiv -t -e -W 75 -t "$n1" & 2>/dev/null
p1=$!
echo -en "[$p1]\n"

echo -en "$n2\t"
qiv -t -W 75 -t "$n2" & 2>/dev/null
p2=$!
echo -en "[$p2]\n"

#wait $p2
while [ 1 ]
do
c=`pidof -o $p2 qiv`
if [ ! "$c" ]; then
break
fi

c=`pidof -o $p1 qiv`
if [ ! "$c" ]; then
break
fi
done

killall -q -s9 qiv 2>&1 1> /dev/null
fi

c=$((c+1))
echo "[+] $c-done $((t-c))-remaining"
echo

done < $input

Saturday, March 15, 2008

Bigger font in WINE applications

In file ../windows/win.ini ::

[Desktop]
MenuFontSize=14
MenuFont=Terminus

Friday, March 14, 2008

Total Frame & Byte counts with tshark


tshark -q -z io,phs -r dump.pcap

Remove weird whitespaces with Sed


cat file.txt | sed -c 's/[[:cntrl:]]//g'

Tuesday, March 11, 2008

My konsole font




sudo apt-get install console-terminus

Monday, March 10, 2008

Hardware information on linux


lshw

or

lshw -html > report.html ... generates a nice single html report.

Big decimal integer constant warning


warning: this decimal constant is unsigned only in ISO C90

if there is no suffix added to the constant:

C90 compilers will follow the following order to read that constant:
  • int
  • long int
  • unsigned long int
while C99 compilers the following order:
  • signed int
  • signed long
  • signed long long
solution:
  1. consult compiler (gcc) documentation
  2. add proper suffix (ex. UL)
code snippet:


if((u64)s[i-1]>4294967295UL) {
s[i-1]=0;
}

Remove leading & trailing spaces with Awk


cat file.txt | awk '{for(i=1;i<=NF;i++){printf("%s ",$i)}; print "\n";}'

Sunday, March 9, 2008

Remove leading & trailing spaces with sed

Both Leading & Trailing spaces:

sed -e '/^$/d'

Trailing spaces only:

sed 's/[[:blank:]]*$//g'

Passing Bash variable in Awk


ext=".jpg" ; awk -v ext=$ext '{print $filename,ext}'

Saturday, March 8, 2008

X forwarding over SSH

sshd_config::

X11Forwarding yes
AllowTcpForwarding yes

ssh_config::
ForwardX11 yes or
ForwardX11Trusted yes


Friday, March 7, 2008

Awk - delete first 3 fields


cat file.txt | awk '{$1=$2=$3="";print $0}'


loss_interval.c output

Cr@p!!! All these time I kept thinking, just replacing "dccp_ccid.ko" will do the debug output trick, but apparently "loss_interval.c"
  • printk() ... prio=4
  • dccp_pr_debug () ... prio=7
  • ccid3_pr_debug() ... prio=7
functions are linked from ::

"../dccp/ccids/lib/dccp_tfrc_lib.ko".

So, replace it toooo !!!

Printk() problem solved !!!

Prink()'s on my systems seem to come as <4> = KERN_WARNING from all my dccp kernel codes.

In order to catch them (by neck :@), the trick was to kill "klogd" and restart it with the following options ::

klogd -x -f - -n -c 8

This will log everything conveniently on the console which can easily be redirected to any file if needed, finally leaving me in peace with exactly what I wanted ;) God bless "klogd" !!!

Thursday, March 6, 2008

HTML tag :: tppabs ??

  • tppabs = Tele.port.pro absolute urls

  • Does'nt mean anything to the normal html, only helps teleport.pro to figure out where the original object was downloaded from.

  • Teleport Pro = http://www.tenmax.com

My silly ktorrent script

I cant explain why ( nor that I intend to ), when I increase my upload speed on ktorrent, the download speed shoots up for a while ... And thus the following script comes into being ... dcop rocks !!!

#!/bin/bash

while [ 1 ]
do
#echo "[+] stopping all"
#dcop ktorrent KTorrent stopAll 1
echo -e "\n[+] INCREASING Upload-rate\n"
dcop ktorrent KTorrent setMaxUploadSpeed 0
sleeptime=10
for ((i=1;i<=$sleeptime;i++))
do
info=`dcop ktorrent KTorrent getInfo | grep "Speed" | awk '{print "UP:",$3,$4," \tDOWN:",$7,$8}'`
eta=`dcop ktorrent KTorrent getTorrentInfo 0 | awk '{if(NR==8) print $1}'`
echo -e "\t$i.$info \tETA:$eta"
sleep 1
done

#dcop ktorrent KTorrent startAll 1
up=`dcop ktorrent KTorrent getInfo | grep "Speed" | sed 's/Speed//g' | awk '{print $2}' | awk -F "." '{print $1}'`
if [ $up -gt 5 ];then
echo -e "\n[+] DECREASING Upload-rate\n"
dcop ktorrent KTorrent setMaxUploadSpeed 1
sleeptime=20
for ((i=1;i<=$sleeptime;i++))
do
info=`dcop ktorrent KTorrent getInfo | grep "Speed" | awk '{print "UP:",$3,$4," \tDOWN:",$7,$8}'`
eta=`dcop ktorrent KTorrent getTorrentInfo 0 | awk '{if(NR==8) print $0}'`
echo -e "\t$i.$info \tETA:$eta"
sleep 1
done
fi
done

Album downloader on TVShark.net

baTakes one argument, the URL of the first image in the album.
#!/bin/bash

n=`echo "$1" | awk -F "=|&" '{print tolower($2)}' | sed 's/+/_/g'`
m=`echo "$1" | awk -F "=|&" '{print $6}'`
l=`echo "$1" | awk -F "=|&" '{print $8}'`

if [ "$l" -eq "0" ]
then
t=""
else
t="_lg"
fi

ii=`seq 1 $m`
for i in $ii
do
url="http://www.tvshark.com/imgs/c/${n}${i}${t}.jpg"
wget -nv $url
done

Email harvest on Premiumforfree.com

#!/bin/bash

for ((i=$1;i<=$2;i++))
do 
email=`wget -q http://premiumforfree.com/index.php?referral=$i -O - | grep 'You are being referred by' | awk -F '&lt;B&gt;' '{print $2}' | sed -e :a -e 's/<[^>]*>//g;/<;/N;//ba'`
 echo $i.$email
 echo $email >> email.txt
done

Kill html tags with Sed

Link:

cat file.txt | sed -e :a -e 's/<[^>]*>//g;/<;/N;//ba'

Printk ()

Links::

Example::
printk( KERN_ERR "Failed to register device %s with major %d\n", MOD_NAME, MAJOR);

It is possible to read and modify the console loglevel using the text file
/proc/sys/kernel/printk.

The file hosts four integer values:
  • current loglevel,
  • default level for messages that lack an explicit loglevel,
  • minimum allowed loglevel
  • the boot-time default loglevel.
Writing a single value to this file changes the current loglevel to that value; thus, for example, you can cause all kernel messages to appear at the console by simply entering:



# echo 8 > /proc/sys/kernel/printk


KERN_* parameters are defined in

include/linux/kernel.h
as follows:



Macro NameNumeric Value
Description
KERN_EMERG0Used for emergency messages, usually those that precede a crash.

KERN_ALERT1A situation requiring immediate action.

KERN_CRIT2Critical conditions, often related to serious hardware or software failures.

KERN_ERR3Used to report error conditions; device drivers often use KERN_ERR to report hardware difficulties.

KERN_WARNING4Warnings about problematic situations that do not, in themselves, create serious problems with the system.

KERN_NOTICE5Situations that are normal, but still worthy of note. A number of security-related conditions are reported at this level.

KERN_INFO6Informational messages. Many drivers print information about the hardware they find at startup time at this level.

KERN_DEBUG7Used for debugging messages.

Tuesday, March 4, 2008

All C/C++ manpages

apt-get install manpages
apt-get install manpages-dev
apt-get install manpages-posix-dev

Lookup source code

grep -R "look-up-string" `pwd`

Monday, March 3, 2008

Disabling bash history

babil@babil:~$HISTSIZE=0

Print particular line in a file


cat file.txt | awk '{if(NR==8) print $0}'

$0 = holds the whole line in awk
NR = number of records in file.txt
NF = number of fields in file.txt


For loop in bash

C-style::
for ((i=9;i<=$sleeptime;i++))
do ... ...
done

Bash-style::
for each pid in $pids
do
... ...
done


Loop continue/break in bash

while [ $x -gt "$i" ]
do
x=$(($x+1))
if [ "$x" -eq 5 ] || [ "$x" -eq 9 ]
then
continue/break
fi
done

Duplicate File/Image Finder

for normal files ::

apt-get install fdupes
usage:: fdupes /home/babil/my_pic

for smart checks on images ::

apt-get install findimagedupes
usage::
findimagedupes -f=mypic.dat --rescan -v=md5 /home/babil/my_pic


IF in bash

for numbers ::

if [ $n1 -eq 100 ]; then

for strings ::

if [ "$n1" == "100" ]; then

more than one condition ::

if [ $n1 -gt 100 ] || [ "$n2" == 0 ]; then

Sunday, March 2, 2008

Photoshop with wine


links http://wiki.winehq.org/AdobePhotoshop

Download winetricks


wget http://kegel.com/wine/winetricks