Friday, 17 July 2015

/* package whatever; // don't place package name! */

similar implimentation to java System.out.println()

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
A a=new A();
A.p.out();
}
}
class P
{
int out()
{
System.out.println("here what prints");
return 0;
}

}
class A
{

 static Prin print=new Prin();

}

Wednesday, 1 July 2015

telerik basic page work

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Include jQuery Mobile stylesheets -->
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
    <link rel="stylesheet" href="css/index.css" />
    <!-- Include the jQuery library -->
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <!-- Include the jQuery Mobile library -->
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

    <script>

        function check() {
            var a = document.getElementById("text1").value;
            var b = document.getElementById("password1").value;
            if (a == "raj" && b == "password" || a == "RAJ" && b == "password" || a == "Raj" && b == "password") {
                window.location.href = "#pagetwo";
                document.getElementById("show").innerHTML = a;
            }
            else {
                alert("wrong username/password");
            }
        }
    </script>

</head>
<body>

    <!--page one-->
    <div data-role="page" id="pageone">
        <div data-role="header">
            <h1> Welcome To HomePAGE </h1>
        </div>
        <p><center><h1>login form</h1></center></p>

        <div data-role="main" class="ui-content">

            <table>
                <tr>
                    <td>username</td>
                    <td><input type="text" id="text1" /></td>
                </tr>
                <tr>
                    <td>password</td>
                    <td><input type="password" id="password1" /></td>
                </tr>
            </table>
            <center><input type="button" value="login" onclick="check()" /></center>

        </div>




        <div data-role="footer" data-position="fixed">
            <h1> FOOTER</h1>

        </div>
    </div>


    <!--page two-->
    <div data-role="page" id="pagetwo">
        <div data-role="header">
            <h1> hello world </h1>

        </div>


        <div data-role="main" class="ui-content">
            <p>Welcome</p>
            <a href="#pageone">go back</a>
            <div id="show">
            </div>
        </div>

        <div data-role="footer" data-position="fixed">
            <h1> FOOTER</h1>

        </div>
    </div>










</body>
</html>

Friday, 26 June 2015

javascript

date object

var today = new date(); // return todays date

to make out own obj

we can we

var day= new Date(2011,0,1);// year month and day , month as an exception starts as 0

var daytime= new Date(2011,0,1,0,0,0);//also adds hours , mins and secs with previous

Get methods of date obj

day.getMonth();
day.getYear();
day.getTime();

Set methods

day.setMonth(5);

comparison

var date1= new Date(2001,1,1);
var date2= new Date(2001,1,1);

if(date1==date2)//false

if(date1.getTime()==date2.getTime())

CREATING NEW OBJECT

var player= new object();

now its data members will be declared as

player.name="fred";
player.age=13;
player.rank=1;

A variable inside a object is called its properties, same as data member

shorthand to create an object

var player= {name: "Fred",age:13,rank:1};







Thursday, 25 June 2015

git bash


git config --global user.name "<name>"

git config --global user.email "<email>"

git init <project>
to make the folder working area for git , ie to make it project folder

git log
see changes made through commit

git status
see the staged area , new files that have come up and the files that have changed

git add .
add all the files of folder to the staged area

git add "filename"
add the particular file to the stage area

git commit -m "any comment to indicate the changes that reflect in this commit"

git diff
show the exact changes that have taken place in files (as their lines of code)
but shows only of unstaged files

git diff --cached
after we add a file to the stage area and we want to see the differences then we need to use --cached otherwise the changes wont show

shortcuts
if the log becomes to big , to come out of it we need to press ctrl+z+z or ctrl+c(checked)

git log --oneline
show all commits with just the associated message

git commit -a -m "message"
it will quickly do commit , and also add the files to the staging area (replacement as one line code)

git status -s
show modifications in shorthand

ssh-keygen -t rsa -C "email address"
generates rsa key for computer

ssh -T git@github.com
checks whether the computer is able to communicate with the gitserver or not after using rsa encryption


git  remote add  origin "git repository ssh "
will add the remote repository from where we will push or pull the data


git push origin master
will push everything on remote repository

git branch
ti know  all braches

git brach branchname
to make a new branch

git checkout branchname
to go to that branch

git clone "ssh url"
to clone a project to local

git remote add variablename "ssh " or
git push varialbe name branch name
git push something in a branch

TO merge
git merge master
this will merge the code of master with our branch





Thursday, 26 March 2015

my php codes

what do we do to display the common file name that php file shares

<?php
//echo 'hello';
echo $_SERVER['SCRIPT_NAME'];// WILL TAKE THE SCRIPT NAME AND DISPLAY IT
//echo $var;
?>

vid lec - 61

first file 1.php
<?php

include 'inc.php';

if(isset($_POST['submit'])){
echo 'process 1';

}

?>

file 2.php

<?php

include 'inc.php';

if(isset($_POST['submit'])){
echo 'process 2';

}

