Archive for category Uncategorized

Formatter Class-Simple example.

A simple example to understand concept of Formatter class.

import java.util.*;

class FormatterExample{

public static void mainn( String a[]){

Formatter fm= new Formattre();

fm.format("Java %s easy %d %f", "is so", 1,91.3);

System.out.println(fm);

}
}

,

No Comments

front3

Given a string, we’ll say that the front is the first 3 chars of the string. If the string length is less than 3, the front is whatever is there. Return a new string which is 3 copies of the front.

front3(”Java”) ? “JavJavJav”
front3(”Chocolate”) ? “ChoChoCho”
front3(”abc”) ? “abcabcabc”

public String front3(String str) {
if(str.length() <3) return str+str+str;
else return str.substring(0,3)+str.substring(0,3)+str.substring(0,3);

}

, ,

No Comments

Program to create linked list and basic operations in C++.

#include<iostream>
using namespace std;
class Polynomial
{
struct node
{
int coeff,a,b,c;
struct node * next;
};
//definition of the structure node
char ans;
int flag;
public:
struct node * head,* tail,* current_ptr,* s,* start,* corpse;
Polynomial()
{
head=new node;
current_ptr=head;
start=current_ptr;
}
//constructor
void getdatafor_node(struct node *);
void insert_node();
Polynomial add_two_polynomials(Polynomial,Polynomial);

struct node * Previous(struct node * current_ptr)
{
struct node * temp=start;
while(temp->next != current_ptr)
{
temp=temp->next;
}
return temp;
}
//to find the previous node of the current pointer
};
//definition of class

void Polynomial::insert_node()
{
ans='y';
struct node * temp;
while(ans=='y')
{
temp=new node;
getdatafor_node(temp);
current_ptr->next=temp;
current_ptr=current_ptr->next;
cout<<"continue?(y/n):";
cin>>ans;
}
if(ans=='n')
{
start=start->next;
current_ptr->next=start;
}
}
//for inserting a node in the circular linked list

void Polynomial::getdatafor_node(struct node * temp)
{
cout<<"Enter the input for the node"<<endl;
cout<<"Enter the coefficient:";
cin>>temp->coeff;
cout<<endl;
cout<<"Enter the exponents of x,y,z:";
cin>>temp->a>>temp->b>>temp->c;
}
//to get the data from the user

Polynomial Polynomial::add_two_polynomials(Polynomial P,Polynomial Q)
{
current_ptr=current_ptr->next;
start=current_ptr;
Q.current_ptr=Q.current_ptr->next;
Q.start=Q.current_ptr;
//intialising

if(current_ptr->a==Q.current_ptr->a && current_ptr->b==Q.current_ptr->b && current_ptr->c==Q.current_ptr->c)
{
flag=0;
Q.current_ptr->coeff=Q.current_ptr->coeff+current_ptr->coeff;
}
else
{
flag=1;
Q.current_ptr=Q.current_ptr->next;
}
//to compare first nodes of both

while(Q.current_ptr!=Q.start)
{
if(current_ptr->a==Q.current_ptr->a && current_ptr->b==Q.current_ptr->b && current_ptr->c==Q.current_ptr->c)
{
flag=0;
Q.current_ptr->coeff=Q.current_ptr->coeff+current_ptr->coeff;
Q.current_ptr=Q.start;
}
else
{
flag=1;
Q.current_ptr=Q.current_ptr->next;
}
}
//compare first node of P with Q

if(flag==1)
{
Q.s=Q.Previous(Q.current_ptr);
cout<<(Q.Previous(Q.current_ptr))->coeff;
current_ptr=current_ptr->next;
Q.s->next=Previous(current_ptr);
(Previous(current_ptr))->next=Q.current_ptr;
Q.current_ptr=Q.current_ptr->next;
}
//inserting the node of P in Q

else
current_ptr=current_ptr->next;

while(current_ptr!=start)
{
if(current_ptr->a==Q.current_ptr->a && current_ptr->b==Q.current_ptr->b && current_ptr->c==Q.current_ptr->c)
{
flag=0;
Q.current_ptr->coeff=Q.current_ptr->coeff+current_ptr->coeff;
}
else
{
flag=1;
Q.current_ptr=Q.current_ptr->next;
}

while(Q.current_ptr!=Q.start)
{
if(current_ptr->a==Q.current_ptr->a && current_ptr->b==Q.current_ptr->b && current_ptr->c==Q.current_ptr->c)
{
flag=0;
Q.current_ptr->coeff=Q.current_ptr->coeff+current_ptr->coeff;
Q.current_ptr=Q.start;
}
else
{
flag=1;
Q.current_ptr=Q.current_ptr->next;
}
}
if(flag==1)
{
Q.s=Q.Previous(Q.current_ptr);
cout<<(Q.Previous(Q.current_ptr))->coeff;
current_ptr=current_ptr->next;
cout<<current_ptr->coeff;
Q.s->next=Previous(current_ptr);
(Previous(current_ptr))->next=Q.current_ptr;
cout<<Q.current_ptr->coeff;
Q.current_ptr=Q.current_ptr->next;
}
else
current_ptr=current_ptr->next;
}
cout<<Q.current_ptr->coeff;
cout<<current_ptr->coeff;
return Q;
}
main()
{
Polynomial P,Q,R;
P.insert_node();
Q.insert_node();
R=P.add_two_polynomials(P,Q);
R.current_ptr=R.start;
cout<<(R.Previous(R.current_ptr))->coeff;
while(R.current_ptr->next!=R.start)
{
cout<<"Print the coefficient of resulting polynomial:"<<R.current_ptr->coeff<<endl;
cout<<"Print the exponent of x:"<<R.current_ptr->a<<endl;
cout<<"Print the exponent of y:"<<R.current_ptr->b<<endl;
cout<<"Print the exponent of z:"<<R.current_ptr->c<<endl;
R.current_ptr=R.current_ptr->next;
}
cout<<"Print the coefficient of resulting polynomial:"<<R.current_ptr->coeff<<endl;
cout<<"Print the exponent of x:"<<R.current_ptr->a<<endl;
cout<<"Print the exponent of y:"<<R.current_ptr->b<<endl;
cout<<"Print the exponent of z:"<<R.current_ptr->c<<endl;
//to print the resulting polynomial
}

