<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3218008772058347246</id><updated>2012-03-10T13:40:11.190-08:00</updated><category term='Haskell'/><category term='Python'/><category term='PHP'/><category term='smart code'/><category term='crappy code'/><category term='parapsychology'/><category term='electronic'/><category term='programming'/><category term='C/C++'/><category term='Perl'/><category term='chemistry'/><category term='image processing'/><category term='riddle'/><category term='R'/><category term='life'/><title type='text'>Robert Gawron</title><subtitle type='html'>electronic, chemistry, making robots, software in C, Python and Haskell</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>48</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-838977321406376438</id><published>2011-08-10T01:23:00.000-07:00</published><updated>2011-08-10T01:35:12.766-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>Coma operator and side efffects</title><content type='html'>&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Comma_operator"&gt;Coma operator&lt;/a&gt; may be used to insert &lt;a href="http://en.wikipedia.org/wiki/Side_effect_%28computer_science%29"&gt;side effects&lt;/a&gt; into computations.&lt;/p&gt;

&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;math.h&amp;gt;

int main() {
    int max = 10;
    double x = 0;

    while (&lt;strong&gt;max--, printf(&amp;quot;%d\n&amp;quot;, max), max&lt;/strong&gt;) {
        /* sth */
    }

    &lt;strong&gt;x = printf(&amp;quot;x: %f&amp;quot;, x), x = sqrt(x), printf(&amp;quot;, sqrt(x): %f\n&amp;quot;, x), x;&lt;/strong&gt;

    return EXIT_SUCCESS;
}

&lt;/pre&gt;

&lt;pre&gt;bash-3.2$ gcc -strict -pedantic -Wall main.c &amp;&amp; ./a.out
9
8
7
6
5
4
3
2
1
0
x: 0.000000, sqrt(x): 3.316625
&lt;/pre&gt;

&lt;p&gt;Coma operator is even more interesting in C++, where you may overload it!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-838977321406376438?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/838977321406376438/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/08/coma-operator-and-side-efffects.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/838977321406376438'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/838977321406376438'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/08/coma-operator-and-side-efffects.html' title='Coma operator and side efffects'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-8161663462320060683</id><published>2011-08-07T12:38:00.000-07:00</published><updated>2011-08-07T12:42:19.926-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Milionerzy: najlepsza kolejność wykorzystania kół ratunkowych</title><content type='html'>&lt;p&gt;Grasz w milionerów, masz wszystkie koła ratunkowe i nagle dostajesz makabryczne pytanie. Nie wiesz. Bierzesz koła. Najpierw 50:50, a później publiczność, czy najpierw publiczność, a potem 50:50? Ta dyskusja rozgorzała na joemosterze, wiec i ja postanowiłem się temu przyjrzeć.&lt;/p&gt;

&lt;h3&gt;Warunki początkowe&lt;/h3&gt;

&lt;p&gt;Zakładam, że 10% osób zna odpowiedz na pytanie, a reszta zaznacza losową odpowiedz. Publiczność to około kilkadziesiąt osób, jest ich więc na tyle dużo, że można założyć, że odpowiedzi tych którzy strzelają rozłożą się równomiernie. Mamy zatem:

&lt;pre&gt;10% - osoby znające odpowiedz
90% - osoby zgadujące&lt;/pre&gt;

&lt;h3&gt;Wariant I, najpierw 50:50&lt;/h3&gt;

&lt;p&gt;Jeśli weźniemy najpierw 50:50, to zostawimy publiczności wybór między dwiema opcjami, rozkład odpowiedzi będzie wyglądał następująco:&lt;/p&gt;

&lt;pre&gt;odpowiedz poprawna: 0.5 * 90% + 10% = 55%
odpowiedz błędna:   0.5 * 90% = 45%&lt;/pre&gt;

&lt;p&gt;Poprawną odpowiedz wskaże 55% głosujących.&lt;/p&gt;

&lt;h3&gt;Wariant II, najpierw publiczność&lt;/h3&gt;

&lt;p&gt;Jeśli najpierw skorzystamy z publiczności, to rozkład odpowiedzi będzie wyglądał następująco:&lt;/p&gt;

&lt;pre&gt;0.25 * 90% + 10% = 32.5%
0.25 * 90% = 22.5%
0.25 * 90% = 22.5%
0.25 * 90% = 22.5%&lt;/pre&gt;

&lt;p&gt;Ponieważ dwie błędne odpowiedzi odpadają, to zostajemy z poprawną odpowiedzią, która miała 32.5% i jedną błędną, która miała 22.5%. Pamiętamy, że 32.5% + 22.5% = 55%, a nie 100%, zatem obie wartości dzielimy przez 55%, byśmy móc porównać je z rezultatem pierwszego wariantu. Mamy zatem:&lt;/p&gt;

&lt;pre&gt;odpowiedz poprawna: 32.5% / 55% = 59%
odpowiedz błędna:   22.5% / 55% = 41%&lt;/pre&gt;

&lt;p&gt;Poprawną odpowiedz wskaże 59% głosujących.&lt;/p&gt;

&lt;h3&gt;Rezultat&lt;/h3&gt;

&lt;p&gt;Lepiej skorzystać najpierw z głosu publiczności, w ten sposób osoby, które nie znają odpowiedzi będą miały mniejszy wpływ na ostateczny rezultat głosowania.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-8161663462320060683?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/8161663462320060683/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/08/milionerzy-najlepsza-kolejnosc.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8161663462320060683'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8161663462320060683'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/08/milionerzy-najlepsza-kolejnosc.html' title='Milionerzy: najlepsza kolejność wykorzystania kół ratunkowych'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-6119234535580187183</id><published>2011-07-31T07:45:00.001-07:00</published><updated>2011-07-31T09:41:04.307-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='parapsychology'/><title type='text'>Różdżka, jak ją wykonać i jak się nią posługiwać?</title><content type='html'>&lt;h3&gt;Zasada działania i wykorzystanie różdżek&lt;/h3&gt;

&lt;p&gt;Różdżki są wykorzystywane do poszukiwania wody, żył wodnych, zagubionych przedmiotów, a czasami też do przepowiadania przyszłości. Zazwyczaj są one wykonywane z drutu (co opiszę w tym artykule) lub z gałązek.&lt;/p&gt;

&lt;p&gt;Zdania, co do tego, czy różdżka to użyteczny przedmiot czy bujda są podzielone. Część osób jest zdania, że różdżki nie działają, część uważa, że działają lecz są one kierowane (świadomie lub nie) ruchami dłoni, a część uważa, że w grę wchodzi tu jeszcze inna siła.&lt;/p&gt;

&lt;p&gt;Osobiście skłaniam się ku teorii, że ruch różdżki spowodowany jest nieświadomym ruchem dłoni badającego. Skąd bierze się zatem ten ruch, i dlaczego jego efektem jest udzielenie poprawnej odpowiedzi? Jedna z koncepcji zakłada, że podświadomość stara się nam odpowiedzieć na pytanie, które postawiliśmy. Nasza podświadomość jest zaś częścią globalnej "podświadomości" i z niej czerpie potrzebne informacje.&lt;/p&gt;  

&lt;h3&gt;Wykonanie różdżki z drutu&lt;/h3&gt;

&lt;p&gt;Potrzebne nam ok. 2m twardego drutu, piła, imadło i młotek. Z drutu wycinamy dwa odcinki o długości 1m, z każdego z nich wyginamy odcinki 2cm, 70cm, 15cm, 2cm, tak, by uformować kształt pokazany na zdjęciu. Nadmiar drutu odcinamy.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-9AxXYVbQ_eg/TjV0uKApCKI/AAAAAAAAAs4/krncCgK8LpA/s1600/r%25C3%25B3%25C5%25BCd%25C5%25BCka.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 235px;" src="http://1.bp.blogspot.com/-9AxXYVbQ_eg/TjV0uKApCKI/AAAAAAAAAs4/krncCgK8LpA/s400/r%25C3%25B3%25C5%25BCd%25C5%25BCka.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5635538845033892002" /&gt;&lt;/a&gt;


&lt;h3&gt;Sposób wykorzystania różdżki&lt;/h3&gt;

&lt;h4&gt;Poszukiwanie wody, żył wodnych, zagubionych w domu przedmiotów&lt;/h4&gt;

&lt;p&gt;Stoimy, trzymamy różdżki w obu rękach za odcinek 15cm. Są dwa sposoby trzymania różdżki, jeden to taki, gdzie odcinki 70cm są ułożone równolegle do siebie, a końcówki różdżek znajdują się przed nami, drugi to taki, gdzie 70cm odcinki są ułożone w jedną linię, koniec lewej różdżki wskazuje nasza lewą stronę, a koniec prawej różdżki wskazuje wskazuje w naszą prawą stronę.&lt;/p&gt;

&lt;p&gt;Następnie (na głos lub po cichu) zadajemy pytanie i obserwujemy wychylenie różdżek, możemy sobie pomóc chodząc w różnych kierunkach i sprawdzając, gdzie wychylenie jest największe lub chociaż obserwowalne.&lt;/p&gt;

&lt;h4&gt;Przepowiadanie przyszłości&lt;/h4&gt;

&lt;p&gt;Po swojej lewej stronie umieszczamy kartkę z napisem "TAK", a po prawej kartkę z napisem "NIE", trzymając różdżki zadajemy pytanie i obeserwujemy kierunek wychylenia się różdżek - powinny nam one wskazać odpowiedź.&lt;/p&gt;

&lt;h3&gt;Bezpieczeństwo&lt;/h3&gt;

&lt;p&gt;Korzystając z różdżki musimy uważać by nie dźgnąć nią (zwłaszcza w oko) postronnych ludzi.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-6119234535580187183?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/6119234535580187183/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/07/rozdzka-jak-ja-wykonac-i-jak-sie-nia.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/6119234535580187183'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/6119234535580187183'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/07/rozdzka-jak-ja-wykonac-i-jak-sie-nia.html' title='Różdżka, jak ją wykonać i jak się nią posługiwać?'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-9AxXYVbQ_eg/TjV0uKApCKI/AAAAAAAAAs4/krncCgK8LpA/s72-c/r%25C3%25B3%25C5%25BCd%25C5%25BCka.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-3028792180037190486</id><published>2011-07-31T04:00:00.000-07:00</published><updated>2011-08-12T06:54:48.911-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='image processing'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>How to hide image inside another image?</title><content type='html'>&lt;p&gt;At first glance, there's nothing special on bellow image..&lt;/p&gt; 

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-RpAuE2ZqFHQ/TjU5R_rrw3I/AAAAAAAAAso/GRjoaT5LGRs/s1600/hidden.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 240px;" src="http://2.bp.blogspot.com/-RpAuE2ZqFHQ/TjU5R_rrw3I/AAAAAAAAAso/GRjoaT5LGRs/s400/hidden.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5635473490039260018" /&gt;&lt;/a&gt;

&lt;p&gt;But in fact, on this picture is hidden another one, that is visible bellow:&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-XqCfhtBB1lg/TjU5SRuZSwI/AAAAAAAAAsw/MgKXfgKaNkk/s1600/extracted.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 240px;" src="http://2.bp.blogspot.com/-XqCfhtBB1lg/TjU5SRuZSwI/AAAAAAAAAsw/MgKXfgKaNkk/s400/extracted.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5635473494882470658" /&gt;&lt;/a&gt;

&lt;p&gt;It was done, by using &lt;a hre="http://en.wikipedia.org/wiki/Steganography"&gt;steganography&lt;/a&gt;, second image was stored on two lowest bits of pixels. On two bits we may save values from 0 to 7, pixel in image may have values from 0 to 255, so such small change is not visible for human eye.&lt;/p&gt;

&lt;p&gt;I used bellow python script:&lt;/p&gt;

&lt;pre&gt;#!/usr/bin/env python
import sys
import Image, ImageOps

def extract_image(from_image, s=4):
    data = Image.open(from_image) 
    for x in range(data.size[0]):
        for y in range(data.size[1]):
            p = data.getpixel((x, y))
            red   = (p[0] % s) * 255 / s
            green = (p[1] % s) * 255 / s
            blue  = (p[2] % s) * 255 / s
            data.putpixel((x, y), (red, green, blue))
    return data

def hide_image(public_img, secret_img, s=4):
    data = Image.open(public_img)
    key =  ImageOps.autocontrast(Image.open(secret_img))
    for x in range(data.size[0]):
        for y in range(data.size[1]):
            p = data.getpixel((x, y))
            q = key.getpixel((x, y))
            red   = p[0] - (p[0] % s) + (s * q[0] / 255)
            green = p[1] - (p[1] % s) + (s * q[1] / 255)
            blue  = p[2] - (p[2] % s) + (s * q[2] / 255)
            data.putpixel((x, y), (red, green, blue))
    return data

def show_help():
        print &amp;quot;wrong usage, try:&amp;quot;
        print &amp;quot;%s show from.jpg&amp;quot; % sys.argv[0]
        print &amp;quot;%s hide public.jpg secret.jpg&amp;quot; % sys.argv[0]

if __name__==&amp;quot;__main__&amp;quot;:

    if len(sys.argv) != 3 and len(sys.argv) != 4:
       show_help()

    elif sys.argv[1] == &amp;quot;show&amp;quot;:
        print &amp;quot;image will be saved as extracted.png&amp;quot;
        extract_image(sys.argv[2]).save(&amp;quot;extracted.png&amp;quot;);

    elif sys.argv[1] == &amp;quot;hide&amp;quot;:
        hide_image(sys.argv[2], sys.argv[3]).save(&amp;quot;hidden.png&amp;quot;)

    else:
        show_help()&lt;/pre&gt;

&lt;p&gt;Below is example of usage, first line shows how to hide image, second shows how to extract image.&lt;/p&gt;

&lt;pre&gt;bash-3.2$ ./hider.py hide kosciol_Marii_Magdaleny.jpg GOR-Rabka.JPG  
bash-3.2$ ./hider.py show hidden.png 
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-3028792180037190486?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/3028792180037190486/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/07/how-to-hide-image-inside-anther-image.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/3028792180037190486'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/3028792180037190486'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/07/how-to-hide-image-inside-anther-image.html' title='How to hide image inside another image?'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-RpAuE2ZqFHQ/TjU5R_rrw3I/AAAAAAAAAso/GRjoaT5LGRs/s72-c/hidden.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-4093390129453555279</id><published>2011-07-23T13:32:00.000-07:00</published><updated>2011-07-23T13:34:20.140-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><category scheme='http://www.blogger.com/atom/ns#' term='R'/><title type='text'>Zipf's law in natural languages</title><content type='html'>&lt;p&gt;When we count appearance of words in a sample of (most) &lt;a href="http://en.wikipedia.org/wiki/Natural_language"&gt;human languages&lt;/a&gt;, it will be visible, that they have &lt;a href="http://en.wikipedia.org/wiki/Zipf%27s_law"&gt;Zipf's distribution&lt;/a&gt;. Example is presented on bellow chart.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-oG9wwtmPngE/TistkjIj8YI/AAAAAAAAAsg/Arj1OQuJ0e8/s1600/results.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 286px;" src="http://3.bp.blogspot.com/-oG9wwtmPngE/TistkjIj8YI/AAAAAAAAAsg/Arj1OQuJ0e8/s400/results.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5632645864886628738" /&gt;&lt;/a&gt;

&lt;p&gt;It's common for natural languages, but dummy randomly generated text doesn't meet this law!&lt;/p&gt;

&lt;p&gt;If some of you would like to check this, bellow I will share scripts and programs, that I used. First one (written in C++) is used to parse text file and print on &lt;i&gt;stdout&lt;/i&gt; its distribution. Second one (created in &lt;a href="http://www.r-project.org/"&gt;R&lt;/a&gt;) is used to made chart with this distribution. &lt;/p&gt;

&lt;p&gt;You need installed &lt;a href="http://www.boost.org/"&gt;boost&lt;/a&gt; to compile bellow program (during compilation add &lt;i&gt;-I&lt;/i&gt; and path to boost directory, e.g. &lt;i&gt;g++ -Wall -I/opt/local/include main.c&lt;/i&gt;).&lt;/p&gt;

&lt;pre&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;algorithm&amp;gt;
#include &amp;lt;fstream&amp;gt;
#include &amp;lt;sstream&amp;gt;
#include &amp;lt;vector&amp;gt;
#include &amp;lt;map&amp;gt;
#include &amp;lt;boost/foreach.hpp&amp;gt;
#include &amp;lt;boost/tokenizer.hpp&amp;gt;

using namespace std;
using namespace boost;

int main(int argc, char* argv[])
{
    if (2 != argc)
    {
        cout &amp;lt;&amp;lt; &amp;quot;usage: &amp;quot; &amp;lt;&amp;lt; argv[0] &amp;lt;&amp;lt; &amp;quot; filename&amp;quot; &amp;lt;&amp;lt;endl;
        return EXIT_SUCCESS;
    }

    // read whole file into string
    ifstream t(argv[1]);
    stringstream fileBuffer;
    fileBuffer &amp;lt;&amp;lt; t.rdbuf();
    string text = fileBuffer.str();
    // make content of file lower case
    transform(text.begin(), text.end(), text.begin(), ::tolower);

    // create hash, where key = word, value = amount of this word in text
    char_separator&amp;lt;char&amp;gt; sep(&amp;quot; \t\n-;.,&amp;quot;);
    tokenizer&amp;lt; char_separator&amp;lt;char&amp;gt; &amp;gt; tokens(text, sep);
    map&amp;lt;string, unsigned&amp;gt; words;
    typedef std::pair&amp;lt;string, unsigned&amp;gt; wordPairType;

    BOOST_FOREACH (string t, tokens)
    {
        bool isIn = words.find(t) != words.end();
        words[t] = isIn ? words[t] + 1 : 1;
    }

    // create vector with amounts of all words in text
    vector&amp;lt;unsigned&amp;gt; distribution;
    BOOST_FOREACH (wordPairType t, words) {
        distribution.push_back(t.second);
    }

    // amounts of words needs to be sorted
    sort(distribution.rbegin(), distribution.rend());

    // show results
    BOOST_FOREACH (unsigned i, distribution)
    {
        cout &amp;lt;&amp;lt; i &amp;lt;&amp;lt; endl;
    }

    return 0;
}

&lt;/pre&gt;

&lt;p&gt;Bellow is mentioned &lt;a href="http://www.r-project.org/"&gt;R&lt;/a&gt; script. You need &lt;a href=""http://www.r-project.org/&gt;R&lt;/a&gt; installed on your computer to run it.&lt;/p&gt; 

&lt;pre&gt;args &amp;lt;- commandArgs(TRUE)
sizes &amp;lt;- scan(args[1])

png(filename = &amp;quot;results.png&amp;quot;, height = 500, width = 700, bg = &amp;quot;white&amp;quot;)
plot(sizes, xlab = &amp;quot;words&amp;quot;, ylab = &amp;quot;occurences&amp;quot;, type=&amp;quot;l&amp;quot;,log=&amp;quot;yx&amp;quot; )&lt;/pre&gt; 


&lt;p&gt;Assuming, that C++ program was compiled into ./a.out, R script was saved as chart.r, sample of text was saved to test4.txt, execution of bellow command should create results.png with chart.&lt;/p&gt;

&lt;pre&gt;bash-3.2$ ./a.out test4.txt &gt; results.txt &amp;&amp; Rscript chart.r results.txt
Read 314 items
&lt;/pre&gt;

&lt;p&gt;Bellow is a sample, that was used to produce chart presented in the beginning of this post.&lt;/p&gt;

&lt;blockquote&gt;Józef Piłsudski, herbu Piłsudski[2] urodził się 5 grudnia 1867 w Zułowie na Litwie, w
rodzinie o tradycjach patriotycznych. Ojciec, Józef Wincenty (1833–1902), był podczas
powstania w 1863 komisarzem Rządu Narodowego na powiat rosieński[3], matka – Maria z
Billewiczów (1842–1884) – pochodziła ze znanego rodu szlacheckiego herbu Mogiła. Rodzice
zawarli związek małżeński bezpośrednio przed powstaniem. Po stłumieniu powstania, uchodząc
przed prześladowaniem ze strony Rosjan, Józef Wincenty Piłsudski uciekł ze Żmudzi na
Litwę, gdzie też kilkakrotnie zmieniał miejsce pobytu.  Dopiero jesienią lub zimą 1863
nowożeńcy zamieszkali na stałe w posagowym Zułowie.  Józef Wincenty Piłsudski postawił na
uprzemysłowienie – poddał majątki żony (ok. 12 000 ha) gruntownej modernizacji, sprowadził
specjalistów, również z zagranicy. Nad brzegiem Mery wybudował duży trzypiętrowy młyn,
dużą gorzelnię, wytwórnię drożdży, cegielnię i wytwórnię terpentyny. Wzniósł również nowy
dwór[3]. W Zułowie 5 grudnia 1867 urodził się Józef Klemens Piłsudski. Był czwartym w
kolejności dzieckiem – w 1864 urodziła się Helena, w 1865 – Zofia, a w 1866 – Bronisław
Piłsudski. Po Józefie, którego w rodzinie nazywano Ziukiem[4], urodzili się także Adam,
Kazimierz i Maria, Jan, Ludwika, Kacper oraz bliźnięta Piotr i Teodora (zmarły w wieku 1,5
roku).  Józef został ochrzczony 15 grudnia 1867 w kościele rzymskokatolickim w majątku
Sorokpol (dekanat święciański) przez księdza Tomasza Wolińskiego. Rodzicami chrzestnymi
byli Józef Marcinkowski i Konstancja Rogalska[5]. Maria Piłsudska wychowywała swoje dzieci
w duchu głęboko patriotycznym, dbała też o ich wykształcenie. Dzieci uczyli sprowadzeni do
dworu nauczyciele. Języków uczyły dwie bony, Niemka i Francuzka[3]. Nieudana działalność
inwestycyjna ojca doprowadziła zarządzane przez niego majątki do ruiny. Problemy rodziny
pogłębił pożar, po którym w 1874 Piłsudscy przenieśli się do Wilna, zmuszeni tam do
egzystencji w trudnych warunkach materialnych[6].  Tu w 1877 Józef, wraz z bratem
Bronisławem, rozpoczął naukę w I Gimnazjum wileńskim, mieszczącym się w gmachu dawnego
uniwersytetu. W gimnazjum bracia, razem z innymi uczniami, poddawani byli intensywnej
rusyfikacji[7]. W 1882 obaj bracia (wraz z innymi kolegami) założyli kółko
samokształceniowe o nazwie Spójnia, zajmujące się sprowadzaniem z Warszawy polskich
książek[8]. We wrześniu 1884 zmarła ciężko chora od lat Maria Piłsudska. Rok później Józef
zdał maturę (najlepsze oceny z historii – czwórka i geografii – piątka, najsłabsze – z
języków, z wyjątkiem francuskiego). Jesienią rozpoczął studia medyczne na Uniwersytecie
Charkowskim.  Tam zaczął działalność konspiracyjną w niepodległościowych organizacjach
studenckich, trafiając m.in. w szerokie kręgi osób kojarzonych z rewolucyjną organizacją
rosyjską Narodnaja Wola (uczestniczył w kilku jej spotkaniach). 2 i 3 marca 1886 brał
udział w studenckiej demonstracji z okazji 25. rocznicy uwłaszczenia, znajdując się potem
wśród ponad 150 zatrzymanych przez policję carską. Po zaliczeniu I roku, próbował
przenieść się wiosną 1886 na uniwersytet w Dorpacie, jednak tam odmówiono mu przyjęcia
dokumentów z powodu jego uprzedniej działalności opozycyjnej.
&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-4093390129453555279?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/4093390129453555279/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/07/zipfs-law-in-natural-languages.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/4093390129453555279'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/4093390129453555279'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/07/zipfs-law-in-natural-languages.html' title='Zipf&apos;s law in natural languages'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-oG9wwtmPngE/TistkjIj8YI/AAAAAAAAAsg/Arj1OQuJ0e8/s72-c/results.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-4736664424796169627</id><published>2011-07-10T04:28:00.001-07:00</published><updated>2011-07-10T05:11:31.762-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>How to distinguish human languages by frequencies of letters?</title><content type='html'>&lt;p&gt;Let's say, that we have a sample of text and we want to know in what language it's written. There are many ways to do this and one of them is to calculate frequencies of letters in sample and compare it to those frequencies for known languages. For example in polish 'a' letter is about 0.0551146 of all letters, in french it's 0.049458 and in german 0.0434701. Those known values for languages are computed from samples of texts and may vary according to used samples.&lt;/p&gt;

