Friday, August 26, 2011

Beware! MTDC Photo Competition is Extortion!

Maharashtra Tourism Development Corporation (MTDC) has organised a photography competition for August 2011. Here is what I found in the document that details the `Rules' for the competition:

All photos submitted in this competition will become sole property of MTDC. MTDC reserves the right to use the photograph on their official web site or any printing material published by MTDC in any format.

Interestingly; this particular rule is not to be found on their website. In fact; there is no mention whatsoever of the copyright or ownership of the photos submitted on that page. Luckily; Googling for `MTDC Competition' brings up the PDF document that I've linked above; as the first result.

There is also a discrepancy in the prize money mentioned in the PDF and on the website. But that is a minor issue.

I'm no legal expert; but I can clearly see the following facts:
  • Since all the rights are to be handed to MTDC, they're essentially buying out all the photos submitted to the competition. Note, submitted and not just the prize winners. In essence, non-winners will be handing their work to MTDC for free! The winners will have to contend with a sum of a maximum of Rs. 51ooo/-.
  • Since this is not just licensing, but full ownership of the photos, MTDC can effectively use them anywhere, in any format with no need to even attribute the photo to its creator.
  • It could also mean that MTDC will be able to sell these photos as their own any time, anywhere and in any format. None of this will ever reach the creator - forget money, not even the attribution or credits.
  • A very very twisted scenario presents itself as follows. MTDC could simply refute to announce the winners. Quoting the PDF document, "MTDC management reserves all rights to select or reject any photographs. Decision of MTDC will be final with respect to this competition and will be binding for all." They could just walk away with all the photos submitted, without even the need to give the prizes away.
Not surprisingly, only (decently) high resolution images are being accepted:

Each photograph should not be more than 5 MB

The PDF document even goes to mention the following (arguably laughable) points:

Photos captured by mobile cameras will not be entertained.
Photos captured through Digital/Professional Cameras will only be accepted.

It could just be me, but the tone of the word `entertained' could be considered derogatory to such work. Anyway, that is beside the point.

As such, seeing as though all this information is `hidden' in the PDF, most photographers submitting their work for the competition will likely be unaware of the above issues. I hope this post will serve to educate such photographers, now and in the future, to first and foremost understand the legalities involved in publishing their work in any way. So please, spread the word.

On a side note, compare the above `rules' with the following on Steve Huff's Daily Inspiration page:
  • Image can be taken with ANY camera make or model. Film or digital.
  • You will have all rights and ownership to your image. I will simply be posting it here for all to enjoy and be inspired by!
  • You will receive no compensation, no prizes or anything tangible. Just a link to your gallery/portfolio if you have one.
  • The image will remain in the blog archives forever providing you exposure every time the image and your link is viewed!
Which one seems more `profitable' to you?

Friday, September 28, 2007

Messing with arrays in bash

A couple of days ago, a problem was being discussed in #bash.

`How does one append to every element of an array?'

The usual answer is, run it in a loop. The better answer, however, is a one line parameter expansion thingie. Well, here's your answer:

$ array=( "${array[@]/%/foo}" )

That's it. One line of code to replace an entire for loop.

Here's a working example:

$ array=( foo bar baz )
$ echo "${array[@]}"
foo bar baz
$ array=( "${array[@]/%/foo}" )
$ echo "${array[@]}"
foofoo barfoo bazfoo

So how does it work?

Well, what we have here is actually the pattern matching and replacement operator from the Parameter Expansion facility of bash. The general syntax is as follows:

${parameter/pattern/string}

This way, the pattern to be matched can be replaced with the string in the value of the variable. When applied to an array index of either * or @, it performs the match and replace operation for every element of the array.

One curious feature of this operator is the use of %.

If the pattern to be matched starts with a %, it is matched at the end of the string. In our case, we've simply matched nothing at the end of the string and replaced it with foo. The result is that foo is appended to every element of the array. Cool eh?

Just be mindful of the double quotes in case your array elements have spaces or newlines in the values. :)



Once upon a time, I learnt that the expansion of "$*" or "${array[*]}" results in all the values separated with the first character of the value of $IFS. I always wondered where this feature could be used. Then all of sudden, I ended up using it twice in the space of two days.

The first problem was creating a few directories. Brace expansion was ideal. The values for directory names were coming from an array. Here's how I solved it.

(
DIRNAMES=( foo bar baz )
oIFS="$IFS"
IFS=","
eval mkdir -p /foo/{"${DIRNAMES[*]}"}
IFS="$oIFS"
)

I've put the entire thing in a subshell because I'm changing the value of IFS, which could be dangerous in a script. By using a subshell I'm making sure that rest of the script won't be affected. On top of that I'm saving the original value in $oIFS just to be sure. Yeah, paranoid. :)

eval is necessary because brace expansion happens before the parameter expansion takes place.

Anyway, "${DIRNAMES[*]}" actually expands to:

foo,bar,baz

So the whole command becomes:

$ mkdir -p /foo/{foo,bar,baz}

Nifty. :)

Here's another one.. I needed to feed some values from an array into a regex.

$ EXTENS=( txt c cpp h )
$ IFS="|"
$ awk "\$2 ~ /\.(${EXTENS[*])$/ { foo; }"

The expanded value becomes:

(txt|c|cpp|h)

:)

Friday, June 29, 2007

Happiness with AIDS

We all misinterpreted HIV's intentions; really! Check this out if you don't believe me:

That was a mousepad at the IT department of a client we serviced; yesterday. I wonder how several dozens of those ever got printed!

Thursday, May 17, 2007

Gentoo Bugzilla Exploration!

Heheh, `interesting' conversation in #gentoo-amd64 today.. I'm blogging here with the guys' permission :)


