<?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>Ponton&#039;s site &#187; my code</title>
	<atom:link href="http://www.ponton.srednikpe.org/tag/my-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ponton.srednikpe.org</link>
	<description>blog głównie matematyczno-informatyczny (nie chce mi się pisać o życiu)</description>
	<lastBuildDate>Mon, 18 Jan 2010 22:23:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>My GitHub account</title>
		<link>http://www.ponton.srednikpe.org/2009/10/26/my-github-account/</link>
		<comments>http://www.ponton.srednikpe.org/2009/10/26/my-github-account/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 22:58:31 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[my code]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=271</guid>
		<description><![CDATA[I&#8217;ve recently added the link to my GitHub profile. I signed up some time ago, but now I&#8217;ve started to use git for my university projects and push them to GitHub.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently added the link to <a title="my GitHub profile" href="http://github.com/ponton">my GitHub profile</a>. I signed up some time ago, but now I&#8217;ve started to use git for my university projects and push them to GitHub.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2009/10/26/my-github-account/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Matrix chain multiplication: parallel and sequential</title>
		<link>http://www.ponton.srednikpe.org/2009/06/25/matrix-chain-multiplication-parallel-and-sequential/</link>
		<comments>http://www.ponton.srednikpe.org/2009/06/25/matrix-chain-multiplication-parallel-and-sequential/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 19:56:51 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[my code]]></category>
		<category><![CDATA[studia]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=259</guid>
		<description><![CDATA[Yep, that&#8217;s the project that uses threads. Nothing more is worth to add &#8212; the problem is well-known, as well as the algorithm. Source: http://www.srednikpe.org/src/matrix/]]></description>
			<content:encoded><![CDATA[<p>Yep, that&#8217;s the project that uses threads. Nothing more is worth to add &#8212; the problem is well-known, as well as the algorithm.</p>
<p>Source: <a href="http://www.srednikpe.org/src/matrix/">http://www.srednikpe.org/src/matrix/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2009/06/25/matrix-chain-multiplication-parallel-and-sequential/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>boost::thread and std::list</title>
		<link>http://www.ponton.srednikpe.org/2009/06/22/boostthread-and-stdlist/</link>
		<comments>http://www.ponton.srednikpe.org/2009/06/22/boostthread-and-stdlist/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 01:28:49 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[boost]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[my code]]></category>
		<category><![CDATA[stl]]></category>
		<category><![CDATA[thread]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=243</guid>
		<description><![CDATA[I had to create many threads in C++. Of course I didn&#8217;t want to use pthread, because it&#8217;s ugly C. I chose boost::thread instead. Then I needed some container to keep all these threads. Arrays were out of the question for the same reason as pthread. I could use boost:array but stl::list was easier. The [...]]]></description>
			<content:encoded><![CDATA[<p>I had to create many threads in C++. Of course I didn&#8217;t want to use pthread, because it&#8217;s ugly C. I chose boost::thread instead. Then I needed some container to keep all these threads. Arrays were out of the question for the same reason as pthread. I could use boost:array but stl::list was easier.</p>
<p>The problem was&#8212;how to keep this thread objects? I couldn&#8217;t use std::list&lt;boost::thread&gt; nor std::list&lt;boost::thread &amp;&gt; because threads cannot be copied. I had to dynamically create the object in order to prevent the destruction after the scope. But for some reason I got compiler error while trying std::list&lt; std::auto_ptr&lt;boost::thread&gt; &gt; in the line where I pushed_back newly created threads.</p>
<p>The cause of the error was that the argument of std::list::push_back() was a constant reference. And while assinging one auto_ptr to another, the first one is getting call release() method, but it can&#8217;t since the reference is constant and release() change the state of the object.</p>
<p>To solve this problem one can use boost::shared_ptr.</p>
<p>Example:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #339900;">#include &lt;list&gt;</span>
<span style="color: #339900;">#include &lt;boost/thread.hpp&gt;</span>
<span style="color: #339900;">#include &lt;boost/date_time.hpp&gt;</span>
<span style="color: #339900;">#include &lt;boost/smart_ptr.hpp&gt;</span>
&nbsp;
<span style="color: #0000ff;">using</span> std<span style="color: #008080;">::</span><span style="color: #007788;">list</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">using</span> std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">using</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">struct</span> foo
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">void</span> operator<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> id<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;starting thread &quot;</span> <span style="color: #000080;">&lt;&lt;</span> id <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #008080;">;</span>
		boost<span style="color: #008080;">::</span><span style="color: #007788;">this_thread</span><span style="color: #008080;">::</span><span style="color: #007788;">sleep</span><span style="color: #008000;">&#40;</span>boost<span style="color: #008080;">::</span><span style="color: #007788;">posix_time</span><span style="color: #008080;">::</span><span style="color: #007788;">seconds</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">3</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;ending thread &quot;</span> <span style="color: #000080;">&lt;&lt;</span> id <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">typedef</span> boost<span style="color: #008080;">::</span><span style="color: #007788;">shared_ptr</span><span style="color: #000080;">&lt;</span>boost<span style="color: #008080;">::</span><span style="color: #007788;">thread</span><span style="color: #000080;">&gt;</span> thread_ptr<span style="color: #008080;">;</span>
	list<span style="color: #000080;">&lt;</span>thread_ptr<span style="color: #000080;">&gt;</span> thread<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;creating threads<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">10</span><span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		thread.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span>boost<span style="color: #008080;">::</span><span style="color: #007788;">shared_ptr</span><span style="color: #000080;">&lt;</span>boost<span style="color: #008080;">::</span><span style="color: #007788;">thread</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">new</span> boost<span style="color: #008080;">::</span><span style="color: #007788;">thread</span><span style="color: #008000;">&#40;</span>foo<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, i<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;after creation, now joining them<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span>list<span style="color: #000080;">&lt;</span>thread_ptr<span style="color: #000080;">&gt;</span><span style="color: #008080;">::</span><span style="color: #007788;">iterator</span> it <span style="color: #000080;">=</span> thread.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> it <span style="color: #000040;">!</span><span style="color: #000080;">=</span> thread.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #000040;">++</span>it<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>it<span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>join<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;ending program&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>And the result:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">tomek<span style="color: #000000; font-weight: bold;">@</span>notlob:~<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">g++</span> <span style="color: #660033;">-o</span> threads threads.cpp <span style="color: #660033;">-O2</span> <span style="color: #660033;">-Wall</span> -lboost_thread-mt
tomek<span style="color: #000000; font-weight: bold;">@</span>notlob:~<span style="color: #000000; font-weight: bold;">%</span> .<span style="color: #000000; font-weight: bold;">/</span>threads
creating threads
starting thread <span style="color: #000000;">1</span>
starting thread <span style="color: #000000;">0</span>
starting thread <span style="color: #000000;">2</span>
starting thread <span style="color: #000000;">3</span>
starting thread starting thread <span style="color: #000000;">4</span>
<span style="color: #000000;">5</span>
starting thread <span style="color: #000000;">6</span>
starting thread <span style="color: #000000;">7</span>
starting thread <span style="color: #000000;">8</span>
starting thread <span style="color: #000000;">9</span>
after creation, now joining them
ending thread <span style="color: #000000;">1</span>
ending thread <span style="color: #000000;">3</span>
ending thread <span style="color: #000000;">5</span>
ending thread <span style="color: #000000;">4</span>
ending thread <span style="color: #000000;">0</span>
ending thread <span style="color: #000000;">2</span>
ending thread <span style="color: #000000;">6</span>
ending thread <span style="color: #000000;">8</span>
ending thread <span style="color: #000000;">7</span>
ending thread <span style="color: #000000;">9</span>
ending program</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2009/06/22/boostthread-and-stdlist/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Program verification conditions</title>
		<link>http://www.ponton.srednikpe.org/2008/12/22/program-verification-conditions/</link>
		<comments>http://www.ponton.srednikpe.org/2008/12/22/program-verification-conditions/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 00:39:01 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[my code]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=159</guid>
		<description><![CDATA[Yay, another parser in Haskell! That was a Haskell week, but I&#8217;m glad I had an opportunity to recall this beautiful full-of-math language. This program reads an annotated program &#8212; a program with assertions. Assertions are just logic formulas. We use them to describe the program state between instructions, ie. variable x is equal to [...]]]></description>
			<content:encoded><![CDATA[<p>Yay, another parser in Haskell! That was a Haskell week, but I&#8217;m glad I had an opportunity to recall this beautiful full-of-math language.</p>
<p>This program reads an annotated program &#8212; a program with assertions. Assertions are just logic formulas. We use them to describe the program state between instructions, ie. variable x is equal to variable y squared. But assertions cannot be random, they must be derived from Hoare&#8217;s logic axioms and rules (which base on the formal semantic of the language). How do we know if there is an derivation of a program?</p>
<p>Here verification condicitions come. They are logic formulas too, but generated from annotated program. If all of them are true, then the program is derivable. More information here: <a href="http://www.macs.hw.ac.uk/~air/hic-hisd/">http://www.macs.hw.ac.uk/~air/hic-hisd/</a> and <a href="http://www.daimi.au.dk/~bra8130/Wiley_book/wiley.html">http://www.daimi.au.dk/~bra8130/Wiley_book/wiley.html</a>. The whole point is about formal verification of programs. Nowadays compiler can tell only whether given program has a syntax or type error. It doesn&#8217;t know anything about how this program should work and can&#8217;t  say something like: &#8220;This program certainly does not multiply matrices.&#8221;. Assertions are some way to tell the programmer&#8217;s intentions to the compiler: &#8220;This is my piece of code and it should multiply two matrices&#8221;, and thus, by generating verification conditions and using automated theorem proving it could say: &#8220;It does.&#8221;.</p>
<p>So after a boring digression&#8230; this program reads an annotated program in a simple imperative language and generates verification conditions. That&#8217;s all.</p>
<p>All files are here: <a href="http://srednikpe.org/src/vc/">http://srednikpe.org/src/vc/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2008/12/22/program-verification-conditions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reverse Polish notation calculator in Haskell</title>
		<link>http://www.ponton.srednikpe.org/2008/12/22/reverse-polish-notation-calculator-in-haskell/</link>
		<comments>http://www.ponton.srednikpe.org/2008/12/22/reverse-polish-notation-calculator-in-haskell/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 00:02:51 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[my code]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=155</guid>
		<description><![CDATA[Just a few lines of code, written when I was slightly bored. module Main where &#160; data Token = Plus &#124; Minus &#124; Divide &#124; Times &#124; Num Integer &#160; rpnEval :: &#91;Token&#93; -&#62; Integer rpnEval = rpnEval' &#91;&#93; where rpnEval' &#40;i:s&#41; &#91;&#93; = i rpnEval' s &#40;&#40;Num i&#41;:t&#41; = rpnEval' &#40;i:s&#41; t rpnEval' &#40;a:b:s&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>Just a few lines of code, written when I was slightly bored.</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">data</span> Token <span style="color: #339933; font-weight: bold;">=</span> Plus <span style="color: #339933; font-weight: bold;">|</span> Minus <span style="color: #339933; font-weight: bold;">|</span> Divide <span style="color: #339933; font-weight: bold;">|</span> Times <span style="color: #339933; font-weight: bold;">|</span> <span style="color: #cccc00; font-weight: bold;">Num</span> <span style="color: #cccc00; font-weight: bold;">Integer</span>
&nbsp;
rpnEval <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#91;</span>Token<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Integer</span>
rpnEval <span style="color: #339933; font-weight: bold;">=</span> rpnEval' <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #06c; font-weight: bold;">where</span>
		rpnEval' <span style="color: green;">&#40;</span>i:s<span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">=</span> i
		rpnEval' s <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Num</span> i<span style="color: green;">&#41;</span>:t<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> rpnEval' <span style="color: green;">&#40;</span>i:s<span style="color: green;">&#41;</span> t
		rpnEval' <span style="color: green;">&#40;</span>a:b:s<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>op:t<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> rpnEval' <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>evalOp op a b<span style="color: green;">&#41;</span>:s<span style="color: green;">&#41;</span> t
&nbsp;
		evalOp Plus <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">+</span><span style="color: green;">&#41;</span>
		evalOp Minus <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">-</span><span style="color: green;">&#41;</span>
		evalOp Times <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">*</span><span style="color: green;">&#41;</span>
		evalOp Divide <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">div</span>
&nbsp;
toToken <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">String</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> Token
toToken <span style="background-color: #3cb371;">&quot;+&quot;</span> <span style="color: #339933; font-weight: bold;">=</span> Plus
toToken <span style="background-color: #3cb371;">&quot;-&quot;</span> <span style="color: #339933; font-weight: bold;">=</span> Minus
toToken <span style="background-color: #3cb371;">&quot;*&quot;</span> <span style="color: #339933; font-weight: bold;">=</span> Times
toToken <span style="background-color: #3cb371;">&quot;/&quot;</span> <span style="color: #339933; font-weight: bold;">=</span> Divide
toToken s <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #cccc00; font-weight: bold;">Num</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">read</span> s<span style="color: green;">&#41;</span>
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
	l <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">getContents</span>
	<span style="font-weight: bold;">mapM</span> <span style="font-weight: bold;">print</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">map</span> <span style="color: green;">&#40;</span>rpnEval <span style="color: #339933; font-weight: bold;">.</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">map</span> toToken<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">words</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">lines</span> l<span style="color: green;">&#41;</span></pre></div></div>

<p>Update: See comments for better solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2008/12/22/reverse-polish-notation-calculator-in-haskell/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Kości</title>
		<link>http://www.ponton.srednikpe.org/2008/08/30/kosci/</link>
		<comments>http://www.ponton.srednikpe.org/2008/08/30/kosci/#comments</comments>
		<pubDate>Sat, 30 Aug 2008 00:18:12 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[Polskie]]></category>
		<category><![CDATA[my code]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=104</guid>
		<description><![CDATA[Nie mieliśmy kości na sesję, to trzeba było coś napisać. NWOD-owy rzucacz kośćmi w Pythonie: #!/usr/bin/python &#160; import time import random import sys &#160; # argumenty: ile_scian = int&#40;sys.argv&#91;1&#93;&#41; # ilusciennymi koscmi rzucamy sukces = int&#40;sys.argv&#91;2&#93;&#41; # od ilu oczek jest sukces ile_rzutow = int&#40;sys.argv&#91;3&#93;&#41; # ile razy rzucamy &#160; def kostka&#40;sciany&#41;: rzut = random.randint&#40;1, [...]]]></description>
			<content:encoded><![CDATA[<p>Nie mieliśmy kości na sesję, to trzeba było coś napisać. NWOD-owy rzucacz kośćmi w Pythonie:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">random</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># argumenty: </span>
ile_scian = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>    <span style="color: #808080; font-style: italic;"># ilusciennymi koscmi rzucamy</span>
sukces = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>       <span style="color: #808080; font-style: italic;"># od ilu oczek jest sukces</span>
ile_rzutow = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>   <span style="color: #808080; font-style: italic;"># ile razy rzucamy</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> kostka<span style="color: black;">&#40;</span>sciany<span style="color: black;">&#41;</span>:
    rzut = <span style="color: #dc143c;">random</span>.<span style="color: black;">randint</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, sciany<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> rzut
    <span style="color: #ff7700;font-weight:bold;">return</span> rzut
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'------------------------------'</span>
&nbsp;
<span style="color: #dc143c;">random</span>.<span style="color: black;">seed</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
sukcesy = <span style="color: #ff4500;">0</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, ile_rzutow<span style="color: black;">&#41;</span>:
    rzut = kostka<span style="color: black;">&#40;</span>ile_scian<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> rzut <span style="color: #66cc66;">&gt;</span>= sukces:
        sukcesy += <span style="color: #ff4500;">1</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">while</span> rzut == ile_scian:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Przerzut!'</span>
&nbsp;
        rzut = kostka<span style="color: black;">&#40;</span>ile_scian<span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">if</span> rzut <span style="color: #66cc66;">&gt;</span>= sukces:
            sukcesy += <span style="color: #ff4500;">1</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Sukcesy: &quot;</span>, sukcesy</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2008/08/30/kosci/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Just another wget clone</title>
		<link>http://www.ponton.srednikpe.org/2008/06/10/just-another-wget-clone/</link>
		<comments>http://www.ponton.srednikpe.org/2008/06/10/just-another-wget-clone/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 13:38:25 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[my code]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/?p=46</guid>
		<description><![CDATA[While nothing interesting is happening in my life I post my recent program. Simply wget clone, with -m option it downloads all images and some stylesheets from the page and changes them to local adresses. Sorry for Polish comments and names in source file. Source]]></description>
			<content:encoded><![CDATA[<p>While nothing interesting is happening in my life I post my recent program. Simply wget clone, with -m option it downloads all images and some stylesheets from the page and changes them to local adresses. Sorry for Polish comments and names in source file.</p>
<p><a href="http://www.srednikpe.org/src/sieci/prac3/httpget.cpp">Source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2008/06/10/just-another-wget-clone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LOLCode Compiler (my own!)</title>
		<link>http://www.ponton.srednikpe.org/2008/04/23/lolcode-compiler-my-own/</link>
		<comments>http://www.ponton.srednikpe.org/2008/04/23/lolcode-compiler-my-own/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 23:18:42 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[lolcode]]></category>
		<category><![CDATA[my code]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/2008/04/23/lolcode-compiler-my-own/</guid>
		<description><![CDATA[Hah! My dream have come through! I wrote my first compiler with my own lexer and parser. It compiles LOLCode (slightly modified version, see in specification [in polish, but only output language]) to stack machine language. My project contains also stack machine which interprets output files and prints them in human readable assembler and three [...]]]></description>
			<content:encoded><![CDATA[<p>Hah! My dream have come through! I wrote my first compiler with my own lexer and parser. It compiles LOLCode (slightly modified version, see in specification [in polish, but only output language]) to stack machine language. My project contains also stack machine which interprets output files and prints them in human readable assembler and three examples of LOLCode programs. It&#8217;s all GPL so you can learn how it works. It&#8217;s written in C and I didn&#8217;t have much time to write pretty dynamic arrays and If someone will fix it, I would be verry happy. If you&#8217;ve got question about how it works, go ahead, write me and ask.</p>
<p>Source: <a title="LCC Source" href="http://www.srednikpe.org/src/lcc/">http://www.srednikpe.org/src/lcc/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2008/04/23/lolcode-compiler-my-own/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>pyhttpd &#8211; a tiny HTTP deamon written in Python</title>
		<link>http://www.ponton.srednikpe.org/2008/02/11/pyhttpd-a-tiny-http-deamon-written-in-python/</link>
		<comments>http://www.ponton.srednikpe.org/2008/02/11/pyhttpd-a-tiny-http-deamon-written-in-python/#comments</comments>
		<pubDate>Mon, 11 Feb 2008 18:21:24 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[my code]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/2008/02/11/pyhttpd-a-tiny-http-deamon-written-in-python/</guid>
		<description><![CDATA[It&#8217;s for my Python Course. It provides only very basic HTTP, but yet can be used for simple WWW hosting. Source. Features: GET and POST methods New thread for new connection Directory listing Error pages Document index Deafult type and charset Python scripts ;) Configuration file &#8230; and my own modules to handle these TODOs: [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s for my Python Course. It provides only very basic HTTP, but yet can be used for simple WWW hosting. <a title="pyhttpd" href="http://www.srednikpe.org/src/pyhttpd/">Source</a>.</p>
<p>Features:</p>
<ul>
<li>GET and POST methods</li>
<li>New thread for new connection</li>
<li>Directory listing</li>
<li>Error pages</li>
<li>Document index</li>
<li>Deafult type and charset</li>
<li>Python scripts ;)</li>
<li>Configuration file</li>
<li>&#8230; and my own modules to handle these</li>
</ul>
<p>TODOs:</p>
<ul>
<li>Logging</li>
<li>Much more stability (exceptions handling, etc.)</li>
<li>Sending gzipped or chunked data (if accepted)</li>
<li>Range headers</li>
<li>&#8230; and many, many other</li>
</ul>
<p>To run just edit pyhttpd.conf and change Port and Document root. Then type &#8220;python pyhttpd.py&#8221; and it should be now listening for connections.</p>
<p>How to run a python script and its output send to client? Pyhttpd checks if the requesting file is a python one. If so then it opens a python interpreter by a pipe, sends _GET and _POST dictionaries and file contents. And finally, sends interpreter outputs to client.</p>
<p>_GET and_POST are just dictionaries with variable names as keys. So if there is a foobar.py?i=500 request then _GET will be { &#8216;i&#8217; : &#8217;500&#8242; } (note that this is always a string value).</p>
<p>It&#8217;s GPL if someone asked.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2008/02/11/pyhttpd-a-tiny-http-deamon-written-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JZW Interpreter source and examples</title>
		<link>http://www.ponton.srednikpe.org/2007/09/09/jzw-interpreter-source-and-examples/</link>
		<comments>http://www.ponton.srednikpe.org/2007/09/09/jzw-interpreter-source-and-examples/#comments</comments>
		<pubDate>Sun, 09 Sep 2007 18:00:49 +0000</pubDate>
		<dc:creator>ponton</dc:creator>
				<category><![CDATA[Computer science and math]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[interpreter]]></category>
		<category><![CDATA[jzwi]]></category>
		<category><![CDATA[my code]]></category>

		<guid isPermaLink="false">http://www.ponton.srednikpe.org/2007/09/09/jzw-interpreter-source-and-examples/</guid>
		<description><![CDATA[All right. I said I&#8217;ll show my jzwi source and here it is: http://www.srednikpe.org/src/jzwi/ It is almost ended. It doesn&#8217;t only check local variable if they have unique names. I&#8217;m too lazy to do that. But after all it works fine and quite fast (compared to other interpreters written by my colleagues). To run jzwi [...]]]></description>
			<content:encoded><![CDATA[<p>All right. I said I&#8217;ll show my jzwi source and here it is: <a title="JZW interpreter source and examples" href="http://www.srednikpe.org/src/jzwi/">http://www.srednikpe.org/src/jzwi/</a></p>
<p>It is almost ended. It doesn&#8217;t only check local variable if they have unique names. I&#8217;m too lazy to do that. But after all it works fine and quite fast (compared to other interpreters written by my colleagues).</p>
<p>To run jzwi program just run  &#8220;jzwi program.jzw argument1 argument2 &#8230;&#8221;.</p>
<p>It&#8217;s all licensed on GPL (any version). There is no guarantee that it&#8217;ll work. ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ponton.srednikpe.org/2007/09/09/jzw-interpreter-source-and-examples/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