&lt;p&gt;I made a small program, that takes as an argument path to file with unknown language and print, how this language differs from its known languages. Frequencies of letters in known languages are computed from files in &lt;i&gt;samples&lt;/i&gt;  directory. The lowest result is the best match.&lt;/p&gt;

As example, here is a text in French:

&lt;blockquote&gt;Au contraire de Józef Piłsudski, qui rêvait d'une grande fédération slave alliée à l'Allemagne contre la Russie, Roman Dmowski était désireux de fonder une Pologne alliée à la Russie : il a ainsi soutenu l'idée d'une association avec l'Empire russe, puis, malgré son anticommunisme, avec l'Union soviétique, qu'il considère malgré tout comme un prolongement de la politique des tsars.
De même, bien qu'agnostique, Dmowski ne concevait l'existence d'un État polonais que sur une base catholique, et ethniquement homogène, ce qui impliquait pour les populations allogènes (Baltes, Ukrainiens, Allemands et mêmes Juifs) l'expulsion ou l'assimilation, rejetant ainsi le concept de République des Deux Nations, avancé par la gauche et les libéraux.&lt;/blockquote&gt;

&lt;p&gt;Bellow is output for this file, where it's visible, that the lowest value was for French, so it's probably this language.&lt;/p&gt;

&lt;pre&gt;bash-3.2$ ./a.out test3.txt 
difference between Polish language: 0.0965482
&lt;strong&gt;difference between French language: 0.0442431&lt;/strong&gt;
difference between German language: 0.0945827&lt;/pre&gt;

&lt;p&gt;For those, who would like to try it, bellow is the source code. Compiled program needs learning texts in directory &lt;i&gt;samples&lt;/i&gt; (see samples.* variables in main() for names of those files). It can be also easily extended for next languages.&lt;/p&gt;

&lt;pre&gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;
#include &amp;lt;algorithm&amp;gt;
#include &amp;lt;fstream&amp;gt;
#include &amp;lt;sstream&amp;gt;
#include &amp;lt;vector&amp;gt;
#include &amp;lt;map&amp;gt;
#include &amp;lt;math.h&amp;gt;

using namespace std;

class Language {
public:
    Language (vector&amp;lt;string&amp;gt; filenames) {
        for (vector&amp;lt;string&amp;gt;::iterator i = filenames.begin(); i != filenames.end(); i++) {
            // read whole file into string
            ifstream t(i-&amp;gt;c_str());
            stringstream buffer;
            buffer &amp;lt;&amp;lt; t.rdbuf();
            string data = buffer.str();
            // make content of file lower case
            transform(data.begin(), data.end(), data.begin(), ::tolower);
            sample += data;
        }
        computeLettersDistribution();
    }

    map&amp;lt;char, double&amp;gt; getLettersDistribution() {
        return lettersDistribution;
    }

    double compare(Language a) {
        double error = 0.0;
        for (map&amp;lt;char, double&amp;gt;::iterator i = lettersDistribution.begin(); i != lettersDistribution.end(); i++) {
            error += pow((*i).second - a.getLettersDistribution()[(*i).first], 2);
        }
        return pow(error, 0.5);
    }

protected:
    void computeLettersDistribution() {
        for (char c = 'a'; c &amp;lt;= 'z'; c++) {
            lettersDistribution[c] = 0;
        }

        for (string::iterator c = sample.begin(); c != sample.end(); c++) { // over letters in sample
            if (*c &amp;gt;= 'a' &amp;amp;&amp;amp; *c &amp;lt;= 'z') {
                lettersDistribution[*c]++;
            }
        }

        for (map&amp;lt;char, double&amp;gt;::iterator d = lettersDistribution.begin(); d!= lettersDistribution.end(); d++) {
            lettersDistribution[ (*d).first ]  = (*d).second / sample.length();
        }
    }

    string sample;
    map&amp;lt;char, double&amp;gt; lettersDistribution; // key is a letter, value is quantity of this letter in file
};

int main(int argc, char* argv[]) {

    if (2 != argc) {
        cout &amp;lt;&amp;lt; &amp;quot;usage: &amp;quot; &amp;lt;&amp;lt; argv[0] &amp;lt;&amp;lt; &amp;quot; filename&amp;quot; &amp;lt;&amp;lt;endl;
        return EXIT_SUCCESS;
    }

    vector&amp;lt;string&amp;gt; samplesPL; // vector of filenames
    samplesPL.push_back(&amp;quot;samples/polski_1.txt&amp;quot;);
    samplesPL.push_back(&amp;quot;samples/polski_2.txt&amp;quot;);
    Language polish(samplesPL);

    vector&amp;lt;string&amp;gt; samplesFR; // vector of filenames
    samplesFR.push_back(&amp;quot;samples/francais_1.txt&amp;quot;);
    samplesFR.push_back(&amp;quot;samples/francais_2.txt&amp;quot;);
    samplesFR.push_back(&amp;quot;samples/francais_3.txt&amp;quot;);
    Language francais(samplesFR);

    vector&amp;lt;string&amp;gt; samplesDE; // vector of filenames
    samplesDE.push_back(&amp;quot;samples/deutsch_1.txt&amp;quot;);
    samplesDE.push_back(&amp;quot;samples/deutsch_2.txt&amp;quot;);
    Language deutsch(samplesDE);
 
    vector&amp;lt;string&amp;gt; investigatedSamples; // vector of filenames
    investigatedSamples.push_back(argv[1]);
    Language investigated(investigatedSamples);

    cout &amp;lt;&amp;lt; &amp;quot;difference between Polish language: &amp;quot; &amp;lt;&amp;lt; investigated.compare(polish) &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; &amp;quot;difference between French language: &amp;quot; &amp;lt;&amp;lt; investigated.compare(francais) &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; &amp;quot;difference between German language: &amp;quot; &amp;lt;&amp;lt; investigated.compare(deutsch) &amp;lt;&amp;lt; endl;
}

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-4736664424796169627?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/4736664424796169627/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/07/how-to-distinguish-human-languages-by_10.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/4736664424796169627'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/4736664424796169627'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/07/how-to-distinguish-human-languages-by_10.html' title='How to distinguish human languages by frequencies of letters?'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-7515622077779485042</id><published>2011-06-19T05:43:00.000-07:00</published><updated>2011-06-19T06:06:16.855-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><category scheme='http://www.blogger.com/atom/ns#' term='smart code'/><title type='text'>do/while, goto and error handling</title><content type='html'>&lt;p&gt;Error handling in C is often done by using &lt;strong&gt;goto&lt;/strong&gt; and labels. Bellow is one of examples  in Linux kernel:&lt;/p&gt;

&lt;pre&gt;static struct avc_node *avc_alloc_node(void)
{
    struct avc_node *node;

    node = kmem_cache_zalloc(avc_node_cachep, GFP_ATOMIC);
    &lt;strong&gt;if (!node)  
        goto out;&lt;/strong&gt;

    INIT_RCU_HEAD(&amp;amp;node-&amp;gt;rhead);
    INIT_HLIST_NODE(&amp;amp;node-&amp;gt;list);
    avc_cache_stats_incr(allocations);

    if (atomic_inc_return(&amp;amp;avc_cache.active_nodes) &amp;gt; avc_cache_threshold)
        avc_reclaim_node();
   
&lt;strong&gt;out:
    return node;&lt;/strong&gt;
}&lt;/pre&gt;

&lt;p&gt;There's a trick with usage of do/while construction, that allows to write the same code without using goto label. Its idea is presented on bellow snippets:&lt;/p&gt;

&lt;pre&gt;// with goto label
if (!bar()) {
    goto error;
}
someValue = baz();
error:&lt;/pre&gt;


&lt;pre&gt;// with do/while construction
do {
    if (!bar()) {
        break;
    }
    someValue = baz();
} while (0);&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-7515622077779485042?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/7515622077779485042/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/06/dowhile-goto-and-error-handling.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/7515622077779485042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/7515622077779485042'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/06/dowhile-goto-and-error-handling.html' title='do/while, goto and error handling'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-8015305211720265476</id><published>2011-05-28T08:31:00.000-07:00</published><updated>2011-08-12T03:43:09.025-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>[pl] Prosty i smaczny przepis na kurczaka po chińsku</title><content type='html'>&lt;p&gt;Czas przygotowania: 30-40min, ilość porcji: 1-2 osoby.&lt;/p&gt;

&lt;h3&gt;Składniki&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;2 torebki ryżu&lt;/li&gt;
&lt;li&gt;1-1.5 piersi z kurczaka lub indyka&lt;/li&gt;
&lt;li&gt;0.5 opakowania chińskiej mieszanki warzyw&lt;/li&gt;
&lt;li&gt;2-3 łyżki oliwy z oliwek&lt;/li&gt;
&lt;li&gt;1 łyżka curry&lt;/li&gt;
&lt;li&gt;2-3 łyżki sosu sojowego&lt;/li&gt;
&lt;/ul&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-Kvn2RkIcjKo/TeEbKLUWYCI/AAAAAAAAApU/whVLf-sUMSg/s1600/gotowe_do_spozycia.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 300px;" src="http://2.bp.blogspot.com/-Kvn2RkIcjKo/TeEbKLUWYCI/AAAAAAAAApU/whVLf-sUMSg/s400/gotowe_do_spozycia.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5611796472331132962" /&gt;&lt;/a&gt;



&lt;h3&gt;Przygotowanie&lt;/h3&gt;

&lt;p&gt;Kurczaka kroimy w drobną kostkę, wkładamy do miseczki. Polewamy sosem sojowym i mieszamy, czynność powtarzamy dopóki sos wchłania się w mięso. Nadmiar sosu wylewamy. Kurczaka odstawiamy na 5-10minut&lt;/p&gt;

&lt;p&gt;Do garnka wlewamy wodę, wkładamy dwa woreczki ryżu i wsypujemy ok. 1 łyżkę curry. Garnek stawiamy na gaz.&lt;/p&gt;

&lt;p&gt;Po 5-10 min. na patelnie wlewamy 2-3 łyżki oliwy (oliwy, nie oleju!!!) i wrzucamy zamarynowanego kurczaka. Smażymy na maksymalnym ogniu. Gdy mięso staje się jaśniejsze, łopatką przepoławiamy jeden z kawałków mięsa, jeśli nie jest w środku surowe, to wrzucamy pół opakowania chińskiej mieszanki warzywnej i zmniejszamy ogień na mały. Mieszamy zawartość patelni by nic się nie przypaliło.&lt;/p&gt;

&lt;p&gt;Gotowy ryż odcedzamy, wsypujemy na talerz a na wierzchu umieszczamy zawartość patelni.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-8015305211720265476?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/8015305211720265476/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/05/pl-szybki-i-prosty-przepis-na-kurczaka.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8015305211720265476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8015305211720265476'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/05/pl-szybki-i-prosty-przepis-na-kurczaka.html' title='[pl] Prosty i smaczny przepis na kurczaka po chińsku'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-Kvn2RkIcjKo/TeEbKLUWYCI/AAAAAAAAApU/whVLf-sUMSg/s72-c/gotowe_do_spozycia.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-106290867596944722</id><published>2011-05-22T08:39:00.000-07:00</published><updated>2011-05-24T13:53:51.344-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>If programmers have make a plane</title><content type='html'>&lt;center&gt;&lt;iframe width="480" height="390" src="http://www.youtube.com/embed/UZq4sZz56qM" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;/center&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-106290867596944722?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/106290867596944722/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/05/if-programmers-have-make-plane.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/106290867596944722'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/106290867596944722'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/05/if-programmers-have-make-plane.html' title='If programmers have make a plane'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://img.youtube.com/vi/UZq4sZz56qM/default.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-2818472059960377826</id><published>2011-05-21T12:21:00.000-07:00</published><updated>2011-05-21T12:26:09.830-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Perl'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>Automated code generation used to help in error handling [sources of Perl interpreter]</title><content type='html'>&lt;p&gt;In sources of Perl interpreter, there's an interesting mechanism, that checks if function arguments are correct. Bellow is its example from &lt;i&gt;util.c&lt;/i&gt; file.&lt;/p&gt;

&lt;pre&gt;char *
Perl_delimcpy(register char *to, 
      register const char *toend, 
      register const char *from, 
      register const char *fromend, 
      register int delim, I32 *retlen)
{
    register I32 tolen;

    PERL_ARGS_ASSERT_DELIMCPY;

    /* ... */
}&lt;/pre&gt;

&lt;p&gt;Body of &lt;i&gt;PERL_ARGS_ASSERT_DELIMCPY&lt;/i&gt; is present in &lt;i&gt;proto.h&lt;/i&gt; file:&lt;/p&gt;

&lt;pre&gt;#define PERL_ARGS_ASSERT_DELIMCPY   \
    assert(to); assert(toend); assert(from); assert(fromend); assert(retlen)&lt;/pre&gt;

&lt;p&gt;What makes those particular macros interesting, is that they are automatically generated. This is done by using perl script, that reads configuration and header files and creates from them above macros.&lt;/p&gt;

&lt;p&gt;This tool is more powerful and can generate even more code, but we will focus only on this part. So let's say, that we would like to change of one of those macros, or add new one. Data about them is stored in &lt;i&gt;embed.fnc&lt;/i&gt; file. In the beginning of this file, there's a list of all possible parameters, that may be generated. Example entry can looks as bellow:&lt;/p&gt;

&lt;pre&gt;: Used in util.cp
op  |void   |example_function   |NN const char *name|STRLEN len|&lt;/pre&gt;

&lt;p&gt;After we introduced changes in above file, we need to generate sources by invoking &lt;i&gt;regen.pl&lt;/i&gt; script:&lt;/p&gt;

&lt;pre&gt;bash-3.2$ ./regen.pl 
/usr/bin/perl regen/opcode.pl
/usr/bin/perl regen/overload.pl
/usr/bin/perl regen/reentr.pl
/usr/bin/perl regen/regcomp.pl
/usr/bin/perl regen/warnings.pl
/usr/bin/perl regen/embed.pl
Changed: proto.h&lt;/pre&gt;

&lt;p&gt;That's all, macro is ready for use!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-2818472059960377826?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/2818472059960377826/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/05/automated-code-generation-used-to-help.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/2818472059960377826'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/2818472059960377826'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/05/automated-code-generation-used-to-help.html' title='Automated code generation used to help in error handling [sources of Perl interpreter]'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-8779142580437402405</id><published>2011-05-18T12:30:00.000-07:00</published><updated>2011-05-28T08:07:42.060-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='electronic'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>Remote control of devices by using PC Speaker</title><content type='html'>&lt;p&gt;This is one of my older projects, that aims to control external devices directly, by using &lt;a href="http://pl.wikipedia.org/wiki/PC_speaker"&gt;PC Speaker&lt;/a&gt; port. It can operate multiple devices at one go, but they must be powered one at a time. I made it a couple of years ago and it was working fine, but due to mistake during plugging it literally burned ;( &lt;/p&gt;

&lt;p&gt;Now, when both cheap USB chips are available and PC speaker is unused (or integrated with sound card) it doesn't make sense, to build it, but this is still an interesting concept.&lt;/p&gt;

&lt;h3&gt;Hardware part&lt;/h3&gt;

&lt;p&gt;Device is plugged instead of &lt;a href="http://pl.wikipedia.org/wiki/PC_speaker"&gt;system speaker&lt;/a&gt;, it uses &lt;a href="http://en.wikipedia.org/wiki/Molex_connector"&gt;drive power connectors&lt;/a&gt; as a source of voltage. Every try to play a sound is interpreted as a signal, this signal is increasing 4017 counter, when it counts to 3, it resets itself to 0.&lt;/p&gt;

&lt;p&gt;For every state, 4017 has separate pin, for example, when it count to 3, only Q3 pin is set to high state, when it counts to 1, only Q1 pin is set to hight. To each of those pins we may plug devices, they can't take too much current, otherwise we will need to add to this circuit transistors (base plugged to 4017's pin, emitter to GND, collector to GND pin of plugged device, V&lt;sub&gt;CC&lt;/sub&gt; of device plugged to V&lt;sub&gt;cc&lt;/sub&gt; of our circuit).&lt;/p&gt;

&lt;p&gt;After computer is turned-on, device plugged to Q0 is powered, when we want to power device plugged to Q2, we need to send two signals to PC Speaker, this will turn-on Q1 for a short time, and after that Q2. By involving additional logic on software side, we may use this behavior, to control all plugged devices.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-vxzabk-SYmk/TdQILb-OpdI/AAAAAAAAAoA/1X3QWMveQRE/s1600/DEVICE.GIF"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 184px;" src="http://2.bp.blogspot.com/-vxzabk-SYmk/TdQILb-OpdI/AAAAAAAAAoA/1X3QWMveQRE/s400/DEVICE.GIF" border="0" alt=""id="BLOGGER_PHOTO_ID_5608116428563457490" /&gt;&lt;/a&gt;

&lt;p&gt;Unfortunately, I don't remember, what was the values of used elements.&lt;/p&gt;

&lt;h3&gt;Software part&lt;/h3&gt;

&lt;p&gt;What is the easiest way, to play a sound on mentioned port? On older computer it can be done by "displaying" on stdout bell character. It's presented on bellow snippet.&lt;/p&gt;

&lt;pre&gt;printf("\a");&lt;/pre&gt;

&lt;p&gt;To create driver for this device, there are also needed some delays, variable, that stores actual high pin and some way to get data from user.&lt;/p&gt;

&lt;p&gt;I have original sources, but I don't want to show them - they are totally crap ;(&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-8779142580437402405?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/8779142580437402405/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/05/remote-control-of-devices-by-using-pc.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8779142580437402405'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8779142580437402405'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/05/remote-control-of-devices-by-using-pc.html' title='Remote control of devices by using PC Speaker'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-vxzabk-SYmk/TdQILb-OpdI/AAAAAAAAAoA/1X3QWMveQRE/s72-c/DEVICE.GIF' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-1125281602682649962</id><published>2011-05-16T08:55:00.000-07:00</published><updated>2011-06-04T05:40:27.091-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>CMS written entirely in PL/pgSQL</title><content type='html'>&lt;p&gt;In one of my previous jobs, I heard, that it would be inspiring, to write CMS with *all* logic stored and executed on database side. Every request will be preformed in stored procedures, theirs result will be HTML page sent back to user.&lt;p&gt;

&lt;p&gt;In this post, I will preset, how to do that by using PotgreSQL, Apache, Linux and bash scripting. The bash script is a bit of cheating, because I promised to write everything in stored procedures, but as you will see, it's just a gateway to database, there isn't logic in it.&lt;/p&gt;

&lt;p&gt;We will start from configuration of the Apache server, as a root, go to &lt;i&gt;/etc/apache2&lt;/i&gt; and create &lt;i&gt;web-sql&lt;/i&gt; file in &lt;i&gt;sites-available&lt;/i&gt; directory. Bellow is content of this file.&lt;/p&gt;

&lt;pre&gt;NameVirtualHost 127.0.0.1:8888
&amp;lt;VirtualHost 127.0.0.1:8888&gt;
        ServerAdmin webmaster@localhost

        DocumentRoot /opt/websql
        &amp;lt;Directory /&gt;
                Options FollowSymLinks
                AllowOverride None
        &amp;lt;/Directory&gt;
        &amp;lt;Directory /opt/websql&gt;
                Options Indexes FollowSymLinks MultiViews ExecCGI
                AllowOverride None
                Order allow,deny
                allow from all
                # This directive allows us to have apache2's default start page
                # in /apache2-default/, but still have / go to the right place
                #RedirectMatch ^/$ /apache2-default/
        &amp;lt;/Directory&gt;

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined
        ServerSignature On

&amp;lt;/VirtualHost&gt;
&lt;/pre&gt;

&lt;p&gt;In &lt;i&gt;/etc/apache2/sites-enabled&lt;/i&gt; make link to above file. After typing &lt;i&gt;ls -la&lt;/i&gt; in command line it should looks like:&lt;/p&gt;

&lt;pre&gt;lrwxrwxrwx 1 root root   26 2008-05-26 00:00 web-sql -&gt; ../sites-available/web-sql&lt;/pre&gt;

&lt;p&gt;Now we have virtual server, that runs on &lt;i&gt;127.0.0.1&lt;/i&gt; address, on &lt;i&gt;8888&lt;/i&gt; port and that keeps its files in &lt;i&gt;/opt/websql&lt;/i&gt; directory.&lt;/p&gt;

&lt;p&gt;In &lt;i&gt;/opt&lt;/i&gt; make &lt;i&gt;websql&lt;/i&gt; directory. Make in it &lt;i&gt;main.cgi&lt;/i&gt; file, bellow is its content.&lt;/p&gt;

&lt;pre&gt;#!/bin/sh
echo "select index('$QUERY_STRING')" | psql  -U userszybkosci -t --no-align -d testszybkosci&lt;/pre&gt;

&lt;p&gt;This scripts executes index() procedure with string, that was given as an input parameter by user. We don't want to display number of returned rows, so we are using &lt;i&gt;-t&lt;/i&gt; parameter, spaces automatically inserted by psql are disabled by using &lt;i&gt;--no-align&lt;/i&gt;. Those two options assure us, that output of the script is equivalent to output of index() procedure. Remaining options are used to connect to database: &lt;i&gt;-U&lt;/i&gt; to select user and &lt;i&gt;-d&lt;/i&gt; to select database.&lt;/p&gt;

&lt;p&gt;We need to create user, database and enable PL/pgSQL language on that database. It's demonstrated bellow.&lt;/p&gt;

&lt;pre&gt;robert@robert855:~$ sudo bash
Password:
root@robert855:~# su postgres 
postgres@robert855:/home/robert$ createuser userszybkosci
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
CREATE ROLE
postgres@robert855:/home/robert$ createdb -O userszybkosci testszybkosci
CREATE DATABASE
postgres@robert855:/home/robert$ createlang plpgsql testszybkosci
&lt;/pre&gt;


&lt;p&gt;Now we may move to the merits of the case and start to create stored procedures and tables. They will be used to provide functionality of our simple CMS. Bellow is dump with them.&lt;/p&gt;

&lt;pre&gt;--
-- Name: atrybut; Type: TABLE; Schema: public; Owner: userszybkosci; Tablespace: 
--

CREATE TABLE atrybut (
    tag integer,
    nazwa text,
    wartosc text
);


ALTER TABLE public.atrybut OWNER TO userszybkosci;

--
-- Name: str_seq; Type: SEQUENCE; Schema: public; Owner: userszybkosci
--

CREATE SEQUENCE str_seq
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.str_seq OWNER TO userszybkosci;

--
-- Name: strona; Type: TABLE; Schema: public; Owner: userszybkosci; Tablespace: 
--

CREATE TABLE strona (
    id integer NOT NULL,
    tresc text,
    nazwa_pliku text,
    tytul text
);


ALTER TABLE public.strona OWNER TO userszybkosci;

--
-- Name: tag; Type: TABLE; Schema: public; Owner: userszybkosci; Tablespace: 
--

CREATE TABLE tag (
    id integer NOT NULL,
    nazwa text
);


ALTER TABLE public.tag OWNER TO userszybkosci;

--
-- Name: tag_seq; Type: SEQUENCE; Schema: public; Owner: userszybkosci
--

CREATE SEQUENCE tag_seq
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.tag_seq OWNER TO userszybkosci;

--
-- Name: strona_pkey; Type: CONSTRAINT; Schema: public; Owner: userszybkosci; Tablespace: 
--

ALTER TABLE ONLY strona
    ADD CONSTRAINT strona_pkey PRIMARY KEY (id);


--
-- Name: tag_pkey; Type: CONSTRAINT; Schema: public; Owner: userszybkosci; Tablespace: 
--

ALTER TABLE ONLY tag
    ADD CONSTRAINT tag_pkey PRIMARY KEY (id);

-- tutaj trafiaja zapytania, ona generuje tresc, taki
-- engine, mozna by dorobic obsluge akcji etc..
CREATE OR REPLACE FUNCTION index(text) RETURNS text AS $$
DECLARE
    nazwa_pliku ALIAS FOR $1;
    DECLARE output TEXT DEFAULT E'Content-Type: text/html\n\n';