[07:00] [floyd_n_milan] !bug 1
[07:00] * floyd_n_milan kicks jeeves! you stupid bot!
[07:06] [angelos] mhm
[07:06] [angelos] Bug #1 does not exist.
[07:07] [angelos] tis what bugzie says :p
[07:07] [perry_] !bug 2
[07:07] [jeeves] perry_: https://bugs.gentoo.org/2 nor, P2, x86,
tneidt@fidnet.com->micke@codefactory.se, RESOLVED, FIXED,
How do I attach an ebuild.
[07:07] [floyd_n_milan] that's weird :S
[07:07] [floyd_n_milan] how do i attach an ebuild? o.0
[07:07] [floyd_n_milan] to the bugzilla?
[07:07] [floyd_n_milan] maybe
[07:07] [floyd_n_milan] bug 1 was.. we need a bug tracking system!
[07:07] [floyd_n_milan] there ARE bugs!
[07:08] [angelos] yeah, flying around everywhere
[07:08] [perry_] lol
[07:08] [perry_] bug 3 was the guy attaching an ebuild
[07:08] [jeeves] perry_: https://bugs.gentoo.org/3 nor, P2, x86,
tneidt@fidnet.com->danarmak@gentoo.org, RESOLVED, FIXED,
poedit-1.1.5.ebuild
[07:09] [angelos] yay poedit is still in the tree!
[07:09] [floyd_n_milan] 1.3.6 hmm
[07:11] [angelos] grubconfig is evil
[07:11] [angelos] bug 666
[07:11] [jeeves] angelos: https://bugs.gentoo.org/666 nor, P2, x86,
mr.big@biglinux.de->woodchip@gentoo.org, RESOLVED, FIXED,
grubconfig-1.5.ebuild
[07:12] [floyd_n_milan] lol
[07:12] [Draconx] bug 1337
[07:12] [jeeves] Draconx: https://bugs.gentoo.org/1337 nor, P2, x86,
danarmak@gentoo.org->davisjp@gmail.com, RESOLVED, INVALID,
Bugzilla asks password over and over for every page
[07:12] [Draconx] invalid my ass


Seriously, IRC can be great fun.. and a huge waste of time at times too :P

Sunday, May 06, 2007

Magicians

I stumbled upon this beauty today:

Sunday, April 15, 2007

श्यामची आई - एक सुंदर विचार!

"या जगात नुसते प्रेम, केवळ दया असूनच भागत नाही. जीवन सुंदर व यशस्वी करण्यास तीन गुणांची जरुरी असते. पहिली गोष्ट म्हणजे प्रेम पाहिजे. दुसरी गोष्ट म्हणजे ज्ञान आणि तिसरी गोष्ट म्हणजे शक्ती. प्रेम, ज्ञान व बळ या तीनही गोष्टी ज्याच्याजवळ आहेत, त्याला जगात कृतार्थ होता येईल. प्रेमहीन ज्ञान तेही व्यर्थ; ज्ञानहीन प्रेम तेही फुकट; प्रेमज्ञानहीन शक्ति व शक्तिहीन प्रेम व ज्ञान तीही व्यर्थच. माझ्या अंगात शक्ती असली; परंतु दुसर्यावर प्रेम नसेल, तर त्या शक्तीचा दुरुपयोग व्हावयाचा. मजजवळ ज्ञान आहे; परंतु दुसर्यावर प्रेम नसेल, तर त्या ज्ञानाचा फायदा मी दुसर्यास देणार नाही आणि प्रेम असून ज्ञान नसेल, तर ते प्रेमही अपाय करील. एखाद्या आईचे मुलावर प्रेम आहे; परंतु त्या मुलाची आजारीपणात कशी शुश्रूषा करावी, याचे ज्ञान जर तिला नसेल, तर त्या आंधळ्या प्रेमाने जे खावयास देऊ नये, तेही ती देईल आणि तिच्या आंधळ्या प्रेमानेच बाळ मरून जाईल! समजा, आईजवळ प्रेम आहे. ज्ञानही आहे; परंतु ती जर स्वतः अशक्त आणि पंगू असेल तरीही तिच्या प्रेमाचा व ज्ञानाचा फायदा मिळणार नाही. प्रेम, ज्ञान व शक्ती यांचा विकास जीवनात हवा. प्रेम म्हणजे हृदयाचा विकास; ज्ञान म्हणजे बुद्धीचा विकास व शक्ती म्हणजे शरीराचा विकास. शरीर, मन व बुद्धी या तीनहींची वाढ जीवनात हवी."

