<?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>Coding Friends &#187; Languages</title>
	<atom:link href="http://www.codingfriends.com/index.php/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codingfriends.com</link>
	<description>Coding Friends, place for developers.</description>
	<lastBuildDate>Sun, 04 Dec 2011 21:11:08 +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>Google python code, string2.py</title>
		<link>http://www.codingfriends.com/index.php/2011/12/04/google-python-code-string2-py/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=google-python-code-string2-py</link>
		<comments>http://www.codingfriends.com/index.php/2011/12/04/google-python-code-string2-py/#comments</comments>
		<pubDate>Sun, 04 Dec 2011 21:11:08 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[google code]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1764</guid>
		<description><![CDATA[As from the previous post, I am doing the google&#8217;s python class code and if any one comes up different solutions to the googles version or mine, please post. So here is the string2.py solutions from me. Verbing, needs to check for string over 3 and then only compare the last 3 characters for &#8216;ing&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>As from the <a href="http://www.codingfriends.com/index.php/2011/12/04/google-python-code/">previous post</a>, I am doing the google&#8217;s python class code and if any one comes up different solutions to the googles version or mine, please post.  So here is the string2.py solutions from me.</p>
<p>Verbing, needs to check for string over 3 and then only compare the last 3 characters for &#8216;ing&#8217;</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># D. verbing</span>
<span style="color: #808080; font-style: italic;"># Given a string, if its length is at least 3,</span>
<span style="color: #808080; font-style: italic;"># add 'ing' to its end.</span>
<span style="color: #808080; font-style: italic;"># Unless it already ends in 'ing', in which case</span>
<span style="color: #808080; font-style: italic;"># add 'ly' instead.</span>
<span style="color: #808080; font-style: italic;"># If the string length is less than 3, leave it unchanged.</span>
<span style="color: #808080; font-style: italic;"># Return the resulting string.</span>
<span style="color: #ff7700;font-weight:bold;">def</span> verbing<span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>:
  <span style="color: #808080; font-style: italic;"># +++your code here+++</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">3</span>:
     <span style="color: #ff7700;font-weight:bold;">return</span> s
  <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: black;">&#40;</span>s<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">3</span>:<span style="color: black;">&#93;</span> ==<span style="color: #483d8b;">'ing'</span><span style="color: black;">&#41;</span>:
     <span style="color: #ff7700;font-weight:bold;">return</span> s + <span style="color: #483d8b;">'ly'</span>
  <span style="color: #ff7700;font-weight:bold;">else</span>:
     <span style="color: #ff7700;font-weight:bold;">return</span> s + <span style="color: #483d8b;">'ing'</span></pre></div></div>

<p>Not bad, find the &#8216;not&#8217; and &#8216;bad&#8217;, if bad after not then replace.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># E. not_bad</span>
<span style="color: #808080; font-style: italic;"># Given a string, find the first appearance of the</span>
<span style="color: #808080; font-style: italic;"># substring 'not' and 'bad'. If the 'bad' follows</span>
<span style="color: #808080; font-style: italic;"># the 'not', replace the whole 'not'...'bad' substring</span>
<span style="color: #808080; font-style: italic;"># with 'good'.</span>
<span style="color: #808080; font-style: italic;"># Return the resulting string.</span>
<span style="color: #808080; font-style: italic;"># So 'This dinner is not that bad!' yields:</span>
<span style="color: #808080; font-style: italic;"># This dinner is good!</span>
<span style="color: #ff7700;font-weight:bold;">def</span> not_bad<span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>:
  <span style="color: #808080; font-style: italic;"># +++your code here+++</span>
  notV = s.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'not'</span><span style="color: black;">&#41;</span>
  badV = s.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'bad'</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>badV <span style="color: #66cc66;">&gt;</span> notV<span style="color: black;">&#41;</span>:
     <span style="color: #ff7700;font-weight:bold;">return</span> s<span style="color: black;">&#91;</span>:notV<span style="color: black;">&#93;</span> + <span style="color: #483d8b;">'good'</span> + s<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>badV+<span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>:<span style="color: black;">&#93;</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> s</pre></div></div>

<p>Font back, here we needed the modulus function to find out the reminder of a division.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># F. front_back</span>
<span style="color: #808080; font-style: italic;"># Consider dividing a string into two halves.</span>
<span style="color: #808080; font-style: italic;"># If the length is even, the front and back halves are the same length.</span>
<span style="color: #808080; font-style: italic;"># If the length is odd, we'll say that the extra char goes in the front half.</span>
<span style="color: #808080; font-style: italic;"># e.g. 'abcde', the front half is 'abc', the back half 'de'.</span>
<span style="color: #808080; font-style: italic;"># Given 2 strings, a and b, return a string of the form</span>
<span style="color: #808080; font-style: italic;">#  a-front + b-front + a-back + b-back</span>
<span style="color: #ff7700;font-weight:bold;">def</span> front_back<span style="color: black;">&#40;</span>a, b<span style="color: black;">&#41;</span>:
  <span style="color: #808080; font-style: italic;"># +++your code here+++</span>
  aV = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>/<span style="color: #ff4500;">2</span>+<span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span><span style="color: #66cc66;">%</span>2<span style="color: black;">&#41;</span>
  bV = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>b<span style="color: black;">&#41;</span>/<span style="color: #ff4500;">2</span>+<span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>b<span style="color: black;">&#41;</span><span style="color: #66cc66;">%</span>2<span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> a<span style="color: black;">&#91;</span>:aV<span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span>:bV<span style="color: black;">&#93;</span>+a<span style="color: black;">&#91;</span>aV:<span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span>bV:<span style="color: black;">&#93;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2011/12/04/google-python-code-string2-py/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google python code</title>
		<link>http://www.codingfriends.com/index.php/2011/12/04/google-python-code/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=google-python-code</link>
		<comments>http://www.codingfriends.com/index.php/2011/12/04/google-python-code/#comments</comments>
		<pubDate>Sun, 04 Dec 2011 21:04:00 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[google code]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1762</guid>
		<description><![CDATA[After been talking with some friends, they said about putting some of the google code from there classes online encase other people come up with any other versions. So from the first of the classes that they was talking about was Python , so here is my code for these, may be other people may [...]]]></description>
			<content:encoded><![CDATA[<p>After been talking with some friends, they said about putting some of the <a href="http://code.google.com/edu/">google code</a> from there classes online encase other people come up with any other versions.  So from the first of the classes that they was talking about was <a href="http://code.google.com/edu/languages/google-python-class/">Python </a>, so here is my code for these, may be other people may be doing and come up with different code ?</p>
<p>For first string1.py test there is 4 functions that you have code up and in order from the source code.</p>
<p>Donut, as from the below you just need do a compare on the parameter in.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># A. donuts</span>
<span style="color: #808080; font-style: italic;"># Given an int count of a number of donuts, return a string</span>
<span style="color: #808080; font-style: italic;"># of the form 'Number of donuts: &lt;count&gt;', where &lt;count&gt; is the number</span>
<span style="color: #808080; font-style: italic;"># passed in. However, if the count is 10 or more, then use the word 'many'</span>
<span style="color: #808080; font-style: italic;"># instead of the actual count.</span>
<span style="color: #808080; font-style: italic;"># So donuts(5) returns 'Number of donuts: 5'</span>
<span style="color: #808080; font-style: italic;"># and donuts(23) returns 'Number of donuts: many'</span>
<span style="color: #ff7700;font-weight:bold;">def</span> donuts<span style="color: black;">&#40;</span>count<span style="color: black;">&#41;</span>:
  <span style="color: #808080; font-style: italic;"># +++your code here+++</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> count <span style="color: #66cc66;">&gt;</span>= <span style="color: #ff4500;">10</span>:
     <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">'Number of donuts: many'</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">'Number of donuts: '</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>count<span style="color: black;">&#41;</span></pre></div></div>

<p>Both end, it is string manipulation and returning part of the string if longer enough.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># B. both_ends</span>
<span style="color: #808080; font-style: italic;"># Given a string s, return a string made of the first 2</span>
<span style="color: #808080; font-style: italic;"># and the last 2 chars of the original string,</span>
<span style="color: #808080; font-style: italic;"># so 'spring' yields 'spng'. However, if the string length</span>
<span style="color: #808080; font-style: italic;"># is less than 2, return instead the empty string.</span>
<span style="color: #ff7700;font-weight:bold;">def</span> both_ends<span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>:
  <span style="color: #808080; font-style: italic;"># +++your code here+++</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">2</span>:
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">''</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> s<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span> + s<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">2</span>:<span style="color: black;">&#93;</span></pre></div></div>

<p>Fix start, replace the characters within the string with a * that the same as the first character, so just need to concatenate the first character with the rest of the characters with any replaced <img src='http://www.codingfriends.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># C. fix_start</span>
<span style="color: #808080; font-style: italic;"># Given a string s, return a string</span>
<span style="color: #808080; font-style: italic;"># where all occurences of its first char have</span>
<span style="color: #808080; font-style: italic;"># been changed to '*', except do not change</span>
<span style="color: #808080; font-style: italic;"># the first char itself.</span>
<span style="color: #808080; font-style: italic;"># e.g. 'babble' yields 'ba**le'</span>
<span style="color: #808080; font-style: italic;"># Assume that the string is length 1 or more.</span>
<span style="color: #808080; font-style: italic;"># Hint: s.replace(stra, strb) returns a version of string s</span>
<span style="color: #808080; font-style: italic;"># where all instances of stra have been replaced by strb.</span>
<span style="color: #ff7700;font-weight:bold;">def</span> fix_start<span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>:
  <span style="color: #808080; font-style: italic;"># +++your code here+++</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> s<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> + s<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>,<span style="color: #483d8b;">'*'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Mix up, change the first 2 characters from the two parameters around.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># D. MixUp</span>
<span style="color: #808080; font-style: italic;"># Given strings a and b, return a single string with a and b separated</span>
<span style="color: #808080; font-style: italic;"># by a space '&lt;a&gt; &lt;b&gt;', except swap the first 2 chars of each string.</span>
<span style="color: #808080; font-style: italic;"># e.g.</span>
<span style="color: #808080; font-style: italic;">#   'mix', pod' -&gt; 'pox mid'</span>
<span style="color: #808080; font-style: italic;">#   'dog', 'dinner' -&gt; 'dig donner'</span>
<span style="color: #808080; font-style: italic;"># Assume a and b are length 2 or more.</span>
<span style="color: #ff7700;font-weight:bold;">def</span> mix_up<span style="color: black;">&#40;</span>a, b<span style="color: black;">&#41;</span>:
  <span style="color: #808080; font-style: italic;"># +++your code here+++</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> b<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>+a<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span>:<span style="color: black;">&#93;</span>+<span style="color: #483d8b;">' '</span>+a<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span>:<span style="color: black;">&#93;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2011/12/04/google-python-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Final and auto load a class</title>
		<link>http://www.codingfriends.com/index.php/2011/11/09/final-and-auto-load/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=final-and-auto-load</link>
		<comments>http://www.codingfriends.com/index.php/2011/11/09/final-and-auto-load/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 22:18:31 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[auto load]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[final]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1759</guid>
		<description><![CDATA[To include a class within many languages you have to define it at the top and then off you go with programming with using that class. Well within PHP you can use the __autoload function that is called when you try to create a new instance of a class. function __autoload&#40;$class_name&#41; &#123; include &#34;classes/&#34;.$class_name.&#34;.php&#34;; &#125; [...]]]></description>
			<content:encoded><![CDATA[<p>To include a class within many languages you have to define it at the top and then off you go with programming with using that class.  Well within PHP you can use the __autoload function that is called when you try to create a new instance of a class.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> __autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$class_name</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">include</span> <span style="color: #0000ff;">&quot;classes/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$class_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>this __autoload function above takes a parameter as the class name to load and then within the code it will try and load that class with how ever you want to, in this case I have placed the classes within the directory called classes and under there classname.php filename.</p>
<p>So if you try to load the class</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$newclass</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> basic<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>it will look within the classes directory for the file basic.php for the autoload function above, you can alter it to load from where ever and how ever you want to.</p>
<p>The next part of this post is about the keyword &#8216;final&#8217;, the final keyword means that it is final so if you try and extend that class and extend the function that has been declared as final this will cause php interpretor to fail due to syntax error with something similar to</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Fatal error: Cannot override final method class_name::function_name<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>For an example here is two classes one is called basic and the other is called extendbasic, where the basic class has the final function within it</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> basic
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sayHello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; : Hello&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	final <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sayGoodbye<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; : Goodbye&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>and here is the extendclass</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> extendbasic <span style="color: #000000; font-weight: bold;">extends</span> basic
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sayHello<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; : the newer hello!!&quot;</span><span style="color: #339933;">;</span>	
		parent<span style="color: #339933;">::</span><span style="color: #004000;">sayHello</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
        <span style="color: #666666; font-style: italic;">// this will cause the php engine to fail!!!!!. because it is trying to over load the function sayGoogbye which has been declared as final</span>
<span style="color: #666666; font-style: italic;">/*	public function sayGoodbye()
	{
		echo &quot;I should not get here!!&quot;;
	}*/</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here is some code to call them both which they have been placed within a directory called &#8216;classes&#8217;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> __autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$class_name</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">include</span> <span style="color: #0000ff;">&quot;classes/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$class_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$basicClass</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> basic<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$basicClass</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sayHello</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$basicClass</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sayGoodbye</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$basicClass</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> extendbasic<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$basicClass</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sayHello</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$basicClass</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sayGoodbye</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>and the output would be</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">basic : Hello
basic : Goodbye
extendbasic : the newer hello<span style="color: #000000; font-weight: bold;">!!</span>
extendbasic : Hello
extendbasic : Goodbye</pre></div></div>

<p>I am calling the parent function from within the extendbasic class sayHello function.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2011/11/09/final-and-auto-load/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ckeditor &#8211; not allow posting of images from the local harddrive</title>
		<link>http://www.codingfriends.com/index.php/2011/10/19/ckeditor-not-allow-posting-of-images-from-the-local-harddrive/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ckeditor-not-allow-posting-of-images-from-the-local-harddrive</link>
		<comments>http://www.codingfriends.com/index.php/2011/10/19/ckeditor-not-allow-posting-of-images-from-the-local-harddrive/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 20:26:51 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[CKEditor]]></category>
		<category><![CDATA[local harddrive]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1743</guid>
		<description><![CDATA[Within the CKEditor you can also add on to the prototypes that allow more control of what is allowed on your website. Sometimes you do not want to allow the user to copy and paste local files to the CKEditor so this is what I done to remove the file:// from within the img tag [...]]]></description>
			<content:encoded><![CDATA[<p>Within the <a href="http://ckeditor.com/" title="CKEDITOR" target="_blank">CKEditor</a> you can also add on to the prototypes that allow more control of what is allowed on your website.</p>
<p>Sometimes you do not want to allow the user to copy and paste local files to the CKEditor so this is what I done to remove the file:// from within the img tag within the copy and paste with using the CKEditor htmlDataProcessor group of functions, in this case the &#8216;toHtml&#8217; function which is called when the user pastes any content into the CKEditor window.  All I am doing it using the regular expression to search for the &lt;img src=&#8221;file .. and replace with a &lt;mg tag&gt; which when they double click on that it will open the CKEditor&#8217;s image browser (which you can include a upload part to it as well <img src='http://www.codingfriends.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">CKEDITOR.<span style="color: #660066;">htmlDataProcessor</span>.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">toHtml</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> data<span style="color: #339933;">,</span> fixForBody <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> data.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\&lt;img src=\&quot;file:([^\&gt;])*\&gt;/ig</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&lt;img title=<span style="color: #000099; font-weight: bold;">\&quot;</span>Please use the Media/Image uploader because can not show files on your harddrive<span style="color: #000099; font-weight: bold;">\&quot;</span> alt=<span style="color: #000099; font-weight: bold;">\&quot;</span>Please use the Media/Image uploader because can not show files on your harddrive<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>It was very helpful for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2011/10/19/ckeditor-not-allow-posting-of-images-from-the-local-harddrive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Classes</title>
		<link>http://www.codingfriends.com/index.php/2011/05/25/classes/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=classes</link>
		<comments>http://www.codingfriends.com/index.php/2011/05/25/classes/#comments</comments>
		<pubDate>Wed, 25 May 2011 09:17:51 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Classes]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1611</guid>
		<description><![CDATA[Since Python is a object oriented programming language then you can use things like classes to define a object, a class is a bunch of methods that act on the data that is stored within the class itself. You can store data within the class, but unlike c++/java/c# etc, there is no private/public/protected, everything is [...]]]></description>
			<content:encoded><![CDATA[<p>Since Python is a object oriented programming language then you can use things like classes to define a object, a class is a bunch of methods that act on the data that is stored within the class itself.  You can store data within the class, but unlike c++/java/c# etc, there is no private/public/protected, everything is public accessible.</p>
<p>In the example below, the class constructor is called (__init__ method) and the first parameter is the class object itself, which is why it is there and for many reasons why it is called self as a variable name.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">#  self means the object itself.</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> mysimpleclass :
        __myvar = <span style="color: #ff4500;">0</span>
        <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>,value = <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span> :
                <span style="color: #008000;">self</span>.__myvar = value
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">def</span> printValue<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span> :
                <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #008000;">self</span>.__myvar
&nbsp;
simple = mysimpleclass<span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>
simple.<span style="color: black;">printValue</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>the printValue method just does that, it will print the value that is sorted within the class object and here is the output</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">5</span></pre></div></div>

<p> if you did not put in the self in the example above for printing out the class object variable __myvar as below</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> mysimpleclass ....
       ....
       <span style="color: #ff7700;font-weight:bold;">def</span> printValue<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> :
            <span style="color: #ff7700;font-weight:bold;">print</span> __myvar</pre></div></div>

<p>the error would be</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">NameError: global name <span style="color: #ff0000;">'_mysimpleclass__myvar'</span> is not defined</pre></div></div>

<p>because the interrupter is looking for a global variable and not a variable attached to that object.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2011/05/25/classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add two numbers</title>
		<link>http://www.codingfriends.com/index.php/2011/05/05/add-two-numbers-6/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=add-two-numbers-6</link>
		<comments>http://www.codingfriends.com/index.php/2011/05/05/add-two-numbers-6/#comments</comments>
		<pubDate>Thu, 05 May 2011 20:37:55 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Add two numbers]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1606</guid>
		<description><![CDATA[To carry on my normal process of notes on this website for different languages here is the how to add two numbers with a return value from a function. To define a function you use the &#8220;def&#8221; syntax within the programming language and then the next bit of text before the parameters for the function [...]]]></description>
			<content:encoded><![CDATA[<p>To carry on my normal process of notes on this website for different languages here is the how to add two numbers with a return value from a function.</p>
<p>To define a function you use the &#8220;def&#8221; syntax within the programming language and then the next bit of text before the parameters for the function itself ( in this case the parameters are the (number1, number2) ), is the function name and how to call the function.  </p>
<p>The function below takes two parameters and returns back there result of the mathematical addition, the last part is how to call the function.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> addTwo<span style="color: black;">&#40;</span>number1, number2<span style="color: black;">&#41;</span> : 
	<span style="color: #ff7700;font-weight:bold;">return</span> number1 + number2
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> addTwo<span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span></pre></div></div>

<p>and the output would be</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">3</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2011/05/05/add-two-numbers-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Read / Write</title>
		<link>http://www.codingfriends.com/index.php/2011/05/03/read-write/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=read-write</link>
		<comments>http://www.codingfriends.com/index.php/2011/05/03/read-write/#comments</comments>
		<pubDate>Tue, 03 May 2011 20:32:39 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Read]]></category>
		<category><![CDATA[Write]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1604</guid>
		<description><![CDATA[Here is how to open and read/write to a file within Python. Most languages supply a basic file opening and read/writing methods with the closing method, and Python is no different which makes going from one language to another very easy (you just need to learn the classes that are capable to doing the interesting [...]]]></description>
			<content:encoded><![CDATA[<p>Here is how to open and read/write to a file within Python.  Most languages supply a basic file opening and read/writing methods with the closing method, and Python is no different which makes going from one language to another very easy (you just need to learn the classes that are capable to doing the interesting stuff <img src='http://www.codingfriends.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ).</p>
<p>To write to a file, you have to open it first within a write mode (&#8216;w&#8217;) and then write to that file *handler*, in the code below the variable &#8216;f&#8217; is the file *handler*</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'write.txt'</span>,<span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
f.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'hi there<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
f.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'this is genux<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
f.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'and my site is codingfriends.com<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
f.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'pyhon does OO<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'File has been written<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #66cc66;">;</span></pre></div></div>

<p>which will write to the &#8220;write.txt&#8221; the following text</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hi there
this is genux
and my site is codingfriends.com
pyhon does OO</pre></div></div>

<p>and then to read in the file you use the read mode &#8216;r&#8217;, you are able to use the Iterator style of coding with using a &#8216;for <variable name> in <iterator variable>:&#8217;  or if you wish to read one line at a time you can use the &#8216;readline()&#8217; method, and to seek within a file you use the method &#8216;seek(
<place within file>)&#8217;.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'write.txt'</span>,<span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> readInLine <span style="color: #ff7700;font-weight:bold;">in</span> f:
	<span style="color: #ff7700;font-weight:bold;">print</span> readInLine<span style="color: #66cc66;">;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'seek to the start of the file'</span><span style="color: #66cc66;">;</span>
f.<span style="color: black;">seek</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
anotherLine = f.<span style="color: #dc143c;">readline</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> anotherLine<span style="color: #66cc66;">;</span>
&nbsp;
f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span></pre></div></div>

<p>and here is the output</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hi there
&nbsp;
this is genux
&nbsp;
and my site is codingfriends.com
&nbsp;
pyhon does OO
&nbsp;
seek to the start of the <span style="color: #c20cb9; font-weight: bold;">file</span>
hi there</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2011/05/03/read-write/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