BEGIN
    -- zadanie wyslania arkusza styli
    IF nazwa_pliku='style' THEN
        output = output || add_styles();
        RETURN output;
    END IF;
    output = output || '&amp;lt;html&gt;&amp;lt;link rel="stylesheet" href="main.cgi?style"/&gt;&amp;lt;body&gt;' || 
             page_content(nazwa_pliku) ||
             '&amp;lt;/html&gt;&amp;lt;/body&gt;';
    RETURN output;
END;
$$ LANGUAGE 'plpgsql';


-- zraca style, gotowe do wsadzenia w zanaczniki &amp;lt;style&gt; albo do 
-- wpisanie w plik CSS
CREATE OR REPLACE FUNCTION add_styles() RETURNS text AS $$
DECLARE
    DECLARE record RECORD;
    DECLARE subrecord RECORD;
    DECLARE output TEXT DEFAULT '';
BEGIN
    -- petla po wszystkich tagach w arkuszy styli
    FOR record IN SELECT * FROM tag LOOP
        output:= output || record.nazwa || E' {\n'; -- poczatkowa klamerka
        -- petla po wszytkich atrybutach dla tagu
        FOR subrecord IN SELECT nazwa, wartosc FROM atrybut WHERE tag=record.id LOOP
            output:= output || subrecord.nazwa || ':' || subrecord.wartosc ||  E';\n';
        END LOOP;
        output:= output || E'}\n'; -- koncowa klamerka
    END LOOP;
    -- skoro jestesmy tuta to w zmiennej output mamy gotowy plik css 
    RETURN output;
END;
$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION page_content(TEXT) RETURNS text AS $$
DECLARE
    DECLARE output TEXT DEFAULT '';
    klucz ALIAS FOR $1;
    DECLARE r RECORD;
BEGIN
    SELECT INTO r *  FROM strona WHERE nazwa_pliku=klucz;
    IF NOT FOUND THEN
        return 'Podana strona nie istnieje.';
    END IF;
    output = '&amp;lt;h1&gt;tytul: ' || r.tytul || '&amp;lt;/h1&gt;&amp;lt;hr/&gt;tresc: ' || r.tresc;
    RETURN output;
END;
$$ LANGUAGE plpgsql;
&lt;/pre&gt;

&lt;p&gt;Above data is just a dump of my database, it may be fetched by executing bellow formula in command line:&lt;/p&gt;

&lt;pre&gt;plpgsql -U user_name -d databse_name -f name_of_file_with_above_dump&lt;/pre&gt;

&lt;p&gt;Now, when database is ready, we may reset the Apache server (&lt;i&gt;/etc/init.d/apache2 restart&lt;/i&gt;) and add articles by using psql. Results are visible on bellow screen:&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-36lAdvrXmhw/TdFUCx3N3gI/AAAAAAAAAn4/MO8aIQzyScQ/s1600/screen.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 167px;" src="http://4.bp.blogspot.com/-36lAdvrXmhw/TdFUCx3N3gI/AAAAAAAAAn4/MO8aIQzyScQ/s400/screen.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5607355417774382594" /&gt;&lt;/a&gt;

&lt;p&gt;You may download sources (directory &lt;strong&gt;cms_entirely_in_plpgsql&lt;/strong&gt;) by cloning &lt;strong&gt;git@github.com:RobertGawron/snippets.git&lt;/strong&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-1125281602682649962?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/1125281602682649962/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/01/cms-written-entirely-by-using-plpgsql.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/1125281602682649962'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/1125281602682649962'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/01/cms-written-entirely-by-using-plpgsql.html' title='CMS written entirely in PL/pgSQL'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-36lAdvrXmhw/TdFUCx3N3gI/AAAAAAAAAn4/MO8aIQzyScQ/s72-c/screen.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-5395332377894969255</id><published>2011-05-07T06:55:00.000-07:00</published><updated>2011-05-07T07:02:39.511-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Curious version numbers</title><content type='html'>&lt;pre&gt;1.0
1.1
...
1.8
1.9
&lt;b&gt;1.10
1.11&lt;/b&gt;
...
&lt;b&gt;1.19
1.20&lt;/b&gt;
...
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-5395332377894969255?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/5395332377894969255/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/05/curious-version-numbers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/5395332377894969255'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/5395332377894969255'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/05/curious-version-numbers.html' title='Curious version numbers'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-8333531739519552166</id><published>2011-04-25T05:42:00.001-07:00</published><updated>2011-04-25T05:43:59.151-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>[pl] Rabka, moja mała ojczyzna</title><content type='html'>&lt;p&gt;Rabka to dość stare uzdrowisko, otoczone górami, położone ok. 70km od Krakowa
(1.5h drogi) i tyle samo od Zakopanego. To moje rodzime miasteczko.&lt;/p&gt;

&lt;p&gt;Wjeżdżając od jednej strony można zobaczyć jakieś bezkształtne ulice, domki,
uliczki itp. Bez obaw, to nie Rabka, ale wioski leżące obok (Skawa, Chabówka).
Już w samej Rabce również można się pochopnie rozczarować - widok drogi
krzyżowej koło kościoła i pomnika Mikołaja. To są osobiste wizje odpowiednio:
księży i burmistrza.&lt;/p&gt;

&lt;p&gt;Dworzec jest dość mały, prowincjonalny, zaraz obok jest droga do lasu, w
góry. Gdy człowiek się spóźni na busa można, iść do lasu i posiedzieć chwilę w
ciszy. Tak więc ścieżka prowadzi na Banie i Krzywoń. To niskie góry, słoneczne,
z lasami iglastymi, polami, łąkami. Zawsze ktoś tam spaceruje, głównie matki z
dziećmi lub całe rodziny, gdyż jest blisko do miasta. Idąc dalej dochodzi się na
wyciąg narciarski, ponoć dość dobry, z kolei na skraju lasu jest liceum, tam się
uczyłem. Jako, że położone jest na górze widać je z połowy miasta.&lt;/p&gt;

&lt;p&gt;Idąc dalej na prawo Rabkę ogranicza (góra) Maciejową. To tak z 1-1.5h drogi z
centrum, toteż tam chodzą tylko turyści, którzy przyjechali spacerować po
górach. By dojść do lasu, do gór trzeba przejść przez polną drogę wśród traw,
upraw, a jako iż nie ma drzew więc w lecie jest tam strasznie gorąco.&lt;/p&gt;

&lt;p&gt;Po środku miasta jest duży park, taki zwykły. Kiedyś było tam bardzo ładnie,
byli ludzie, którzy opiekowali się kwiatami, fontannami, jednym słowem, to
wszystko było zadbane. Potem to wszystko zaczęło się walić i tak jest już do
dziś, nie tylko z parkiem. W środku parku jest sanatorium, a zaraz obok drugie.
W parku jest też cmentarz żołnierzy radzieckich.&lt;/p&gt;

&lt;p&gt;Obok jest ścieżka zdrowia. Dawniej było tam mnóstwo drzew, rosły maliny,
grzyby i dzikie paprocie. Po słonecznych alejah spacerowało mnóstwo ludzi ale w
drobnych uliczkach, gdzie dzięki drzewom panował lekki mrok wciąż można się
było zgubić.&lt;/p&gt;

&lt;p&gt;Idąc dalej jest rzeka, dość brudna, mimo to ludzie się w niej kąpią w lecie.
Owa rzeka też jest dość ładna i malownicza, zwłaszcza tam, gdzie jej nie
uregulowano. Rzeka płynie przez połowę miasta. Obok niej, w lasku koło
sanatorium kardiologicznego znajdują się resztki bunkrów i umocnień
nazistowskich.&lt;/p&gt;

&lt;p&gt;Idąc wzdłuż rzeki, trafia się na jej odnogę. Wypływa ona z Krzywonia. To
jedna z gór otaczających miasto, lecz mało znana. Jest tam zawsze ciemno,
wilgotnie, cicho, nikt tam nie chodzi. Na samym skraju znajduje się źródełko, z
którego część mieszkańców bierze wodę. Nie chodzi o to, iż nie mamy wody, mamy,
ale ta jest czystsza i ponoć zdrowa. To jedno z najładniejszych miejsc w
mieście.&lt;/p&gt;

&lt;p&gt;Wróćmy jednak do centrum. Wbrew dotychczasowemu opisowi w Rabce jest
cywilizacja. Są licea, a dawniej była też szkoła pielęgniarska. Są supermarkety,
biblioteki, centra prasowe, przystanek kolejowy (na którym nie zatrzmuje się
prawie zaden pociąg).&lt;/p&gt;

&lt;p&gt;Jest wiele osiedli, które trochę szpecą miasto, są po prostu zlepkiem domów i
niczym więcej. Nie tak miało być, jednak po wojnie, gdy miasto zaczęło się
rozwijać masa ludzi (m.in. moi dziadkowie) przyjechała z okolicznych wsi. Z
potrzeby powstały zatem bloki i inne dziwne twory.&lt;/p&gt;

&lt;p&gt;Przede wszystkim Rabka to jednak uzdrowisko. Mamy zatem masę sanatorów,
zorientowanych na różnych chorych (dziecięce, kardiologiczne, astmatyczne, dla
matek z dziećmi, ogólne). Jest bardzo dużo możliwości: masarze, basen, kąpiele,
naświetlania. W Rabce przeprowadza się też dość skomplikowane operacje
chirurgiczne. Kiedyś był tu odział leczący mukowiscydozę, lecz został
zamnknięty.&lt;/p&gt;

&lt;p&gt;Dawniej te sanatoria tętniły życiem, gdy szło się po ulicy ciągle mijało się
grupy sanatoryjne, mnóstwo ludzi utrzymywało się z pracy dla, lub w sanatoriach.
Reforma służby zdrowia położyła temu kres, obecnie wiele z tych sanatorów ledwo
wiąże koniec z końcem a miasto powoli staje się tanią alternatywą dla
Zakopanego. Brak kapitału, brak młodych ludzi.&lt;/p&gt;

&lt;p&gt;Rabka była znana od dawna, ze względu na lecznicze wody źródlane. Budki z
nimi można znaleźć w centrum, niestety są  odgrodzone i zamknięte. Wody nie
wydobywa się, więc główna zaleta miasta pozostaje zamknięta na kłódkę. Wody te
są ponoć najsilniejsze w środkowo-wschodniej Europie.&lt;/p&gt;

&lt;p&gt;Nie ma tu jakiś atrakcji turystycznych. Jest jedynie cisza, spokój i
przyroda. Czasem się słyszy iż to takie podhalańskie Bieszczady, nie ma nic i to
jest właśnie fajne. Ucieczka od miasta.  &lt;/p&gt;

(Rabka 23.04.2007)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-8333531739519552166?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/8333531739519552166/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/04/rabka-moja-maa-ojczyzna.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8333531739519552166'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8333531739519552166'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/04/rabka-moja-maa-ojczyzna.html' title='[pl] Rabka, moja mała ojczyzna'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-8531978577981090512</id><published>2011-04-25T05:26:00.001-07:00</published><updated>2011-04-25T05:26:53.482-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>[pl] Medytacja</title><content type='html'>&lt;p&gt;W codziennym życiu koncentrujemy się na otaczającym nas świecie, gdy jesteśmy
w pracy zajmujemy sie pracą, gdy jedziemy autobusem patrzymy na świat za oknem,
a gdy rozmawiamy z kimś, to słuchamy go i współuczestniczymy w rozmowie. To
normalne zachowanie, dzięki któremu możemy utrzymywać się materialnie, istnieć w
społeczeństwie czy też trafić po pracy do domu. Problem zaczyna się, gdy
zewnętrznych spraw jest za dużo lub gdy boimy się pomyśleć o sobie.&lt;/p&gt;

&lt;p&gt;Gdy brakuje czasu by zastanowić sie nad sobą, by dać sobie chwile
wytchnienia, życie często staje się cięższe, co zaś prowadzi do tego, że jest
gorzej i tym bardziej nie ma się czasu albo chęci by się nad sobą zastanowić.
Błędne koło zamyka się, a efektem jest często rezygnacja, rozgoryczenie, lęki i
depresje.  Czytelnik na pewno spotkał się z ludźmi wiecznie narzekającymi na
świat, na sprawiedliwość i wszytko na co się da narzekać.&lt;/p&gt;