श्यामची आई, रात्र अकरावी: भूतदया.
मा. श्री. साने गुरुजी.

Tuesday, March 06, 2007

The `Different' Colours of Holi

I stopped celebrating Holi a few years ago. I don't really know why, but maybe because I didn't like all those colours messing up my nice long hair back then :P Anyway, this year I decided to join in.

YUVA (Youth Ultra Vision Association), of which I'm a member, decided to visit the folks at Aasara (आसरा). It is an organisation working towards the welfare of homeless or underprivileged children. We visited two of their shelter homes. One in Thane and the other in the village of Digha in New Mumbai. It turned out to be a unique and immensely satisfying experience.

How does one imagine how much we have to be happy with our lives, no matter how difficult/cruel/uncomfortable/unfair it may seem? We can't really know how many privileges we enjoy till we meet the folks who are not so lucky as we are. I'll tell you a couple of `stories' I heard about a few of the children from the people working for Aasara.

One of the girls, somewhere around 9 years of age, had been abandoned by her parents. A brother-sister pair, even younger than 9 I think, had no father. Their mother couldn't afford them. These children were taken in by the shelter home. They were fed, given clothing and a home. They were schooled.

There were three or four teenagers, about to take their SSC examinations. One of them wants to be a computer engineer. Another has a job. He's a welder. Another wants to be a singer. Obviously, we asked him to grant us the pleasure of listening to him. He obliged.. and really, he sings mighty well. So what's so special about these three cases? Well, they have been in the shelter home for a decade now. They've been taken care of and they've been provided as many facilities as possible.

Aasara gets its finances off the donations from various people and NGOs. Aasara has a computer lab, courtesy of such donations. Aasara had the musical training arranged for the interested. An NGO was so impressed with the work Aasara does, they decided to finance ten of the kids. Hmmm. So, even with the absence of `luxuries', which have become our necessities, at least the real basic needs of these children are taken care of by Aasara. Food, shelter, clothing and education.

So what's with YUVA being there?

What we were told was that there was one important aspect missing from these children's' lives. Socialisation. The need to feel and be treated as `normal'. To be a part of the society rather than being abandoned from it. This gap, between the society of `normal' people and these kids, YUVA tried to fill. A squirrel's share maybe. But hey, at least we tried!

We were told at the first shelter home that initially, the Aasara people have to go reach out to the slum children, the children on the streets or railway stations and bring them to the shelter home. The mentality of these different groups are very different and it isn't really easy to get them to mix with each other, but the effort is put in. We decided to add another dimension to this. As the first step, the YUVA members visited these people and celebrated Holi with them.

The festival of colours was painted in very different colours this year, at least for me. Colours of love and compassion. Do you see them?

P.S. YUVA will be keep visiting them in the future, on a regular basis. We are also planning to help out in any way possible. Whatever we can donate... money, books, time.. Whatever we can share.. knowledge perhaps? We shall see. There's a lot to do. Wish us well.

I took a few pics, which I've uploaded on Flickr here: http://www.flickr.com/photos/floyd_n_milan/

Monday, February 12, 2007

Processing procmail logs in bash