, , , , ,

1 Comment

Download pics from idlebrain based on keyword

Here is a script to download many pics all at once based on keywords. Idlebrain.com is a site which has huge collection of pics of many actresses and from many movies. This script is very useful to download large number pics from idlebrain all at once with single click.

Introduction
————

IPD (Idlebrain pics downloader) is used to download pics from idlebrain .This is thought to be primarily aimed at Linux.
You should have “wget” installed in your system to use these scripts.

check your internet connection before running these scripts.
If your having proxy authentication then set http_proxy, ftp_proxy to the corresponding value

COMMAND : export http_proxy=http://<username>:<password>@<proxy-server>:<port>/
export ftp_proxy=ftp://<username>:<password>@<proxy-server>:<port>/

By default wget uses this proxy settings.

This readme contains only the basic information.

Installing:
——–

Get in to the root account.

COMMAND  : su  - 

Create a new folder to save the pics and the scripts
For example :

COMMAND  : mkdir images

Get in to the folder and extract the scripts in to the folder:

COMMAND  : tar -xvf  ipd.tar.gz

This package contains 3 scripts .

  • The first script(idlebrain) is meant for user interface.
  • The second(downloader) to download .
  • The last to resume the unfinished downloads.

And now you have those three files in your folder. just give them execute permissions and you are ready to go.
Command to do that is

COMMAND     : chmod +x idlebrain downloader resume

Running:
——-

It is pretty simple to use these scripts.

COMMAND  : es]#  ./idlebrain <filter>

where filter can be any heroin or movie name from http://idlebrain.com/movie/photogallery/

There is extra option to download all the pics from idlebrain

COMMAND  : es]# ./idlebrain -

The above command will download all the pics from idlebrain. It is very unlikely that u would wish to do that.
Be careful before using this command .It consumes huge amounts of disk space.

There is another script which you would use to for incomplete downloads.

Once you have downloaded the pics with some filter just be careful to use “resume” if you think there are any incomplete downloads rather than using “idlebrain”.

COMMAND  : es]#  ./resume <filter>

*** You should have the directory named “filter” for resume to work.
If you don’t have that directory just use “idlebrain” to start download.

Here is a small example :

COMMAND  : es]#  ./idlebrain anushka

The above command will start downloading the pics.
If you have some problem while downloading or you got disconnected then use

COMMAND  : es]#  ./resume anushka

The above command will complete the download.
Your downloaded pics will be stored in anushka folder (named after the filter).

*** use all small letters while using filter if you have any problem downloading you can try otherwise .

Download the file here :

, , , ,

1 Comment

PHP script to send post data.

The below function will post data to the corresponding site. There are four arguments for this function as you can see. I will explain each parameter in detail.

  • $url — This represents the URL to which we send the POST data to.
  • $header  — This represents the HTTP header used to send POST data.
  • $cookie — This includes the cookies  to be send to authenticate.
  • $p —  This shows the data to be sent as post to the URL.

<?php
function cURL($url, $header, $cookie, $p)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_NOBODY, $header);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, "[proxy server]");
curl_setopt($ch, CURLOPT_PROXYPORT, [proxy port]);
curl_setopt ($ch, CURLOPT_PROXYUSERPWD, "[username]:[password]");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
if ($p) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
}
;
$result = curl_exec($ch);
curl_close($ch);
if ($result) {
return $result;
} else {
return curl_error($ch);
}
}
?>