&lt;p&gt;Rzecz jasna wielu ludzi nie medytuje, a są zadowoleni z życia, medytacja nie
jest czymś koniecznym, natomiast jej stosowanie pomaga, chroni przez kłopotami
takimi ,jak lęki, stres, błędne decyzje życiowe. Pasja, hobby i religia również
na swój sposób działa jak medytacja [wg mnie.&lt;/p&gt;

&lt;p&gt;Dzięki medytacji możemy skupić się na nas samych, naszym wnętrzu, odczuciach,
lekach, teraźniejszości i przyszłości. Możemy też skupić się na wielu, wielu
innych rzeczach, wszystkie one jednak mniej lub bardziej dotyczą właśnie nas a
nie otoczenia. To taka chwila osobistej, własnej ciszy.&lt;/p&gt;

&lt;p&gt;Medytacja redukuje stres, zarówno w rozumieniu chwili jak i jako dłuższego
procesu (stres może trwać tygodniami lub miesiącami), reguluje ciśnienie krwi i
tętno (no ok, tak czy owak ciśnienie zależy od tętna). Pozawala bardziej
obiektywnie dostrzec i przemyśleć swoje błędy, daj nam również szansę, by
zrozumieć i pokonać swoje lęki i problemy z przeszłości. Medytacja potrafi
zmienić nasze życie nasze życie nie tylko w kontekście minut czy tygodni ale
również lat, zmienić życie jako całość.  Dodatkowo -mówiąc przyziemnie-
medytacja jest dobra bo jest miła psychicznie i fizycznie&lt;/p&gt;

&lt;p&gt;Jeśli mówimy o medytacji, to musimy wspomnieć o modlitwie. Wielu ludzi uznaje
prawdziwą i szczerą modlitwa jako rodzaj medytacji (to też chyba opinia
Kościoła). By modlitwa przynosiła skutek trzeba umieć się modlić, tzn mowa tu o
jakimś szczerym, konstruktywnym przekazie a nie o klepaniu formułek. Dużo zależy
od tego, czym określa się modlitwę, a to zaś zależy od każdego człowieka z
osobna ale można [wg mnie] uznać iż modlitwa to również czas refleksji nad sobą,
sobą w kontekście otoczenia, nad zachowaniami, czas na wyciągnięcie wniosków i
podjęcie decyzji. Podsumowując, modlitwa jest bliska medytacji.&lt;/p&gt;

&lt;p&gt;Kolejnym pojęciem, które warto omówić jest kontemplacja. Polega ona na
-mówiąc w skrócie- medytacji gdy celowo skupiamy sie na czymś konkretnym, np.
naszym zdrowiem lub kłopotami finansowymi. Kontemplacją może być również
rozmyślanie nad jakimś pojęciem przez cały dzień, wgryzanie się w nie, czyli
praktyka dość daleka od medytacji. Czy kontemplacja i medytacja to to samo? Tu
zdania są podzielone.&lt;/p&gt;

&lt;p&gt;W poście używam określenia 'skupienie się', co może rodzić nieporozumienia, w
końcu medytacja to [też] forma relaksu a skupianie sie to przeciwieństwo
relaksacji? Owszem, chodzi o formę relaksacji, ale to wymaga pewnej wewnętrznej
dyscypliny, samozaparcia, nie wystarczy tylko położyć się i zamknąć oczy na parę
minut. Jeżeli nigdy tego nie próbowaliśmy to nauka medytacji zajmie nam chwilę
(liczoną w dniach lub tygodniach). Właśnie dlatego używałem określenia
'skupianie się' by wyrazić, iż nie jest to całkiem proste na początku.&lt;/p&gt;

&lt;p&gt;Medytacja to punkt wyjściowy wielu praktyk magicznych czy
parapsychologicznych. Jako iż magia i parapsychologia nie są tematem posta nie
rozwiniemy tego wątku.&lt;/p&gt;

&lt;p&gt;Chociaż medytacja jest miła i pożyteczna sama w sobie [tzn bez pracy nad
sobą lub nad/z otoczeniem] nie rozwiąże poważnych problemów życiowych. Chociaż
nic nie zastąpi osobistej pracy i wysiłku, to dzięki medytacji można ujrzeć
wiele rzeczy z innej perspektywy co może zaoszczędzić wysiłku lub wskazać rzeczy
i czynności złe/zbędne.&lt;/p&gt;

&lt;p&gt;Jako iż temat medytacji jest obecny  w róznej formie na całym świecie od
wieków [jeśli nie od początku istnienia człowieka], to wiedza o niej jest
rozrosła się a i technik jest dużo. Nie musimy stosować wszystkich - wystarczy
jedna czy dwie, np. te, które omówimy dalej.&lt;/p&gt;

&lt;p&gt;Jak często medytować? Jedna z koncepcji mówi, iż po pewnym czasie cały dzień
jest niekończącą sie medytacją (podoba mi sie, no ale ok, dość ciężkie).
Niektórzy mówią, że wystarczy 1h rano i 1h wieczorem a jeszcze inni, iż
powinniśmy ćwiczyć, kiedy mamy ochotę, nie zmuszając się do niczego, wsłuchując
sie w siebie kiedy, w to, jak długo chcemy. Niestety ostatnie podejście może się
skończyć tym iż zarzucimy to w ogóle lub będziemy medytować raz na 2-3 tygodnie
po 30s.&lt;/p&gt;

&lt;p&gt;Czas przejść do opisu technik, omówmy zatem pierwszą, chyba najbardziej
popularną metodę czyli medytację z oddechem. Siadamy po turecku lub kładziemy
sie na czymś płaskim (koc lub łóżko bez poduszki), z rękami wzdłuż tułowia i
wyprostowanymi nogami. Gdy opanujemy tą medytacje możemy ćwiczyć gdziekolwiek, w
dowolnej pozycji, jednak te dwie są najlepsze na początek. Zamykamy oczy. W
pokoju powinno być cicho, nikt nie powinien nam przeszkadzać, najlepszą porą
jest ranek lub wieczór. Wciągamy powietrze nosem a wydychamy ustami. Nie robimy
tego robić specjalnie, po prostu tak jak chce tego organizm. Odprężamy się,
powoli zapominamy o otaczającym nas świecie, o tym gdzie jesteśmy, o bieżących
sprawach, po pewnym czasie oddech zwalnia i stajemy się zrelaksowani. Myśli
stają się coraz rzadsze, a otaczająca nas rzeczywistość coraz bardziej traci
znaczenie. Wciąż jeśli myślimy, to o oddechu. Tak powinniśmy wytrzymać na
początku kilkadziesiąt sekund, a po kilku dniach kilka minut.&lt;/p&gt; 

&lt;p&gt;Kolejną techniką jest medytacja nad płomieniem świecy. Tu sytuacja jest
podobna, z tym, że nie zamykamy oczu, tylko patrzymy cały czas na płomień
świecy. Trzeba uważać by nie spowodować pożaru, świeca powinna stać na talerzyku
lub na świeczniku. Kolor świecy symbolizuje różne wartości, są to m.in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;czerwony - bezpieczeństwo materialne&lt;/li&gt;
&lt;li&gt;zielony - zdrowie, energia życiowa&lt;/li&gt;
&lt;li&gt;żółty - intelekt&lt;/li&gt;
&lt;li&gt;niebieski - duchowość&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Interpretacji kolorów jest bardzo dużo, część z nich jest sprzeczna z w/w.
Kiedyś opiszę jak wykonać samodzielnie świece, to nie jest trudne ani drogie a
satysfakcja jest duża.&lt;/p&gt;

&lt;p&gt;Modyfikacją w/w metody jest medytacja nad punktem. Jako, że nie patrzymy na
płomień, a w punkt, możemy ćwiczyć wszędzie. Ponoć gdy opanuje się tą metodę,
można wpatrywać się w punkt przez kilka godzin nie czując żadnego napięcia.&lt;/p&gt;

&lt;p&gt;Zamiast skupiać się na oddechu można skupić sie na liczeniu, np zaczynając od
wyobrażenia sobie liczby 100 powoli zmniejszając ją, aż do liczby 1. Z czasem
relaksacja postępować będzie coraz szybciej i można zacząć od np 50 czy 20. Gdy
już dojdziemy do 1 nie musimy kończyć, możemy postać w takim stanie medytacji i
rozluźnienia tak długo, jak chcemy.&lt;/p&gt;

&lt;p&gt;Medytując można również skupić się na zmyśle, np. słuchu - staramy sie
w ogóle nie myśleć, nie odbierać informacji z innych zmysłów tylko dać się
ponieść temu jednemu, wybranemu. Nie analizujemy tego co odbieramy tym zmysłem a
skupiamy sie na nim, jak dziecko, które nie rozumie ale jest czymś
zaintrygowane.&lt;/p&gt;

&lt;p&gt;Dzięki medytacji można skrócić czas poświęcany na sen. Po prostu wstaje się
wcześniej i jest się bardziej wypoczętym. Chociaż medytacja ma pozytywny wpływ
na zdrowie to jednak jeżeli jest się chorym to oczywiście nie może zastąpić
wizyty u lekarza.&lt;/p&gt;
 
&lt;p&gt;Na koniec, wspomnijmy czym jest medytacja z materialnego punktu widzenia.
Umysł [akurat to potwierdzili naukowcy, więc jakkolwiek by to nie brzmiało jest
zgodne z medycyną akademicką] pracuje na kilku poziomach, normalnie, czyli np.
teraz  jesteśmy w stanie beta natomiast gdy śpimy w stanie alfa. Medytacja
wprowadza umysł w stan alfa, czyli taki jak w czasie snu pozwalając ciału
zrelaksować się.&lt;/p&gt;

(Rabka 02.11.2007)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-8531978577981090512?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/8531978577981090512/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/04/pl-medytacja.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8531978577981090512'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8531978577981090512'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/04/pl-medytacja.html' title='[pl] Medytacja'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-6107242962567249898</id><published>2011-04-25T04:51:00.000-07:00</published><updated>2011-04-25T04:54:01.807-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='life'/><title type='text'>[pl] Karetka</title><content type='html'>&lt;p&gt;Wczoraj, gdy jechałem busem obok przejechała karetka. Niby nic i większość ludzi nawet by  nie zauważyła.&lt;/p&gt;

&lt;p&gt;Ja zawsze jednak zwracam na to uwagę, widok takiej karetki to nic innego jak znak, iż ktoś dziś będzie płakał, ktoś wróci do domu i będzie sam a ktoś zadzwoni do reszty rodziny i powie co się stało.&lt;/p&gt;

&lt;p&gt;Racja, ludzie umierają codziennie i mnie to mnie zupełnie nie obchodzi. Nie znam ich, jednak tu, taki widok karetki sprawia iż na chwilę są mi bliscy. Gdy wierzyłem w boga katolików to modliłem się w takich sytuacjach przez (krótką) chwilę.&lt;/p&gt;

&lt;p&gt;Może i moja reakcja na widok karetek jest dziwna ale przynajmniej szczera. A propos szczerości i śmierci, strasznie drażnią mnie żałoby narodowe, relacje z wypadków itp. Co mają powiedzieć rodziny osób które odeszły anonimowo, o których nikt nie mówił w mediach. Rodziny którym nikt nie wysyłał pieniędzy, rodziny, którym w dzisiejszym anonimowym świecie nikt nie współczuł.&lt;/p&gt;

&lt;p&gt;Gdy jakieś pół roku temu była eksplozja w kopalni na początku na wszystkich forach portali (Interia, WP, Onet) zapanowały, łzawe i bezmyślne posty. Nikt nie przejmował się że w tym samym momencie ktoś tam umiera np. na raka, ze ktoś chce skończyć z życiem.&lt;/p&gt;

&lt;p&gt;Nastała żałoba narodowa i zamknięto dyskoteki, odwołano imprezy masowe...&lt;/p&gt;

&lt;p&gt;Wtedy z dna na dzień ludzie przestali wypisywać jak to są zrozpaczeni tragedią. Wtedy okazało się iż te imprezy powinny być, iż ludzie którzy to pisali jak jednoczą się z rodzinami i znajomymi ofiar nie chcą tego pokazać czynami rezygnując z zabaw.&lt;/p&gt;

&lt;p&gt;Nienawidzę ludzkiej obłudy i uczuć na pokaz.&lt;/p&gt;

(Kraków 2007.09.05)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-6107242962567249898?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/6107242962567249898/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/04/pl-karetka.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/6107242962567249898'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/6107242962567249898'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/04/pl-karetka.html' title='[pl] Karetka'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-7473003637225364092</id><published>2011-04-24T12:17:00.000-07:00</published><updated>2011-06-04T05:42:34.958-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Parse assembler by using Finite State Machine?</title><content type='html'>&lt;h3&gt;Finite State Machine - abstract&lt;/h3&gt;

&lt;p&gt;Often data must be analyzed chunk by chunk, checked if all of those chunks
are valid (if this chunk is valid and if it's valid in context of previous
chunks) and when some actions must be taken according to each type of this
chunks. This can be easily modeled using finite-state machines (FSM).&lt;/p&gt;

&lt;p&gt;Sate Machine has its state and transitions. There is at least one entry
state, there may be termination state. &lt;/p&gt;

&lt;p&gt;One task can be done by using different FSMs but of course we should create
them as simple as possible. What is nice in those tools, is that they may be
easily extended. You may add new states, transitions, split existing state into
new ones or nest new FSM into existing state.&lt;/p&gt;

&lt;p&gt;Title of this post may confusing to people looking for concepts to build
their own compilers or parsers. Shortly, reading them requires parsing code on
three levels: lexical, syntactical and semantical, but presented FSMs may be
directly applied only in the first case.&lt;/p&gt;

&lt;p&gt;In next posts we will explain closer this assembly language and show, how
to made its virtual machine,where FSM will be used as a part of it.&lt;/p&gt;

&lt;h3&gt;Finite-State Machine used to parsing code&lt;/h3&gt;

&lt;p&gt;Bellow is an example of assembly language, that we are going to parse. Each
line contains zero or more words like numbers, labels, names of mnemonics or
comments, that are separated by whitespaces.&lt;/p&gt;

&lt;p&gt;What each of those parts means and how to execute them isn't the case here,
we will focus on splitting them, line by line and remove pointless whitespaces
and comments.&lt;/p&gt;

&lt;pre&gt;main:
    int 1
    call square
    int 0
ret

square:
    store 0
    load 0
    load 0
    mul
    load 0
    mul
ret&lt;/pre&gt;

&lt;p&gt;Bellow are given severals notes, that characterise our language:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;comment starts from &lt;strong&gt;;&lt;/strong&gt; sign and ends at the end of the line,&lt;/li&gt;
    &lt;li&gt;mnemonic may be indented by using either \t or any amount of spaces,&lt;/li&gt;
    &lt;li&gt;allowed characters in mnemonics/labels are [0-9a-z:],&lt;/li&gt;
    &lt;li&gt;mnemonic can't have more, that one parameter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this knowledge we may design following FSM:&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-1mGT6vqsNk4/TbR2kXTiH1I/AAAAAAAAAnw/FbyhHvPXRpE/s1600/fsm_diagram.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 315px;" src="http://2.bp.blogspot.com/-1mGT6vqsNk4/TbR2kXTiH1I/AAAAAAAAAnw/FbyhHvPXRpE/s400/fsm_diagram.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5599230603831680850" /&gt;&lt;/a&gt;

&lt;p&gt;Finally, here's the full code of its Finite-State Machine and example of
output from parsing given previous assembly source.&lt;/p&gt;

&lt;pre&gt;
#!/usr/bin/env python
import sys, re

class FiniteStateMachine:
    def get_instruction_parts(self, instruction):
        &amp;quot;&amp;quot;&amp;quot;states: 0 - init, 1 - token, 2 - separator, 3 - end&amp;quot;&amp;quot;&amp;quot;
        state, acumulator, bufer = 0, [], ''
        for character in instruction + '\0':
            # init
            if state == 0:
                 # init -&amp;gt; token (append)
                if re.compile(r&amp;quot;[0-9a-z]&amp;quot;).match(character):
                    bufer += character
                    state = 1 
                # init -&amp;gt; separator (skip)
                elif character in [' ']:
                    state = 2
                # init -&amp;gt; end (append)
                elif character in [';', '\0']:
                    state = 3
                else:
                    print &amp;quot;error, to transition from init state (%c)&amp;quot; % character

            # token
            elif state == 1:
                # token -&amp;gt; token (append)
                if re.compile(r&amp;quot;[0-9a-z.:]&amp;quot;).match(character):
                    bufer += character
                    state = 1 
                # token -&amp;gt; separator (skip)
                elif character == ' ':
                    acumulator.append(bufer)
                    bufer = ''
                    state = 2
                # token -&amp;gt; end (append)
                elif character in [';', '\0']:
                    acumulator.append(bufer)
                    state = 3
                else:
                    print &amp;quot;error, to transition from token state (%c)&amp;quot; % character

            # separator
            elif state == 2:
                 # separator -&amp;gt; token (append)
                if re.compile(r&amp;quot;[0-9a-z]&amp;quot;).match(character):
                    bufer += character
                    state = 1 
                # separator -&amp;gt; separator (skip)
                elif character  == ' ':
                    state = 2
                # separator -&amp;gt; end (append)
                elif character in [';', '\0']:
                    state = 3
                else:
                    print &amp;quot;error, to transition from eparator state (%c)&amp;quot; % character

            # end 
            elif state == 3:
                pass
 
        return acumulator


if __name__==&amp;quot;__main__&amp;quot;:
    fsm = FiniteStateMachine()
    for line in open(sys.argv[1], 'r').read().splitlines():
        print fsm.get_instruction_parts(line)
&lt;/pre&gt;

&lt;pre&gt;
bash-3.2$ python instructiondecoder.py cube.asm 
['main:']
['int', '1']
['call', 'square']
['int', '0']
['ret']
[]
['square:']
['store', '0']
['load', '0']
['load', '0']
['mul']
['load', '0']
['mul']
['ret']
&lt;/pre&gt;

&lt;h3&gt;Conclusions&lt;/h3&gt;

&lt;p&gt;One can ask, why create FSM and not use functions like &lt;i&gt;split()&lt;/i&gt;,
&lt;i&gt;join()&lt;/i&gt; and &lt;i&gt;replace()&lt;/i&gt; instead? The major benefit is ability to
extend one created FSM. It can be also easily presented by using its diagrams.
As example, mentioned code may be easily extended to deal with C-like strings
(marked by " sign, where " sign may be also masked in the body of string).&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-7473003637225364092?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/7473003637225364092/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/04/finite-state-machine-for-parsing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/7473003637225364092'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/7473003637225364092'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/04/finite-state-machine-for-parsing.html' title='Parse assembler by using Finite State Machine?'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-1mGT6vqsNk4/TbR2kXTiH1I/AAAAAAAAAnw/FbyhHvPXRpE/s72-c/fsm_diagram.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-7630003680515083406</id><published>2011-04-24T06:14:00.000-07:00</published><updated>2011-05-03T04:27:06.545-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='riddle'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='R'/><title type='text'>Size of files packed multiple times</title><content type='html'>&lt;p&gt;What happend when you pack packed file? What if you do that again and again? Size of new archives will be bigger, the same or smaller?  I checked this for some popular filetypes, bellow are results and description, how to check this by using simple bash script and R language.&lt;/p&gt; 

&lt;p&gt;In bellow charts first bars show initial file size, next ones shows size of zip file in next iterations.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-Kr9TBgINhNY/TbQx641_nFI/AAAAAAAAAno/nnFGXRJqNcg/s1600/chart%2BWide_Field_and_Planetary_Camera.htm.log%2B.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 286px; height: 400px;" src="http://1.bp.blogspot.com/-Kr9TBgINhNY/TbQx641_nFI/AAAAAAAAAno/nnFGXRJqNcg/s400/chart%2BWide_Field_and_Planetary_Camera.htm.log%2B.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5599155124489395282" /&gt;&lt;/a&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-THxzhfzH414/TbQx6m3N6WI/AAAAAAAAAng/uvu0a5heqXQ/s1600/chart%2Bcleaning_silver_jewelery.JPG.log%2B.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 286px; height: 400px;" src="http://2.bp.blogspot.com/-THxzhfzH414/TbQx6m3N6WI/AAAAAAAAAng/uvu0a5heqXQ/s400/chart%2Bcleaning_silver_jewelery.JPG.log%2B.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5599155119662688610" /&gt;&lt;/a&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-z0w2IYgEigE/TbQx6Iuh96I/AAAAAAAAAnY/fGbZTSK98gM/s1600/chart%2Bempty.log%2B.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 286px; height: 400px;" src="http://4.bp.blogspot.com/-z0w2IYgEigE/TbQx6Iuh96I/AAAAAAAAAnY/fGbZTSK98gM/s400/chart%2Bempty.log%2B.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5599155111573190562" /&gt;&lt;/a&gt;

&lt;p&gt;Bellow is example, how to use mentioned scripts, first I used bash script to mesure changes in each packing, this script produce list of numbers, each one is size of file (in bytes) in current iteration. Then I used R to parse this data and create chart.&lt;/p&gt;

&lt;pre&gt;bash-3.2$ ./ziper.sh cleaning_silver_jewelery.JPG 20 &amp;gt; cleaning_silver_jewelery.JPG.log
bash-3.2$ Rscript chart.r &amp;quot;cleaning_silver_jewelery.JPG.log&amp;quot; &amp;quot;JPG file&amp;quot;
Read 22 items
bash-3.2$&lt;/pre&gt;

&lt;p&gt;Content of ziper.sh&lt;/p&gt;

&lt;pre&gt;#!/bin/bash
## $1 stores filename of compressed file
## $2 stores number of iterations

if [ ! $# -eq 2 ] ; then
    echo &amp;quot;usage: $0 file_name number_of_iterations&amp;quot;
    exit 1
elif [ ! -f $1 ]; then
    echo &amp;quot;$1 - file does not exists&amp;quot;
    exit 1
else
    ls -l $1 | awk '{ print $5 }' 
    zip -q test_$1_0.zip $1 &amp;amp;&amp;amp; ls -l test_$1_0.zip | awk '{ print $5 }' 
    for (( i=1; i&amp;lt;=$2; i++ )); do
        zip -q test_$1_$i.zip test_$1_$((i-1)).zip &amp;amp;&amp;amp; ls -l test_$1_$i.zip | awk '{ print $5 }'
    done
    rm test*zip
fi
&lt;/pre&gt; 

&lt;p&gt;Content of chart.r&lt;/p&gt;

&lt;pre&gt;args &amp;lt;- commandArgs(TRUE)
sizes &amp;lt;- scan(args[1])
image_name &amp;lt;- paste( &amp;quot;./chart&amp;quot;, args[1], &amp;quot;.png&amp;quot;)

png(filename=image_name, height=700, width=500, bg=&amp;quot;white&amp;quot;)

barplot(sizes, main=args[2], xlab=&amp;quot;iterations&amp;quot;,
    ylab=&amp;quot;size of zip archive [bytes]&amp;quot;, xpd=F, col=&amp;quot;black&amp;quot;,
    ylim=c(min(sizes), max(sizes)))

axis(2, at=c(min(sizes), max(sizes)))&lt;/pre&gt;

&lt;p&gt;They say, that if you type "Google" into Google browser, you will blow up the Internet, fortunately presented in tis post experiment is more safety :]&lt;/p&gt;


&lt;p&gt;You may download sources (directory &lt;strong&gt;ziper&lt;/strong&gt;) by cloning &lt;strong&gt;git@github.com:RobertGawron/snippets.git&lt;/strong&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-7630003680515083406?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/7630003680515083406/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/04/size-of-files-packed-multiple-times.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/7630003680515083406'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/7630003680515083406'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/04/size-of-files-packed-multiple-times.html' title='Size of files packed multiple times'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-Kr9TBgINhNY/TbQx641_nFI/AAAAAAAAAno/nnFGXRJqNcg/s72-c/chart%2BWide_Field_and_Planetary_Camera.htm.log%2B.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-7786014464031534455</id><published>2011-04-23T06:52:00.000-07:00</published><updated>2011-04-23T06:52:07.041-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='electronic'/><title type='text'>Regular diode used as a photo-element</title><content type='html'>&lt;p&gt;There are special diodes, that are designed to measure light intensity, also regular LED can be used for this, but I was wondering, if any diode is suitable here? In this post I will share results of those experiments.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-Juc6HzhiwBo/TbLIru7g_xI/AAAAAAAAAlc/W9gYoCRH_K4/s1600/assembled%2Bsensor%2B1.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 286px;" src="http://3.bp.blogspot.com/-Juc6HzhiwBo/TbLIru7g_xI/AAAAAAAAAlc/W9gYoCRH_K4/s320/assembled%2Bsensor%2B1.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5598757940432535314" /&gt;&lt;/a&gt;

&lt;p&gt;Theoretical background of this is well described in Wikipedia: "A photodiode is a PN junction or PIN structure. When a photon of sufficient energy strikes the diode, it excites an electron, thereby creating a free electron (and a positively charged electron hole). This mechanism is also known as the photoelectric effect. [...] Since transistors and ICs are made of semiconductors, and contain P-N junctions, almost every active component is potentially a photodiode." &lt;a href="http://en.wikipedia.org/wiki/Photodiode"&gt;[source]&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;P-N junction needs to be exposed to light, so we will need diodes in glass bulb, like popular 1n148, Bellow are examples of regular diodes, that can be used to measure light intensity. Pictures were captured by &lt;a href="http://shoorick.org.ua/index_en.html"&gt;Shoorick&lt;/a&gt;, thanks!.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-i6BuyJeBhFo/TbLMjasBMOI/AAAAAAAAAmU/Q2nKJPfC5wY/s1600/d8.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 244px;" src="http://3.bp.blogspot.com/-i6BuyJeBhFo/TbLMjasBMOI/AAAAAAAAAmU/Q2nKJPfC5wY/s320/d8.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5598762195606384866" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-jiOa49J1gWo/TbLMjHj3U8I/AAAAAAAAAmM/ziKE1B0vi30/s1600/d5.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 167px;" src="http://4.bp.blogspot.com/-jiOa49J1gWo/TbLMjHj3U8I/AAAAAAAAAmM/ziKE1B0vi30/s320/d5.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5598762190471910338" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-JHH9ahu4-NY/TbLMixn0_oI/AAAAAAAAAmE/mFkSvHpaHu0/s1600/d1.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 173px;" src="http://4.bp.blogspot.com/-JHH9ahu4-NY/TbLMixn0_oI/AAAAAAAAAmE/mFkSvHpaHu0/s320/d1.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5598762184582954626" /&gt;&lt;/a&gt;

&lt;p&gt;I used bellow circuit, where diode works as an element, that changes its resistance accordingly to intensity of light, that comes to it. This signal has small amplitude, so I used &lt;a href="http://en.wikipedia.org/wiki/Darlington_transistor"&gt;Darlington pair&lt;/a&gt; to gain it into the level, that may be easily measured. Additional capacitor filters noises.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-mUzS8Xro0aE/TbLIsSuQAhI/AAAAAAAAAls/KI0M2KqT4-c/s1600/diagram%2Bof%2Busage%2Bregular%2Bdiode%2Bas%2Ba%2Blight%2Bsensor.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 222px;" src="http://2.bp.blogspot.com/-mUzS8Xro0aE/TbLIsSuQAhI/AAAAAAAAAls/KI0M2KqT4-c/s320/diagram%2Bof%2Busage%2Bregular%2Bdiode%2Bas%2Ba%2Blight%2Bsensor.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5598757950040572434" /&gt;&lt;/a&gt;

&lt;table&gt;
&lt;tr&gt;
      &lt;td&gt;D1&lt;/td&gt;&lt;td&gt;1n148 or see text&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
      &lt;td&gt;T1, T2&lt;/td&gt;&lt;td&gt;BC548 or similar&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
      &lt;td&gt;C1&lt;/td&gt;&lt;td&gt;680n&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
      &lt;td&gt;R1&lt;/td&gt;&lt;td&gt;2M&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;Above circuit is quite popular, it works with LEDs, photo-diodes and photo-resistors. One could modify it to obtain better stability by changing Darlington to operation amplifier and then, by replacing single diode with bridge (diode + resistor, where one diode would be exposed to light, and second would be protected from light by paint or similar substance).&lt;/p&gt;

&lt;p&gt;Bellow are pictures of assembled circuit. Unfortunately I don't know, how to measure diode characteristic in it, because it would be related to spectrum of used light source. It would be the best to have a couple of light sources that emit light with the same light intensity, but in different, short light spectrum. It becomes quite complicated to check this at home. Note, that lightbulb on second picture is turn on, on third is turn off.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-cBU7cQOEScM/TbLIsDEGsCI/AAAAAAAAAlk/_e8EotTlf2s/s1600/assembled%2Bsensor%2B2.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 235px;" src="http://3.bp.blogspot.com/-cBU7cQOEScM/TbLIsDEGsCI/AAAAAAAAAlk/_e8EotTlf2s/s320/assembled%2Bsensor%2B2.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5598757945837269026" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-O6pLaUYDJx8/TbLIslHBzVI/AAAAAAAAAl8/dYlyXL2lqzo/s1600/diode%2Blight%2Bsensor%2Bin%2Blight.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://4.bp.blogspot.com/-O6pLaUYDJx8/TbLIslHBzVI/AAAAAAAAAl8/dYlyXL2lqzo/s320/diode%2Blight%2Bsensor%2Bin%2Blight.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5598757954976337234" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-luVkgfgw3Po/TbLIsdSGvbI/AAAAAAAAAl0/rp5a7OldRwM/s1600/diode%2Blight%2Bsensor%2Bin%2Bdark.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://4.bp.blogspot.com/-luVkgfgw3Po/TbLIsdSGvbI/AAAAAAAAAl0/rp5a7OldRwM/s320/diode%2Blight%2Bsensor%2Bin%2Bdark.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5598757952875314610" /&gt;&lt;/a&gt;

&lt;p&gt;It was quite interesting experiment to check it, if you have ideas about it, please share them!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-7786014464031534455?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/7786014464031534455/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/04/regular-diode-used-as-photo-element.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/7786014464031534455'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/7786014464031534455'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/04/regular-diode-used-as-photo-element.html' title='Regular diode used as a photo-element'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-Juc6HzhiwBo/TbLIru7g_xI/AAAAAAAAAlc/W9gYoCRH_K4/s72-c/assembled%2Bsensor%2B1.jpg' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-7603860112463115519</id><published>2011-04-17T09:46:00.000-07:00</published><updated>2011-06-04T04:11:08.987-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='chemistry'/><title type='text'>Clean silver with aluminum foil and salt water</title><content type='html'>&lt;p&gt;There's a simple and useful way to dissolve stains from &lt;strong&gt;silver jewelry&lt;/strong&gt; by using water, salt and aluminum foul and couple of other, popular products. Bellow it's described in details, how to do this cleaning.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;dish washing liquid&lt;/strong&gt; and &lt;strong&gt;toothbrush&lt;/strong&gt; to clean jewelry from sweat and dirt.&lt;/li&gt;
&lt;li&gt;Take a glass of &lt;strong&gt;hot water&lt;/strong&gt; and dissolve a spoon of &lt;strong&gt;kitchen salt&lt;/strong&gt; in it.&lt;/li&gt;
&lt;li&gt;Put &lt;strong&gt;aluminum foil&lt;/strong&gt; into the water and on top of it put your silver jewelry.&lt;/li&gt;
&lt;li&gt;Wait 30minutes, then clean silver under current water and let it dry.&lt;/p&gt;
&lt;/ul&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-FVJvfPd410I/TadQf-B-AfI/AAAAAAAAAlU/kaeKAak1EBs/s1600/cleaning_silver_jewelery.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://3.bp.blogspot.com/-FVJvfPd410I/TadQf-B-AfI/AAAAAAAAAlU/kaeKAak1EBs/s320/cleaning_silver_jewelery.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5595529572188553714" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-7603860112463115519?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/7603860112463115519/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/04/cleaning-silver-with-aluminum-foil-and.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/7603860112463115519'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/7603860112463115519'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/04/cleaning-silver-with-aluminum-foil-and.html' title='Clean silver with aluminum foil and salt water'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-FVJvfPd410I/TadQf-B-AfI/AAAAAAAAAlU/kaeKAak1EBs/s72-c/cleaning_silver_jewelery.JPG' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-878919258992352449</id><published>2011-04-10T11:52:00.000-07:00</published><updated>2011-04-10T12:03:26.442-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='crappy code'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>Checking if null</title><content type='html'>&lt;p&gt;This is a bit modified real word example, found by tool for static analysis. In this code, &lt;i&gt;foo()&lt;/i&gt; is a function, that returns pointer to std::string or null pointer.&lt;/p&gt;

&lt;pre&gt;std::cout &amp;lt;&amp;lt; foo()-&amp;gt;length() &amp;lt;&amp;lt; std::endl;&lt;/pre&gt;

&lt;p&gt;There is obvious bug here: executing length() method on value returned by &lt;i&gt;foo()&lt;/i&gt; without checking if this variable is not null. At first it looks, that it could be fixed in bellow way:&lt;/p&gt;

&lt;pre&gt;if (foo()) {
    std::cout &amp;lt;&amp;lt; foo()-&amp;gt;length() &amp;lt;&amp;lt; std::endl;
}&lt;/pre&gt;

&lt;p&gt; Unfortunately above code is also invalid, because it can't be sure, that if function once returned not null value, then it will returns it next time. This may be fixed in bellow way, where temporary variable was used to check if &lt;i&gt;length()&lt;/i&gt; may be executed on variable retured by &lt;i&gt;foo()&lt;/i&gt;.&lt;/p&gt;

&lt;pre&gt;std::string* fooObj = foo();
if (fooObj) {
    std::cout &amp;lt;&amp;lt; fooObj-&amp;gt;length() &amp;lt;&amp;lt; std::endl;
}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-878919258992352449?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/878919258992352449/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/04/checking-if-null.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/878919258992352449'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/878919258992352449'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/04/checking-if-null.html' title='Checking if null'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-9155991421448491324</id><published>2011-04-09T07:30:00.000-07:00</published><updated>2011-04-09T07:34:04.099-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='electronic'/><title type='text'>Home made pressure sensor</title><content type='html'>&lt;p&gt;Pressure sensor is an element that changes its parameters according to
changes of pressure, that is put on it. Today I will present how to build it by
using common and cheap materials like chewing gum and pencil.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-xiscnGcKxsY/TaBfzSOQs_I/AAAAAAAAAk0/rgVtCDmoUgY/s1600/no_presure.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 308px;" src="http://4.bp.blogspot.com/-xiscnGcKxsY/TaBfzSOQs_I/AAAAAAAAAk0/rgVtCDmoUgY/s320/no_presure.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5593576071863776242" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-rUjmQv2ueM4/TaBfzjSA1sI/AAAAAAAAAk8/7qjIipqfhbs/s1600/with_presure.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 316px;" src="http://1.bp.blogspot.com/-rUjmQv2ueM4/TaBfzjSA1sI/AAAAAAAAAk8/7qjIipqfhbs/s320/with_presure.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5593576076442916546" /&gt;&lt;/a&gt;

&lt;p&gt;In my implementation when pressure increases, then electrical resistance of sensor decreases. Main part is elastic conductor, that is in between of two electrodes connected to multimeter, that indicates resistance between them. Minor role plays here elastic rubber around of conductor - it helps bring element to its original shape.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-pWSINAqThhs/TaBsf7wdrWI/AAAAAAAAAlM/SDOKgfHdQX8/s1600/diagram.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 207px;" src="http://3.bp.blogspot.com/-pWSINAqThhs/TaBsf7wdrWI/AAAAAAAAAlM/SDOKgfHdQX8/s320/diagram.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5593590033066863970" /&gt;&lt;/a&gt;

&lt;p&gt;Mentioned element contains a lot of small conducting parts. When pressure increases, those elements are closer to each other, so the overall resistance of element is decreasing. When pressure goes down, element returns to its original shape and resistance.&lt;/p&gt;

&lt;p&gt;I made experiments with two conducting elements. First was silicon glue
mixed with graphite powder made from crunched pencil fill. Bellow is picture of paste made from silicon glue and graphite.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-hXU2VxWydYU/TZ4n4RYiPzI/AAAAAAAAAj8/26LY9O-5FvM/s1600/blend.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 318px;" src="http://4.bp.blogspot.com/-hXU2VxWydYU/TZ4n4RYiPzI/AAAAAAAAAj8/26LY9O-5FvM/s320/blend.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5592951634933202738" /&gt;&lt;/a&gt;

&lt;p&gt;Second attempt was also with graphite powder, but instead of silicon glue I used chewing gum. Bellow is picture of paste made from chewing gum and graphite.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-dGrxI53U7fc/TaBeYf3-lAI/AAAAAAAAAks/9msNBWPk9i8/s1600/elastic_material.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 320px;" src="http://2.bp.blogspot.com/-dGrxI53U7fc/TaBeYf3-lAI/AAAAAAAAAks/9msNBWPk9i8/s320/elastic_material.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5593574512160314370" /&gt;&lt;/a&gt;

&lt;p&gt;Bellow are couple of pictures of sensor assembled with silicon glue. Its resistance was in range 600-700 Ohms.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-A5IJeu1qrl0/TZ4n5CVc39I/AAAAAAAAAkM/UBXZnMkZQH0/s1600/upper-right-view.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 230px;" src="http://1.bp.blogspot.com/-A5IJeu1qrl0/TZ4n5CVc39I/AAAAAAAAAkM/UBXZnMkZQH0/s320/upper-right-view.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5592951648073605074" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-82q-np2qAH0/TZ4n5XQYakI/AAAAAAAAAkU/x5rkgj67jJ8/s1600/upper-view.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 303px; height: 320px;" src="http://2.bp.blogspot.com/-82q-np2qAH0/TZ4n5XQYakI/AAAAAAAAAkU/x5rkgj67jJ8/s320/upper-view.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5592951653689485890" /&gt;&lt;/a&gt;

&lt;p&gt;Here are pictures of sensor with chewing gum, its resistance was it range 600-900 Ohms.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-3Jesg0P55e0/TaBow0KuQcI/AAAAAAAAAlE/oUlmq6LUkfA/s1600/sensor_with_chewing_gum_before_assembly.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 266px;" src="http://4.bp.blogspot.com/-3Jesg0P55e0/TaBow0KuQcI/AAAAAAAAAlE/oUlmq6LUkfA/s320/sensor_with_chewing_gum_before_assembly.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5593585925040783810" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-SQJMBW6ImGw/TZ4pxSENYnI/AAAAAAAAAkc/e6z6bAN5J4s/s1600/assembled_pressure_sensor.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 188px;" src="http://3.bp.blogspot.com/-SQJMBW6ImGw/TZ4pxSENYnI/AAAAAAAAAkc/e6z6bAN5J4s/s320/assembled_pressure_sensor.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5592953713880556146" /&gt;&lt;/a&gt;


&lt;p&gt;If you would like to made this by yourself, please remember, that its parameters will vary according to shape of electrodes, size of used conducting element and its materials. Those parameters will also probably change with time.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-9155991421448491324?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/9155991421448491324/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/04/home-made-pressure-sensor.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/9155991421448491324'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/9155991421448491324'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/04/home-made-pressure-sensor.html' title='Home made pressure sensor'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-xiscnGcKxsY/TaBfzSOQs_I/AAAAAAAAAk0/rgVtCDmoUgY/s72-c/no_presure.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-1385474197288403980</id><published>2011-03-22T06:58:00.000-07:00</published><updated>2011-06-04T04:00:59.655-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='electronic'/><title type='text'>Home made computer microphone</title><content type='html'>&lt;p&gt;All you need is a bunch of popular electronic elements and knowledge how to solder, to made at home a &lt;strong&gt;simple computer microphone&lt;/strong&gt;.&lt;/p&gt;

&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-BP44aELr7M4/TYipzNiI-jI/AAAAAAAAAiA/FWOnyH4FbuQ/s1600/microphone_1.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="248" width="320" src="http://3.bp.blogspot.com/-BP44aELr7M4/TYipzNiI-jI/AAAAAAAAAiA/FWOnyH4FbuQ/s320/microphone_1.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;You may listen a sample track recorded by this my microphone.&lt;/p&gt;

&lt;center&gt;&lt;script type="text/javascript" src="http://www.wrzuta.pl/embed_audio.js?key=0tSJnjX2hGv&amp;login=rgawron&amp;width=450&amp;bg=ffffff"&gt;&lt;/script&gt;&lt;/center&gt;

&lt;p&gt;Used electret microphones need simple electronic device to make them work. In this configuration, R1 polarises microphone, C1 removes noises from power line, C2 isolates sound card from constant current in our circuit.&lt;/p&gt;

&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-Mk9Xsdp013c/TYip5iw4uwI/AAAAAAAAAio/DaXUHz2vv4Q/s1600/microphone_circuit.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="298" width="320" src="http://1.bp.blogspot.com/-Mk9Xsdp013c/TYip5iw4uwI/AAAAAAAAAio/DaXUHz2vv4Q/s320/microphone_circuit.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;table&gt;&lt;tr&gt;         &lt;th&gt;Element&lt;/th&gt;         &lt;th&gt;Value&lt;/th&gt;     &lt;/tr&gt;
&lt;tr&gt;         &lt;td&gt;R1&lt;/td&gt;         &lt;td&gt;10k&lt;/td&gt;     &lt;/tr&gt;
&lt;tr&gt;         &lt;td&gt;C1&lt;/td&gt;         &lt;td&gt;220u, 25V&lt;/td&gt;     &lt;/tr&gt;
&lt;tr&gt;         &lt;td&gt;C2&lt;/td&gt;         &lt;td&gt;100n&lt;/td&gt;     &lt;/tr&gt;
&lt;tr&gt;         &lt;td&gt;M&lt;/td&gt;         &lt;td&gt;electret microphone&lt;/td&gt;     &lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;Jack cable can be obtained from broken headphones. Electret microphone can be from broken camera or laptop. Of course you may just buy them in shop with electronic elements.&lt;/p&gt;

&lt;p&gt;Picture bellow describes, how wires in jack cable should be plugged. It's easy to make mistake, so you may help yourself by using multimeter.&lt;/p&gt;

&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-H5JZnLFTi3U/TYip50HDKCI/AAAAAAAAAiw/7KpN8Q2V-OA/s1600/microphone_plug.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="238" width="320" src="http://1.bp.blogspot.com/-H5JZnLFTi3U/TYip50HDKCI/AAAAAAAAAiw/7KpN8Q2V-OA/s320/microphone_plug.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-OX1X__QSk54/TYipzMB0bXI/AAAAAAAAAiI/-zBGzHZLQrw/s1600/microphone_2.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="226" width="320" src="http://3.bp.blogspot.com/-OX1X__QSk54/TYipzMB0bXI/AAAAAAAAAiI/-zBGzHZLQrw/s320/microphone_2.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-SBXfQwPhk9g/TYipzcLJbqI/AAAAAAAAAiQ/1-9EeVNBcgA/s1600/microphone_3.jpg" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="213" width="320" src="http://1.bp.blogspot.com/-SBXfQwPhk9g/TYipzcLJbqI/AAAAAAAAAiQ/1-9EeVNBcgA/s320/microphone_3.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-1385474197288403980?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/1385474197288403980/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/03/home-made-computer-microphone.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/1385474197288403980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/1385474197288403980'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/03/home-made-computer-microphone.html' title='Home made computer microphone'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-BP44aELr7M4/TYipzNiI-jI/AAAAAAAAAiA/FWOnyH4FbuQ/s72-c/microphone_1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-1170002311347890327</id><published>2011-03-22T05:06:00.001-07:00</published><updated>2011-03-22T05:08:27.989-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='electronic'/><title type='text'>Capacitors used for engraving</title><content type='html'>&lt;p&gt;In this post I will present simple way of creating shapes on metal objects.
Those shapes are made from "dots" of surface burned by sparks. Small sparks are
sufficient, so we may use a single capacitor as a source of energy for them.&lt;/p&gt;

&lt;p&gt;First, capacitor is loaded by current from power supplier, engraved object is
connected to one of electrodes of capacitor. Next, power supplier is
disconnected, second electrode of capacitor touches engraved object in place,
where new dot should be burned. In this moment small spark flies. Bellow is
diagram of this circuit.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-PmLmRG09uu8/TYiRBrTKu7I/AAAAAAAAAgg/Ughqpnwz5bg/s1600/engraving_circuit.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 142px;" src="http://3.bp.blogspot.com/-PmLmRG09uu8/TYiRBrTKu7I/AAAAAAAAAgg/Ughqpnwz5bg/s320/engraving_circuit.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5586874795742116786" /&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;Warning, electrolytic capacitors may explode when they are plugged in
wrong direction!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Pixel by pixel we made desired shape. This tedious task could be automatized
with a small electronic device, but even this way was efficient.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-fG0cME2Jst0/TYiRGAYlHVI/AAAAAAAAAgo/ueV2zizfOGg/s1600/engraving_1.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 261px;" src="http://4.bp.blogspot.com/-fG0cME2Jst0/TYiRGAYlHVI/AAAAAAAAAgo/ueV2zizfOGg/s320/engraving_1.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5586874870121438546" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-y6wXDCx5l-k/TYiRBYlhCYI/AAAAAAAAAgY/SbGS635q2PY/s1600/engraving_2.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 180px;" src="http://1.bp.blogspot.com/-y6wXDCx5l-k/TYiRBYlhCYI/AAAAAAAAAgY/SbGS635q2PY/s320/engraving_2.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5586874790718802306" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-1170002311347890327?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/1170002311347890327/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/03/capacitors-used-for-engraving.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/1170002311347890327'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/1170002311347890327'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/03/capacitors-used-for-engraving.html' title='Capacitors used for engraving'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-PmLmRG09uu8/TYiRBrTKu7I/AAAAAAAAAgg/Ughqpnwz5bg/s72-c/engraving_circuit.JPG' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-4522393036801119831</id><published>2011-03-10T11:26:00.000-08:00</published><updated>2011-03-10T11:36:21.139-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='riddle'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Sorted numbers</title><content type='html'>&lt;p&gt;You get 10 numbers on STDIN, each followed by newline character, after that you have to display them sorted from the smaller to the bigger. You can not use sorting algorithms.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-4522393036801119831?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/4522393036801119831/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/03/sorted-numbers.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/4522393036801119831'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/4522393036801119831'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/03/sorted-numbers.html' title='Sorted numbers'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-6447456005617647132</id><published>2011-03-05T11:13:00.000-08:00</published><updated>2011-03-05T11:13:00.406-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='riddle'/><title type='text'>The riddle of stolen wood</title><content type='html'>&lt;p&gt;Sometimes piles of wood are marked by paint to protect them against thief. Continuous line is painted on the trees, that are on the top of the pile, if one will stole some of them, then painted line on remaining stack will be discontinuous. To illustrate this tactic I made bellow picture.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-nA0NHDfQuDo/TXKGpTCI4uI/AAAAAAAAAfk/8bO8O6sSbgI/s1600/wood.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 123px;" src="http://2.bp.blogspot.com/-nA0NHDfQuDo/TXKGpTCI4uI/AAAAAAAAAfk/8bO8O6sSbgI/s320/wood.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5580670932307469026" /&gt;&lt;/a&gt;

&lt;p&gt;If thief would like to hide his act, then what should he do? Present algorithm to take n% of original trees and leave continuos red line on remain pile.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-6447456005617647132?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/6447456005617647132/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/03/riddle-of-stolen-wood.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/6447456005617647132'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/6447456005617647132'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/03/riddle-of-stolen-wood.html' title='The riddle of stolen wood'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-nA0NHDfQuDo/TXKGpTCI4uI/AAAAAAAAAfk/8bO8O6sSbgI/s72-c/wood.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-728531525574137521</id><published>2011-03-01T12:23:00.000-08:00</published><updated>2011-03-01T12:25:11.307-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='riddle'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>3 x if</title><content type='html'>&lt;p&gt;Bellow snippets in C check if &lt;i&gt;foo()&lt;/i&gt; and &lt;i&gt;bar()&lt;/i&gt; returns nonzero value, if yes, they execute &lt;i&gt;something()&lt;/i&gt;. Are they equivalent? Why? You may post your analyze in comments.&lt;/p&gt; 

&lt;pre&gt;    // first version
    if (foo() &amp;amp;&amp;amp; bar()) {
        something();
    }
&lt;/pre&gt;

&lt;pre&gt;    // second version
    if (bar() &amp;amp;&amp;amp; foo()) {
        something();
    }
&lt;/pre&gt;

&lt;pre&gt;    // third version
    if (foo()) {  
        if (bar()) {
            something();
        }
    }&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-728531525574137521?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/728531525574137521/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/03/3-x-if.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/728531525574137521'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/728531525574137521'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/03/3-x-if.html' title='3 x if'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-420479333025436300</id><published>2011-02-28T09:28:00.000-08:00</published><updated>2011-05-15T14:10:55.841-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='chemistry'/><title type='text'>Coating with copper by using galvanisation</title><content type='html'>&lt;h3&gt;Abstract&lt;/h3&gt;

&lt;p&gt;Galvanization is a method of coating metal objects with layer of other metal. It can be useful for protect against corrosion or to create decorative shapes on metal objects. Chemical background of this process is difficult, but the idea is simple (forgive me my indolence) - use electricity to move a bit of metal to coated object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This experiment should be done with carefully and away from fire! Explosive mixture of H&lt;sub&gt;2&lt;/sub&gt; and O&lt;sub&gt;2&lt;/sub&gt; is being created during this process.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;Tools and materials&lt;/h3&gt;

&lt;ul&gt;
    &lt;li&gt;plastic plate,&lt;/li&gt;
    &lt;li&gt;one glass of warm water,&lt;/li&gt;
    &lt;li&gt;pinch of kitchen salt,&lt;/li&gt;
    &lt;li&gt;copper wire with removed isolation,&lt;/li&gt;
    &lt;li&gt;aluminum tea-spoon,&lt;/li&gt;
    &lt;li&gt;DC power supply (3-10V).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;How to do that&lt;/h3&gt;

&lt;p&gt;Tip water into the cup, throw salt and mix. Insert electrodes as presented on picture bellow and plug them to power supply. Put coated object into the water near to the copper electrode. From time to time move object to achieve steady layer.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_gcjDBIrbvyw/TRePe3Jw6uI/AAAAAAAAAaw/pqh38xQTnPI/s1600/diagram.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 253px;" src="http://1.bp.blogspot.com/_gcjDBIrbvyw/TRePe3Jw6uI/AAAAAAAAAaw/pqh38xQTnPI/s320/diagram.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5555066425748548322" /&gt;&lt;/a&gt;

&lt;p&gt;Time of object's exposition should be chosen empirically according to expected layer's thickness, object's size, parameters of used power supplier and amount of salt in the water.&lt;/p&gt;

&lt;h3&gt;Results&lt;/h3&gt;

&lt;p&gt;Note, that the nail has been covered 6-7 years ago and its surface still shines.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_gcjDBIrbvyw/TRePipdyJyI/AAAAAAAAAa4/TfveaFz0F-U/s1600/nail.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://2.bp.blogspot.com/_gcjDBIrbvyw/TRePipdyJyI/AAAAAAAAAa4/TfveaFz0F-U/s320/nail.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5555066490793895714" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_gcjDBIrbvyw/TRePTNZJBKI/AAAAAAAAAao/oOFhN3lJP-w/s1600/coins.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 160px;" src="http://3.bp.blogspot.com/_gcjDBIrbvyw/TRePTNZJBKI/AAAAAAAAAao/oOFhN3lJP-w/s320/coins.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5555066225560192162" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-420479333025436300?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/420479333025436300/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/02/coating-with-copper-by-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/420479333025436300'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/420479333025436300'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/02/coating-with-copper-by-using.html' title='Coating with copper by using galvanisation'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_gcjDBIrbvyw/TRePe3Jw6uI/AAAAAAAAAaw/pqh38xQTnPI/s72-c/diagram.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-2104932256201907934</id><published>2011-02-27T10:13:00.000-08:00</published><updated>2011-05-16T10:57:46.429-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PHP'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>Handling exceptions in C by using try/catch</title><content type='html'>&lt;h3&gt;Abstract&lt;/h3&gt;

&lt;p&gt;Recently I saw in PHP engine smart trick for handling exceptions by using try/catch construct known from languages like Java or Python. In C it's usually done by checking function's return value or by using error variables.&lt;/p&gt;

&lt;p&gt;Bellow is real example of this hack.&lt;/p&gt;

&lt;pre&gt;int php_request_startup(TSRMLS_D)
{
    int retval = SUCCESS;

    /* unimportant stuff */

    zend_try {
        PG(during_request_startup) = 1;
        php_output_activate(TSRMLS_C);
       /* unimportant stuff */
    } zend_catch {
        retval = FAILURE;
    } zend_end_try();

    return retval;
}&lt;/pre&gt;

&lt;p&gt;If instruction in "try" block rises exception, then evaluation of this block is terminated and execution flow moves to "catch" block.&lt;/p&gt;

&lt;h3&gt;How is it done?&lt;/h3&gt;

&lt;p&gt;The trick lays in use of &lt;i&gt;setjmp&lt;/i&gt;, &lt;i&gt;longjonp&lt;/i&gt; and &lt;i&gt;sigsetjmp&lt;/i&gt; from &lt;i&gt;setjmp.h&lt;/i&gt;. On some systems it's preferred to use theirs replacements: &lt;i&gt;sigsetjmp&lt;/i&gt;, &lt;i&gt;siglongjmp&lt;/i&gt;, &lt;i&gt;sigjmp_buf&lt;/i&gt;. This nuance was hidden in bellow macros (Zend/zend.h):&lt;/p&gt;

&lt;pre&gt;
#include &amp;lt;setjmp.h&amp;gt;

#ifdef HAVE_SIGSETJMP
# define SETJMP(a) sigsetjmp(a, 0)
# define LONGJMP(a,b) siglongjmp(a, b)
# define JMP_BUF sigjmp_buf
#else
# define SETJMP(a) setjmp(a)
# define LONGJMP(a,b) longjmp(a, b)
# define JMP_BUF jmp_buf
#endif
&lt;/pre&gt;

&lt;p&gt;All &lt;i&gt;zend_try&lt;/i&gt;, &lt;i&gt;zend_catch&lt;/i&gt;, &lt;i&gt;zend_end_try&lt;/i&gt; constructions are also macros, they are deffined in Zend/zend.h:&lt;/p&gt;

&lt;pre&gt;
#define zend_try                                                \
    {                                                           \
        JMP_BUF *__orig_bailout = EG(bailout);                  \
        JMP_BUF __bailout;                                      \
                                                                \
        EG(bailout) = &amp;__bailout;                               \
        if (SETJMP(__bailout)==0) {
#define zend_catch                                              \
        } else {                                                \
            EG(bailout) = __orig_bailout;
#define zend_end_try()                                          \
        }                                                       \
        EG(bailout) = __orig_bailout;                           \
    }&lt;/pre&gt;

&lt;p&gt;&lt;i&gt;EG&lt;/i&gt; looks interesting, it's another macro, but it's difficult and not really related to our try/catch construct. Important is that deep inside is a place, where exception may be rised (Zend/zend.c):&lt;/p&gt;

&lt;pre&gt;
BEGIN_EXTERN_C()
ZEND_API void _zend_bailout(char *filename, uint lineno) /* {{{ */
{
    TSRMLS_FETCH();

    if (!EG(bailout)) {
        zend_output_debug_string(1, &amp;quot;%s(%d) : Bailed out without a bailout address!&amp;quot;, filename, lineno);
        exit(-1);
    }
    CG(unclean_shutdown) = 1;
    CG(in_compilation) = EG(in_execution) = 0;
    EG(current_execute_data) = NULL;
    LONGJMP(*EG(bailout), FAILURE);
}
&lt;/pre&gt;

&lt;p&gt;That's enough to extract it, so bellow is my own implementation. Note, that it can deal with nested try/catch. All those "bailout" variables could be also hidden under some smart macros.&lt;/p&gt;

&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;setjmp.h&amp;gt;

// comes from: Zend/zend.h 

#ifdef HAVE_SIGSETJMP
#   define SETJMP(a) sigsetjmp(a, 0)
#   define LONGJMP(a,b) siglongjmp(a, b)
#   define JMP_BUF sigjmp_buf
#else
#   define SETJMP(a) setjmp(a)
#   define LONGJMP(a,b) longjmp(a, b)
#   define JMP_BUF jmp_buf
#endif

#define zend_try                                                \
    {                                                           \
        JMP_BUF __bailout;                                      \
                                                                \
        if (SETJMP(__bailout)==0) {
#define zend_catch                                              \
        } else {                                                
#define zend_end_try()                                          \
        }                                                       \
    }

// my macros
#define EXCEPTION_RISE do { LONGJMP(__bailout,-1); } while(0)

void function_that_may_rise_exception(JMP_BUF __bailout) {
    EXCEPTION_RISE;
}

int main() {
    int retval = 0;

    zend_try {
        printf(&amp;quot;flow of instructions..\n&amp;quot;);

        zend_try {
            function_that_may_rise_exception(__bailout);
        } zend_catch {
            printf(&amp;quot;nested try/catch\n&amp;quot;);
        } zend_end_try();

        function_that_may_rise_exception(__bailout);

        printf(&amp;quot;more flow..&amp;quot;);
    } zend_catch {
        retval = 3;
    } zend_end_try();

    printf(&amp;quot;retval: %d\n&amp;quot;, retval);
}
&lt;/pre&gt;

its output:

&lt;pre&gt;bash-3.2$ ./a.out 
flow of instructions..
nested try/catch
retval: 3&lt;/pre&gt;

&lt;p&gt;While it's smart I don't like it. IMHO the most natural way for handling with error conditions in C is checking of function's return value.&lt;/p&gt;

&lt;p&gt;You may download sources (directory c_exceptions) by cloning &lt;strong&gt;git@github.com:RobertGawron/snippets.git&lt;/strong&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-2104932256201907934?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/2104932256201907934/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/02/handling-exceptions-in-c-by-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/2104932256201907934'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/2104932256201907934'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/02/handling-exceptions-in-c-by-using.html' title='Handling exceptions in C by using try/catch'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-2543352714471216540</id><published>2011-02-22T12:26:00.001-08:00</published><updated>2011-02-22T12:48:33.728-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='crappy code'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>Weird casting in C++</title><content type='html'>&lt;p&gt;What is the value of &lt;i&gt;foo&lt;/i&gt; variale after execution of bellow line if &lt;i&gt;foo&lt;/i&gt; is type of &lt;i&gt;int&lt;/i&gt;?

&lt;pre&gt;foo = static_cast&amp;lt;int&amp;gt;(foo + 0.5);&lt;/pre&gt;

&lt;p&gt;At first it looks like this code doesn't do anything. Integer value is added to 0.5 but this 0.5 is removed when value is casted back to intiger. What is interesting here, is what happend, when &lt;i&gt;foo&lt;/i&gt; is smaller that zero, then te result will be value of &lt;i&gt;foo&lt;/i&gt; increased by one. Bellow is more detailed example with its output.&lt;/p&gt;

&lt;pre&gt;#include &amp;lt;iostream&amp;gt;

int main() {
    int foo;

    foo = 10;
    foo = static_cast&amp;lt;int&amp;gt;(foo + 0.5);
    std::cout &amp;lt;&amp;lt; foo &amp;lt;&amp;lt; std::endl;

    foo = -10;
    foo = static_cast&amp;lt;int&amp;gt;(foo + 0.5);
    std::cout &amp;lt;&amp;lt; foo &amp;lt;&amp;lt; std::endl;
}

&lt;/pre&gt;

&lt;pre&gt;bash-3.2$ ./a.out 
10
-9
&lt;/pre&gt;

This construction could be written as:

&lt;pre&gt;foo = 10;
&lt;strong&gt;if (foo &amp;lt; 0) {
    foo++;
}&lt;/strong&gt;
std::cout &amp;lt;&amp;lt; foo &amp;lt;&amp;lt; std::endl;
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-2543352714471216540?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/2543352714471216540/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/02/weird-casting-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/2543352714471216540'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/2543352714471216540'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/02/weird-casting-in-c.html' title='Weird casting in C++'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-4604688315744069551</id><published>2011-02-19T08:00:00.001-08:00</published><updated>2011-02-20T13:28:32.697-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='electronic'/><title type='text'>Geek pendrive hidden in electrolytic capacitor</title><content type='html'>&lt;h3&gt;Intro&lt;/h3&gt;

&lt;p&gt;Usually pendrives have the same, boring design, I wanted to change it, so I made my own geeky pendrive. Now it's hidden in old electrolytic capacitor.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-KdmiLglqYx0/TV_xSv-aDZI/AAAAAAAAAeU/i3MY02EkLf8/s1600/pendrive2.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 186px;" src="http://2.bp.blogspot.com/-KdmiLglqYx0/TV_xSv-aDZI/AAAAAAAAAeU/i3MY02EkLf8/s320/pendrive2.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5575440168126123410" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-E1ITm_N1rxM/TV_xS2FHnEI/AAAAAAAAAec/viFP_4q8fjw/s1600/pendrive3.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://4.bp.blogspot.com/-E1ITm_N1rxM/TV_xS2FHnEI/AAAAAAAAAec/viFP_4q8fjw/s320/pendrive3.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5575440169764887618" /&gt;&lt;/a&gt;

&lt;h3&gt;Materials&lt;/h3&gt;

&lt;ul&gt;
    &lt;li&gt;pendrive :)&lt;/li&gt;
    &lt;li&gt;1-2 big electrolytic capacitors, they can be found in power suppliers or in motherboards,&lt;/li&gt;
    &lt;li&gt;superglue or other glue, that may glue aluminium,&lt;/li&gt;
    &lt;li&gt;silicon glue,&lt;/li&gt;
    &lt;li&gt;aluminum can.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Tools&lt;/h3&gt;

