user-avatar
Today is Saturday
April 20, 2024

Category: programming

May 13, 2014

JavaScript browser code to invite all your friends to like facebook page

by viggy — Categories: FOSS, FSMK, FSMK, programming, web — Tags: , , , , , 1 Comment

We have recently announced the FSMK Summer Camp for the year 2014 and also have a facebook page for the same. We wanted to spread the word out about the page by inviting all our friends to ‘like’ the page. FB shows you a list of your friends  and gives an option to click ‘invite’ for each one of them separately. When you do this, the invited friend gets a notification about the invite and hence more chances of his liking the page.

However this is still cumbersome as it means to invite all your friends which may be around 1000+, you have to click invite so many times.

But you have java script to the rescue. All you need to do is open javascript console on your browser and then execute the following code:


//Note that there is a space after uiButton. This class is the class of the invite button.
var inputs =
document.getElementsByClassName('uiButton _1sm');

for( var i=0; i < inputs.length; i++)
{
inputs[i].click();
}


To find out how to run javascript code in Firefox, check the following link.

If sadly you are not using the best and fastest browser, Firefox, then you can of course find similar tutorials for other browsers or realize it is time to switch to Firefox as Firefox29 is just released and its AWESOME!!!

P.S. The code was shared to me by Karthik Nayak from BMSIT GLUG.

August 8, 2011

How to use mail command to mail the contents of the file to somebody

by viggy — Categories: FOSS, linux, programming, shell, tech — Tags: , , Leave a comment

$cat “Filename” | mail -s “subject” “mailid”

The assumption here is that you have sendmail configured in the system and the mailid that you have provided accepts mails from unknown addresses. Gmail doesnt.

July 4, 2010

Shell script to search for a type of file in a directory recursively and copy it in a destination

by viggy — Categories: shell — Tags: , , Leave a comment

I had used wget and downloaded all the java videos from the java tutorial site( and also all the other files on the website). There were around 20 of them. The problem was that the lectures were each present in a separate folder and I had to traverse to each of them to watch them. So I thought of writing a script which would search the main directory recursively for the lectures and then copy it in a specific folder. Luckily in my case each of the lecture were named differently and hence I didnt have to rename them and there were no issues of file name getting clashed. Below is my shell program:

#!/bin/sh

list=$`find . -type f | grep ".mp4"`
cp $list ./lectures

This would search all the files which had .mp4 in their name and copy them into the folder lectures.

November 3, 2009

one line perl command to get the @INC array

by viggy — Categories: perl, programming, tech — Tags: , Leave a comment

Below is a one line command to display all the entry in @INC array which contains the paths where perl programs looks for perl modules.

perl -e ‘foreach $_ (@INC){ print $_,”n”};’

October 18, 2009

bash script to telnet

by viggy — Categories: programming, shell, tech — Tags: , Leave a comment

It is sad that I have found this solution after so many days. It is more sad that I never tried to look for this solution earlier. I must have found it atleast 3 months ago. Anyways now that I have found it, let me tell you what exactly I want to do and how the simple script helps me do it.

I have been playing with qmail and qpsmtpd from last 3-4 months. Now to test my set-up, I used to telnet to the port and then used to enter different telnet commands and used to watch the logs simultaneously to get errors.
Now everytime I used to enter the commands manually and that too I couldnt just go to history and execute it as telnet does not support storing commands in history.
Anyway finally today I got fed up of it and I thought let me see if there is a solution so that I dont have to enter commands manually. I didnt expect a solution. But when I searched for it, I found that it was so easy to do it. You just need to execute the following command.
./smtp.sh | telnet

and the contents of smtp.sh is given below:
#!/bin/sh
host=127.0.0.1
port=25
echo open $host $port
sleep 10
echo helo deeproot.co.in
sleep 10
echo mail from:test2@domain
sleep 10
echo rcpt to:test3@domain
sleep 50
echo data
sleep 10
echo checking
echo .
sleep 10
echo quit
#end

You can customize the script to anything that will make your life easier with telnet. I found this solution here, http://www.linuxforums.org/forum/linux-programming-scripting/92466-telnet-script.html

July 21, 2009

How to search a perl function’s man page

by viggy — Categories: perl — Tags: , , Leave a comment

If you know the name of the function and you want to see the man page for that function, then you can use the following command.

perldoc -f “function name” //without quotes

for example,

perldoc -f our
perldoc -f sysopen

July 21, 2009

Perl-error “.pm did not return a true value at”

by viggy — Categories: perl — Tags: , , Leave a comment

This is one of the errors that I got when I started using perl modules.
It was because I had not put “1;” at the end of my perl module. So I did not get the error after I put “1;” at the end of the perl module.

why is the “1;” necessary at the end of perl modules?

Typically, a module contains a bunch of subroutine definitions.  A
module may also contain code which is not part of a subroutine. This
code is executed at the time the module is loaded, so it can be used
to initialize the module. For example, the module might open
adatatbase connection or initialize some time at the time it is
loaded.


Such code might be successful, or it might fail. Perl allows the
module to indicate the result by returning a true or false value back
to its caller. If the value is false, Perl aborts the compilation
with an error message.

Unfortunately, the default return value is *false*, so a module which
just defines a bunch of subroutines, and which has no initialization
code, accidentally returns a false value back to the caller, and Perl
aborts. So we insert "1;" at the end to suppress this misbehavior.

http://dev.perl.org/rfc/269.pod
http://dev.perl.org/rfc/269.html

discusses this in some more detail.

For documentation, see perldiag:

%s did not return a true value
(F) A required (or used) file must return a true value
to indicate that it compiled correctly and ran its
initialization code correctly. It's traditional to
end such a file with a "1;", though any true value
would do. See the require entry in the perlfunc man-
page.

and the relevant part of 'perlfunc':

The file must return true as the last statement
to indicate successful execution of any initialization code, so
it's customary to end such a file with "1;" unless you're sure
it'll return true otherwise. But it's better just to put the
"1;", in case you add more statements.

Courtsey: http://lists.netisland.net/archives/phlpm/phlpm-2001/msg00426.html