Well, the comments in the script should be self explanatory. It was awesome fun writing this! See if you `like' it ;)



#!/bin/bash
#
# Date: Monday 12th February 2007
#
# Processing procmail logs.
# It copies the original procmail log file to a
# temporary file called procmail after some grepping.
# After that, another temporary file procswapped is
# created and processed. Both files can be safely
# deleted afterwards.
#
# Only one drawback, it requires grep 2.5 or above.

# This is the input:
# From theobald@bar-plate.com Sun Feb 11 17:04:36 2007
# Subject: [SPAM] [+++++++++++++++] Re:
# Folder: /home/tnowak/Maildir/.Spam/new/_DzB.U6zzFB.dingo 13416
# From geuzzld@eriksbikeshop.com Sun Feb 11 17:30:40 2007
# Subject: [SPAM] [+++++++++++++] Still waiting
# Folder: /home/tnowak/Maildir/.Spam/new/_SFC.wS0zFB.dingo 30131
# From commercialtalk.com@esoleau.com Sun Feb 11 17:49:00 2007
# Subject: [SPAM] [+++++++++++] She will love you more than any other guy
# Folder: /home/tnowak/Maildir/.Spam/new/_5QC.8j0zFB.dingo 2309

# TomekN had run this much:

grep -B1 "\[SPAM\]" .procmail.log | grep -v "\--" > procmail

# Here's the procmail file at this stage:
#
# From trutawan056@yahoo.com Sat Jan 27 22:06:05 2007
# Subject: [SPAM] [+++++++++++++++] =?windows-874?B?odLDqNG0t9PhvLm608PYp8PRocnS
# From aw-confirm@ebay.com Sat Jan 27 22:39:56 2007
# Subject: [SPAM] [+++++++] You're a Silver PowerSeller Now!
# From 863kurtis@lightningdezignz.com.au Sun Jan 28 01:56:00 2007
# Subject: [SPAM] [+++] Fwd: Too busy to go back to school,{} but need a Un
# From trutawan055@yahoo.com Sun Jan 28 03:47:48 2007
# Subject: [SPAM] [+++++++++++++++++] =?windows-874?B?odLD46rp4rfDyNG+t+wgtdS0te

sed -ne '/^From/{
s/^/ /
h
n
s/^ *//
G
p
}' procmail > procswapped

# Here's the procswapped file at this stage:
#
# Subject: [SPAM] [+++++++++++++++] =?windows-874?B?odLDqNG0t9PhvLm608PYp8PRocnS
# From trutawan056@yahoo.com Sat Jan 27 22:06:05 2007
# Subject: [SPAM] [+++++++] You're a Silver PowerSeller Now!
# From aw-confirm@ebay.com Sat Jan 27 22:39:56 2007
# Subject: [SPAM] [+++] Fwd: Too busy to go back to school,{} but need a Un
# From 863kurtis@lightningdezignz.com.au Sun Jan 28 01:56:00 2007
# Subject: [SPAM] [+++++++++++++++++] =?windows-874?B?odLD46rp4rfDyNG+t+wgtdS0te
# From trutawan055@yahoo.com Sun Jan 28 03:47:48 2007

while read line
do
subarray[$i]="$line"
((i++))
done < <(egrep '^Subject' procswapped)

# I've read the Subject lines into an array called subarray
# Now I'll sort them according to the number of '+'s
# I've created a new array called plus, which has only the sorted
# '+' patters, including the [ at the beginning and the ] at the end.
#
# Use sort -r if you want the list to be reversed.

plus=($(for (( i=0;i<${#subarray[@]};i++ )); do echo "${subarray[$i]}" | egrep -o '\[\+*\]'; done | sort | uniq))

# Now the final work. The array plus is formatted into a form sed
# will understand as the address, by escaping the proper characters using
# guess what, sed!

for (( i=0;i<${#plus[@]};i++ ))
do
sed -n "/$(echo ${plus[$i]} | sed -n 's/\[\([^[]*\)\]/\\[\1\\]/p')/{
N
p
}" procswapped
done

# Here's the final output:
#
# Subject: [SPAM] [+++] Fwd: Too busy to go back to school,{} but need a Un
# From 863kurtis@lightningdezignz.com.au Sun Jan 28 01:56:00 2007
# Subject: [SPAM] [+++++++] You're a Silver PowerSeller Now!
# From aw-confirm@ebay.com Sat Jan 27 22:39:56 2007
# Subject: [SPAM] [+++++++++++++++] =?windows-874?B?odLDqNG0t9PhvLm608PYp8PRocnS
# From trutawan056@yahoo.com Sat Jan 27 22:06:05 2007
# Subject: [SPAM] [+++++++++++++++++] =?windows-874?B?odLD46rp4rfDyNG+t+wgtdS0te
# From trutawan055@yahoo.com Sun Jan 28 03:47:48 2007
#
# Sorted, based on the spam level indicated by the number of '+'s.

Sunday, January 21, 2007

Newlines and sed

Blogger gave me hell trying to post this, so I asked techno_freak to post it for me, on his blog; which he kindly agreed to :)

Thanks dude.

Here's the link to the post:

http://technofreakatchennai.wordpress.com/2007/01/19/newlines-and-sed/

Wednesday, January 17, 2007

Console Locking

I stumbled upon this today:

* app-misc/vlock
     Available versions: 1.3-r1 1.3-r2
     Istalled: none
     Homepage: ftp://ftp.ibiblio.org/pub/Linux/utils/console/
     Description: A console screen locker


Pretty handy stuff. You can lock just the current console with vlock -c. That's quite basic. I liked the vlock -a option. It locks all the consoles. You can't even switch them using Alt+Ctrl+F* keys. Pretty handy.

Saturday, November 18, 2006

Sanctuaries

Ok, it all started with my friend Chetan letting this out yesterday:

"Windows will never be virus-free. Those anti-virus companies need to survive, don't they?"

Hmmm. That one reminded me of this one:

"World will never be rid of wars. The weapons industry needs them!"

The mention of war led to remind me of this one:

"Not everything man does is evil to nature. After all, some of us DO try and help and preserve animals. There ARE sanctuaries."

Right. Like there would be a need for sanctuaries if man hadn't threatened their existence in the first place!

This led to Vika remembering someone saying this:

"Americans didn't massacre the Indians. They're helping them preserve their culture.."

Like Vika says... nifty!

Friday, November 10, 2006

Running Faith


This is Amanda.

I started doing this one on 5th November and finished it on 10th November. Took nearly 8 hours.

Pencils used: HB, 2B, 4B, 6B, 8B, 2H, 4h, 6H.

I used the eraser quite a bit for highlighting.

Wednesday, November 08, 2006

A bash script to post on pastebin(s)

OK, ed-209 referred me to this script by zer0python, located here: http://www.alpadesign.com/shpost

I ended up adding features to it and in the process, making it ugly :-/. Anyway, here it is:


#!/bin/bash
# A Script that automates pasting to pastebin(s)..
# Thanks to ed-209 for this wonderful idea.. you can see his version
# which is located at http://www.alpadesign.com/shpost .. :>
#
# Author: floyd_n_milan
# Date: 08th November 2006
# Comments: Added features to the original script by zer0python
#
# Changelog:
# 08/11/06: Removed an unnecessary [ and added timeout to curl
#
# Usage: shpost.sh [-n nick] [-t type] [-s service] [-d description] \
# [-f source] [-h|--help|help]
######################################################################

function showusage
{
cat 1>&2 << EOF

nopaste: Automatic posting to pastebin(s).

Usage:
$0 [-n nick] [-t type] [-s service] [-d description] [-f source] [-h|--help|help]

Default nick is randomized.

type is one of the following:

"C89", "C", "C++", "C#"
"Java", "Pascal", "Perl"
"PHP", "PL/I", "Python"
"Ruby", "SQL", "VB"
"Plain Text"

BE SURE TO USE THE QUOTES FOR AT LEAST "Plain Text"

Default is Plain Text.

service can be one of the following:

rafb - http://rafb.net/post
sh - http://sh.nu/p/

Default is rafb.

Description must be quoted (""), if more than one word.

Default source is read from the keyboard. :-)

-h or --help or help shows this usage summery.

Mail comments, suggestions, bugs etc to
mrugeshkarnik@gmail.com
EOF
}

nick=""
lang=""
service=""
desc=""
input=""
url=""

if grep help <<<"$@"; then
showusage
exit 0
elif [[ ! $1 ]]; then
input="$(</dev/stdin)"
nick="shpostuser${$}"
lang="Plain Text"
service="rafb"
desc="shpost Post"
fi

while getopts ":n:t:s:d:f:h" opt; do
case $opt in
n )
nick="${OPTARG:=nopasteuser$$}"
;;

t )
lang="${OPTARG:="Plain Text"}"
;;

s )
service="${OPTARG:=rafb}"
;;

d )
desc="${OPTARG:="shpost Post"}"
;;

f )
input="$(<"${OPTARG:=/dev/stdin}")"
;;

h )
showusage
exit 0;;

? )
showusage
exit 64 #E_WRONGARGS (What's that?)
esac
done

input="${input:="$(</dev/stdin)"}"
nick="${nick:="shpostuser${$}"}"
lang="${lang:="Plain Text"}"
service="${service:="rafb"}"
desc="${desc:="shpost Post"}"

if [[ $service = rafb ]]; then
url=$(\
curl -i --connect-timeout 10\
-F "lang=$lang" \
-F "nick=$nick" \
-F "desc=$desc" \
-F "cvt_tabs=2" \
-F "text=$input" \
http://rafb.net/paste/paste.php 2>/dev/null | grep -i location)
echo "Your paste can be seen here: http://rafb.net${url:10}"
exit 0
elif [[ $service = sh ]]; then
curl --connect-timeout 10 -F "code=$input" -F "poster=$nick" http://sh.nu/p/
exit 0
fi

exit 0

Tuesday, November 07, 2006

bash Quoting

I thought I'd compile a list for bash's quoting rules for my own easy reference. I guess it might help others as well. Here goes then..

Escape Character (\)

Backslash (\) is used to remove the special meaning of the following character.
For example, \$ prints a $ instead of it being interpreted to signify a parameter.

An exception to the above statement is \. In the case of this sequence, bash looks for line continuation. Essentially, the character is removed completely.

Single Quotes ('')

Single quotes ('') are strong quotes. They bypass all the expansions. Everything inside single quotes is untouched.

You cannot have single quotes inside single quotes. Not even when backslash escaped. Use '\'' instead.

Double Quotes ("")

Double quotes allow parameter expansion, command substitution and arithmetic exansion. In short, all the expansions associated with $.

` is the archaic way of command substitution and is allowed inside double quotes.