&lt;ul&gt;
    &lt;li&gt;small knife,&lt;/li&gt;
    &lt;li&gt;pincers,&lt;/li&gt;
    &lt;li&gt;metal-cutting saw.&lt;/li&gt;
 &lt;/ul&gt;

&lt;h3&gt;Assembly&lt;/h3&gt;

Electrolytic capacitors.

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-OzfXLormyNY/TV_yyg5WVTI/AAAAAAAAAes/QPIFyx-Epf8/s1600/capacitors.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 206px;" src="http://2.bp.blogspot.com/-OzfXLormyNY/TV_yyg5WVTI/AAAAAAAAAes/QPIFyx-Epf8/s320/capacitors.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5575441813345817906" /&gt;&lt;/a&gt;

Pendrive with removed fabric enclosure.

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-m9HAuLc5kRA/TV_yysITwVI/AAAAAAAAAe0/6TtXXvvjgzU/s1600/pendrive_electronic.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 246px;" src="http://3.bp.blogspot.com/-m9HAuLc5kRA/TV_yysITwVI/AAAAAAAAAe0/6TtXXvvjgzU/s320/pendrive_electronic.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5575441816361353554" /&gt;&lt;/a&gt;

&lt;p&gt;Capacitor with removed label - it needs to be done carefully, because after inserting pendrive into capacitor label will be moved back to its place. Capacitor's head was removed by saw (well, it could be done better :)). Content of capacitor was removed by using pincers.&lt;/p&gt; 

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-6JfxuJDXReg/TV_32vX4iOI/AAAAAAAAAfE/h4XUj6Lmj_g/s1600/capacitor_removed_ending.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 203px;" src="http://4.bp.blogspot.com/-6JfxuJDXReg/TV_32vX4iOI/AAAAAAAAAfE/h4XUj6Lmj_g/s320/capacitor_removed_ending.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5575447383509600482" /&gt;&lt;/a&gt;