?>

inc.php

<?php

$script_name= $_SERVER['SCRIPT_NAME'];// WILL TAKE THE SCRIPT NAME AND DISPLAY IT
echo $script_name;
?>

<form action="<?php echo $script_name; ?>"  method="POST">
<input type="submit" name="submit" value="Submit">
</form>
//

will display the name of page we are in inspite of the fact that the running code of that part was included but that became independent bcz of the use of server[script_name];



to see your ip address

<?php

$ip_address= $_SERVER['REMOTE_ADDR'];
echo $ip_address;

// this isnt always a good way to get users ip address, esp when they are on a shared network
// or someone may be using proxy
?>

so what we can do is that we cant check wherether he using a proxy, or is in a shared network
there are ready made functions discussed in video lec

to print an array we use print_r();

to check whether the form has been left empty in the type POST  or get,
we use function (!empty(nameofvariable))

isset()-> just checks whether the submit button has been clicked or not

when we start a session , we create a file on the server side , and that file after its created should be accessible to every page.

SIMPLE CODE FOR SETTING UP SESSION
<?php
session_start();
$_SESSION['name']="alex";
//echo $_SESSION['name'];
?>

CODE TO VIEW SESSION

<?php

session_start();
echo $_SESSION['name'];

?>

a better way to log in , and to check whether user has his session or not and ask him to log in

<?php

session_start();
if(isset($_SESSION['name'])){
echo $_SESSION['name'];
}
else
{
echo 'plz log in.. ';
}
?>

TO END SESSION

<?php
// unset a session

session_start();  // though we are unsetting a session we do need to start the session

unset($_SESSION['name']);
?>

COOKIES

setcookie('username','value',time);// time in seconds

the time here is in terms of timestamp so we save the time stamp
$time= time(); // this time() returns timestamp
and in the parameter we write $time+5 , that sets the cookie for 5 secs

now if one wants to log out , can again set the cookie with time-> $time -5

sql database connection

now, when we connect to database , if there is an improper connection it might show an error,
 to avoid that display of error we write thr statement like

<?php
$mysql_host = 'localhost';
$mysql_user='alex';
$mysql_pass='';

mysql_connect($mysql_host, $mysql_user, $mysql_pass );

// instead of writing the above statement  (which can display the error mesg)we can write

mysql_connect($mysql_host, $mysql_user, $mysql_pass ) or die('could not connect');

>?

we can write the above code in a file and include wherever needed

after connecting to the dbms we need to specify the dbms we need to connect to

my_sql_dbms(nameofDbms);

for any query we need to write it as a string and save that in a variable and then pass that in the function
mysql_query();













Sunday, 22 February 2015

Bit-masking in DP

Bit-masking

generally uses the concept of representing number in form of bits and then performing the required operations .
(usually used for the selection process in a given set , a given element)
lets take an example

Let there be an set of 4 elements {3,5,2,1}
Now we want to all the different elements we can make by selecting some the elements out of this set ,
so what are the possible sums.
To find that out we will have to take out numbers out of sets in different combinations

how to think of selection out of sets in terms of maths and computer programming
Here comes the role of Bit masking P)

out of the set we either select the number or dont select it , that makes it a _ _ _ _ (four dashes of true or false)
we plan to represent these four dashes as 0 or 1 .(which makes it binary)
so the possible representations can be
0 0 1 0 ---> if we select only 2 that is 3rd element and sum becomes 2
0 1 0 1 ---> if we select both 5 and 1 , that sums up to 6

This binary representation is good , but now we need to help ourselves to use it more efficiently
alas we plan to convert into decimal and work upon it, and use that as binary as per when required

we will be able to use this concept whenever the number of elements in the set happens to be less equal to 64( for we can represent max of 64 bit in a computer)

any time with n elements in the set and max possible combination will be 2^n
In the above case its 2^4 that is 16
from
0 0 0 0 - - - when we select no element TO
1 1 1 1 - - - when we select all (decimal 15)

pseudo algo

int n // number of elements in a set

int tp=1<<n   // 2^n  total possible combination

for(int i=0;i<tp;i++)
{
for(int j=0;j<n;j++)// here we will work on whether we will select the element or not as per i
{
if((1<<j)&i) // if the particular bit of i is on , then true ,(*) explined at bottom
{
//select it
}
}

}

if i is 5 0101
loop over j (0 to 3)
0 -> 2^0     0 0 0 1 & 0 1 01 so true
1-> 2^1      0 0 1 0 & 0 1 0 1 so false
2->2^2       0 1 0 0 & 0 1 0 1 so true
3->2^3       1 0 0 0 & 0 1 0 1 so false

hence 5 and 1 are selected

question

http://community.topcoder.com/stat?c=problem_statement&pm=13166

solution

http://community.topcoder.com/stat?c=problem_solution&cr=22777422&rd=15854&pm=13166