\ inside double quotes is allowed only when used for \, `, $ and . In short, all the special characters which retain their special meaning inside double quotes.

Double quotes inside double quotes are allowed with used with a \. That is, \"

If history expansion is enabled, it'll be performed when ! is encountered inside double quotes. This can be bypassed with \!. The backslash preceding the ! is NOT removed.

Note: This can be annoying in your interactive shell when you get an error about history expansion when doing something like echo "Hello world!". The way to bypass this is to do "Hello world"\! or 'Hello world!' or Hello world\!

Examples:

Expression Value

$testvar hello
\$testvar $testvar
'$testvar' $testvar
"$testvar" hello
"'$testvar'" 'hello'
""$testvar"" hello
"\"$testvar\"" "hello"
~mrugesh /home/mrugesh
"~mrugesh" ~mrugesh
'~mrugesh' ~mrugesh

$' and $"

$'string' expands the string and the backslash escaped characters are replaced by the ANSI C standards. The expanded result is equivalent to being single quoted, as if $ is not present. Here are the characters expanded:

\a alert (bell)
\b backspace
\e an escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\' single quote
\nnn the eight-bit character whose value is the octal value nnn (one to three digits)
\xHH the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)
\cx a control-x character

As an example:
$ echo -e 'Hello\nworld'
Hello
world

$ echo $'Hello\nworld'
Hello
world

$" translates the quoted string according to the current locale. For C and POSIX locales, the $ sign is ignored. If translated and replaced, the replacement is double quoted.

$* and $@

These two special variables are used in terms of positional parameters. They produce the same output when unquoted. When double quoted however, "$*" produces one word with all the positional parameters separated by the first IFS character; while "$@" produces different words, separated by spaces.

To elaborate, if "$*" is fed as an argument to a command, it is just one single argument ($# will show you 1). If "$@" is fed as an argument, it is several different arguments($# will show you N, where N equals the number of positional parameters provided.).

Most times, you'd want to use "$@".

When unquoted, the output of both is grounds for word splitting.

For example,

$ set -- "first argument" "second argument" "third argument"

$ for i in "$@"; do echo ">${i}<"; done
>first argument<
>second argument<
>third argument<

$ for i in "$*"; do echo ">${i}<"; done
>first argument second argument third argument<

$ for i in $@; do echo ">${i}<"; done
>first<
>argument<
>second<
>argument<
>third<
>argument<

$ for i in $*; do echo ">${i}<"; done
>first<
>argument<
>second<
>argument<
>third<
>argument<

This post is for a quick reference. Look here for a proper explanation: http://www.grymoire.com/Unix/Quote.html. This document is not restricted to just bash.

Saturday, November 04, 2006

Two Birds with One Stone!

I had this problem with KDM while I was using amd64 on this Sempron64 machine. KDM would work fine for a while and then would become very slow on startup. By slow, I mean nearly 20 seconds. The NVIDIA logo would show up, followed by a blank screen with a busy mouse pointer in the middle. Normally, this screen would last only for a couple of seconds and KDM would show up. But here, it would keep showing for all of those 20 seconds. After that KDM would appear. During the blank screen period, there would a lot of disk activity.

The problem was very irritating. But I never bothered to solve it on that system.

I replaced the amd64 system with x86 last month. KDM had been fine till the start of this week. Then came the same problem. 20 seconds to start up. Very frustating. Today, I actually went on about investigating it. So here's how it went.

First of all, I needed to check the 'span' of the problem. I had had an X server crash today (Beryl and NVIDIA beta.. "Shit happens" ;-)). I noticed that after the crash, KDM started up normally, in no time at all. I logged out and the same thing happened. It started up normally. So apparently, the problem was only with the initial startup.

I next checked if KDM was the last thing starting on bootup, just to make sure that it isn't some other init script that starts up after KDM that causes this. After a few changes using rc-update and a reboot or two, I managed to conclude that the problem was with KDM itself.

Next, I removed xdm from the runlevel. Logged in as root and tried to run xdm. No go. No X and this in Xorg.0.log:

(II) Loader running on linux
(II) LoadModule: "bitmap"
(WW) Warning, couldn't open module bitmap
(II) UnloadModule: "bitmap"
(EE) Failed to load module "bitmap" (module does not exist, 0)
(II) LoadModule: "pcidata"
(WW) Warning, couldn't open module pcidata
(II) UnloadModule: "pcidata"
(EE) Failed to load module "pcidata" (module does not exist, 0)

Fatal server error:
Unable to load required base modules, Exiting...

(WW) xf86CloseConsole: KDSETMODE failed: Bad file descriptor
(WW) xf86CloseConsole: VT_GETMODE failed: Bad file descriptor


Ok. That didn't actually come as a surprise. I was unable to start that init script manually on the amd64 system either. X wouldn't start, syslog saying that VT7 was not available. I had ignored this too, back then. Well, I decided to fix it today.

I don't know why, but I opened up /etc/conf.d/xdm file. I didn't even know it existed before this. I found this in the file:

# Tell X to always start on VT7. Otherwise it autodetects the first available
# VT, which means it has to wait until all gettys are started so it doesn't suck
# up a VT that should have had a login prompt (very slow).
# If XSTATICVT is on, the login manager will start as soon as possible during
# the boot process. If you want X to dynamically start on the first unoccupied
# VT after all gettys have started and you are using xdm, also remove the "vt7"
# from /etc/X11/xdm/Xservers.
XSTATICVT="yes"


I changed XSTATICVT to no and issued a /etc/init.d/xdm start and behold! X started up fine. But, again, KDM took a lifetime to start.

This time though, I was already logged in on tty1. I switched to it and ran top while KDM was in that blank screen phase. I could see kdm_greet eating away at the CPU all the while the blank screen was displayed. I stopped the xdm init script and launched it again. KDM startup was normal this time. So the culprit was found. kdm_greet did something on the first startup that it didn't have to do on the subsequent startups..

Here's the solution that popped up: http://www.mail-archive.com/debian-qt-kde%40lists.debian.org/msg10087.html

Nice (!). A simple fc-cache -sv and a reboot and I could see the problem solved! The title of this post justified!

You know, its nice to play Sherlock Holmes sometimes.

Btw, big thanks to SimAtWork in #kde for helping me with the KDM issue. He/she was the one that gave me the link to the solution. :-D

Friday, November 03, 2006

'bash'ing!

I love bash. I absolutely love it. It is fun. It is great fun! Take this simple script, posted by GreyCat in #bash for example:

x="hello world"; echo "$x" | read a b; echo "$a $b"; read a b <<< "$x"; echo "$a $b"

Quite simple, isn't it? Well, here's the output:


hello world

Hmm? OK. Let's try again.

hello world
hello world

What's going on?

OK. Now here's the beauty of this little script. It teaches so many fundamentals of bash.

We start off with a simple x="hello world". Next we have a pipeline. A pipe feeds the standard output of one command to the standard input of another command, as we know.

So here, we have the standard output of echo, which is 'hello world' (Well, that's written in English. In bash's terms, the output is equivalent to "hello" "world" I suppose..), being fed as the standard input of read. read stores the two words into two variables, a and b.

The pipeline finishes there and then we simply echo the values of a and b. The output, as we can see, is blank.

Now why exactly? Let's check.. Is the assignment of the variables correct? Yes. read takes the standard input by default, so a and b get assigned the values hello and world respectively. But the output of echo is still blank.

Why?

The answer is subshell. A pipeline spawns a different subshell for each process. So read a b operates in a different subshell.. different from echo "$a $b". As we know, subshells cannot propagate any information back to its parent shell. Hence, the values of a and b are blank, as they don't yet exist in the parent shell.

In the second case, we've used a form of here document - <<<. <<< expands the argument "$x" and feeds it to read a b's standard input. This time, we get a proper hello world output from echo "$a $b", because <<< doesn't spawn a subshell.

Now, if you run the same command line again, in the same session, you'll get this output:

hello world
hello world

How come?

Quite simple. The values of a and b are set by our previously run read a b <<< "$x". The values already exist in our shell, hence.

I suppose power users will find this information quite rudimentary. But, newbies would do well to understand the concepts involved. No matter how good I may become at bash, such small concepts will always be fascinating!

Tuesday, October 31, 2006

"Bilbo, the butt goes in your pocket!"

This is a little story. It has a moral too. And that moral is very very simple. Something that everyone should follow.

Well, here goes.

It was about 9:30 PM. I was coming home. As I reached halfway up the stairs to the first floor of my building; I saw a man standing there; smoking a cigarette. A stranger. I hadn't seen him anywhere near my building before. The sight annoyed me. You are not suppose to smoke a cigarette, standing in the stairs of a residential building; especially one in which you don't live. But I was helpless as the society had't put up any notice to prevent this.

So I had to ignore him and climb up past him. I reached the first floor and started up on the second flight of stairs; when the man finished with his cigarette. I stood there observing him. And exactly as I expected; he threw the butt right there in the stairs. Then he started climbing up. He threw a blank stare at me as he noticed me observing him.

"Excuse me. Why did you just throw that cigarette in the stairs?" I enquired.

"Oh. Doesn't matter. Its so small!" He exclaimed; because really; this was routine to him and to him it really didn't matter.

"Well, there are dustbins around to throw your garbage into. Why did you just throw it in the stairs?"

"Oh. Fine. I'll throw it in the dustbin next time." He was annoyed; I could tell. This was probably the first time he was being interrogated regarding such an action.

"What of the one that you've just thrown onto the stairs?"

"What? You want me to pick it up and put it in my pocket or what?" He was literally fuming!

And hahahah! Thank you. He chose his own doom hahahah! I merely gave him a stare and he understood. He went downstairs and started searching for the cigarette butt; some two feet away from where he had thrown it.

"Where is it? I can't even see it. It is so small? What of this? This is garbage too!" He had picked up some random string of wool lying there. I'm sure he'd have cut off my head had that been a sword instead!

"Yes, it is. Thanks for picking it up. But your garbage still remains.." I obliged.

"I can't even see it! It is so small and irrelevant!!" He stomped around a bit.

I went to where he had thrown that butt, picked it up, handed it to him. He took and put it in his pocket.

"Happy now?"

"Yes sir! Absolutely. Thank you. Now just remember to use the dustbin from now on." I said pleasantly and started climbing upstairs.

A few seconds later; I head him banging the door of the first floor residents; whom he had apparently come to pay a visit.

That's about it.

Moral of the story? Don't smoke a cigarette in a residential place. It annoys people like me. No; I am fine with people smoking. All my pals do; even I do, seldom; but not in the stairs of a residential building. If you do have the urge to do so; however; make sure that building isn't mine. If the building is mine; make sure you don't throw the butt anywhere other than into a dustbin; especially; when I'm around. Oh and make sure you scuff it out. Because if I find you at this; that butt might just burn a hole in your favourite shirt's pocket.

Saturday, October 21, 2006

Ketaki


Ah finally! This is my first portrait ever!

This is my friend Ketaki.

This one took some real efforts. I had to span it across two days. On the first day, 15th October 2006, I finished the face. On the second, 21st October 2006, I dealt with the hair. Pretty tough work. Anyway, I think it looks pretty decent. Not bad for the first effort.

Saturday, September 23, 2006

Another step closer to "Bye bye Windows!"

Alright. Wine is seriously cool! The only problem is that it takes a LOT of time to compile and it took out nearly 400MB from my /usr!!

Anyway, its way too cool to cry about all that.

The thing is, Guitar Pro 5 works great in wine. All I needed to do was to install timidity++. I had to go ~amd64 on it, because the current stable 2.13.2 didn't compile. I was not in a mood to debug it, so I just changed the keywords and the testing version 2.13.2-r2 worked perfectly. I went with the default timidity-eawpatches.

Next came wine. It failed during ./configure because /usr/X11R6/lib/libGL.a existed, which, from what the error message said, prevented linking against the OpenGL libs. I thought of going -opengl for wine, but then felt like experimenting and moved the libGL.a file somewhere else. libGL.la exists in the same location anyway. Wine got installed fine then.

Once, done with winecfg, I launched the Guitar Pro installer with winelauncher. It installed fine, even with that RSE thing selected.

With RSE however, it doesn't play the sound properly. I had to remove RSE and it worked perfectly. Also, do not touch the Change Skin button in GP5. Trashed mine. Plus of course, the Windows Volume Control button doesn't work, which is kinda obvious.

I have slight performance problems when a KDE notification pops up while playing a file in GP5. But that's a minor. Maybe I wouldn't have the problem if I disabled XGL. Who knows?

Anyway, so there I am. Another step closer to "Bye bye Windows!". The only thing that remains now, is running Pro Evolution Soccer on Linux and this will be a single boot box of Gentoo! :D

Friday, September 22, 2006

The Chosen One?


Well, here's Vader and Sideous. This is a scene in Revenge of the Sith. Done with poster colours on a normal A4 size drawing paper. Took me nearly 5 hours. Vader's face alone took nearly 4 hours. By the time I reached Sideous, I was totally spent, because I had been running a high fever during the whole time I was painting this. Hence, Sideous hasn't been done properly. Otherwise, I'm happy with the way Vader's face turned out.