&lt;p&gt;Piece of aluminum was cut out from can, convoluted and inserted into capacitor's tube. Ending was cut as show on picture to made place for USB plug.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-vVgmBvTjDRw/TV_3TUBWm9I/AAAAAAAAAe8/j6w6ThpHjI0/s1600/ready_to_assembly.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 269px;" src="http://1.bp.blogspot.com/-vVgmBvTjDRw/TV_3TUBWm9I/AAAAAAAAAe8/j6w6ThpHjI0/s320/ready_to_assembly.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5575446774871923666" /&gt;&lt;/a&gt;

&lt;p&gt;Pendrive was inserted into capacitor's tube and all was filled with silicon glue.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-YfsLUtf7imU/TV_32yo7mSI/AAAAAAAAAfM/FiFhhY8nivw/s1600/filled_with_glue.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://4.bp.blogspot.com/-YfsLUtf7imU/TV_32yo7mSI/AAAAAAAAAfM/FiFhhY8nivw/s320/filled_with_glue.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5575447384386410786" /&gt;&lt;/a&gt;

&lt;p&gt;Capacitor's ends were glued to aluminium slice from can. Label from capacitor was inserted on its old place. Bellow is image with final result.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-MG4kMFCn2Kw/TV_xSWMQAUI/AAAAAAAAAeM/GqJwPf8EIlE/s1600/pendrive1.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 214px;" src="http://3.bp.blogspot.com/-MG4kMFCn2Kw/TV_xSWMQAUI/AAAAAAAAAeM/GqJwPf8EIlE/s320/pendrive1.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5575440161204863298" /&gt;&lt;/a&gt;


&lt;h3&gt;After..&lt;/h3&gt;

&lt;p&gt;IIRC I made it in 2008 and it was working for about 1,5 years. I'm not sure if this short period was caused by my modification or by the fact, that I used cheap no-name pendrive. Anyway it looked good, other people liked it too.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-4604688315744069551?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/4604688315744069551/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/02/geek-pendrive-hidden-in-electrolytic.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/4604688315744069551'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/4604688315744069551'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/02/geek-pendrive-hidden-in-electrolytic.html' title='Geek pendrive hidden in electrolytic capacitor'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-KdmiLglqYx0/TV_xSv-aDZI/AAAAAAAAAeU/i3MY02EkLf8/s72-c/pendrive2.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-2733620268118637833</id><published>2011-02-19T03:44:00.001-08:00</published><updated>2011-02-20T13:37:05.033-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='crappy code'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>Access to object's fields by using `this` + pointer arithmetic</title><content type='html'>&lt;p&gt;Normally method refers to its object's field by using their name. It's presented bellow, where we want to get value of &lt;i&gt;description&lt;/i&gt; field in &lt;i&gt;getDescription&lt;/i&gt; method.&lt;/p&gt;

&lt;pre&gt;class Car {
    std::string getDescription() {
        return description; // &amp;lt;- we returns value of this field
    }

    std::string description;
};
&lt;/pre&gt;

&lt;p&gt;This may be done also by using a little dirty hack. If we cast &lt;i&gt;this&lt;/i&gt; and get pointer from it, then we will obtain value of the first of its object's fields. Similarly, if we increment this pointer by n, we will get value of n'th field. It's presented bellow:&lt;/p&gt;

&lt;pre&gt;#include &amp;lt;iostream&amp;gt;

class Car {
public:
    Car (int _weight, int _maxSpeed, std::string _description) :
        weight(_weight), maxSpeed(_maxSpeed), description(_description) {
    }
    std::string getDescription() {
        return description;
    }
    std::string getDescriptionUsingThisKeyword() {
        return *((std::string*)((int*)this + 2));
    } 
private:
    int weight, maxSpeed;
    std::string description;
};

int main() {
    Car myCar(200, 200, &amp;quot;my best car ever&amp;quot;);
    std::cout &amp;lt;&amp;lt; myCar.getDescription() &amp;lt;&amp;lt; std::endl;
    std::cout &amp;lt;&amp;lt; myCar.getDescriptionUsingThisKeyword() &amp;lt;&amp;lt; std::endl;
}

&lt;/pre&gt;

This will output:

&lt;pre&gt;bash-3.2$ ./a.out 
my best car ever
my best car ever
&lt;/pre&gt;

&lt;p&gt;It's error-prone, e.g. when someone will change order of fields in class code.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-2733620268118637833?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/2733620268118637833/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/02/access-to-objects-fields-by-using-this.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/2733620268118637833'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/2733620268118637833'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/02/access-to-objects-fields-by-using-this.html' title='Access to object&apos;s fields by using `this` + pointer arithmetic'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-5219117630357905846</id><published>2011-02-19T03:26:00.001-08:00</published><updated>2011-05-16T13:41:20.832-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PHP'/><category scheme='http://www.blogger.com/atom/ns#' term='image processing'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><category scheme='http://www.blogger.com/atom/ns#' term='smart code'/><title type='text'>Hardcoded images in source of PHP engine</title><content type='html'>&lt;h3&gt;Abstract&lt;/h3&gt;

&lt;p&gt;How server sends images? Usually it takes them from file system or creates them dynamically (e.g. by using &lt;a href="http://www.libgd.org/Main_Page"&gt;GD&lt;/a&gt; or &lt;a href="http://www.pythonware.com/products/pil/"&gt;PIL&lt;/a&gt; library) but there is other option - hardcode images in source code. This rare concept is, what I would like to present today.&lt;/p&gt;

&lt;p&gt;Image may be hardcoded in a regular array, where its fields contains values of bytes in original image file. If it isn't clear for you let's imagine that you open image in a hex editor, you will see content of it in a form of long chain of bytes. You can copy them into your sources, every byte as a field in array. Then, if you will iterate thought it, you will get exactly the same data as those, stored in the original file.&lt;/p&gt;  

&lt;p&gt;I will show, how it's done in PHP source, then I will show my implementation based on this. It will be a simple HTTP server, that serves image stored in that way.&lt;/p&gt;

&lt;p&gt;There will be a lot of code from different files, so we need compact way to refer to them - I will use vim's syntax:&lt;/p&gt;

&lt;pre&gt;path_to_file/file_name +line_in_file&lt;/pre&gt;

&lt;h3&gt;Implementation in PHP engine&lt;/h3&gt;

&lt;p&gt;Array with content of image is stored in &lt;i&gt;main/logos.h +21&lt;/i&gt;:&lt;/p&gt;

&lt;pre&gt;#define CONTEXT_TYPE_IMAGE_GIF &amp;quot;Content-Type: image/gif&amp;quot;

static const unsigned char zend_logo[] = {
  71,  73,  70,  56,  57,  97, 113,   0,  72,   0, 
 213,   0,   0,  13,  13,  14,   1,   3,   6,   2, 
   5,   9,  46,  68,  94,  21,  29,  39,   5,  15, 


...&lt;/pre&gt;


&lt;p&gt;Above file is used in &lt;i&gt;main/php_logos.c +60&lt;/i&gt;:&lt;/p&gt;

&lt;pre&gt;int php_init_info_logos(void)
{
 if(zend_hash_init(&amp;amp;phpinfo_logo_hash, 0, NULL, NULL, 1)==FAILURE) 
  return FAILURE;

 php_register_info_logo(PHP_LOGO_GUID    , &amp;quot;image/gif&amp;quot;, php_logo    , sizeof(php_logo));
 php_register_info_logo(PHP_EGG_LOGO_GUID, &amp;quot;image/gif&amp;quot;, php_egg_logo, sizeof(php_egg_logo));
 php_register_info_logo(ZEND_LOGO_GUID   , &amp;quot;image/gif&amp;quot;, zend_logo   , sizeof(zend_logo));

 return SUCCESS;
}&lt;/pre&gt;


&lt;p&gt;Above function is used in &lt;i&gt;main/main.c +1994&lt;/i&gt;:&lt;/p&gt;

&lt;pre&gt;int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_modules, uint num_additional_modules)
{

...

 /* initialize registry for images to be used in phpinfo() 
    (this uses configuration parameters from php.ini)
  */
 if (php_init_info_logos() == FAILURE) {
  php_printf(&amp;quot;PHP:  Unable to initialize info phpinfo logos.\n&amp;quot;);
  return FAILURE;
 }

...&lt;/pre&gt;


&lt;p&gt;It seams that there isn't any interesting stuff here so we will move back to &lt;i&gt;php_init_info_logos&lt;/i&gt; and look closer on it. It uses &lt;i&gt;php_register_info_logo&lt;/i&gt;, is implemented in &lt;i&gt;main/php_logos.c +36&lt;/i&gt;:&lt;/p&gt;

&lt;pre&gt;PHPAPI int php_register_info_logo(char *logo_string, const char *mimetype, const unsigned char *data, int size)
{
 php_info_logo info_logo;

 info_logo.mimetype = mimetype;
 info_logo.mimelen  = strlen(mimetype);
 info_logo.data     = data;
 info_logo.size     = size;

 return zend_hash_add(&amp;amp;phpinfo_logo_hash, logo_string, strlen(logo_string), &amp;amp;info_logo, sizeof(php_info_logo), NULL);
}&lt;/pre&gt;

body of &lt;i&gt;php_info_logo&lt;/i&gt; is in the same file:

&lt;pre&gt;typedef struct _php_info_logo { 
 const char *mimetype;
 int mimelen;
 const unsigned char *data; 
 int size; 
} php_info_logo;&lt;/pre&gt;


&lt;p&gt;This structure will be useful, but lets take a look on the rest of the functions in this file, because  there is another interesting:&lt;/p&gt;

&lt;pre&gt;#define CONTENT_TYPE_HEADER &amp;quot;Content-Type: &amp;quot;
int php_info_logos(const char *logo_string TSRMLS_DC)
{
 php_info_logo *logo_image;
 char *content_header;
 int len;

 if(FAILURE==zend_hash_find(&amp;amp;phpinfo_logo_hash, (char *) logo_string, strlen(logo_string), (void **)&amp;amp;logo_image))
  return 0;

 len = sizeof(CONTENT_TYPE_HEADER) - 1 + logo_image-&amp;gt;mimelen;
 content_header = emalloc(len + 1);
 memcpy(content_header, CONTENT_TYPE_HEADER, sizeof(CONTENT_TYPE_HEADER) - 1);
 memcpy(content_header + sizeof(CONTENT_TYPE_HEADER) - 1 , logo_image-&amp;gt;mimetype, logo_image-&amp;gt;mimelen);
 content_header[len] = '\0';
 sapi_add_header(content_header, len, 0);

 PHPWRITE(logo_image-&amp;gt;data, logo_image-&amp;gt;size);
 return 1;
}&lt;/pre&gt;

&lt;p&gt;I extracted this function + &lt;i&gt;php_info_logo&lt;/i&gt; structure into my program. Well, it's enough information and we could finish here, but we can move on, e.g. to &lt;i&gt;PHPWRITE&lt;/i&gt; macro with is defined in &lt;i&gt;main/php.h +389&lt;/i&gt;:&lt;/p&gt;


&lt;pre&gt;#define PHPWRITE(str, str_len)                php_body_write((str),
(str_len) TSRMLS_CC))&lt;/pre&gt;


&lt;p&gt;&lt;i&gt;php_body_write&lt;/i&gt; is implemented in &lt;i&gt;main/output.c +121&lt;/i&gt;&lt;/p&gt;

&lt;pre&gt;PHPAPI int php_body_write(const char *str, uint str_length TSRMLS_DC)
{
 return OG(php_body_write)(str, str_length TSRMLS_CC); 
}&lt;/pre&gt;

&lt;p&gt;&lt;i&gt;OG&lt;/i&gt; is a macro, I didn't search where it's defined - it's getting to complicated. Well, it seems, that we shouldn't move on, it was pointless :)&lt;/p&gt;

&lt;h3&gt;My implementation based on code from PHP engine&lt;/h3&gt;

&lt;p&gt;As a base I used &lt;i&gt;main/logos.h&lt;/i&gt; and &lt;i&gt;main/php_logos.c&lt;/i&gt;. I didn't touch &lt;i&gt;logos.h&lt;/i&gt;, but in php_logos.c I made minor changes.&lt;/p&gt;

&lt;p&gt;I also created &lt;i&gt;main.c&lt;/i&gt;, &lt;i&gt;Makefile&lt;/i&gt; and a small shell script that was used as a HTTP server (based on &lt;a href="http://paulbuchheit.blogspot.com/2007/04/webserver-in-bash.html"&gt;script created by Paul Buchheit&lt;/a&gt;).&lt;/p&gt;

Mentioned HTTP sever should be run in this way:

&lt;pre&gt;./script_name port_to_listen binary_to_execute_after_connection&lt;/pre&gt;

If we run it and point web browser to it's address we may see this:

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-QGBTeXsAlfY/TV-qOesuMZI/AAAAAAAAAd8/SY7bVUP18GY/s1600/php_zend_icon.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 141px;" src="http://1.bp.blogspot.com/-QGBTeXsAlfY/TV-qOesuMZI/AAAAAAAAAd8/SY7bVUP18GY/s320/php_zend_icon.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5575362029443494290" /&gt;&lt;/a&gt;

Image is available for users, so it works!


&lt;p&gt;You may download sources (directory &lt;strong&gt;hardcoded_image&lt;/strong&gt;) by cloning &lt;strong&gt;git@github.com:RobertGawron/snippets.git&lt;/strong&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-5219117630357905846?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/5219117630357905846/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/02/hardcoded-images-in-source-of-php.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/5219117630357905846'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/5219117630357905846'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/02/hardcoded-images-in-source-of-php.html' title='Hardcoded images in source of PHP engine'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-QGBTeXsAlfY/TV-qOesuMZI/AAAAAAAAAd8/SY7bVUP18GY/s72-c/php_zend_icon.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-3213018820057989117</id><published>2011-02-15T10:07:00.000-08:00</published><updated>2011-02-19T10:03:14.918-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><category scheme='http://www.blogger.com/atom/ns#' term='smart code'/><title type='text'>Smarter strings in C</title><content type='html'>&lt;p&gt;In C, strings are usually stored in variables with char* type, it's just container for characters, there isn't stored other data/metadata. This can be tedious, e.g. if we want to iterate thought string we need to obtain its length (e.g by invoke strlen() function on it) or carry its length in some additional variables.&lt;/p&gt;

&lt;p&gt;This can be simplified by wrapping raw char* string in a simple structure. Its string's length has unsigned type, therefore mistakes with assigning negative values will be easier to find. Its &lt;strong&gt;first&lt;/strong&gt; argument is its content (with char* type), so it can be just passed to functions, that requires regular char* arguments (although it will create warning, it's safe IMHO).&lt;/p&gt;

Here is implementation:

&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;

typedef struct string {
    char* data;
    unsigned length;
} string;

int main() {
    string myHome;
    myHome.data = &amp;quot;it's big and white&amp;quot;;
    myHome.length = strlen(myHome.data);

    // now we don't have to check for size of string,
    // e.g. we don't have to use strlen() to iterate thought charcters
    int i;
    for (i = 0; i &amp;lt; myHome.length; i++) {
        printf(&amp;quot;%c&amp;quot;, myHome.data[i]);
    }
    printf(&amp;quot;\n&amp;quot;);

    // backward compatibility with char*
    printf(&amp;quot;%s\n&amp;quot;, myHome.data);
    printf(&amp;quot;%s\n&amp;quot;, myHome); // this will raise warning but is legal
}

&lt;/pre&gt;

&lt;p&gt;It's a bit unpopular trick, but may be seen in snippets on some forums, also &lt;a href="http://pine.cs.yale.edu/pinewiki/C/Structs"&gt;here is tutorial about similar implementation of such strings&lt;/a&gt;.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-3213018820057989117?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/3213018820057989117/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/02/smarter-strings-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/3213018820057989117'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/3213018820057989117'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/02/smarter-strings-in-c.html' title='Smarter strings in C'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-8645680963667443696</id><published>2011-02-13T05:19:00.001-08:00</published><updated>2011-06-04T04:14:40.996-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><category scheme='http://www.blogger.com/atom/ns#' term='smart code'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Modulo operation using bitwise multiplication</title><content type='html'>&lt;p&gt;Modulo operation of &lt;strong&gt;a&lt;/strong&gt; and &lt;strong&gt;b&lt;/strong&gt; numbers returns reminder from dividing &lt;strong&gt;a&lt;/strong&gt; by &lt;strong&gt;b&lt;/strong&gt;. Many languages provides built-in support for this, just to mention a few: C, PHP, Python or Haskell. In some conditions this operation can be also done by using &lt;strong&gt;bitwise operation&lt;/strong&gt;, this is the idea of this post.&lt;/p&gt;  

&lt;p&gt;Let's back to our &lt;strong&gt;a&lt;/strong&gt; and &lt;strong&gt;b&lt;/strong&gt; numbers, if &lt;strong&gt;b&lt;/strong&gt; is a power of 2 its binary representation looks like 1(and maybe some zeroes here). Numbers with smaller from &lt;strong&gt;b&lt;/strong&gt; amount of digits (in binary representation) will be smaller, number one smaller from b will contain only ones (as many ones as many there were zeroes in b) - lets call this new number &lt;strong&gt;c&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now if we will made &lt;strong&gt;bitwise multiplication&lt;/strong&gt; of a and c we will get number where 1. bits may be set to ones only when they were set in &lt;strong&gt;a&lt;/strong&gt; 2. bits on higher position, that the highest position in &lt;strong&gt;c&lt;/strong&gt; will be ignored. In this case it's equal to modulo operation. Following samples in C and Python illustrate it.&lt;/p&gt;

&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {
    // 8(dec) = 1000(bin)
    // 7(dec) =  111(bin)
    printf(&amp;quot;19 mod 8 (with %%) %d\n&amp;quot;, 19 % 8);
    printf(&amp;quot;19 mod 8 (with &amp;amp;) %d\n&amp;quot;,  19 &amp;amp; 7);

    // 16(dec) = 10000(bin)
    // 15(dec) =  1111(bin)
    printf(&amp;quot;16 mod 16 (with %%) %d\n&amp;quot;, 16 % 16);
    printf(&amp;quot;16 mod 16 (with &amp;amp;) %d\n&amp;quot;,  16 &amp;amp; 15);
}

&lt;/pre&gt;

after execution:

&lt;pre&gt;bash-3.2$ llvm-gcc modulo.c &amp;amp;&amp;amp; ./a.out
19 mod 8 (with %) 3
19 mod 8 (with &amp;amp;) 3
16 mod 16 (with %) 0
16 mod 16 (with &amp;amp;) 0
&lt;/pre&gt;

in Python's CLI:

&lt;pre&gt;bash-3.2$ python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type &amp;quot;help&amp;quot;, &amp;quot;copyright&amp;quot;, &amp;quot;credits&amp;quot; or &amp;quot;license&amp;quot; for more information.
&amp;gt;&amp;gt;&amp;gt; 19 % 8
3
&amp;gt;&amp;gt;&amp;gt; 19 &amp;amp; 7
3
&amp;gt;&amp;gt;&amp;gt; 
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-8645680963667443696?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/8645680963667443696/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/02/modulo-operation-using-bitwise.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8645680963667443696'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8645680963667443696'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/02/modulo-operation-using-bitwise.html' title='Modulo operation using bitwise multiplication'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-8050215969422532534</id><published>2011-01-22T03:45:00.000-08:00</published><updated>2011-06-04T04:42:51.532-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='image processing'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Super-resolution algorithm implemented in Python</title><content type='html'>&lt;h3&gt;﻿Abstract&lt;/h3&gt;

&lt;p&gt;Super-resolution algorithms are family of algorithms used to obtain higher resolution image from set of images in lower resolutions. It's important to notice, that by using those methods higher resolution image contains more information (its more detailed) in opposite to resizing (and debluring) methods.&lt;/p&gt;

&lt;p&gt;This technique can be applied in many domains, such as data from spying or meteorological satellites, telescopes or medical equipments like tomographs or X-ray machines. It can be also applied to 3D sceneries.&lt;/p&gt;

&lt;p&gt;In this article, I will describe &lt;strong&gt;super resolution algorithm&lt;/strong&gt; proposed by
&lt;a href="http://www.cs.huji.ac.il/~peleg/papers/icpr90-SuperResolutionSequences.pdf"&gt;Irani and Peleg&lt;/a&gt;. I will also present its simple implementation in Python.&lt;/p&gt;