No Comments

Program to calculate Square root of X manually.

#include<stdio.h>
float sqroot(float n)
{ int x=0;
float guess=10.0,quot,avg;
while(x!=20)
{
quot=n/guess;
guess=(guess+quot)/2;
x++;
}
return guess;
}
main()
{ float n;
printf("\nEnter the number to calculate Square root of it!!");
scanf("%f",&n);
printf("\nSquare root of n is=%f",sqroot(n));
}

, , ,

No Comments

Program to check the address storage of a multidimensional array.

#include <stdio.h>

int main()
{
int a[10][10], i, j;

for(i=0;i<10;i++)
for(j=0;j<10;j++)
printf("&a[%d][%d]=%u\n",i,j,&a[i][j]);

return 0;
}

, ,

No Comments

Auto Add friend requests userscript

When you want to add someone in orkut, you click on “add as a friend” and again it will refresh to some add page and then you click add again to actually send friend request. This process is made simple by the below script. When you click “add as a friend” in orkut it will automatically add the user. This is just a one click process now.

Hope you like this userscript

You need firefox ( Web browser )
and greasemonkey add-on to be installed to use this script.

Click on the link below to install the script.

No Comments

Visit us at www.hackattacking.com

 
         ==---------------==                                                    
       =-                   -=          ====SSS===                              
     S-    Come See Me At     S       =SSSSSSSSSSSS=                            
     S                        S      SSSSSSSSSSSSSSSSS=                          
     S www.hackattacking.com  S    =SSSSSSSSSSSSSSSSSSS=                        
      -=                     =-    SSSSSSSSSSSSSSSSSSSSS                        
        -==      ===========-     SSS-SSSSSSSSSSSSSSSSSS=                       
           -=   S                SSS = --------SSSSSSSSSS                       
            -=  -=               SS- -=         -SSSSSSSSS                      
              -=  -=             SS   -S==S      -SSSSSSSS                        
                -== -=           SS=          S=   -SSSSSSS                     
                   -----          SS           -S=S  SSSSSS                       
                                =SSSS  -=  -=        SSSSSS                      
                               =SS -S=  S--==   =====SSSSSS                     
                               SS   -SS=-S==S-=S----SSSSSSS                    
                               SS     -SS==  =S      SSSSSS                  
                               SS       --SSSS-      SSSSSS                  
                               SSSSS=  =====S-       SSSSSS                   
                             =SS--  =SS----SS       SSSSSSS                   
                            SS-    SS-    =S-      SSSSSSSS                   
                           SS     =S  =S==S-      SSSSSSSSS                    
                          SS-S    S-  S =S-      =SSSSSS--                      
                          S==S    S=  SSSS      =S-SS--                         
                          -SS-    -S   SS       S- SS                           
                            SS=    SS  S-      S-  -S=                          
                             -SS====SS=S      S-    SS                          
                               --SS--SS      =S     SS                          
                                 SS =S-     =S      SS                          
                                 SS=S-     =S-       SS=                        
                                 SSS-     =S-        -SSS=                      
                                 SSS     =S-           -SS=                     
                               ==SS-    =SSS=            SS=                    
                            ==SSSS     =SSS--             SS=                   
                         ==SSS-SS  ===SS--                SSS                   
                      ==SSS--  SSSSS--                     SS                   
                   ==SSS--  ==SSS--                       =S-                   
                ==SSS--  ==SS---                          SS                    
              =SSS--  ==SS--                            =SS                     
            =SS--    =S--                           ===SS=                      
           =SS-     SS-                        ====SSSSSSSSSSS=                 
           SSS     SS-                    ===SSSS---------   -SS                
           SS-     SS=              ====SSS----                SS               
           -SS      SS             -SS----                      S=              
            SS=     -S=                                    =S    S=             
             SSS==   -SS=                                 =SSS    -=   
              -SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS- SSSSSSS       
                 -----------------------------------------    -----             

No Comments

perl rename script

Usage: $ME [OPTION]… PERLEXPR FILE…
Rename FILE(s) using PERLEXPR on each filename.

-b, –backup make backup before removal
-f, –force remove existing destinations, never prompt
-i, –interactive prompt before overwrite
-S, –suffix=SUFFIX override the usual backup suffix
-v, –verbose explain what is being done
-V, –version-control=WORD override the usual version control
-n, –just-print, –dry-run don’t rename, implies –verbose
-l, –link-only link file instead of reame
–help display this help and exit
–version output version information and exit

The backup suffix is ~, unless set with SIMPLE_BACKUP_SUFFIX. The
version control may be set with VERSION_CONTROL, values are:

t, numbered make numbered backups
nil, existing numbered if numbered backups exist, simple otherwise
never, simple always make simple backups

