<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ask Your Question &#187; Tutorial</title>
	<atom:link href="http://askbahar.com/category/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://askbahar.com</link>
	<description>Lets Talk</description>
	<lastBuildDate>Sun, 11 Mar 2012 09:50:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to run Python scripts in your shared hosting server</title>
		<link>http://askbahar.com/2010/10/28/how-to-run-python-scripts-in-your-shared-hosting-server/</link>
		<comments>http://askbahar.com/2010/10/28/how-to-run-python-scripts-in-your-shared-hosting-server/#comments</comments>
		<pubDate>Thu, 28 Oct 2010 03:38:18 +0000</pubDate>
		<dc:creator>Habib Ullah Bahar</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Shared Hosting]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips n Tricks]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[cgi-bin]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[run python]]></category>

		<guid isPermaLink="false">http://askbahar.com/?p=108</guid>
		<description><![CDATA[<p>Direct to the how-to </p> First make sure your hosting supports Python. Now a days almost all shared hosting providers support Python. Find your python installation location, this is required for &#8220;shebang&#8221; line added at the top of your python script. Usually this is /usr/bin/python or /usr/local/bin/python Make sure to include two print statements which [...]]]></description>
			<content:encoded><![CDATA[<p>Direct to the how-to <img src='http://askbahar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<ol>
<li>First make sure your hosting supports Python. Now a days almost all shared hosting providers support Python.</li>
<li>Find your python installation location, this is required for &#8220;shebang&#8221; line added at the top of your python script. Usually this is <em>/usr/bin/python </em>or <strong><em>/usr/local/bin/python</em></strong></li>
<li>Make sure to include two print statements which will print the content-type and an empty line.<strong> </strong></li>
<li>Now put the script in <em>cgi-bin</em> directory inside your root public folder, usually <strong><em>public_html</em></strong></li>
<li>Change the permission of the script to <strong><em>0755</em></strong></li>
<li>Try to browse now <img src='http://askbahar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ol>
<p><span id="more-108"></span></p>
<p>Example, hello.py:</p>
<blockquote><p>#! /usr/bin/python</p>
<p>print &#8216;Content-type: text/html&#8217;<br />
print &#8221;<br />
print &#8216;Hello, World!&#8217;</p></blockquote>
<p>Now look at the top of hello.py script, you will notice the &#8216;shebang&#8217; is <strong><em>#! /usr/bin/python</em></strong>.And also the first two print statements <img src='http://askbahar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now its little bit annoying to put all python scripts inside that cgi-bin directory. So heres what you will need to do to run a python script inside any directory&#8230;</p>
<ol>
<li>Make an empty <em style="font-weight: bold;">.htaccss </em>file inside the directory you want to drop your python scripts. (Just open the existing .htaccess file, make sure you have enabled &#8216;Show Hidden Files&#8217; in cPanel File Manager or in your favorite FTP manager)</li>
<li>Add the following two lines and save.</li>
</ol>
<blockquote><p>Options +ExecCGI<br />
AddHandler cgi-script .py</p></blockquote>
<p>Tips:</p>
<ol>
<li>You will get <em style="font-weight: bold;">500 </em>error if anything goes wrong.</li>
<li>Make sure to clear your cache, when you modify any settings/content</li>
<li>And there is always the nice people waiting for you in hosting support section, try them <img src='http://askbahar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ol>
<p>I hope it helps. Let me know your comment <img src='http://askbahar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://askbahar.com/2010/10/28/how-to-run-python-scripts-in-your-shared-hosting-server/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to find all seven dates of any week in python</title>
		<link>http://askbahar.com/2010/10/23/find-all-seven-dates-of-week-in-python/</link>
		<comments>http://askbahar.com/2010/10/23/find-all-seven-dates-of-week-in-python/#comments</comments>
		<pubDate>Sat, 23 Oct 2010 05:23:02 +0000</pubDate>
		<dc:creator>Habib Ullah Bahar</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[python-date-calculation]]></category>
		<category><![CDATA[python-datetime]]></category>

		<guid isPermaLink="false">http://askbahar.com/?p=98</guid>
		<description><![CDATA[<p>I am new to Python (in comparison to my experience in other languages) Last month I have done some experiment with python date time calculation. Also one of my project required a function, which will compute all 7 dates of any week of any year in Python.</p> <p>After some learning (and searching) heres my work [...]]]></description>
			<content:encoded><![CDATA[<p>I am new to Python (in comparison to my experience in other languages) <img src='http://askbahar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Last month I have done some experiment with python date time calculation. Also one of my project required a function, which will compute all 7 dates of any week of any year in Python.</p>
<p>After some learning (and searching) heres my work :</p>
<p><span id="more-98"></span></p>
<pre class="syntax python">__author__ = "bahar"
__date__ = "$Sep 23, 2010 4:13:29 PM$"

import datetime
from time import strptime, strftime

def _getWeekDates(_Year = 0, _weekStart = 2, _weekNo = 0):
    """
        Returns a list with all the 7 dates of provided week and year (or any supplied week number)
        _year , example 2010. will be computed, if not provided
        _weekStart, (0 is Saturday, 6 is Friday) to start day of week
        _weekNo, will be computed, if not provided
    """

    now = datetime.datetime.now()
    if _Year = 0:
        _Year = now.year

    if _weekNo = 0:
        _weekNo = datetime.date(now.year,now.month,now.day).isocalendar()[1]
    WeekDates = []
    janOne = strptime('%s-01-01' % _Year, '%Y-%m-%d')

    dayOfFirstWeek = ((7-int((strftime("%u",janOne)))+ int(_weekStart)) % 7)

    if dayOfFirstWeek == 0:
        dayOfFirstWeek = 7
    dateOfFirstWeek = strptime('%s-01-%s' % (_Year, dayOfFirstWeek), '%Y-%m-%d')
    dayOne = datetime.datetime( dateOfFirstWeek.tm_year, dateOfFirstWeek.tm_mon, dateOfFirstWeek.tm_mday )
    daysToGo = 7*(int(_weekNo)-1)
    lastDay = daysToGo+6
    dayX = None
    while daysToGo = lastDay:
        dayX = dayOne + datetime.timedelta(days = daysToGo)
        resultDateX = strptime('%s-%s-%s' % (dayX.year, dayX.month, dayX.day), '%Y-%m-%d')
        WeekDates.append(strftime("%Y-%m-%d", resultDateX))
        daysToGo += 1
    return WeekDates

if __name__ == '__main__':
        now = datetime.datetime.now()
        weekNo = datetime.date(now.year,now.month,now.day).isocalendar()[1]

        WeekData = _getWeekDates()
        days = ['Monday', 'Tuesday', 'Wedensday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
        result = dict(zip(days, WeekData))

        for day in days:
            print day ,':', result[day]</pre>
<blockquote><p>Output:</p>
<div id="_mcePaste">
<div id="_mcePaste">Monday : 2010-10-18</div>
<div id="_mcePaste">Tuesday : 2010-10-19</div>
<div id="_mcePaste">Wedensday : 2010-10-20</div>
<div id="_mcePaste">Thursday : 2010-10-21</div>
<div id="_mcePaste">Friday : 2010-10-22</div>
<div id="_mcePaste">Saturday : 2010-10-23</div>
<div id="_mcePaste">Sunday : 2010-10-24</div>
</div>
</blockquote>
<p>For Python date time related functions/modules, I find this site useful: <a href="http://www.tutorialspoint.com/python/python_date_time.htm" target="_blank">http://www.tutorialspoint.com/python/python_date_time.htm</a></p>
<p>Any suggestion/advice via comments are welcome <img src='http://askbahar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://askbahar.com/2010/10/23/find-all-seven-dates-of-week-in-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to generate getter/setter in PHP easily</title>
		<link>http://askbahar.com/2010/07/14/generate-getter-setter-in-php-easily/</link>
		<comments>http://askbahar.com/2010/07/14/generate-getter-setter-in-php-easily/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 04:21:16 +0000</pubDate>
		<dc:creator>Habib Ullah Bahar</dc:creator>
				<category><![CDATA[Tips n Tricks]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[generator]]></category>
		<category><![CDATA[get-set]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://askbahar.com/?p=70</guid>
		<description><![CDATA[<p>For one of my current project I need to write getter/setter functions for 20+ variables. You know, how annoying it is! Well, I can use magic quotes, but I don&#8217;t like it. More over getter setter will help you later to use the class when your IDE (in my case <a title="Netbeans IDE" href="http://netbeans.org" target="_self">Netbeans</a>) [...]]]></description>
			<content:encoded><![CDATA[<p>For one of my current project I need to write getter/setter functions for 20+ variables. You know, how annoying it is! Well, I can use magic quotes, but I don&#8217;t like it. More over getter setter will help you later to use the class when your IDE (in my case <a title="Netbeans IDE" href="http://netbeans.org" target="_self">Netbeans</a>) supports <em>auto complete suggestion</em>. Though all Java development environments allow to generate getter and  setter code automatically.<br />
Then I started coding a php script for generating getter/setter for supplied variables, but I was lucky as suddenly I thought &#8220;why don&#8217;t I look for something like this online&#8221; <img src='http://askbahar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>And here is the link I got, its quite good. <a title="PHP Getter Setter Generator" href="http://www.icurtain.co.uk/getset.php" target="_blank">http://www.icurtain.co.uk/getset.php</a>, It saved my time.</p>
]]></content:encoded>
			<wfw:commentRss>http://askbahar.com/2010/07/14/generate-getter-setter-in-php-easily/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to enable Apache HTTP Authentication using PHP</title>
		<link>http://askbahar.com/2009/11/11/enable-apache-http-authentication-using-php/</link>
		<comments>http://askbahar.com/2009/11/11/enable-apache-http-authentication-using-php/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 09:24:39 +0000</pubDate>
		<dc:creator>Habib Ullah Bahar</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tips n Tricks]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Authentication]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://askbahar.com/?p=48</guid>
		<description><![CDATA[<p>The easiest way to password-protect a site is to use HTTP Authentication, where if a browser’s request for a protected page is not accompanied by the correct username and password, the Web server replies with an HTTP 401 error – which means “Unauthorized Access” – and an invitation for the browser to re-submit the request [...]]]></description>
			<content:encoded><![CDATA[<p>The easiest way to password-protect a site is to use HTTP Authentication, where if a browser’s request for a protected page is not accompanied by the correct username and password, the Web server replies with an HTTP 401 error – which means “Unauthorized Access” – and an invitation for the browser to re-submit the request with a proper username and password. From the user’s point of view, most of this dialogue is hidden. Following that first failed request, the browser prompts the user (in a dialog box) for a username and password, and then re-submits the request, this time with the authentication information attached. Assuming the username/password combo is on the list of allowed users, the Web server then sends the page requested. The Web browser will likewise continue to send that username/password with all subsequent requests.</p>
<p>Look at the following code:<br />
<span id="more-48"></span></p>
<pre>
<code>
<?php
/*
    Document   : auth
    Created on : Nov 11, 2009, 9:08:32 AM
    @author    : Bahar
    Email      : bahar@progmaatic.com
    Copyright  : http://progmaatic.com

    Description: Authenticate user
*/

require_once 'settings.php';

$failure_msg = " <HTML>
 <HEAD><TITLE>Authorization Failed</TITLE></HEAD>
 <BODY>
 <H1>Authorization Failed</H1>
 <P>Without a valid username and password,
    access to this page cannot be granted.
    Please click 'reload' and enter a
    username and password when prompted.
 </P>
 </BODY>
 </HTML>";

if (!isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER']!==$site_user || $_SERVER['PHP_AUTH_PW']!==$site_pass)
   {
       header("WWW-Authenticate: Basic realm=\"Protected Page: Enter your username and password for access.\"");
       header("HTTP/1.0 401 Unauthorized");
       exit($failure_msg);
   }

?>
</code>
</pre>
<p>For each page, you want to authenticate user, each page must have the above code. You can save this code to a script (for example <em>auth.php</em>) and include <em>auth.php</em> to any page, hence save yourself from rewriting the code for each page.</p>
]]></content:encoded>
			<wfw:commentRss>http://askbahar.com/2009/11/11/enable-apache-http-authentication-using-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