&lt;p&gt;Bellow it's visible image, that contains one of low resolution captured images (lower part) and estimated higher resolution image (upper part). For easier comparison of details, low resolution image was resized by using Lanchos3 algorithm to fit dimensions of estimated image.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_gcjDBIrbvyw/TTrEyIHgLDI/AAAAAAAAAdk/SHN5PUP08iQ/s1600/super-resolution.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 160px; height: 156px;" src="http://1.bp.blogspot.com/_gcjDBIrbvyw/TTrEyIHgLDI/AAAAAAAAAdk/SHN5PUP08iQ/s320/super-resolution.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5564976655021124658" /&gt;&lt;/a&gt;


&lt;h3&gt;Introduction&lt;/h3&gt;

&lt;p&gt;The most important role in presented &lt;strong&gt;super resolution&lt;/strong&gt; algorithm plays imaging process, so I will start from its explanation. Lets assume following notation:&lt;/p&gt;

&lt;pre&gt;HR –  original, high resolution image
LR(n) - n'th lower resolution image
s&amp;darr; - downsampling factor
h&lt;sup&gt;psf&lt;/sup&gt; – &lt;a href="http://en.wikipedia.org/wiki/Point_spread_function"&gt;point spread function&lt;/a&gt;
N – noise
T – movement of constant vector [x,y]&lt;/pre&gt;

&lt;p&gt;Image process of capturing n-th image can be described, by using bellow formula.&lt;/p&gt;

&lt;pre&gt;LR(n) = ((T(HR) + N)*h&lt;sup&gt;psf&lt;/sup&gt;) s&amp;darr;&lt;/pre&gt;

&lt;p&gt;This says, that any LR image may is captured by taking HR image, 1) moving it by T vector, 2) blurring it by noises and  h&lt;sup&gt;psf&lt;/sup&gt; and 3) downsizing it. It's important to notice, that from one HR image we can get multiple different LR images, because T and N may vary.&lt;/p&gt;

&lt;p&gt;The goal is, to take this equitation, known factors and low resolution images (its left side) and try to extract HR from it. This may be achieved by bellow algorithm.&lt;/p&gt;

&lt;pre&gt;
Input data:
number of iterations
upsampling factor
set of low resolution pictures with know movement from original HR image
point spread function

Algorithm:
1. Create initial upsampled image. Simple resizing algorithm with optional debluring may be also used in this step. Let's name this image E.
2. For all LR images simulate image process from E; Different images are taken with different offsets, so simulated LR images will differ.
3. For each LR image get the difference between simulated and captured image, backproject this difference to E.
4. if not extended number of iteration, then back to 2.

Output data:
E is the SR-image
&lt;/pre&gt;

&lt;p&gt;It's useful to have function, that tells in each iteration how much estimated image E differ from original HR image. For this purpose we sum in all LR images differences between values of simulated pixels and captured pixels. This factor is normalized by product of numbers of pictures, width of LR image and height of LR image. This information may be used to tweak input constants or to compare, how algorithm behaves on different sets of input images.&lt;/p&gt;

&lt;h3&gt;Software&lt;/h3&gt;

&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Python_(programming_language)"&gt;Python&lt;/a&gt; was used due to its easy syntax and support for functional programming. Variables that can be changed by user were placed in &lt;a href="http://en.wikipedia.org/wiki/YAML"&gt;YAML&lt;/a&gt; file, with is shared between both of scripts.&lt;/p&gt;

&lt;p&gt;Both, point spread function and movement of LR images from HR image can be estimated but it's far away from scope of this text. For easier implementation I don't use real images, instead I use artificial generated ones with know movement and point spread function.&lt;/p&gt;

&lt;p&gt;For easier implementation noises wasn't included.&lt;/p&gt;

&lt;p&gt;Help is available by running script with &lt;i&gt;--help&lt;/i&gt; option. Samples of images, that can be used as a base for tests are available in &lt;i&gt;examples&lt;/i&gt; directory.&lt;/p&gt;


Example of usage:
&lt;pre&gt;bash-3.2$ ./make_samples.py sample_images/diagram.tif
INFO:root:saved: input_images/-1_-1.tif
INFO:root:saved: input_images/0_-1.tif
INFO:root:saved: input_images/1_-1.tif
INFO:root:saved: input_images/-1_0.tif
INFO:root:saved: input_images/0_0.tif
INFO:root:saved: input_images/1_0.tif
INFO:root:saved: input_images/-1_1.tif
INFO:root:saved: input_images/0_1.tif
INFO:root:saved: input_images/1_1.tif
bash-3.2$ ./sr_restore.py 
INFO:root:iteration:  0, estimation error: 38.026709
INFO:root:iteration:  1, estimation error: 33.289592
INFO:root:iteration:  2, estimation error: 33.142236
INFO:root:iteration:  3, estimation error: 33.118768
INFO:root:iteration:  4, estimation error: 33.103748
INFO:root:iteration:  5, estimation error: 33.120353
INFO:root:iteration:  6, estimation error: 33.130707
INFO:root:iteration:  7, estimation error: 33.144355
INFO:root:iteration:  8, estimation error: 33.165020
INFO:root:iteration:  9, estimation error: 33.186993

&lt;/pre&gt;

&lt;p&gt;Sources can be obtained from GitHub from the following location:
&lt;a href="http://github.com/RobertGawron/supper-resolution"&gt;http://github.com/RobertGawron/supper-resolution&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;There are plenty of articles about &lt;strong&gt;super resolution algorithms&lt;/strong&gt; but almost none of them includes implementation in one of popular programing language. In presented here simple implementation, that works correctly and can be used as a base for further researches.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-8050215969422532534?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/8050215969422532534/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/01/super-resolution-algorithm-implemented.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8050215969422532534'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8050215969422532534'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/01/super-resolution-algorithm-implemented.html' title='Super-resolution algorithm implemented in Python'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_gcjDBIrbvyw/TTrEyIHgLDI/AAAAAAAAAdk/SHN5PUP08iQ/s72-c/super-resolution.png' height='72' width='72'/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-3063794995847508577</id><published>2011-01-19T06:53:00.000-08:00</published><updated>2011-02-19T10:01:59.736-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='electronic'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Step motor as a source of electricity</title><content type='html'>&lt;p&gt;Recently I saw in old electronic magazine reprint of project, where step motor was used as a source of power for LED torch. It was interesting, so I made my own version. In post I will show, how it can be used as a source of energy for single LED or clock.&lt;/p&gt;

&lt;div class="youtube"&gt;&lt;object width="480" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/sIzy7BFTNbA?fs=1&amp;amp;hl=pl_PL&amp;amp;rel=0"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/sIzy7BFTNbA?fs=1&amp;amp;hl=pl_PL&amp;amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;

&lt;p&gt;I used 4 pin step motor from ink printer. By trial and error I found how to connect its pins to obtain the biggest voltage. Because I wanted to power electronic devices I soldered a circuit, that gives DC voltage and protects against over-voltage. It's modified board from popular AC/DC power adapter.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_gcjDBIrbvyw/TTb7yjfPq-I/AAAAAAAAAdI/xhqvXqDrEyE/s1600/step_motor_power_source.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 199px;" src="http://2.bp.blogspot.com/_gcjDBIrbvyw/TTb7yjfPq-I/AAAAAAAAAdI/xhqvXqDrEyE/s320/step_motor_power_source.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5563911235601148898" /&gt;&lt;/a&gt;
&lt;p&gt;Here are examples with powering small motor from DVD player, clock and a single LED.&lt;/p&gt;

&lt;p&gt;There is standard diode bridge and after that goes two filtering capacitors. There is also resistor (27 Ohms, 3W) and 3 silicon diodes used to protect output from over-voltage in cases, when step motor provides to much of voltage. Originally there were also 4 ceramic capacitors, but they were pointless here so I didn't put them on the diagram.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_gcjDBIrbvyw/TTb7y8wg2LI/AAAAAAAAAdQ/au7PVM95BSk/s1600/step_motor_source_of_energy_fron_view.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 210px;" src="http://4.bp.blogspot.com/_gcjDBIrbvyw/TTb7y8wg2LI/AAAAAAAAAdQ/au7PVM95BSk/s320/step_motor_source_of_energy_fron_view.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5563911242384464050" /&gt;&lt;/a&gt;

&lt;div class="youtube"&gt;&lt;object width="480" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/ijxMYYWpRF8?fs=1&amp;amp;hl=pl_PL&amp;amp;rel=0"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/ijxMYYWpRF8?fs=1&amp;amp;hl=pl_PL&amp;amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;

&lt;div class="youtube"&gt;&lt;object width="480" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/0UQrKkirz3U?fs=1&amp;amp;hl=pl_PL&amp;amp;rel=0"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/0UQrKkirz3U?fs=1&amp;amp;hl=pl_PL&amp;amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;


&lt;div class="youtube"&gt;&lt;object width="480" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/sIzy7BFTNbA?fs=1&amp;amp;hl=pl_PL&amp;amp;rel=0"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/sIzy7BFTNbA?fs=1&amp;amp;hl=pl_PL&amp;amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-3063794995847508577?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/3063794995847508577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/01/step-motor-as-source-of-electricity.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/3063794995847508577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/3063794995847508577'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/01/step-motor-as-source-of-electricity.html' title='Step motor as a source of electricity'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_gcjDBIrbvyw/TTb7yjfPq-I/AAAAAAAAAdI/xhqvXqDrEyE/s72-c/step_motor_power_source.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-3192657775070226918</id><published>2011-01-17T06:48:00.001-08:00</published><updated>2011-02-19T09:56:49.805-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='electronic'/><title type='text'>Homemade speaker</title><content type='html'>&lt;p&gt;It's a simple speaker, that may be build at home from inexpensive and freely available materials: magnet, cardboard and tape, isolated wire from signal transformer and mini-jack cable from broken headphones.&lt;/p&gt;

&lt;div class="youtube"&gt;&lt;object width="480" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/dcbKo4nBOsQ?fs=1&amp;amp;hl=pl_PL&amp;amp;rel=0"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/dcbKo4nBOsQ?fs=1&amp;amp;hl=pl_PL&amp;amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;

&lt;p&gt;Above is sample taken from this speaker. In real it's really quiet but its sound quality is pretty good ;)&lt;/p&gt;

&lt;p&gt;First I made inductor (about 80 wire loops) and plugged it into mini-jack cable. Then I made circle in cardboard and used tape to attach inductor in the middle of it. Then I placed it on the top of the magnet. Bellow you may find pictures from building it.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_gcjDBIrbvyw/TTRbgShYVuI/AAAAAAAAAcY/M-Y87sccyj0/s1600/homemade_speaker_wire.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 190px;" src="http://4.bp.blogspot.com/_gcjDBIrbvyw/TTRbgShYVuI/AAAAAAAAAcY/M-Y87sccyj0/s320/homemade_speaker_wire.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5563172049995192034" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_gcjDBIrbvyw/TTRc0kQzuTI/AAAAAAAAAcw/70xl9Cm7NTk/s1600/wire_attached.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://4.bp.blogspot.com/_gcjDBIrbvyw/TTRc0kQzuTI/AAAAAAAAAcw/70xl9Cm7NTk/s320/wire_attached.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5563173497866533170" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_gcjDBIrbvyw/TTRdtPwbYKI/AAAAAAAAAc4/x38Bk-dCSUo/s1600/speaker_plate_and_magnet.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 275px; height: 320px;" src="http://2.bp.blogspot.com/_gcjDBIrbvyw/TTRdtPwbYKI/AAAAAAAAAc4/x38Bk-dCSUo/s320/speaker_plate_and_magnet.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5563174471614554274" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_gcjDBIrbvyw/TTRdtUp3-1I/AAAAAAAAAdA/--zMXrG6bBQ/s1600/speaker_top_view.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 199px;" src="http://3.bp.blogspot.com/_gcjDBIrbvyw/TTRdtUp3-1I/AAAAAAAAAdA/--zMXrG6bBQ/s320/speaker_top_view.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5563174472929246034" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-3192657775070226918?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/3192657775070226918/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/01/homemade-speaker_17.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/3192657775070226918'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/3192657775070226918'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/01/homemade-speaker_17.html' title='Homemade speaker'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_gcjDBIrbvyw/TTRbgShYVuI/AAAAAAAAAcY/M-Y87sccyj0/s72-c/homemade_speaker_wire.JPG' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-3303950281090990355</id><published>2011-01-08T07:23:00.000-08:00</published><updated>2011-02-19T10:01:59.737-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><title type='text'>Programming Songs</title><content type='html'>&lt;h2&gt;Code monkey&lt;/h2&gt;

&lt;p&gt;Written by Jonathan Coulton, &lt;a href="http://www.leoslyrics.com/listlyrics.php?hid=%2Fm03GGhfPAk%3D"&gt;link to lyric&lt;/a&gt;.&lt;/p&gt;


&lt;div class="youtube"&gt;&lt;object type="application/x-shockwave-flash" style="width:500px; height:410px;" data="http://www.youtube.com/v/v4Wy7gRGgeA"&gt;
&lt;param name="movie" value="http://www.youtube.com/v/v4Wy7gRGgeA" /&gt;
&lt;/object&gt;&lt;/div&gt;

&lt;h2&gt;Kill dash nine!&lt;/h2&gt;

&lt;p&gt;There is no guitar here but in the clip there's guitar player :)&lt;/p&gt;

&lt;div class="youtube"&gt;&lt;object type="application/x-shockwave-flash" style="width:500px; height:410px;" data="http://www.youtube.com/v/Fow7iUaKrq4"&gt;
&lt;param name="movie" value="http://www.youtube.com/v/Fow7iUaKrq4" /&gt;
&lt;/object&gt;&lt;/div&gt;

&lt;h2&gt;Write in C&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://www.lyrics007.com/Anonymous%20Lyrics/Write%20In%20C%20Lyrics.html"&gt;Click for lyric.&lt;/a&gt;&lt;/p&gt;

&lt;div class="youtube"&gt;&lt;object type="application/x-shockwave-flash" style="width:500px; height:410px;" data="http://www.youtube.com/v/J5LNTTGDKYo"&gt;
&lt;param name="movie" value="http://www.youtube.com/v/J5LNTTGDKYo" /&gt;
&lt;/object&gt;&lt;/div&gt;

&lt;h2&gt;Programmer song&lt;/h2&gt;

&lt;div class="youtube"&gt;&lt;object type="application/x-shockwave-flash" style="width:500px; height:410px;" data="http://www.youtube.com/v/q2h_uKypdGE"&gt;
&lt;param name="movie" value="http://www.youtube.com/v/q2h_uKypdGE" /&gt;
&lt;/object&gt;&lt;/div&gt;

&lt;h2&gt;Julia Ecklar - the eternal flame&lt;/h2&gt;

&lt;p&gt;It's for all LISP bastards out there :] thanks to mulander.&lt;/p&gt;

&lt;div class="youtube"&gt;&lt;object type="application/x-shockwave-flash" style="width:500px; height:410px;" data="http://www.youtube.com/v/5-OjTPj7K54"&gt;
&lt;param name="movie" value="http://www.youtube.com/v/5-OjTPj7K54" /&gt;
&lt;/object&gt;&lt;/div&gt;

&lt;h2&gt;Programistyczna piosenka&lt;/h2&gt;

&lt;p&gt;It's a Polish accent, once again, thanks to mulander for this one.&lt;/p&gt;

&lt;div class="youtube"&gt;&lt;object type="application/x-shockwave-flash" style="width:500px; height:410px;" data="http://www.youtube.com/v/bXoc9hOIj3M"&gt;
&lt;param name="movie" value="http://www.youtube.com/v/bXoc9hOIj3M" /&gt;
&lt;/object&gt;&lt;/div&gt;


&lt;h2&gt;Bad Religion - I Love My Computer&lt;/h2&gt;
&lt;p&gt;&lt;a href="http://www.lyricsfreak.com/b/bad+religion/i+love+my+computer_20011908.html"&gt;Click for lyric.&lt;/a&gt;&lt;/p&gt;

&lt;div class="youtube"&gt;&lt;object type="application/x-shockwave-flash" style="width:500px; height:410px;" data="http://www.youtube.com/v/G1LkbXTTSrQ"&gt;
&lt;param name="movie" value="http://www.youtube.com/v/G1LkbXTTSrQ" /&gt;
&lt;/object&gt;&lt;/div&gt;

&lt;h2&gt;The Free Software Song&lt;/h2&gt;
&lt;p&gt;Last but not least comes &lt;a href="http://www.gnu.org/music/free-software-song.html"&gt;The Free Software Song&lt;/a&gt; by &lt;a href="http://stallman.org/"&gt;Richard Stallman&lt;/a&gt;.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-3303950281090990355?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/3303950281090990355/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/01/programming-songs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/3303950281090990355'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/3303950281090990355'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/01/programming-songs.html' title='Programming Songs'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-5683512699902620336</id><published>2011-01-08T05:57:00.000-08:00</published><updated>2011-02-19T10:03:14.919-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><category scheme='http://www.blogger.com/atom/ns#' term='smart code'/><title type='text'>Avoid mistakes in conditional instructions</title><content type='html'>&lt;p&gt;In C or C++ it's easy to make mistake in expression of conditional instruction and use assignment instead of comparation. It's presented in bellow snippet, where we want to check if x is equal to 6:&lt;/p&gt;

&lt;pre&gt;
int main(){
    int x;

    /* first case */
    /* OK */
    if(x==6){
        /* sth */
    }
    /* WRONG */
    if(x=6){
        /* sth */
    }

    /* second case */
    /* OK */
    if(x!=6){
        /* sth */
    }
    /* WRONG */
    if(x=!6){
        /* sth */
    }

    return 0;
}
&lt;/pre&gt;

&lt;p&gt;This code will be compiled successfully because its syntax is valid.&lt;/p&gt;

&lt;p&gt;Those mistakes may be reduced by using following practice: &lt;strong&gt;while comparing something unmodifiable (string, number..) and variable, variable is written always on the right side.&lt;/strong&gt; This is presented bellow:&lt;/p&gt;

&lt;pre&gt;
int main(){
    int x;

    /* first case */
    /* OK */
    if(6==x){
        /* sth */
    }
    /* WRONG */
    if(6=x){
        /* sth */
    }

    /* second case */
    /* OK */
    if(6!=x){
        /* sth */
    }
    /* WRONG */
    if(6=!x){
        /* sth */
    }

    return 0;
}
&lt;/pre&gt;

&lt;p&gt;Now conditional instructions with mistakes contain incorrect syntax and may be caught and fixed during compilation:&lt;/p&gt;

&lt;pre&gt;
rgawron@foo:~$ gcc s2.c
s2.c: In function ‘main’:
s2.c:10: error: lvalue required as left operand of assignment
s2.c:20: error: lvalue required as left operand of assignment
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-5683512699902620336?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/5683512699902620336/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/01/in-c-or-c-its-easy-to-make-mistake-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/5683512699902620336'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/5683512699902620336'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/01/in-c-or-c-its-easy-to-make-mistake-in.html' title='Avoid mistakes in conditional instructions'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-8331605225272409139</id><published>2011-01-06T08:54:00.000-08:00</published><updated>2011-05-03T04:25:29.765-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Protecting images against saving</title><content type='html'>&lt;p&gt;If you share on the Internet your images, then you may want to make them protected against saving. There's a lot of ways to do that, watermarks, cutting images into multiple smaller and reassembling by using CSS, tricks with CSS or JavaScript and others. None of them is accurate against experienced users, but for most people they will be sufficient.&lt;/p&gt;

&lt;p&gt;Today I will show different approach to protecting images. It's a bit impractical due to high visitor's CPU usage but it works. The idea is to convert image into HTML table, where each image's pixel is one cell with corresponding colour.&lt;/p&gt;

&lt;p&gt;Project contains 3 parts: script, HTML template and CSS file. Script requires as an argument location of the input image. As an output it generate output.html file, fro viewing it it must be stored in the same location as inline_image.css file.&lt;/p&gt;

&lt;p&gt;You may download sources (directory &lt;strong&gt;image2table&lt;/strong&gt;) by cloning &lt;strong&gt;git@github.com:RobertGawron/snippets.git&lt;/strong&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-8331605225272409139?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/8331605225272409139/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/01/protecting-images-against-saving.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8331605225272409139'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8331605225272409139'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/01/protecting-images-against-saving.html' title='Protecting images against saving'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-7230264019351204489</id><published>2011-01-02T05:32:00.000-08:00</published><updated>2011-02-19T10:05:46.365-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='image processing'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Making captcha easier to break</title><content type='html'>&lt;p&gt;Almost all sites use images with text, that user has to retype to prove, that he's a human not spambots. A lot of those images (called captcha) contains small lines, dots and other noises to make theirs analyze more difficult for spambots. This noise may be easily removed which is the concept of this post.&lt;/p&gt;

&lt;p&gt;I used Python and its PIL library for processing captchas. First step is to transform image to grey-scale (this made further work easier) and blur it. Blur image makes small objects, theirs edges less visible. PIL's blur filter is a bit poor for that, but SMOTH filter works great (but it need to be taken twice on image to made it enough blurred). Next step is to check all pixels if their value is higher that some certain constant, if yes, then pixels will become white, if not they will be black. This constant may be set from command line.&lt;/p&gt;

&lt;p&gt;Bellow is example how to use script (first argument is path to image, second is mentioned constant), some samples of usage and source code.&lt;/p&gt;

&lt;pre&gt;rgawron@vk1004:~/noiseReduction$ python noise.py captcha2.jpg 90&lt;/pre&gt;


&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_gcjDBIrbvyw/TSCELa9EaxI/AAAAAAAAAbY/lfVpFcg_Z24/s1600/captcha1.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 100px; height: 25px;" src="http://4.bp.blogspot.com/_gcjDBIrbvyw/TSCELa9EaxI/AAAAAAAAAbY/lfVpFcg_Z24/s320/captcha1.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5557587271924083474" /&gt;&lt;/a&gt;

pass_factor = 100

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_gcjDBIrbvyw/TSCELTFZIrI/AAAAAAAAAbg/hrBasQ8i50c/s1600/out_captcha1.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 100px; height: 25px;" src="http://1.bp.blogspot.com/_gcjDBIrbvyw/TSCELTFZIrI/AAAAAAAAAbg/hrBasQ8i50c/s320/out_captcha1.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5557587269811511986" /&gt;&lt;/a&gt;




&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_gcjDBIrbvyw/TSCELrrWiQI/AAAAAAAAAbo/SwbantVUk4c/s1600/captcha2.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 100px; height: 25px;" src="http://3.bp.blogspot.com/_gcjDBIrbvyw/TSCELrrWiQI/AAAAAAAAAbo/SwbantVUk4c/s320/captcha2.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5557587276413176066" /&gt;&lt;/a&gt;

pass_factor = 90

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_gcjDBIrbvyw/TSCEL19u3lI/AAAAAAAAAbw/k5En7Sw_fUU/s1600/out_captcha2.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 100px; height: 25px;" src="http://4.bp.blogspot.com/_gcjDBIrbvyw/TSCEL19u3lI/AAAAAAAAAbw/k5En7Sw_fUU/s320/out_captcha2.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5557587279174622802" /&gt;&lt;/a&gt;




&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_gcjDBIrbvyw/TSCEh9islNI/AAAAAAAAAcI/O_HHJH-Zk0M/s1600/captcha4.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 80px; height: 20px;" src="http://2.bp.blogspot.com/_gcjDBIrbvyw/TSCEh9islNI/AAAAAAAAAcI/O_HHJH-Zk0M/s320/captcha4.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5557587659165832402" /&gt;&lt;/a&gt;

pass_factor = 100

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_gcjDBIrbvyw/TSCEiHhh7HI/AAAAAAAAAcQ/SojSH89bvMg/s1600/out_captcha4.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 80px; height: 20px;" src="http://4.bp.blogspot.com/_gcjDBIrbvyw/TSCEiHhh7HI/AAAAAAAAAcQ/SojSH89bvMg/s320/out_captcha4.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5557587661845294194" /&gt;&lt;/a&gt;






&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_gcjDBIrbvyw/TSCELySX6rI/AAAAAAAAAb4/C9XPpqtZLog/s1600/captcha3.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 80px; height: 30px;" src="http://1.bp.blogspot.com/_gcjDBIrbvyw/TSCELySX6rI/AAAAAAAAAb4/C9XPpqtZLog/s320/captcha3.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5557587278187457202" /&gt;&lt;/a&gt;