#!/usr/bin/perl

use strict;

use Getopt::Long;
use Text::Abbrev;
use File::Basename;

Getopt::Long::config(qw(bundling));
$Getopt::Long::prefix = '--';

my $ME = $0;
($ME = $0) =~ s!.*/!!;
$| = 1;

my $nothing         = 0;
my $backup          = 0;
my $force           = 0;
my $interactive     = 0;
my $verbose         = 0;
my $help            = 0;
my $version         = 0;
my $linkonly        = 0;
my $backup_suffix   = $ENV{SIMPLE_BACKUP_SUFFIX} || '~';
my $version_control = $ENV{VERSION_CONTROL} || 'existing';

my $vcm             = 0;

sub error {
    my($ERROR) = @_;
    print "$ME: $ERROR\n";
    print "try: `$ME --help' for more information.\n";
    exit 1;
}

{
    local $SIG{__WARN__} = sub {
	if ($_[0] =~ /^Unknown option: (\S+)/) {
	    error("unrecognized option `--$1'");
	} else {
	    print @_;
	}
    };
    GetOptions(
	       'b|backup'             => \$backup,
	       'f|force'              => \$force,
	       'i|interactive'        => \$interactive,
	       'v|verbose'            => \$verbose,
	       'S|suffix=s'           => \$backup_suffix,
	       'V|version-control=s'  => \$version_control,
	       'n|just-print|dry-run' => \$nothing,
               'l|link-only'          => \$linkonly,
	       'help'                 => \$help,
	       'version'              => \$version,
	      );
}

if ($version) {
    print "$ME $VERSION\n";
    exit 0;
}

if ($help) {
    print< VCM_TEST,
	       existing => VCM_TEST,
	       t        => VCM_NUMBERED,
	       numbered => VCM_NUMBERED,
	       never    => 0,
	       simple   => 0,
	   }}{$vcm};
}

my $op = shift
    or error('missing arguments');

if (!@ARGV) {
    @ARGV = ;
    chomp(@ARGV);
}

for (@ARGV) {
    my $was = $_;
    {
        no strict;
        eval $op;
    }
    die $@ if $@;
    next if $was eq $_;

    if (-e $_) {
        unless ($force) {
	    if (! -w && -t) {
		printf "%s: overwrite `%s', overriding mode 0%03o? ",
                       $ME, $_, (stat _)[2]&0777;
		next unless  =~ /^y/i;
	    } elsif ($interactive) {
		print "$ME: replace `$_'? ";
		next unless  =~ /^y/i;
	    }
	}
	if ($backup) {
            my $old;
	    if ($vcm) {
		($old) = sort {($b=~/~(\d*)~/)[0] <=> ($a=~/~(\d*)~/)[0]} <$_.~*~>;
		$old =~ s/~(\d*)~$/'~'.($1+1).'~'/e;
		if ($vcm & VCM_TEST) {
		    $old ||= "$_$backup_suffix";
		} elsif ($vcm & VCM_NUMBERED) {
		    $old ||= "$_.~1~";
		}
	    } else {
		$old = "$_$backup_suffix";
	    }
            print "backup: $_ -> $old\n" if $verbose && $nothing;

            unless ($nothing) {
                if (rename($_,$old)) {
                    warn "$ME: cannot create `$_': $!\n";
                    next;
                }
            }
        }
    }

    print "$was ", $linkonly?"=":'-', "> $_\n" if $verbose || $nothing;

    if (m,/,) {
        my $dir = File::Basename::dirname($_);
        unless (-d $dir) {
            if ($nothing) {
                print "mkdir: $dir\n" if $verbose;
            }
            else {
                mkpath($dir) || next;
            }
         }
    }

    unless ($nothing) {
        if ($linkonly) {
	    link($was,$_) || warn "$ME: cannot create `$_': $!\n";
        } else {
            rename($was,$_) || warn "$ME: cannot create `$_': $!\n";
	}
    }
}

sub mkpath {
    my($path) = @_;
    $path .= '/' if $^O eq 'os2' and $path =~ /^\w:\z/s; # feature of CRT
    # Logic wants Unix paths, so go with the flow.
    if ($^O eq 'VMS') {
        next if $path eq '/';
        $path = VMS::Filespec::unixify($path);
        if ($path =~ m:^(/[^/]+)/?\z:) {
            $path = $1.'/000000';
        }
    }
    return 1 if -d $path;
    my $parent = File::Basename::dirname($path);
    unless (-d $parent or $path eq $parent) {
        mkpath($parent) || return;
    }
    #print "mkdir: $path\n" if $verbose;
    unless (mkdir($path, 0777)) {
        unless (-d $path) {
            warn "$ME: cannot mkdir `$path': $!\n";
            return;
        }
    }
    return 1;
}

__END__

1 Comment