learn python

Posted: April 7, 2015 in Python

Hello All,

Though PHP is powerful language, python also has its own capabilities.

This blog is dedicated to learn python step by step

After downloading python latest version form https://www.python.org/downloads/

There are multiple python editors available on market.

Eclipse is one of the best editor for python too. We can play by installing the python plugin.

The following code illustrates from variable declaration to loops and lists of python.

The following points would be helpful for the php experts.

1. No $ sign provided for variables in python

2. No start or End tags (<?php and ?>)

3. No braces used for if for loops. Here indentation will take care of that.

4. No switch case in python

Create a test.py file and copy the following code and all examples and you can change the code and re execute it.

As these examples are provided in organized way, your learning time would be saved and you would be familiar with topics quickly.

 

In Eclipse Ctrl +F11 is the shortcut to run the code.

 

#!/usr/bin/python

”’
Created on Mar 31, 2015

@author: chandrasekhar
”’

# print statement

print “Hello World”;

#### authmatic operation ####

## Addition

a =10;
b = 5;

c = a + b;

print (c);

## Multiplication

a =10;
b = 5;

c = a * b;

print (c);

# concatination

a = “string 1”;
b = “string 2″;

c = a+” And “+b;

print (c);

# condition

a = 10;
b = 5;

if a > b:
print (“a bigger”);
else:
print (“b bigger”);

########### Lists ########################

list1 = [1,2,3,4,5]

print (“list values index 1”)
print (list1[1])

list1[4] = 10

print (“new list values index 4″)
print (list1[4])

”’
Range function

”’

print(list(range(1,5))); # output is [1, 2, 3, 4]

########### Loops ##########################

fruits = [“applie”, “banana”, “mango”]
for fruit in fruits:
print (“current fruit “+fruit)

name = “chandra sekhar”;

for letter in name:
print (“current letter in name is “+letter);

########## date functions ##################

import datetime;
today = datetime.date.today();
print (today);

# formatting date

”’

%d is the day number
%m is the month number
%b is the month abbreviation
%y is the year last two digits
%Y is the all year

”’

print (today.strftime(‘We are the %d, %b %Y’));

”’
add 10 days to current date

”’

import datetime

#start_date = “10/04/15”
today = datetime.date.today();
start_date = today.strftime(‘%m/%d/%y’)

date_1 = datetime.datetime.strptime(start_date, “%m/%d/%y”)

end_date = date_1 + datetime.timedelta(days=10)

print (end_date)

 

 

 

 

 

Generally we will track created date and modified dates in tables.

It is the best practice to handle from mysql itself.

The default value is provided as current timestamp, we can not provide default timestamp for modified date. We can provide current timestamp for only one field.

So, you can make use of following trigger to update the modified date field, when ever table got modified.

DROP TRIGGER IF EXISTS `Sampltrigger_update_entry`;
DELIMITER //
CREATE TRIGGER `Sampltrigger_update_entry` BEFORE UPDATE ON `sampletable`
FOR EACH ROW SET NEW.modifieddate = CURRENT_TIMESTAMP

Sampltrigger_update_entry = view name

sampletable = table name

modifieddate = field name in sampletable.

SIMILARITIES BETWEEN JAVA AND .NET

Posted: December 12, 2014 in Uncategorized

TechWordsInfo

SIMILARITIES BETWEEN JAVA AND .NET :

->  Both are Object oriented programming languages.
->Both use their own intermediate language. Java calls it as ―byte code  and .NET
calls it as ―MSIL code.
->  Both are platform independent.
-> Both support ―Garbage collection‖, which automatically clears the un-used
memory.
->  Both offer better security features in their own style.
->  Both support Remoting.
->  Both support multi-threading.
->Both of these support to develop console applications, windows applications, web
sites, web services etc.
->  Both support web related languages like Java Script, XML, CSS etc.
->  Both support the recent web development technology like AJAX.
->Both support to develop the applications for small devices like PDA‘s, mobile
phones, smart phones etc.

View original post

Jquery restricting right click

Posted: August 8, 2014 in Jquery

use the following code to restrict back button code on jquery

 

 

$(document).ready(function() {
	
	$(document).bind("contextmenu",function(e) {				 
		
		alert("Right click not allowed.");

		return false;
	});
});

When user clicks on the browser back button, if you want to redirect to other url. Then use the following code

jQuery(document).ready(function($) {

if (window.history && window.history.pushState) {

window.history.pushState(‘forward’, null, ‘./#forward’);

$(window).on(‘popstate’, function() {
window.location.href = “www.example.com/homepage”;
});

}
});

Use the below example to convert from UTC to PDT

$timeZone = 'PDT';  //timezone to be converted
$dateSrc = '2014-11-08 07:00:00';
$dateTime = new DateTime($dateSrc, new DateTimeZone('UTC'));
$dateTime->setTimeZone(new DateTimeZone($timeZone));
echo 'Converted Date: '.$dateTime->format('Y-m-d H:i:s')

Use the following example to check the any one of checkbox checked or not

 

<input type=”checkbox” name=”test[0]”  value=”1″  />
<input type=”checkbox” name=”test[1]”   value=”1″  />
<input type=”checkbox” name=”test[2]” value=”1″  />
<input type=”checkbox” name=”test[3]”  value=”1″  />
<input type=”button” id=”submitbutton” />

 

$(“#submitbutton”).click(function () {
if ($(‘input[name^=test]:checked’).length <= 0) {
alert(“No checkbox checked”)
}
});