pass_factor = 130

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_gcjDBIrbvyw/TSCEhxnG-YI/AAAAAAAAAcA/3-S2VMtvCcE/s1600/out_captcha3.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 80px; height: 30px;" src="http://4.bp.blogspot.com/_gcjDBIrbvyw/TSCEhxnG-YI/AAAAAAAAAcA/3-S2VMtvCcE/s320/out_captcha3.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5557587655963113858" /&gt;&lt;/a&gt;

&lt;pre&gt;
import sys
import Image
import ImageFilter

def prepare_image(img):
    &amp;quot;&amp;quot;&amp;quot;Transform image to greyscale and blur it&amp;quot;&amp;quot;&amp;quot;
    img = img.filter(ImageFilter.SMOOTH_MORE)
    img = img.filter(ImageFilter.SMOOTH_MORE)
    if 'L' != img.mode:
        img = img.convert('L')
    return img

def remove_noise(img, pass_factor):
    for column in range(img.size[0]):
        for line in range(img.size[1]):
            value = remove_noise_by_pixel(img, column, line, pass_factor)
            img.putpixel((column, line), value)
    return img

def remove_noise_by_pixel(img, column, line, pass_factor):
    if img.getpixel((column, line)) &amp;lt; pass_factor:
        return (0)
    return (255)


if __name__==&amp;quot;__main__&amp;quot;:
    input_image = sys.argv[1]
    output_image = 'out_' + input_image
    pass_factor = int(sys.argv[2])

    img = Image.open(input_image)
    img = prepare_image(img)
    img = remove_noise(img, pass_factor)
    img.save(output_image)
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-7230264019351204489?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/7230264019351204489/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2010/11/almost-all-sites-use-images-with-text.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/7230264019351204489'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/7230264019351204489'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2010/11/almost-all-sites-use-images-with-text.html' title='Making captcha easier to break'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_gcjDBIrbvyw/TSCELa9EaxI/AAAAAAAAAbY/lfVpFcg_Z24/s72-c/captcha1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-2530653552321734195</id><published>2011-01-02T02:30:00.000-08:00</published><updated>2011-02-19T10:03:14.919-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='crappy code'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><title type='text'>Nasty code #1, copy content of structure</title><content type='html'>&lt;p&gt;There is instance (let's call it p0) of structure, we create new instance (p1) of the same structure and want to copy content of fields from p0 to p1.&lt;/p&gt;

&lt;p&gt;The simplest (IMHO also the best) way is to copy field by field. It's presented in following code (in case of p1 all fields are copied, in case of p2 only some).&lt;/p&gt;

&lt;pre&gt;
/* output: 
foo (3.800000, 4.900000): #121212
bar (3.800000, 4.900000): #335566
*/
#include &amp;lt;stdlib.h&amp;gt;

struct Point {
    char desc[5];
    double x, y;
    char color[8];
};

int main() {
    struct Point p0 = {.desc = &amp;quot;foo&amp;quot;, .x = 3.8, .y = 4.9, .color = &amp;quot;#121212&amp;quot;};

    struct Point p1;
    snprintf(p1.desc, sizeof(p1.desc), p0.desc);
    p1.x = p0.x;
    p1.y = p0.y;
    snprintf(p1.color, sizeof(p1.color), p0.color);
    printf(&amp;quot;%s (%f, %f): %s\n&amp;quot;, p1.desc, p1.x, p1.y, p1.color);

    struct Point p2;
    snprintf(p2.desc, sizeof(p2.desc), &amp;quot;bar&amp;quot;);
    p2.x = p0.x;
    p2.y = p0.y;
    snprintf(p2.color, sizeof(p2.color), &amp;quot;#335566&amp;quot;);
    printf(&amp;quot;%s (%f, %f): %s\n&amp;quot;, p2.desc, p2.x, p2.y, p2.color);

    return EXIT_SUCCESS;
}

&lt;/pre&gt;

&lt;p&gt;Second way is use memcpy to copy content of memory allocated for p0 directly into p1. It's presented in next snippet.&lt;/p&gt;

&lt;pre&gt;/* output: 
foo (3.800000, 4.900000): #121212
bar (3.800000, 4.900000): #335566
*/
#include &amp;lt;stdlib.h&amp;gt;

struct Point {
    char desc[5];
    double x, y;
    char color[8];
};

int main() {
    struct Point p0 = {.desc = &amp;quot;foo&amp;quot;, .x = 3.8, .y = 4.9, .color = &amp;quot;#121212&amp;quot;};

    struct Point p1;
    memcpy(&amp;amp;p1, &amp;amp;p0, sizeof(p0));
    printf(&amp;quot;%s (%f, %f): %s\n&amp;quot;, p1.desc, p1.x, p1.y, p1.color);

    struct Point p2;
    snprintf(p2.desc, sizeof(p2.desc), &amp;quot;bar&amp;quot;);
    memcpy(&amp;amp;p2.x, &amp;amp;p0.x, sizeof(p2.x) + sizeof(p2.y));
    snprintf(p2.color, sizeof(p2.color), &amp;quot;#335566&amp;quot;);
    printf(&amp;quot;%s (%f, %f): %s\n&amp;quot;, p2.desc, p2.x, p2.y, p2.color);

    return EXIT_SUCCESS;
}

&lt;/pre&gt;
&lt;p&gt;For me second way is really tricky ;)&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-2530653552321734195?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/2530653552321734195/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2011/01/nasty-code-1-copy-content-of-structure.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/2530653552321734195'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/2530653552321734195'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2011/01/nasty-code-1-copy-content-of-structure.html' title='Nasty code #1, copy content of structure'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-2167518066357773549</id><published>2010-12-30T12:51:00.000-08:00</published><updated>2011-02-19T10:02:24.765-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='electronic'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='Haskell'/><title type='text'>Displaying text files in old mp3 player</title><content type='html'>&lt;p&gt;Creative MuVo is an old mp3 player, that has a small monochromatic display but normally is unable to display any files on it. The trick I used here to force it to do that is to use its ability to show lyrics for songs.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_gcjDBIrbvyw/TRzx9iRlh6I/AAAAAAAAAbA/q8ginMu6POc/s1600/player_normal.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 166px;" src="http://2.bp.blogspot.com/_gcjDBIrbvyw/TRzx9iRlh6I/AAAAAAAAAbA/q8ginMu6POc/s320/player_normal.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5556582079743231906" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_gcjDBIrbvyw/TRzx97W0UzI/AAAAAAAAAbI/NfHEuP_gyPM/s1600/player_text1.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 146px;" src="http://2.bp.blogspot.com/_gcjDBIrbvyw/TRzx97W0UzI/AAAAAAAAAbI/NfHEuP_gyPM/s320/player_text1.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5556582086476059442" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_gcjDBIrbvyw/TRzx-DlWirI/AAAAAAAAAbQ/tHLamtXBRds/s1600/player_text2.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 144px;" src="http://1.bp.blogspot.com/_gcjDBIrbvyw/TRzx-DlWirI/AAAAAAAAAbQ/tHLamtXBRds/s320/player_text2.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5556582088684505778" /&gt;&lt;/a&gt;

&lt;p&gt;Following simple script in Haskell takes as input path to text file, that should be displayed and path to mp3 file stored on mp3 player. As an output it produces lyric file that can be read by player.&lt;/p&gt;

&lt;p&gt;Lyric file generated by script needs to be copied to LRC directory on player, this may be simplified by first putting script in mentioned directory (player doesn't complain about that).&lt;/p&gt;

source:

&lt;pre&gt;import System.Environment
import System.IO
import Control.Exception
import System.FilePath.Posix

main = do
    args &amp;lt;- getArgs
    let sourceFile : mp3File: _ = args
    let lrcFile = (takeBaseName (takeFileName mp3File)) ++ ".lrc"
    bracket (openFile sourceFile ReadMode) hClose 
        (\hIn -&amp;gt; 
            bracket (openFile lrcFile WriteMode) hClose 
                (\hOut -&amp;gt; parseMe hIn hOut 0))
    return()

parseMe :: Handle -&amp;gt; Handle -&amp;gt; Integer -&amp;gt; IO()
parseMe hIn hOut time = do
    isEOF &amp;lt;- hIsEOF hIn
    if isEOF then return() else do
        line &amp;lt;- hGetLine hIn
        let secs' = mod time 60
            mins' = div time 60
            -- we neeed time in form [mm:ss], that's why we add zeros
            secs = (if secs' &amp;lt; 10 then "0" else "") ++ show(secs')
            mins = (if mins' &amp;lt; 10 then "0" else "") ++ show(mins') 
            in hPutStrLn hOut ("[" ++ mins ++ ":" ++ secs ++ "]" ++ line)
        parseMe hIn hOut (time + 4)

&lt;/pre&gt;

example of output file:

&lt;pre&gt;[00:00]
[00:04]/*
[00:08] * Copyright (C) Igor Sysoev
[00:12] */
[00:16]
[00:20]
[00:24]#ifndef _NGX_OS_H_INCLUDED_
[00:28]#define _NGX_OS_H_INCLUDED_
[00:32]
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-2167518066357773549?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/2167518066357773549/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2010/12/displaying-text-files-in-old-mp3-player.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/2167518066357773549'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/2167518066357773549'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2010/12/displaying-text-files-in-old-mp3-player.html' title='Displaying text files in old mp3 player'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_gcjDBIrbvyw/TRzx9iRlh6I/AAAAAAAAAbA/q8ginMu6POc/s72-c/player_normal.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-8320800830362354878</id><published>2010-12-26T03:28:00.000-08:00</published><updated>2011-02-19T09:56:20.972-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='electronic'/><title type='text'>Making a robot, part 1</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_gcjDBIrbvyw/TRdydqta5QI/AAAAAAAAAZo/DUPInVWwLgs/s1600/back.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 276px;" src="http://2.bp.blogspot.com/_gcjDBIrbvyw/TRdydqta5QI/AAAAAAAAAZo/DUPInVWwLgs/s320/back.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5555034519391364354" /&gt;&lt;/a&gt;

&lt;p&gt;I tried many times in past to build a simple robot, but I always stuck in making mechanical part. This time I tried to divide this task into parts in hope, that it will make it easier and more modular. In this post I will describe a simple chassis with engine, that can only move forward and backward. Following materials and tools are needed:&lt;/p&gt;

&lt;ul&gt;
 &lt;li&gt;battery car&lt;/li&gt;
 &lt;li&gt;2x CD&lt;/li&gt;
 &lt;li&gt;laminate and plastic&lt;/li&gt;
 &lt;li&gt;power drill&lt;/li&gt;
 &lt;li&gt;screws and caps&lt;/li&gt;
 &lt;li&gt;hand saw for metals&lt;/li&gt;
 &lt;li&gt;ruler and pencil&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I detached engine from battery car, then by using ruler and pencil I designed chassis, then I cut it in laminate by using saw and drill. Engine was mounted into chassis by screws, then I attached CDs to wheels from car and inserted them back into engine.&lt;/p&gt;

&lt;p&gt;Construction is primitive but it's easy to build and may be used as a fast base for further projects. Bellow you may see pictures, how it was build.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_gcjDBIrbvyw/TRdyhByXcBI/AAAAAAAAAZw/QZwZko0pXu8/s1600/chassis.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 114px;" src="http://1.bp.blogspot.com/_gcjDBIrbvyw/TRdyhByXcBI/AAAAAAAAAZw/QZwZko0pXu8/s320/chassis.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5555034577125732370" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_gcjDBIrbvyw/TRdyndouRrI/AAAAAAAAAaA/QXg_dIOjsQs/s1600/wheels.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_gcjDBIrbvyw/TRdyndouRrI/AAAAAAAAAaA/QXg_dIOjsQs/s320/wheels.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5555034687680693938" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_gcjDBIrbvyw/TRdykReN4VI/AAAAAAAAAZ4/g3OxRT_7F0s/s1600/front.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 306px;" src="http://4.bp.blogspot.com/_gcjDBIrbvyw/TRdykReN4VI/AAAAAAAAAZ4/g3OxRT_7F0s/s320/front.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5555034632875794770" /&gt;&lt;/a&gt;




&lt;div class="youtube"&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/GSUTBU5QYfo&amp;hl=en&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/GSUTBU5QYfo&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-8320800830362354878?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/8320800830362354878/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2010/12/i-tried-many-times-in-past-to-build.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8320800830362354878'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8320800830362354878'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2010/12/i-tried-many-times-in-past-to-build.html' title='Making a robot, part 1'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_gcjDBIrbvyw/TRdydqta5QI/AAAAAAAAAZo/DUPInVWwLgs/s72-c/back.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-8100056396375263221</id><published>2010-12-25T11:40:00.001-08:00</published><updated>2011-02-19T09:57:56.332-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='chemistry'/><title type='text'>Homemade gas burner for chemical experiments</title><content type='html'>&lt;p&gt;A lot of chemical reactions require heating reagents by using some kind of burner, but when I made may first experiments I didn't have money or access to such tools. I built my own burner, it quite successful concept, in this post I will describe, how to build it. It's really important to be careful here, because leaky or wrong made &lt;strong&gt;burner may explode!&lt;/strong&gt; Following materials will be needed:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;gas igniter for gas-stove, only those with theirs own gas container may be used&lt;/li&gt;
    &lt;li&gt;silicon glue&lt;/li&gt;
    &lt;li&gt;metal lid from jar&lt;/li&gt;
    &lt;li&gt;telescopic antenna or thin metal pipe&lt;/li&gt;
    &lt;li&gt;glue tape&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From igniter I took plastic pipe and gas container. Next I cut from antenna a short pipe, in lid I made two holes, and I put in one of them pipe. To made it tight I used glue, next I used tape to place gas container in place. Gas goes from container, through plastic pipe and metal pipe.&lt;/p&gt;

&lt;p&gt;To use it I push valve build into container and put fire into end of metal pipe. You may see, how it works on below video.&lt;/p&gt;

&lt;div class="youtube"&gt;&lt;object width="480" height="385"&gt;&lt;param name="movie" value="http://www.youtube.com/v/uifMQ6QPepE?fs=1&amp;amp;hl=pl_PL"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/uifMQ6QPepE?fs=1&amp;amp;hl=pl_PL" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-8100056396375263221?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/8100056396375263221/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2010/12/homemade-gas-burner-for-chemical.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8100056396375263221'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8100056396375263221'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2010/12/homemade-gas-burner-for-chemical.html' title='Homemade gas burner for chemical experiments'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-8913129261560981158</id><published>2010-12-25T10:53:00.000-08:00</published><updated>2011-02-19T10:05:46.366-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='image processing'/><category scheme='http://www.blogger.com/atom/ns#' term='electronic'/><title type='text'>Cheap camera as a night vision device</title><content type='html'>&lt;p&gt;Not many people know, that regular camera can be used as night vision device because it's able to take pictures in &lt;a href="http://en.wikipedia.org/wiki/Infrared"&gt;infra-red spectrum&lt;/a&gt;. If scenery will be lighted by source of those rays, for human eyes it will be dark, but camera will be able to take pictures.&lt;/p&gt;

&lt;p&gt;Sensitivity to IR rays depends on many factors, from manufacturer, model. I tried with poor results SONY and Kodak cameras, but cheap mp4-player worked great. IMO it's because  because better equipment comes with &lt;a href="http://en.wikipedia.org/wiki/Infrared_photography"&gt;infrared blockers&lt;/a&gt;. Bellow picture describes, how this experiment works.&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_gcjDBIrbvyw/TRZAsuZGpaI/AAAAAAAAAY8/nMv-JPcV-XU/s1600/night-vision-howto.jpeg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 214px;" src="http://1.bp.blogspot.com/_gcjDBIrbvyw/TRZAsuZGpaI/AAAAAAAAAY8/nMv-JPcV-XU/s320/night-vision-howto.jpeg" border="0" alt=""id="BLOGGER_PHOTO_ID_5554698327519831458" /&gt;&lt;/a&gt;
  
&lt;p&gt;The easiest source of infra red rays I could find was &lt;a href="http://en.wikipedia.org/wiki/Remote_control"&gt;pilot remote control&lt;/a&gt;, but it could be also made with a couple of inexpensive IR diodes. Here are some pictures (original and computer treatment).&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_gcjDBIrbvyw/TRY_EzsxyBI/AAAAAAAAAYk/7uPaLsf0_mE/s1600/a-before.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 222px;" src="http://1.bp.blogspot.com/_gcjDBIrbvyw/TRY_EzsxyBI/AAAAAAAAAYk/7uPaLsf0_mE/s320/a-before.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5554696542238132242" /&gt;&lt;/a&gt;


&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_gcjDBIrbvyw/TRY_jCX2GOI/AAAAAAAAAYs/FQf-RJxeG4M/s1600/a-after.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 225px;" src="http://3.bp.blogspot.com/_gcjDBIrbvyw/TRY_jCX2GOI/AAAAAAAAAYs/FQf-RJxeG4M/s320/a-after.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5554697061572942050" /&gt;&lt;/a&gt;


&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_gcjDBIrbvyw/TRdzgpdQCgI/AAAAAAAAAaQ/q7M7YCEpuHY/s1600/b-original.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://4.bp.blogspot.com/_gcjDBIrbvyw/TRdzgpdQCgI/AAAAAAAAAaQ/q7M7YCEpuHY/s320/b-original.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5555035670106343938" /&gt;&lt;/a&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_gcjDBIrbvyw/TRdzdK-SvOI/AAAAAAAAAaI/iPLtHqArN74/s1600/b-after.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 221px;" src="http://4.bp.blogspot.com/_gcjDBIrbvyw/TRdzdK-SvOI/AAAAAAAAAaI/iPLtHqArN74/s320/b-after.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5555035610383826146" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-8913129261560981158?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/8913129261560981158/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2010/12/cheap-camera-as-night-vision-device.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8913129261560981158'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/8913129261560981158'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2010/12/cheap-camera-as-night-vision-device.html' title='Cheap camera as a night vision device'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_gcjDBIrbvyw/TRZAsuZGpaI/AAAAAAAAAY8/nMv-JPcV-XU/s72-c/night-vision-howto.jpeg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3218008772058347246.post-6625659764629289318</id><published>2010-12-25T05:17:00.000-08:00</published><updated>2011-02-19T10:03:14.920-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='riddle'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='C/C++'/><category scheme='http://www.blogger.com/atom/ns#' term='Haskell'/><title type='text'>[Riddle] simulation of behaviors in population</title><content type='html'>&lt;p&gt;There are things, that aren’t interesting because they are complicated but because they have simple solutions. Today I will present one of those riddles, that comes from the book "THE SELFISH GENE" by Richard Dawkins. You can find there more of such stuff and all is presented from biological point of view, far away from informatics.&lt;/p&gt;

&lt;p&gt;Consider this problem: in population, in given situation, species may behave in two ways: as a fighter or as a coward. Fighter always wins fight with coward. This behavior is set by a single gene, if a specie behave in a way that give him advantage, then he is in a better position and will have more descendants. For us it means, that his gene have better chance to spread in population.&lt;/p&gt;

&lt;p&gt;Assume, that species don’t remember behavior of other species and that they can’t predict it. Score function, that says, how profitable the behavior is will be needed – we will use arbitrary numbers, like in the book: let's attribute +50 points to win, 0 to fail, -10 to waisting time, -100 for serious damage.&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;Coward&lt;/strong&gt; meets &lt;strong&gt;Coward&lt;/strong&gt;, the winner gets +50 points, both of them get -10 points for waisting time (they could do something valuable instead). Those -10 points are here, because cowards waist time on trying to make their opponents scary, if they can't do that they run away,&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Coward&lt;/strong&gt; meets &lt;strong&gt;Fighter&lt;/strong&gt;, the winner gets 50 points, the looser gets 0 points, as we said, fighter always wins with coward,&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Fighter&lt;/strong&gt; meets &lt;strong&gt;Fighter&lt;/strong&gt;, the winner gets 50 points, the looser gets -100 points for a serious damage.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At the beginning there are only cowards - nothing interesting for us. When fighter (obviously a mutant) appears in population, then he is in a privileged position, his genes spreads quickly. Situation changes when fighters become dominant part in the population, then it’s much better to be a coward. At first it looks like amount of fighters and cowards will changes periodically. In fact it will go into a stable ratio (there is a lot of math here, but it’s not important here). The goal is to display at each generation the percentage of cowards and fighters in population (this should sum to 100% ofc). There is a given number of generations to show and initial generation (again in a form of percentages of cowards and fighters).&lt;/p&gt;

&lt;pre&gt;We will use following notations:
s&lt;sub&gt;f&lt;/sub&gt; – score of all fighters in generation
s&lt;sub&gt;c&lt;/sub&gt; – score of all cowards in generation
p&lt;sub&gt;f&lt;/sub&gt; – percentage of fighters in generation
p&lt;sub&gt;c&lt;/sub&gt; – percentage of cowards in generation&lt;/pre&gt;

Score function may be described as:
&lt;pre&gt;s&lt;sub&gt;f&lt;/sub&gt; = (-25 * p&lt;sub&gt;c&lt;/sub&gt;) + (50 * p&lt;sub&gt;f&lt;/sub&gt;)
s&lt;sub&gt;c&lt;/sub&gt; = (15 * p&lt;sub&gt;c&lt;/sub&gt;) + (0 * p&lt;sub&gt;f&lt;/sub&gt;)&lt;/pre&gt;

&lt;p&gt;As we will see later, it would be better if values of s&lt;sub&gt;f&lt;/sub&gt; and s&lt;sub&gt;c&lt;/sub&gt; would be non negative. We will be also interested rather in ratios that in concrete values, so we may add constant value to both equations:&lt;/p&gt;

&lt;pre&gt;s&lt;sub&gt;f&lt;/sub&gt; = 25 + (-25 * p&lt;sub&gt;c&lt;/sub&gt;) + (50 * p&lt;sub&gt;f&lt;/sub&gt;)
s&lt;sub&gt;c&lt;/sub&gt; = 25 + (15 * p&lt;sub&gt;c&lt;/sub&gt;) + (0 * p&lt;sub&gt;f&lt;/sub&gt;)&lt;/pre&gt;

&lt;p&gt;Now percentage of cowards and fighters in next generation may be counted simply:&lt;/p&gt;

&lt;pre&gt;p&lt;sub&gt;f&lt;/sub&gt; = s&lt;sub&gt;f&lt;/sub&gt; / (s&lt;sub&gt;f&lt;/sub&gt; + s&lt;sub&gt;c&lt;/sub&gt;)
p&lt;sub&gt;c&lt;/sub&gt; = s&lt;sub&gt;c&lt;/sub&gt; / (s&lt;sub&gt;f&lt;/sub&gt; + s&lt;sub&gt;c&lt;/sub&gt;)&lt;/pre&gt;

Bellow are implementations in C and in Haskell.

&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

int main() {
    double pg = 0.9, pj = 0.1;

    const unsigned iters = 20;
    unsigned i;

    for (i=0; i&amp;lt;iters; i++) {
        printf(&amp;quot;pg: %1.2f pg: %1.2f\n&amp;quot;, pg, pj);

        double zg = 25 + (15 * pg) + (0 * pj);
        double zj = 25 + (-25 * pg) + (50 * pj);

        pg = zg / (zg+zj);
        pj = zj / (zg+zj);

    }

    return EXIT_SUCCESS;
}

&lt;/pre&gt;

&lt;pre&gt;main = generate (0.9, 0.1) 20

generate _ 0 = putStr ""
generate (pc, pf) iterations = do
                putStrLn ("pc: " ++ (show pc) ++ ", pf: " ++ (show pf))
                generate (new_pc, new_pf) (iterations-1) where
                                new_pc = sc / (sc + sf)
                                new_pf = sf / (sc + sf)
                                sc = 25 + (15 * pc) + (0 * pf)
                                sf = 25 + (-25 * pc) + (50 * pf)
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3218008772058347246-6625659764629289318?l=robertgawron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://robertgawron.blogspot.com/feeds/6625659764629289318/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://robertgawron.blogspot.com/2010/12/xxx.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/6625659764629289318'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3218008772058347246/posts/default/6625659764629289318'/><link rel='alternate' type='text/html' href='http://robertgawron.blogspot.com/2010/12/xxx.html' title='[Riddle] simulation of behaviors in population'/><author><name>RobertG</name><uri>http://www.blogger.com/profile/10392172189489700514</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
