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

<channel>
	<title>Creyn</title>
	<atom:link href="http://blog.creyn.pl/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.creyn.pl</link>
	<description>Programmer&#039;s notes</description>
	<lastBuildDate>Mon, 22 Aug 2016 07:00:21 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.38</generator>
	<item>
		<title>Invite your friends to your Facebook fanpage like a Dev</title>
		<link>http://blog.creyn.pl/2016/08/22/invite-your-friends-to-your-facebook-fanpage-like-a-dev/</link>
		<comments>http://blog.creyn.pl/2016/08/22/invite-your-friends-to-your-facebook-fanpage-like-a-dev/#comments</comments>
		<pubDate>Mon, 22 Aug 2016 07:00:21 +0000</pubDate>
		<dc:creator><![CDATA[creyn]]></dc:creator>
				<category><![CDATA[Around dev world]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.creyn.pl/?p=509</guid>
		<description><![CDATA[In this post I will show you a very easy way to invite all of your Facebook friends to like your Facebook fanpage. This is a little hack that will require some source code analyzing and dev skills. But after all, this is extremely easy. After I created the Facebook fanpage for this blog (you...]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">In this post I will show you a very easy way to invite all of your Facebook friends to like your Facebook fanpage. This is a little hack that will require some source code analyzing and dev skills. But after all, this is extremely easy.</p>
<p style="text-align: justify;"><span id="more-509"></span></p>
<p style="text-align: justify;">After I created the Facebook fanpage for this blog (you can find it here: <a href="https://facebook.com/creynblog/" target="_blank">https://facebook.com/creynblog/</a>) I decided that I want to invite all of my friends to like it. I wanted them all to join me on my path as a blogger. But the default &#8220;Facebook way&#8221; is to click them one by one on the <strong>&#8220;Invite&#8221;</strong> button next to the photo. And I had a lot of friends (222). So I decided that I will use my dev skills.</p>
<p style="text-align: justify;"><div class='warning2'></p>
<p style="text-align: justify;">If you want to follow, please have in mind that this is not an official method and it worked on 2016-06-14 and maybe it isn&#8217;t working when you are reading this. This is more advanced stuff and you are doing it at your own risk.</p>
<p style="text-align: justify;"></div></p>
<p style="text-align: justify;">So first, go to the Facebook fanpage <strong>&#8220;Invite Friends&#8221;</strong> section:</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-586" src="http://blog.creyn.pl/wp-content/uploads/2016/08/f1.png" alt="f1" width="280" height="284" /></p>
<p style="text-align: justify;">Then you will see the list of your friends. Exactly 100 of your friends. So you have to scroll the list to the very bottom and as you will be doing this, you will notice that more of them are showing. So please scroll to the very bottom of the list (to have all of your friends shown). Next let&#8217;s see under the hood. I am using Chrome browser for this. So right click on the <strong>&#8220;Invite&#8221;</strong> button and choose something like <strong>&#8220;Inspect element&#8221;</strong>. The new window should open and then you can find the source code of the button:</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-587" src="http://blog.creyn.pl/wp-content/uploads/2016/08/f3.png" alt="f3" width="404" height="93" /></p>
<p style="text-align: justify;">You can see that the button has a class attribute called &#8220;<strong>uiButton</strong>&#8220;. So we can select all of the buttons using javasctipt. Open the <strong>Console</strong> tab and now you can execute some code in the context of the website. Quick look at the documentation (<a href="https://developer.chrome.com/devtools/docs/console#selecting-elements" target="_blank">https://developer.chrome.com/devtools/docs/console#selecting-elements</a>) and we can see that to get all elements with specific class we should use the &#8220;$$()&#8221; function. It will give us an array of all buttons that we want to click. So if we count them we should get number of our friends. In my case there was 218, so 4 of my friends were missing. Probably there is some &#8220;don&#8217;t invite me to the fanpage&#8221; option that they selected.</p>
<p style="text-align: justify;">And now the final step. We could execute a &#8220;clicking&#8221; action on each button. It would be exactly like we were clicking all of them manually. This is done by following script:</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-588" src="http://blog.creyn.pl/wp-content/uploads/2016/08/f4.png" alt="f4" width="281" height="25" /></p>
<p style="text-align: justify;">And after just about 1 second (on Chrome browser) all of my friends were spammed with my invitation and I was so happy seeing them accepting the invitation :)</p>
<p style="text-align: justify;">C.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.creyn.pl/2016/08/22/invite-your-friends-to-your-facebook-fanpage-like-a-dev/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Postman: framework for testing API</title>
		<link>http://blog.creyn.pl/2016/06/27/postman-framework-for-testing-api/</link>
		<comments>http://blog.creyn.pl/2016/06/27/postman-framework-for-testing-api/#comments</comments>
		<pubDate>Mon, 27 Jun 2016 06:00:51 +0000</pubDate>
		<dc:creator><![CDATA[creyn]]></dc:creator>
				<category><![CDATA[Programmer's notes]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Postman]]></category>
		<category><![CDATA[tests]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://blog.creyn.pl/?p=531</guid>
		<description><![CDATA[Few times in the past I had to do some testing on my APIs. I needed very simple way to easily call different HTTP method like POST or PUT with some specific custom HTTP Headers. I have used a few tools for this but all of them seem to have some minor or major issues...]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">Few times in the past I had to do some testing on my APIs. I needed very simple way to easily call different HTTP method like POST or PUT with some specific custom HTTP Headers. I have used a few tools for this but all of them seem to have some minor or major issues that I don&#8217;t like. For a while I thought that the <strong>&#8220;<a href="https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo" target="_blank">Advanced Rest Client</a>&#8220;</strong> will be a winner. And everybody at my company were using it. But then it changed in a way that I needed something different. And that is how I found <strong>&#8220;Postman&#8221;</strong>.</p>
<p style="text-align: justify;">It is an extension for Chrome browser. Which is good when you don&#8217;t have permissions to install new software on production, but you can launch some browser extensions ;) The installation is very simple as every extension for Chrome. Just look for the &#8220;<strong>Postman</strong>&#8221; in the Chrome extension manager (<a href="https://chrome.google.com/webstore/" target="_blank">https://chrome.google.com/webstore/</a>) and then click <strong>&#8220;Add to Chrome&#8221;</strong>. It then will show in the Chrome Apps section (<strong>&#8220;chrome://apps/&#8221;</strong>) .</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-533" src="http://blog.creyn.pl/wp-content/uploads/2016/06/p_1.png" alt="_p_1" width="905" height="91" /></p>
<p style="text-align: justify;">After the first launch, you will have an option to create the <strong>&#8220;Postman&#8221;</strong> account. You can skip this step, but having the account will let you sync your test requests with other computers and even colaborate on them with your colleagues. I&#8217;ve choosen the <strong>&#8220;Sign Up with Google&#8221;</strong> option. Then, upon login, Google send me the confirmation SMS with a unique code and polish characters encoding error (so hey, encoding is hard, it happens to everybody ;)). The <strong>&#8220;Postman&#8221;</strong> requirements for my account are very simple and look ok for me, so I allowed it to do so.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-534" src="http://blog.creyn.pl/wp-content/uploads/2016/06/p_2.png" alt="_p_2" width="625" height="552" /></p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-535" src="http://blog.creyn.pl/wp-content/uploads/2016/06/p_3.png" alt="_p_3" width="452" height="214" /></p>
<p style="text-align: justify;"><strong>&#8220;Postman&#8221;</strong> started and I am connected to my account. In the main window, the upper part is the <strong>&#8220;Request&#8221;</strong> section. You can specify all parameters that you want to send, including headers.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-536" src="http://blog.creyn.pl/wp-content/uploads/2016/06/p_4.png" alt="_p_4" width="1264" height="614" /></p>
<p style="text-align: justify;">So let&#8217;s try if it works. In the <strong>&#8220;Enter request URL&#8221;</strong> please enter the <strong>&#8220;<a href="http://blog.creyn.pl" target="_blank">http://blog.creyn.pl</a>&#8220;</strong> and then click on <strong>&#8220;Send&#8221;</strong>. The bottom part of the screen is the <strong>&#8220;Response&#8221;</strong> section. There you can find: response time, response status, response body, cookies and headers. You can see that my blog homepage responded with success.</p>
<p style="text-align: justify;">I really recommend you to save your requests to a <strong>&#8220;Collection&#8221;</strong>, because even if all requests are saved into the <strong>&#8220;History&#8221;</strong> section (on the left), the collection will be usefull for us in the future. After clicking the <strong>&#8220;Save&#8221;</strong> button you will have to create a name for this request. It is also usefull to add some grouping to your requests. So I created a new one called <strong>&#8220;CreynBlog&#8221;</strong>. On the left part there is a <strong>&#8220;History / Collections&#8221;</strong> section and you can see the new request we just added and also some predefined <strong>&#8220;Postman Echo&#8221;</strong> collection. In this default collection you can find some very usefull examples of what can be done with the <strong>&#8220;Postman&#8221;</strong> tests, as this is actually a very nice test framework for your APIs.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-537" src="http://blog.creyn.pl/wp-content/uploads/2016/06/p_5.png" alt="_p_5" width="300" height="544" /><br />
So let&#8217;s pick the <strong>&#8220;Postman Echo &gt; Cookies &gt; Set Cookies&#8221;</strong> test request. This is a <strong>&#8220;GET&#8221;</strong> request to the <strong>&#8220;https://echo.getpostman.com/cookies/set?foo1=bar1&amp;foo2=bar&#8221;</strong> URL. The response from the server set cookies with the names specified in the URL. But what is interesting is the <strong>&#8220;Tests&#8221;</strong> tab in the <strong>&#8220;Request&#8221;</strong> section. You can find there a test case written in JavaScript. Tests are defined in an array called &#8220;tests&#8221; and the names are later shown on the <strong>&#8220;Tests&#8221;</strong> tab in the <strong>&#8220;Response&#8221;</strong> section. There are 4 tests defined and all passed successfully. This will be very usefull in testing our own APIs and I will show you later what we can do with it. And as it is JavaScript we can do a lot.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-538" src="http://blog.creyn.pl/wp-content/uploads/2016/06/p_6.png" alt="_p_6" width="950" height="529" /></p>
<p style="text-align: justify;">I said that having test requests saved in the <strong>&#8220;Collection&#8221;</strong> will be usefull. Now, when we have a collectoin full of test cases we can run them easilly. For that we will use the <strong>&#8220;Runner&#8221;</strong> which is located at the top left part of the window. It will start a new window and you can pick your test collections to run. I will go into details in the future.</p>
<p style="text-align: justify;">C.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.creyn.pl/2016/06/27/postman-framework-for-testing-api/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to create Facebook fanpage for your blog</title>
		<link>http://blog.creyn.pl/2016/06/19/how-to-create-facebook-fanpage-for-your-blog/</link>
		<comments>http://blog.creyn.pl/2016/06/19/how-to-create-facebook-fanpage-for-your-blog/#comments</comments>
		<pubDate>Sun, 19 Jun 2016 18:00:10 +0000</pubDate>
		<dc:creator><![CDATA[creyn]]></dc:creator>
				<category><![CDATA[Around dev world]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[Facebook]]></category>

		<guid isPermaLink="false">http://blog.creyn.pl/?p=503</guid>
		<description><![CDATA[In this short post I will show you how to create a fanpage for your blog (or any other website) on Facebook. In order to do this, you will have to have your own personal Facebook profile and then use it to create a fanpage. So please login to your personal profile on Facebook and...]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">In this short post I will show you how to create a fanpage for your blog (or any other website) on Facebook. In order to do this, you will have to have your own personal Facebook profile and then use it to create a fanpage. So please login to your personal profile on Facebook and go to the <a href="https://web.facebook.com/pages/create" target="_blank">https://web.facebook.com/pages/create</a> site.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-513" src="http://blog.creyn.pl/wp-content/uploads/2016/06/FB_1.png" alt="FB_1" width="880" height="612" /></p>
<p style="text-align: justify;">The first step is to choose the type for the new fanpage. For blog use the &#8220;<strong>Brand or Produc</strong>t&#8221; and then &#8220;<strong>Website</strong>&#8220;. You will have to pick a name and after clicking &#8220;<strong>Get started</strong>&#8221; the fanpage will be created.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-515" src="http://blog.creyn.pl/wp-content/uploads/2016/06/FB_2.png" alt="FB_2" width="271" height="175" /></p>
<p style="text-align: justify;">Now you have to configure the URL of your website (in case of my blog it is: <a href="http://blog.creyn.pl" target="_blank">http://blog.creyn.pl</a>), short description and unique fanpage identifier. It will be used in the link of the fanpage. I wanted to choose &#8220;creyn&#8221; but it was already taken so I choose the &#8220;<strong>creynblog</strong>&#8220;. Now you can go directly to the fanpage of my blog by typing the &#8220;<a href="https://facebook.com/creynblog/" target="_blank">https://facebook.com/creynblog/&#8221;</a> in the browser.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-516" src="http://blog.creyn.pl/wp-content/uploads/2016/06/FB_3.png" alt="FB_3" width="664" height="415" /></p>
<p style="text-align: justify;">On next tab you have to setup the logo. I have to play with few of my old ones. The image should be square because Facebook will crop it otherwise. The problem is that each of the logos you&#8217;ll try will be saved on your timeline and will be visible to your fans. Fortunatelly you can delete them later in the &#8220;<strong>Photos</strong>&#8221; section.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-517" src="http://blog.creyn.pl/wp-content/uploads/2016/06/FB_4.png" alt="FB_4" width="610" height="374" /></p>
<p style="text-align: justify;">Next you can add your new fanpage to &#8220;<strong>Favourites</strong>&#8220;. I decided to do this because it is easier to go to fanpage by clicking on the link in the &#8220;<strong>Favourites</strong>&#8221; menu group. You can also skip this step.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-518" src="http://blog.creyn.pl/wp-content/uploads/2016/06/FB_5.png" alt="FB_5" width="606" height="350" />Next tab, the &#8220;<strong>Preferred Page Audience</strong>&#8221; is a big one. You can pick a location, age and even gender for who your fanpage will be presented. There are a lot of interests that you can choose from. Tooooo many for my taste. Really, it is overwhelming. But hey. This is Facebook, they know how to promote your content. So I spend some time to pick just the two that I find fit the best: &#8220;<strong>Computer programming</strong>&#8221; and &#8220;<strong>Photography</strong>&#8220;. Fortunatelly you can change it later (in the &#8220;<strong>Settings &gt; Preferred Page Audience</strong>&#8221; section of the fanpage).</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-519" src="http://blog.creyn.pl/wp-content/uploads/2016/06/FB_6.png" alt="FB_6" width="477" height="452" /></p>
<p style="text-align: justify;">And this is it. Your new Facebook fanpage is created and configured. Of course you can tweek it later and the number of available settings is huge. Yoy can now explore it and spend some time getting familiar with how it works. Please go and have fun with it :)</p>
<p style="text-align: justify;">I am inviting you to go to my fanpage here: <a href="https://facebook.com/creynblog/" target="_blank">https://facebook.com/creynblog/</a>. I would be honored if you like my fanpage, please say hallo and comment that you came directly from the blog :)</p>
<p align="center"><iframe width="340" height="214" style="border: none; overflow: hidden;" src="https://www.facebook.com/plugins/page.php?href=https%3A%2F%2Fwww.facebook.com%2Fcreynblog%2F&amp;tabs&amp;width=340&amp;height=214&amp;small_header=false&amp;adapt_container_width=true&amp;hide_cover=false&amp;show_facepile=true&amp;appId" scrolling="no" frameborder="0" allowtransparency="true"></iframe></p>
<p style="text-align: justify;">C.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.creyn.pl/2016/06/19/how-to-create-facebook-fanpage-for-your-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to add Google Analytics to WordPress blog, part 2: configure blog</title>
		<link>http://blog.creyn.pl/2016/06/13/how-to-add-google-analytics-to-wordpress-blog-part-2-configure-blog/</link>
		<comments>http://blog.creyn.pl/2016/06/13/how-to-add-google-analytics-to-wordpress-blog-part-2-configure-blog/#comments</comments>
		<pubDate>Mon, 13 Jun 2016 21:00:39 +0000</pubDate>
		<dc:creator><![CDATA[creyn]]></dc:creator>
				<category><![CDATA[Around dev world]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[GoogleAnalytics]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.creyn.pl/?p=496</guid>
		<description><![CDATA[This is the second post from the series about adding the &#8220;Google Analytics&#8221; to the &#8220;WordPress&#8221; blog. In the first post (http://blog.creyn.pl/2016/06/07/how-to-add-google-analytics-to-wordpress-blog-part-1-registration/) we have registered to the &#8220;Google Analytics&#8221; service and acquired a new &#8220;Tracking ID&#8221; for our blog. Now we have to configure our blog to include that &#8220;Tracking ID&#8221; on every page that we want to have...]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">This is the second post from the series about adding the &#8220;<strong>Google Analytics</strong>&#8221; to the &#8220;<strong>WordPress</strong>&#8221; blog. In the first post (<a href="http://blog.creyn.pl/2016/06/07/how-to-add-google-analytics-to-wordpress-blog-part-1-registration/" target="_blank">http://blog.creyn.pl/2016/06/07/how-to-add-google-analytics-to-wordpress-blog-part-1-registration/</a>) we have registered to the &#8220;<strong>Google Analytics</strong>&#8221; service and acquired a new <strong>&#8220;Tracking ID&#8221; </strong>for our blog. Now we have to configure our blog to include that <strong>&#8220;Tracking ID&#8221;</strong> on every page that we want to have analytics on. This actually means that we will add it to all of our pages and posts.</p>
<p style="text-align: justify;">So let&#8217;s go to the second step: Configure blog with the Tracking ID.</p>
<h4 style="text-align: justify;">Step 2: Configure blog</h4>
<p style="text-align: justify;">In the first step, on the <strong>&#8220;Google Analytics&#8221;</strong> website (<a href="https://analytics.google.com/analytics/web/#management/Settings" target="_blank">https://analytics.google.com/analytics/web/#management/Settings</a> &gt; <strong>&#8220;Tracking Info&#8221;</strong> &gt; <strong>&#8220;Tracking Code&#8221;</strong>), right next to the <strong>&#8220;Tracking ID&#8221;</strong> we&#8217;ve found a <strong>&#8220;Tracking Script&#8221;</strong> that could be used to configure our blog.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-456" src="http://blog.creyn.pl/wp-content/uploads/2016/06/PK_6.png" alt="PK_6" width="894" height="273" /></p>
<p style="text-align: justify;"><div class='warning2'></p>
<p style="text-align: justify;">For blogs hosted on the <a href="https://wordpress.com/" target="_blank">https://wordpress.com/</a> there is an instruction how to enable the &#8220;<strong>Google Analytics</strong>&#8221; and how to properly configure it. You can find it here: <a href="https://en.support.wordpress.com/google-analytics/" target="_blank">https://en.support.wordpress.com/google-analytics/</a>.</p>
<p style="text-align: justify;"></div></p>
<p style="text-align: justify;">My blog is a so called &#8220;self hosted&#8221; version. This is an installation on a hosting platform that I paid for and have more controll over my blog. There are many ways to put the tracking code on every webpage. There are many plugins to do it. I decided to try a simple one that inserts snippets of source code in the header and the footer on each webpage. As I didn&#8217;t have it before, I had to install it from the <strong>&#8220;WordPress&#8221;</strong> plugins repository. If you want to follow, please go to the &#8220;<strong>Plugins &gt; Add New</strong>&#8221; section and look for the &#8220;<strong>Header and Footer</strong>&#8221; plugin. The search engine should return many similar plugins but this is the most popular one and has the 5 star score. After installing it, we can find it in the &#8220;<strong>Settings &gt; Header and Footer</strong>&#8221; section.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-458" src="http://blog.creyn.pl/wp-content/uploads/2016/06/PK_8.png" alt="PK_8" width="157" height="134" /></p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-459" src="http://blog.creyn.pl/wp-content/uploads/2016/06/PK_9.png" alt="PK_9" width="575" height="253" /></p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-460" src="http://blog.creyn.pl/wp-content/uploads/2016/06/PK_10.png" alt="PK_10" width="316" height="267" /></p>
<p style="text-align: justify;">From the screenshoot below you can see that it is very customizable and has many options for inserting snippets of code on dfferent pages. I&#8217;ve choosen the &#8220;<strong>&lt;HEAD&gt; Section Injection</strong>&#8221; which inserts code on <strong>&#8220;</strong><strong>Every&#8221;</strong> page of my blog.  Here you have to paste the auto generated <strong>&#8220;</strong><strong>Tracking Script&#8221;</strong> from the &#8220;<strong>Google Analytics</strong>&#8221; website.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-461" src="http://blog.creyn.pl/wp-content/uploads/2016/06/PK_11.png" alt="PK_11" width="760" height="332" /></p>
<p style="text-align: justify;">After this is done we could check if the setup is correct. First go to one of your blog posts and then open the &#8220;<strong>View page source</strong>&#8221; from the browser (you can press <strong>Ctrl+U</strong> on the keyboard, it should work in most browsers). You can now see that the script was succesfully inserted on my &#8220;<a href="http://blog.creyn.pl/2015/06/14/fog-in-warsaw/" target="_blank">Fog in Warsaw</a>&#8221; blog post.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-462" src="http://blog.creyn.pl/wp-content/uploads/2016/06/PK_12.png" alt="PK_12" width="638" height="248" /></p>
<p style="text-align: justify;">On the &#8220;<strong>Google Analytics</strong>&#8221; reporting page (here: <a href="https://analytics.google.com/analytics/web" target="_blank">https://analytics.google.com/analytics/web</a>) we can also see that the script is working and the statistics are send to Google. Please go to the &#8220;<strong>Reporting &gt; Real Time &gt; Conversions</strong>&#8220;. In my case there is already one visitor showing in this report.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-463" src="http://blog.creyn.pl/wp-content/uploads/2016/06/PK_13.png" alt="PK_13" width="586" height="427" /></p>
<p style="text-align: justify;">The reports in other reporting sections are shown with some delay and can not be shown from the very beginning. But it will be there tomorrow. Now we could start promote our blog posts and see which one is the most popular.</p>
<p style="text-align: justify;">To sum up, I already had the &#8220;<strong>Jetpack</strong>&#8221; plugin statistics for my &#8220;<strong>WordPress</strong>&#8221; blog but I have the feeling that they are very simple and I hope that the &#8220;<strong>Google Analytics</strong>&#8221; will give me much more insight into my visitors preferences. We&#8217;ll see. And as it turned out, adding GA to my blog was very easy.</p>
<p style="text-align: justify;">C.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.creyn.pl/2016/06/13/how-to-add-google-analytics-to-wordpress-blog-part-2-configure-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to add Google Analytics to WordPress blog, part 1: registration</title>
		<link>http://blog.creyn.pl/2016/06/07/how-to-add-google-analytics-to-wordpress-blog-part-1-registration/</link>
		<comments>http://blog.creyn.pl/2016/06/07/how-to-add-google-analytics-to-wordpress-blog-part-1-registration/#comments</comments>
		<pubDate>Tue, 07 Jun 2016 14:00:54 +0000</pubDate>
		<dc:creator><![CDATA[creyn]]></dc:creator>
				<category><![CDATA[Around dev world]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[GoogleAnalytics]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.creyn.pl/?p=437</guid>
		<description><![CDATA[In this short series of posts I will show you how to enable the &#8220;Google Analytics&#8221; statistics on your blog. I am writing about the &#8220;WordPress&#8221; blog but this could be easilly adopted for any other blog platform and static websites that you have. The &#8220;Google Analytics&#8220; is a platform that gives a very detailed insight in the...]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">In this short series of posts I will show you how to enable the &#8220;<strong>Google Analytics&#8221;</strong> statistics on your blog. I am writing about the <strong>&#8220;WordPress&#8221;</strong> blog but this could be easilly adopted for any other blog platform and static websites that you have. The &#8220;<strong>Google Analytics</strong><strong>&#8220;</strong> is a platform that gives a very detailed insight in the statistics of the traffic on a website. It is usefull to have more knowledge about your users, their preferences and which content of your blog is the most popular. After all you probably write a blog for someone to read and maybe you should consider writing more posts about what your readers are looking for when comming to your site.</p>
<p style="text-align: justify;">In this post I&#8217;ll focus on the first step that is needed: Registration to the &#8220;<strong>Google Analytics</strong>&#8220;.</p>
<h4 style="text-align: justify;">Step 1: Register</h4>
<p style="text-align: justify;">For the &#8220;<strong>Google Analytics</strong>&#8221; the registration process is actually very simple and it is summarized on this graphic below:</p>
<p style="text-align: justify;"><img class="aligncenter wp-image-451 size-full" src="http://blog.creyn.pl/wp-content/uploads/2016/06/PK_1.png" alt="PK_1" width="1346" height="348" /></p>
<p style="text-align: justify;">First you will need a &#8220;<strong>Google</strong>&#8221; account. I assume you have one already or know how to register for a new one. Then you need to go to the page: <a href="https://www.google.com/analytics/" target="_blank">https://www.google.com/analytics/</a> and login using that account. When logged in you need to go trought a very simple wizard process that helps you create and configure the account.</p>
<p style="text-align: justify;">First step is choosing if the setup will be for a Mobile App or a Website. In case of a blog let&#8217;s choose the &#8220;<strong>Website</strong>&#8221; option. Then you have to set an &#8220;<strong>Account Name</strong>&#8221; and &#8220;<strong>Website Name</strong>&#8220;. Those are for you to differentiate with some other analytics that you might want to have (for example a second blog or some static websites). The &#8220;<strong>Website URL</strong>&#8221; is the URL of your blog. You can copy paste the URL from your blog homepage address (like I did here). The &#8220;<strong>Industry Category</strong>&#8221; section will help Google to prepare some basic raports for you. The last thing is to choose the &#8220;<strong>Reporting Zone Time</strong>&#8220;. You can choose you country and all reports will be properly recalculated to your timezone.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-452" src="http://blog.creyn.pl/wp-content/uploads/2016/06/PK_2.png" alt="PK_2" width="684" height="657" /></p>
<p style="text-align: justify;">Next thing is to allow Google to gather and share some statistics to help them to imrove their service. I allowed for all of them. And after clicking &#8220;<strong>Get Tracking ID</strong>&#8221; and accepting some &#8220;<strong>Terms of Service Agreement</strong>&#8221; you will be send to a new website and the <strong>&#8220;Tracking ID&#8221;</strong> will be generated for you.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-453" src="http://blog.creyn.pl/wp-content/uploads/2016/06/PK_3.png" alt="PK_3" width="718" height="574" /></p>
<p style="text-align: justify;">The &#8220;<strong>Tracking ID</strong>&#8221; is very important. This is an identificator that allows Google to track users on your website. Below the &#8220;<strong>Tracking ID</strong>&#8221; is a section with the JavaScript code. You can just copy paste it on the web page that you want to have tracking enabled. In my case, I want to put it on every page on my blog.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-455" src="http://blog.creyn.pl/wp-content/uploads/2016/06/PK_5.png" alt="PK_5" width="1276" height="624" /></p>
<p style="text-align: justify;">How to do it I will show you in the next post. For now you could play around with the nice <strong>&#8220;Google Analytics&#8221;</strong> website. They have many video tutorials and informations about each report. Even a quick look at the available options will give you the idea of the things you can learn about your visitors. And there are a lot of them.</p>
<p style="text-align: justify;">C.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.creyn.pl/2016/06/07/how-to-add-google-analytics-to-wordpress-blog-part-1-registration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Daj Się Poznać 2016 &#8211; Podsumowanie</title>
		<link>http://blog.creyn.pl/2016/05/31/daj-sie-poznac-2016-podsumowanie/</link>
		<comments>http://blog.creyn.pl/2016/05/31/daj-sie-poznac-2016-podsumowanie/#comments</comments>
		<pubDate>Tue, 31 May 2016 20:46:39 +0000</pubDate>
		<dc:creator><![CDATA[creyn]]></dc:creator>
				<category><![CDATA[Programmer's notes]]></category>
		<category><![CDATA[Daj się poznać 2016]]></category>

		<guid isPermaLink="false">http://blog.creyn.pl/?p=431</guid>
		<description><![CDATA[Dziś jest ostatni dzień konkursu &#8220;Daj Się Poznać 2016&#8243; organizowanego przez Macieja Aniserowicza. Konkursu w którym brałem udział z moim projektem &#8220;Smart Lodówka&#8221;. Przez 10 tygodni powinienem prowadzić projekt: zarówno kodować jak i pisać o postępach na blogu. I o ile początek był całkiem obiecujący to w międzyczasie pojawiły się inne obowiązki oraz dwa mniejsze (teoretycznie)...]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">Dziś jest ostatni dzień konkursu &#8220;Daj Się Poznać 2016&#8243; organizowanego przez Macieja Aniserowicza. Konkursu w którym brałem udział z moim projektem &#8220;Smart Lodówka&#8221;. Przez 10 tygodni powinienem prowadzić projekt: zarówno kodować jak i pisać o postępach na blogu. I o ile początek był całkiem obiecujący to w międzyczasie pojawiły się inne obowiązki oraz dwa mniejsze (teoretycznie) projekty. Prace nad projektem ciągle trwają i nie uważam go za ukończony ani za porzucony. Tym bardziej, że wśród znajomych pojawiły się pozytywne głosy i chęć implementacji gotowego rozwiązania w swojej lodówce :)</p>
<p style="text-align: justify;">Z całego konkursu żałuję, że nie znalazłem czasu na czytanie wszystkich wybranych blogów ani większego udzielania się w społeczności. Czytając inne podsumowania dowiedziałem się np. o Slacku, gdzie uczestnicy dyskutowali o swoich projektach :) Szkoda, że gdzieś mi to umknęło, bo może udałoby się bardziej zintegrować z koleżankami i kolegami z konkursu.</p>
<p style="text-align: justify;">Chciałbym też wyróżnić kilka blogów, które awansowały w moim Feedly (czytnik RSS online) z jednej z 7 kategorii na jakie podzieliłem uczestników do &#8220;Must Read&#8221;:</p>
<ul>
<li style="text-align: justify;">Konrad Kokosa &#8211; Memory Visualizer &#8211; <a href="http://blog.kokosa.net/" target="_blank">http://blog.kokosa.net/</a></li>
<li style="text-align: justify;">CZe SiO  &#8211; Smart Hub &#8211; <a href="http://czesio-w-it.2ap.pl/" target="_blank">http://czesio-w-it.2ap.pl/</a></li>
<li style="text-align: justify;">Tomasz Jarzyński &#8211; Pokerowe Podziemie &#8211; <a href="http://tomaszjarzynski.pl/" target="_blank">http://tomaszjarzynski.pl/</a></li>
<li style="text-align: justify;">Maciej Lesiczka &#8211; DSP Meta &#8211; <a href="http://macieklesiczka.github.io/" target="_blank">http://macieklesiczka.github.io/</a></li>
<li style="text-align: justify;">Szymon Kulec &#8211; RampUp &#8211; <a href="https://blog.scooletz.com/" target="_blank">https://blog.scooletz.com/</a></li>
</ul>
<p style="text-align: justify;">
<p style="text-align: justify;">Na koniec podsumowanie stanu projektu &#8220;Smart Lodówka&#8221;.</p>
<p style="text-align: justify;">Działa :) To najważniejsze. Na chwilę obecną malinka jest podłączona do mojej lodówki i za pomocą sprytnego czujnika otwarcia drzwi monitorowane są zdarzenia: DOOR_OPEN oraz DOOR_CLOSE. Dwie diody LED sygnalizują pracę skryptu: zielona miga jednostajnie a czerwona świeci się tylko gdy są otwarte drzwi. Gdy znajdę chwilę pojawią się wpisy o implementacji i kodzie. A na koniec filmik:</p>
<p>&nbsp;</p>
<blockquote class="instagram-media" style="background: #FFF; border: 0; border-radius: 3px; box-shadow: 0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width: 658px; padding: 0; width: calc(100% - 2px);" data-instgrm-captioned="" data-instgrm-version="7">
<div style="padding: 8px;">
<div style="background: #F8F8F8; line-height: 0; margin-top: 40px; padding: 50.0% 0; text-align: center; width: 100%;"></div>
<p style="margin: 8px 0 0 0; padding: 0 4px;"><a style="color: #000; font-family: Arial,sans-serif; font-size: 14px; font-style: normal; font-weight: normal; line-height: 17px; text-decoration: none; word-wrap: break-word;" href="https://www.instagram.com/p/BGFaWUWxvWy/" target="_blank">#RaspberryPi #SmartLodowka #smart #fridge #DajSiePoznac2016 #IoT</a></p>
<p style="color: #c9c8cd; font-family: Arial,sans-serif; font-size: 14px; line-height: 17px; margin-bottom: 0; margin-top: 8px; overflow: hidden; padding: 8px 0 7px; text-align: center; text-overflow: ellipsis; white-space: nowrap;">Film zamieszczony przez użytkownika @pawel.kowalik <time style="font-family: Arial,sans-serif; font-size: 14px; line-height: 17px;" datetime="2016-05-31T20:11:03+00:00">31 Maj, 2016 o 1:11 PDT</time></p>
</div>
</blockquote>
<p><script src="//platform.instagram.com/en_US/embeds.js" async="" defer="defer"></script></p>
<p>&nbsp;</p>
<p>Pozdrawiam i gratuluję wszystkim uczestnikom :)</p>
<p style="text-align: justify;">C.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.creyn.pl/2016/05/31/daj-sie-poznac-2016-podsumowanie/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Debugowanie skryptu Pythona na Raspberry Pi</title>
		<link>http://blog.creyn.pl/2016/04/25/debugowanie-skryptu-pythona-na-raspberry-pi/</link>
		<comments>http://blog.creyn.pl/2016/04/25/debugowanie-skryptu-pythona-na-raspberry-pi/#comments</comments>
		<pubDate>Mon, 25 Apr 2016 21:30:17 +0000</pubDate>
		<dc:creator><![CDATA[creyn]]></dc:creator>
				<category><![CDATA[Programmer's notes]]></category>
		<category><![CDATA[Daj się poznać 2016]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://blog.creyn.pl/?p=408</guid>
		<description><![CDATA[W poprzednim poście (Visual Studio + Python) opisałem jak zainstalować &#8220;Python Tools for Visual Studio (PTVS)&#8221;. Dzięki temu pluginowi możemy programować w Pythonie w naszym ulubionym IDE. W tym poście pokażę, jak uruchomić kod w Pythonie na Raspberry Pi i go zdebugować. Visual Studio potrafi podłączyć swój debugger do już uruchomionego procesu, czy to lokalnie...]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">W poprzednim poście (<a href="http://blog.creyn.pl/2016/03/12/visual-studio-python/" target="_blank">Visual Studio + Python</a>) opisałem jak zainstalować &#8220;Python Tools for Visual Studio (PTVS)&#8221;. Dzięki temu pluginowi możemy programować w Pythonie w naszym ulubionym IDE. W tym poście pokażę, jak uruchomić kod w Pythonie na Raspberry Pi i go zdebugować.</p>
<p style="text-align: justify;">Visual Studio potrafi podłączyć swój debugger do już uruchomionego procesu, czy to lokalnie czy też na zdalnym komputerze. Także na innym systemie. W tym Raspberry Pi. Scenariusz wygląda następująco:</p>
<ol style="text-align: justify;">
<li>Piszemy skrypt w Pythonie</li>
<li>Dodajemy do naszego skryptu pakiet &#8220;<strong>ptvsd</strong>&#8220;, umożliwia on właśnie zdalne podłączenie się do procesu skryptu</li>
<li>Uruchamiamy nasz skrypt na Raspberry Pi</li>
<li>W Visual Studio podłączamy debugger do malinki (która teraz jest serwerem debugowania)</li>
</ol>
<p style="text-align: justify;">Zdalne debugowanie możliwe jest właśnie dzięki pakietowi &#8220;<strong>ptvsd</strong>&#8220;. Należy go zainstalować na malince:</p>
<p></p><pre class="crayon-plain-tag">pip install ptvsd</pre><p></p>
<p style="text-align: justify;">W skryptcie należy go zaimportować i skonfigurować. W tym przypadku umożliwiamy zdalne podłączanie procesu debugowania oraz ustawiamy nasz sekret &#8220;SomeSecret&#8221;. Będzie on potrzebny w kolejnym kroku.</p>
<p></p><pre class="crayon-plain-tag">import ptvsd
ptvsd.enable_attach("SomeSecret")</pre><p></p>
<p style="text-align: justify;">Możliwe jest także podpięcie certyfikatu i zabezpieczenie naszego połączenia z malinką. Na razie jednak obejdziemy się bez tego. Kod skryptu znajduje się w repozytorium na <a href="https://github.com/creyn/Smart-Lodowka/blob/master/scripts/RaspberryPlayground/RaspberryPlayground/Utils/002_DebugTest.py" target="_blank">githubie</a>.</p>
<p style="text-align: justify;">Po uruchomieniu skryptu możemy podłączyć się do malinki z Visual Studio. W tym celu przechodzimy do &#8220;<strong>Debug</strong>&#8221; &gt; &#8220;<strong>Attach to process</strong>&#8220;. Jako typ Transportu wybieramy &#8220;<strong>Python remote (ptvsd)</strong>&#8220;. Następnie wskazujemy adres naszej malinki wraz z wcześniej wpisanym sekretem i po naciśnięciu na przycisk &#8220;<strong>Refresh</strong>&#8221; powinniśmy dostać listę procesów, do których możemy się podłączyć. W tym przypadku widzimy jeden: &#8220;python @ tcp://192.168.0.11/&#8221;. To nasz uruchomiony skrypt. Podłączamy się więc do niego debuggerem.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-409" src="http://blog.creyn.pl/wp-content/uploads/2016/04/PTVSD_1.png" alt="PTVSD_1" width="874" height="587" /></p>
<p style="text-align: justify;">
<p style="text-align: justify;">W kodzie skryptu ustawiamy breakpoint i czekamy aż wykonywanie skryptu dojdzie do niego. W tym momencie mamy już pełny debugger Visual Studio na procesie z naszym skryptem. Z całym stackiem, zmiennymi i innymi dobrodziejstwami IDE. Na screenie widzimy konsolę z malinki oraz debugger Visual Studio. Skrypt ma pętlę, która wykonuje się aż użytkownik nie przypisze do zmiennej X wartości 0 (zero). Breakpoint ustawiony jest w linii z instrukcją wyświetlenia wartości zmiennej. Poniżej widzimy wartości zmiennych, do których również mamy dostęp z poziomu debuggera.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-410" src="http://blog.creyn.pl/wp-content/uploads/2016/04/PTVSD_2.png" alt="PTVSD_2" width="1045" height="639" /></p>
<p style="text-align: justify;">
<p style="text-align: justify;">
<p style="text-align: justify;">Z okna &#8220;Immediate Window&#8221; możemy wykonywać różne polecenia na malince. Wypiszmy informację, że zaraz zmienimy wartość wpisanej zmiennej: &#8220;VS is changing the X for 0 ;)&#8221; i następnie to zróbmy. W tym momencie, po wznowieniu wykonywania skryptu zostanie spełniony warunek kończący pętlę i skrypt się zakończy pomimo tego, że użytkownik nie wpisał 0.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-411" src="http://blog.creyn.pl/wp-content/uploads/2016/04/PTVSD_3.png" alt="PTVSD_3" width="693" height="654" /></p>
<p style="text-align: justify;">
<p style="text-align: justify;">Mamy więc dostęp do malinki. Tutaj przy okazji pobawiłem się trochę świecącymi diodami. Dla spostrzegawczych, widzicie &#8220;import ptvsd&#8221;? Wygląda to jak początek naszego skryptu :)</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-412" src="http://blog.creyn.pl/wp-content/uploads/2016/04/PTVSD_4.png" alt="PTVSD_4" width="1039" height="346" /></p>
<p style="text-align: justify;">Debugowanie przyda się, kiedy przejdę do kolejnych, bardziej skomplikowanych etapów pracy nad Smart Lodówką. Teraz przyszła już pora na obsługę zdarzeń otwierania drzwi lodówki.</p>
<p style="text-align: justify;">C.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.creyn.pl/2016/04/25/debugowanie-skryptu-pythona-na-raspberry-pi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zapytania HTTP w Pythonie</title>
		<link>http://blog.creyn.pl/2016/04/15/zapytania-http-w-pythonie/</link>
		<comments>http://blog.creyn.pl/2016/04/15/zapytania-http-w-pythonie/#comments</comments>
		<pubDate>Fri, 15 Apr 2016 19:00:06 +0000</pubDate>
		<dc:creator><![CDATA[creyn]]></dc:creator>
				<category><![CDATA[Programmer's notes]]></category>
		<category><![CDATA[Daj się poznać 2016]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.creyn.pl/?p=391</guid>
		<description><![CDATA[Python posiada bibliotekę urllib2 do wykonywania zapytań HTTP, HTTPS, FTP. Dzięki niej łatwo możemy pobrać zawartość strony www czy plik z jakiegoś serwera. W poprzednim poście (&#8220;Simple.Data.SqlServer na hostingu Webio&#8220;) stworzyłem proste Web Api, które zwraca listę obiektów klasy Event z serwera. W celu jej pobrania wystarczy wywołać metodę urlopen(): [crayon-69e73a4ab40c0664955335/] Możemy użyć bezpośrednio URLa lub stworzyć obiekt Request, który...]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">Python posiada bibliotekę <a title="https://docs.python.org/2/library/urllib2.html" href="https://docs.python.org/2/library/urllib2.html" target="_blank"><strong>urllib2</strong> </a>do wykonywania zapytań HTTP, HTTPS, FTP. Dzięki niej łatwo możemy pobrać zawartość strony www czy plik z jakiegoś serwera. W poprzednim poście (&#8220;<a title="http://blog.creyn.pl/2016/04/02/simple-data-sqlserver-na-hotingu-webio/" href="http://blog.creyn.pl/2016/04/02/simple-data-sqlserver-na-hotingu-webio/" target="_blank">Simple.Data.SqlServer na hostingu Webio</a>&#8220;) stworzyłem proste Web Api, które zwraca listę obiektów klasy <strong>Event</strong> z serwera. W celu jej pobrania wystarczy wywołać metodę <strong>urlopen</strong>():</p>
<p style="text-align: justify;"><span id="more-391"></span></p>
<p></p><pre class="crayon-plain-tag">import urllib2

response = urllib2.urlopen('http://smartlodowka.creyn.pl/api/events/')

print response.read()
# [{"Id":2,"Name":"First test event"},{"Id":3,"Name":"And second event"},{"Id":4,"Name":"Test multi 1"},{"Id":5,"Name":"Test multi 2"},{"Id":6,"Name":"New one"},{"Id":7,"Name":"pTest1"}]</pre><p></p>
<p style="text-align: justify;">Możemy użyć bezpośrednio URLa lub stworzyć obiekt <strong>Request</strong>, który umożliwi także ustawianie nagłówków żądania. W tym przykładzie chcę dostać od serwera odpowiedź w formacie XML a nie JSON.</p>
<p></p><pre class="crayon-plain-tag">import urllib2

request = urllib2.Request('http://smartlodowka.creyn.pl/api/events/')
request.add_header('Accept', 'application/xml')
response = urllib2.urlopen(request)

print response.read()
# &lt;ArrayOfEvent xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/SmartLodowkaAPI.DTO"&gt;&lt;Event&gt;&lt;Id&gt;2&lt;/Id&gt;&lt;Name&gt;First test event&lt;/Name&gt;&lt;/Event&gt;&lt;Event&gt;&lt;Id&gt;3&lt;/Id&gt;&lt;Name&gt;And second event&lt;/Name&gt;&lt;/Event&gt;&lt;Event&gt;&lt;Id&gt;4&lt;/Id&gt;&lt;Name&gt;Test multi 1&lt;/Name&gt;&lt;/Event&gt;&lt;Event&gt;&lt;Id&gt;5&lt;/Id&gt;&lt;Name&gt;Test multi 2&lt;/Name&gt;&lt;/Event&gt;&lt;Event&gt;&lt;Id&gt;6&lt;/Id&gt;&lt;Name&gt;New one&lt;/Name&gt;&lt;/Event&gt;&lt;Event&gt;&lt;Id&gt;7&lt;/Id&gt;&lt;Name&gt;pTest1&lt;/Name&gt;&lt;/Event&gt;&lt;/ArrayOfEvent&gt;</pre><p></p>
<p style="text-align: justify;">Pobrana odpowiedź z serwera jest stringiem, przydałoby się zamienić ją na jakiś bardziej przydatny typ danych. Zacznijmy od stworzenia klasy <strong>Event</strong>. Konstruktor klasy w Pythonie nazywa sie &#8220;<strong>__init__</strong>&#8221; i przyjmuje parametr &#8220;<strong>self</strong>&#8220;, dzięki któremu możemy stworzyć property klasy i zainicjować je na odpowiednie dane przekazane przy tworzeniu obiektu.</p>
<p></p><pre class="crayon-plain-tag">class Event:
    def __init__(self, id, name):
        self.Id = id
        self.Name = name
		
ev = Event(1, 'First event')

print 'Name of first event: ' + ev.Name + ' of id: ' + str(ev.Id)
# Name of first event: First event of id: 1</pre><p></p>
<p style="text-align: justify;"><div class='info2'></p>
<p style="text-align: justify;">Nie można łączyć ze sobą stringów i intów. Należy najpierw zamienić int na string. Stąd: <em>str(ev.Id)</em></p>
<p style="text-align: justify;"></div></p>
<p style="text-align: justify;">Następnie należy zrobić deserializację stringa do obiektów naszej nowej klasy. Wiemy, że z serwera dostaniemy listę obiektów typu Event w jednym stringu w formacie JSON. Niestety nie udało mi się znaleźć biblioteki pokroju Json.NET od Newtonsoft. Także napiszemy własnego, skrojonego na miarę &#8220;Json to Event&#8221; parsera opartego na wyrażeniach regularnych:</p>
<p></p><pre class="crayon-plain-tag">import json
import re # regular expresion module

# class representing Event
class Event:
    def __init__(self, id, name):
        self.Id = int(id) # make sure id is integer
        self.Name = name

# response that cames from api
response = '[{"Id":2,"Name":"First test event"},{"Id":3,"Name":"And second event"},{"Id":4,"Name":"Test multi 1"},{"Id":5,"Name":"Test multi 2"},{"Id":6,"Name":"New one"},{"Id":7,"Name":"pTest1"}]'
print response
# [{"Id":2,"Name":"First test event"},{"Id":3,"Name":"And second event"},{"Id":4,"Name":"Test multi 1"},{"Id":5,"Name":"Test multi 2"},{"Id":6,"Name":"New one"},{"Id":7,"Name":"pTest1"}]

# split response and get all objects: between { and }
jsonObjects = re.findall("{.*?}",response)

# foreach of found object, get values between: " and " and between: : and ,
events = []
for o in jsonObjects:
    values = re.findall("\".*?\"|:.*?,", o)
    id = values[1][1:-1] # remove first and last character
    name = values[3][1:-1]
    ev = Event(id, name)
    events.append(ev)
    
print len(events)
# 6

print 'Id is: ' + str(events[3].Id)
# Id is: 5

print 'Name is: ' + events[3].Name
# Name is: Test multi 2</pre><p></p>
<p style="text-align: justify;"><div class='warning2'></p>
<p style="text-align: justify;">Trochę nie podoba mi się zabawa ze stringami i wyrażeniami regularnymi. Jeżeli ktoś z czytelników zna fajną bibliotekę Pythona deserializującą JSONa do obiektów danej klasy, proszę o komentarz :)</p>
<p style="text-align: justify;"></div></p>
<p style="text-align: justify;">Powyższy kod pozostawia wiele do życzenia, co z kolei daje miejsce do poprawy w kolejnych wpisach :)</p>
<p style="text-align: justify;">Skoro już potrafimy pobrać listę zdarzeń z Web Api należałoby teraz wysłać nowe i dodać do kolekcji na serwerze. W tym celu również posłużymy się biblioteką <strong>urllib2</strong> i metodą <strong>urlopen</strong>. Metoda ta, jako pierwszy parametr przyjmuje <strong>URL</strong> lub obiekt <strong>Request</strong> określający docelowy endpoint, do którego się łączy. Jako drugi parametr może przyjąć dane. Jeżeli przekażemy do tej metody dane, to automatycznie zostanie wysłane zapytanie <strong>POST</strong> (zamiast <strong>GET</strong> jak w poprzednich przypadkach). Dane muszą być w formacie &#8216;<strong>application/x-www-form-urlencoded</strong>&#8216;.</p>
<p></p><pre class="crayon-plain-tag">import urllib2

# has to be list of Events

data = 'Events[0].Name=TestURLLIB2'

response = urllib2.urlopen('http://smartlodowka.creyn.pl/api/events/', data)
print response.read()

# [{"Id":8,"Name":"TestURLLIB2"}]</pre><p></p>
<p style="text-align: justify;">Ten dziwny format danych wysłanych w requeście spowodowany jest sposobem w jaki budowane są obiekty C# w Web Api. Kontroler spodziewa się listy obiektów typu <strong>Event</strong>, nazwa tego property to właśnie &#8220;<strong>Events</strong>&#8220;, czyli przesyłamy tablicę i pierwszy element (stąd indeks 0) bindujemy do obiektu <strong>Event</strong> a jego property &#8220;<strong>Name&#8221;</strong> ustawiamy na &#8220;TestURLLIB2&#8243;.</p>
<p></p><pre class="crayon-plain-tag">public IHttpActionResult Post(CreateEventsRequest request)
{
    ...
}
public class CreateEventsRequest
{
    public List&lt;Event&gt; Events { get; set; }
}
public class Event
{
    ...    
    public string Name { get; set; }
}</pre><p></p>
<p style="text-align: justify;">A chcąc przekazać dwa zdarzenia ustawiamy dwa pierwsze elementy tablicy</p>
<p></p><pre class="crayon-plain-tag">import urllib2

url = 'http://smartlodowka.creyn.pl/api/events/'

# has to be list of Events
data = 'Events[0].Name=List1&amp;Events[1].Name=List2'

response = urllib2.urlopen(url, data)
print response.read()
# [{"Id":9,"Name":"List1"},{"Id":10,"Name":"List2"}]

allEvents = urllib2.urlopen(url).read()
print allEvents
# [{"Id":2,"Name":"First test event"},{"Id":3,"Name":"And second event"},{"Id":4,"Name":"Test multi 1"},{"Id":5,"Name":"Test multi 2"},{"Id":6,"Name":"New one"},{"Id":7,"Name":"pTest1"},{"Id":8,"Name":"TestURLLIB2"},{"Id":9,"Name":"List1"},{"Id":10,"Name":"List2"}]</pre><p></p>
<p style="text-align: justify;">Dzięki tym kilku ćwiczeniom znamy już proste zapytania HTTP: pobieranie danych za pomocą <strong>GET</strong> i wysyłanie za pomocą <strong>POST</strong>. W tym momencie to w zupełności wystarczy aby przejść dalej w ramach projektu <a title="http://blog.creyn.pl/2016/03/01/hello-smart-lodowka/" href="http://blog.creyn.pl/2016/03/01/hello-smart-lodowka/" target="_blank"><strong>Smart Lodówka</strong></a> i przymierzyć się do wysyłania zdarzeń ze świata rzeczywistego. Zacznę od dwóch podstawowych typów zdarzeń: Otwarcie i Zamknięcie drzwi lodówki.</p>
<p style="text-align: justify;">C.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.creyn.pl/2016/04/15/zapytania-http-w-pythonie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Frontendowe narzędzia</title>
		<link>http://blog.creyn.pl/2016/04/05/frontendowe-narzedzia/</link>
		<comments>http://blog.creyn.pl/2016/04/05/frontendowe-narzedzia/#comments</comments>
		<pubDate>Tue, 05 Apr 2016 22:49:54 +0000</pubDate>
		<dc:creator><![CDATA[creyn]]></dc:creator>
				<category><![CDATA[Programmer's notes]]></category>
		<category><![CDATA[Daj się poznać 2016]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://blog.creyn.pl/?p=369</guid>
		<description><![CDATA[Poniżej zamieszczam listę i krótki opis narzędzi wykorzystywanych do tworzenia aplikacji frontendowych. Będzie ona z sukcesywnie rozwijana. Node.js (https://nodejs.org/en/) JavaScriptowy silnik (?) do tworzenia aplikacji serwerowych. &#8220;Node.js® is a JavaScript runtime built on Chrome&#8217;s V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.&#8221;   NPM (Node Package Manager)...]]></description>
				<content:encoded><![CDATA[<p style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"><span style="font-family: Calibri; font-size: 11.0pt;">Poniżej zamieszczam listę i krótki opis narzędzi wykorzystywanych do tworzenia aplikacji frontendowych. Będzie ona z sukcesywnie rozwijana.</span></p>
<p style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"><span id="more-369"></span></p>
<table border="0">
<tbody>
<tr>
<td><img class="aligncenter wp-image-372 size-thumbnail" src="http://blog.creyn.pl/wp-content/uploads/2016/04/logo_node-150x150.png" alt="logo_node" width="150" height="150" /></td>
<td>
<ul>
<li><span style="font-family: Calibri; font-size: 11.0pt;">Node.js (</span><a href="https://nodejs.org/en/" target="_blank"><span style="font-family: Calibri; font-size: 11.0pt;">https://nodejs.org/en/</span></a><span style="font-family: Calibri; font-size: 11.0pt;">)</span>
<ul>
<li><span style="font-family: Calibri; font-size: 11.0pt;">JavaScriptowy silnik (?) do tworzenia aplikacji serwerowych.</span></li>
<li><span style="font-family: Calibri; font-size: 11.0pt;">&#8220;Node.js® is a JavaScript runtime built on Chrome&#8217;s V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.&#8221;</span></li>
</ul>
</li>
</ul>
</td>
</tr>
<tr>
<td> <a href="http://blog.creyn.pl/wp-content/uploads/2016/04/logo_npm-e1459896122363.png"><img class="aligncenter wp-image-375 size-full" src="http://blog.creyn.pl/wp-content/uploads/2016/04/logo_npm-e1459896122363.png" alt="logo_npm" width="100" height="39" /></a></td>
<td>
<ul>
<li><span style="font-family: Calibri; font-size: 11.0pt;">NPM (Node Package Manager) (</span><a href="https://www.npmjs.com/" target="_blank"><span style="font-family: Calibri; font-size: 11.0pt;">https://www.npmjs.com/</span></a><span style="font-family: Calibri; font-size: 11.0pt;">)</span>
<ul>
<li><span style="font-family: Calibri; font-size: 11.0pt;">Menadżer paczek dla Node.js.</span></li>
<li><span style="font-family: Calibri; font-size: 11.0pt;">&#8220;npm is the package manager for JavaScript. Find, share, and reuse packages of code from hundreds of thousands of developers — and assemble them in powerful new ways. &#8220;</span></li>
<li><span style="font-family: Calibri; font-size: 11.0pt;">Instaluje się razem z Node.js</span></li>
<li><strong><span style="font-family: Calibri; font-size: 11pt;">Uwaga. Z powodu błędu związanego z przesyłaniem tokenów do uwierzytelnienia zaleca się aktualizację do najnowszej wersji. Więcej tutaj: </span><a href="https://nodejs.org/en/blog/vulnerability/npm-tokens-leak-march-2016/" target="_blank"><span style="font-family: Calibri; font-size: 11pt;">https://nodejs.org/en/blog/vulnerability/npm-tokens-leak-march-2016/</span></a></strong></li>
</ul>
</li>
</ul>
</td>
</tr>
<tr>
<td> <img class="aligncenter size-thumbnail wp-image-378" src="http://blog.creyn.pl/wp-content/uploads/2016/04/logo_grunt-150x150.png" alt="logo_grunt" width="150" height="150" /></td>
<td>
<ul>
<li><span style="font-family: Calibri; font-size: 11.0pt;">Grunt (</span><a href="http://gruntjs.com/" target="_blank"><span style="font-family: Calibri; font-size: 11.0pt;">http://gruntjs.com/</span></a><span style="font-family: Calibri; font-size: 11.0pt;">)</span>
<ul>
<li><span style="font-family: Calibri; font-size: 11.0pt;">Program do automatyzacji</span></li>
<li><span style="font-family: Calibri; font-size: 11.0pt;">&#8220;GruntThe JavaScript Task Runner&#8221;</span></li>
<li><span style="font-family: Calibri; font-size: 11.0pt;">Instalacja za pomocą npm</span></li>
</ul>
</li>
</ul>
</td>
</tr>
<tr>
<td> <img class="aligncenter wp-image-377 size-thumbnail" src="http://blog.creyn.pl/wp-content/uploads/2016/04/logo_gulp-150x150.png" alt="logo_gulp" width="150" height="150" /></td>
<td>
<ul>
<li><span style="font-family: Calibri; font-size: 11.0pt;">Gulp (</span><a href="http://gulpjs.com/" target="_blank"><span style="font-family: Calibri; font-size: 11.0pt;">http://gulpjs.com/</span></a><span style="font-family: Calibri; font-size: 11.0pt;">)</span>
<ul>
<li><span style="font-family: Calibri; font-size: 11.0pt;">Program do automatyzacji (konkurencja Grunta?)</span></li>
<li><span style="font-family: Calibri; font-size: 11.0pt;">&#8220;Automate and enhance your workflow&#8221;</span></li>
<li><span style="font-family: Calibri; font-size: 11.0pt;">Instalacja za pomocą npm</span></li>
</ul>
</li>
</ul>
</td>
</tr>
<tr>
<td> <img class="aligncenter size-thumbnail wp-image-376" src="http://blog.creyn.pl/wp-content/uploads/2016/04/logo_bower-150x150.png" alt="logo_bower" width="150" height="150" /></td>
<td>
<ul>
<li><span style="margin-top: 0; margin-bottom: 0; vertical-align: middle;">Bower (</span><a href="http://bower.io/" target="_blank"><span style="font-family: Calibri; font-size: 11.0pt;">http://bower.io/</span></a><span style="font-family: Calibri; font-size: 11.0pt;">)</span>
<ul>
<li><span style="font-family: Calibri; font-size: 11.0pt;">Menadżer pakietów dla frontendu (npm instaluje pakiety dla Node po stronie serwera, bower po stronie klienta)</span></li>
<li><span style="font-family: Calibri; font-size: 11.0pt;">&#8220;A package manager for the web&#8221;</span></li>
<li><span style="font-family: Calibri; font-size: 11.0pt;">&#8220;Web sites are made of lots of things — frameworks, libraries, assets, and utilities. Bower manages all these things for you.&#8221;</span></li>
<li><span style="font-family: Calibri; font-size: 11.0pt;">Instalacja za pomocą npm (bo jest to pakiet rozszerzający możliwości Node)</span></li>
</ul>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>C.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.creyn.pl/2016/04/05/frontendowe-narzedzia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aurelia, początki</title>
		<link>http://blog.creyn.pl/2016/04/04/aurelia-poczatki/</link>
		<comments>http://blog.creyn.pl/2016/04/04/aurelia-poczatki/#comments</comments>
		<pubDate>Mon, 04 Apr 2016 21:03:14 +0000</pubDate>
		<dc:creator><![CDATA[creyn]]></dc:creator>
				<category><![CDATA[Programmer's notes]]></category>
		<category><![CDATA[Aurelia]]></category>
		<category><![CDATA[Daj się poznać 2016]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.creyn.pl/?p=355</guid>
		<description><![CDATA[Projekt Smart Lodówka będzie miał prostą stronę ze statystykami. Chcę skorzystać z okazji i poznać nowy frontendowy framework. Wiele dobrego słyszałem o Aurelii. Aurelia jest kolejnym frameworkiem JavaScript, a używając słów jej autorów: &#8220;Aurelia is the most powerful, flexible and forward-looking JavaScript client framework in the world.&#8221; &#8220;Aurelia is a next generation UI framework&#8220;. Z...]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">Projekt Smart Lodówka będzie miał prostą stronę ze statystykami. Chcę skorzystać z okazji i poznać nowy frontendowy framework. Wiele dobrego słyszałem o Aurelii. <a href="http://aurelia.io/" target="_blank">Aurelia</a> jest kolejnym frameworkiem JavaScript, a używając słów jej autorów:</p>
<blockquote>
<p style="text-align: justify;">&#8220;<span class="st"><em>Aurelia</em> is the most powerful, flexible and forward-looking JavaScript client framework in the world.</span>&#8221;<br />
&#8220;<span class="st"><em>Aurelia</em> is a next generation UI framework</span>&#8220;.</p>
</blockquote>
<p style="text-align: justify;">Z tego co widzę, jest to taki następca bardzo popularnego Angulara. Choć może bardziej konkurencja. Nigdy nie myślałem o sobie jako o frontendowcu i dlatego wszelkie biblioteki ułatwiające programowanie w JavaScript uważam za świetny pomysł i im więcej tym lepiej.</p>
<p style="text-align: justify;">Jak zatem zacząć? Na stronie Aurelii jest dość dokładny poradnik <a href="http://aurelia.io/docs.html#/aurelia/framework/1.0.0-beta.1.1.4/doc/article/getting-started" target="_blank">Getting Started</a>. Dzięki niemu udało mi się stworzyć przykładową stronę.</p>
<p style="text-align: justify;">Pierwsza rzecz, która rzuca się w oczy: bardzo dużo tutaj wszelkiego rodzaju: gulpów, gruntów, nodów, npmów i jsmpów. Chyba nadeszła chwila, aby dokładniej poznać te narzędzia. Na początek, fajnie że autorzy przygotowali &#8220;Starter Kit&#8221; aby przejść przez tutorial i zacząć poznawać Aurelię. Po pobraniu okazało się że ma on &#8230; 10 MB. Wydało mi się to trochę dużo. Drugą rzeczą jest liczba modułów. Aurelia jest bardzo modułowa i podobno można używać tylko tych, które są naprawdę potrzebne. Okazuje się jednak, że do wyświetlenia mojej banalnej strony potrzebne są praktycznie wszystkie. Nie wykluczam, że coś źle robię i w przyszłości będzie możliwe ograniczenie tej liczby, ale nie wiem czy nie jest to za bardzo modułowe :)</p>
<p style="text-align: justify;">Ucząc się najlepiej zacząć od początku, także chciałem krok po kroku stworzyć najprostszy możliwy projekt. Do solucji w Visual Studio dodałem folder Aurelia i dwa podstawowe pliki: &#8220;config.js&#8221; i &#8220;system.js&#8221;. Pierwszy zawiera listę mapowań modułów na konkretne pliki. Być może tutaj nie potrzebuję mieć wszystkich a jedynie kilka podstawowych. Sprawa do zgłębienia. W każdym razie przenosiłem po kolei pakiety ze &#8220;Starter Kita&#8221; do solucji. Udało mi się uruchomić sam framework w tym sensie, że nie dostawałem już błędów 404 z plikami JavaScript Aurelii. Doszedłem do etapu tworzenia swojej aplikacji.</p>
<p style="text-align: justify;">Aby to zrobić należy stworzyć dwa pliki: &#8220;app.js&#8221; i &#8220;app.html&#8221;. Plik &#8220;app.js&#8221; jest modelem dla widoku z &#8220;app.html&#8221;. Takie MVC. Przychodzący request jest mapowany do konkretnego widoku w ruterze, który konfigurowany jest właśnie w startowym pliku aplikacji &#8220;app.js&#8221;. Ja dodałem tam tylko jeden widok: events. Wyświetla on listę wszystkich zdarzeń pobranych z API, które stworzyłem wcześniej (<a title="http://blog.creyn.pl/2016/03/20/owin-webapi-na-hostingu-webio/" href="http://blog.creyn.pl/2016/03/20/owin-webapi-na-hostingu-webio/" target="_blank">OWIN WebApi na hostingu Webio</a>).</p>
<p style="text-align: justify;">Na koniec opublikowałem zmiany na hosting Webio i uruchomiłem przeglądarkę. Bardzo się zdziwiłem jak długo trwa wczytanie strony. Każdy moduł Aurelii jest pobierany jako jeden plik JavaScript a jest ich wszystkich &#8230; 95. Nic dziwnego, że trochę to trwa (30 sekund).</p>
<p style="text-align: justify;"><img class="aligncenter wp-image-358 size-full" src="http://blog.creyn.pl/wp-content/uploads/2016/04/Aurelia_requests_1.png" alt="Aurelia_requests_1" width="719" height="65" />Ale jest tutaj pole do optymalizacji. W każdym razie drugie załadowanie strony, przy plikach pobranych z cache, jest znośne, choć też zbyt wolne dla tego typu strony. Trwa 1,5 s. Jest to koszt odpalenia frameworka i wszystkich dobroci, które ze sobą niesie, a których chyba nie zauważę w tak prostym projekcie.</p>
<p style="text-align: justify;"><img class="aligncenter wp-image-359 size-full" src="http://blog.creyn.pl/wp-content/uploads/2016/04/Aurelia_requests_2.png" alt="Aurelia_requests_2" width="749" height="65" />Ciekawostka. Przed opublikowaniem tego posta postanowiłem jeszcze raz zrobić test strony po paru godzinach nieaktywności. Strona załadowała się w &#8230; 4 i pół minuty. Wydaje mi się, że na optymalizację będę musiał przeznaczyć więcej czasu niż początkowo zakładałem. Mam też nadzieję że nie będę musiał rezygnować z Aurelii.</p>
<p style="text-align: justify;"><img class="aligncenter size-full wp-image-360" src="http://blog.creyn.pl/wp-content/uploads/2016/04/Aurelia_requests_3.png" alt="Aurelia_requests_3" width="752" height="71" /></p>
<p style="text-align: justify;">Podsumowując, udało mi się uruchomić swoją pierwszą stronę we frameworku Aurelia. Na stronie możliwe będzie monitorowanie zdarzeń jakie wystąpią w mojej Smart Lodówce. Dostępna jest pod adresem: <a href="http://smartlodowka.creyn.pl/" target="_blank">http://smartlodowka.creyn.pl</a> (jeśli długo nic nie widać &#8230; cierpliwości). Dla przypomnienia, ta sama lista zdarzeń z systemu dostępna jest bezpośrednio z API: <a href="http://smartlodowka.creyn.pl/api/events" target="_blank">http://smartlodowka.creyn.pl/api/events</a>.</p>
<p style="text-align: justify;">C.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.creyn.pl/2016/04/04/aurelia-poczatki/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
