<?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:blogger='http://schemas.google.com/blogger/2008' 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-4746658946889574209</id><updated>2026-10-09T23:22:39.495-07:00</updated><category term="Photoshop"/><category term="db-class"/><category term="python"/><category term="php"/><category term="Hackerrank"/><category term="javascript"/><category term="js"/><category term="solution"/><category term="administration"/><category term="thesis"/><category term="CAT"/><category term="Compass"/><category term="SEO"/><category term="apache"/><category term="application"/><category term="aws"/><category term="cosine"/><category term="deep learning"/><category term="htaccess"/><category term="iOS"/><category term="iPhone"/><category term="mysql"/><category term="pearson"/><category term="similarity"/><category term="tanimoto"/><category term="utf-8"/><category term="ΠΕΖ"/><category term="Authoring"/><category term="Delivery"/><category term="Djanog"/><category term="EEG"/><category term="NeuroPez"/><category term="News"/><category term="Personalized"/><category term="Presentation"/><category term="Rewritting"/><category term="Tool"/><category term="UI Dsign"/><category term="URL"/><category term="advice"/><category term="airflow"/><category term="ajax"/><category term="amazon"/><category term="beautiful soup"/><category term="benchmark"/><category term="blog"/><category term="celery"/><category term="collaborative"/><category term="combobox"/><category term="content"/><category term="crawler"/><category term="create transparent"/><category term="dadabik"/><category term="datatable"/><category term="duplicate"/><category term="ec2"/><category term="eip"/><category term="elastic ip"/><category term="euclidean"/><category term="euclidean distance"/><category term="file"/><category term="filtering"/><category term="google"/><category term="greece"/><category term="hint"/><category term="hints"/><category term="hotspot"/><category term="hotspotonthego"/><category term="html"/><category term="image"/><category term="instances"/><category term="internet"/><category term="jquery"/><category term="logs"/><category term="machine learning"/><category term="mail"/><category term="matlab"/><category term="matrix"/><category term="models"/><category term="multiprocessing"/><category term="no photoshop"/><category term="node"/><category term="online"/><category term="parse"/><category term="pdf"/><category term="picassa"/><category term="podcasts"/><category term="processing"/><category term="quora"/><category term="s3"/><category term="scribd"/><category term="search"/><category term="security groups"/><category term="select"/><category term="sort"/><category term="spider"/><category term="tips"/><category term="tree"/><category term="uoa"/><category term="upoad"/><category term="utilities"/><category term="web"/><category term="wifi"/><category term="Διπλωματική"/><category term="Επεξεργασία"/><category term="ΗΕΓ"/><category term="Πανεπιστήμιο"/><category term="Πατρών"/><title type='text'>First Thoughts</title><subtitle type='html'>Photoshop, php, Ajax, SQL, python, node, tutorials</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>78</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-9207642129027098605</id><published>2024-10-01T07:54:00.000-07:00</published><updated>2024-10-01T07:54:49.561-07:00</updated><title type='text'>Interview AI Assistant</title><content type='html'>&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;br class=&quot;Apple-interchange-newline&quot; /&gt;&lt;div class=&quot;absolute top-0 right-0 w-32 h-32 bg-yellow-100 rounded-full mix-blend-multiply filter blur-xl opacity-70 animate-blob animation-delay-2000&quot; style=&quot;--tw-bg-opacity: 1; --tw-blur: blur(24px); --tw-border-opacity: 1; --tw-brightness: var(--tw-empty, ); --tw-contrast: var(--tw-empty, ); --tw-drop-shadow: var(--tw-empty, ); --tw-grayscale: var(--tw-empty, ); --tw-hue-rotate: var(--tw-empty, ); --tw-invert: var(--tw-empty, ); --tw-ring-color: rgba(59, 130, 246, 0.5); --tw-ring-inset: var(--tw-empty, ); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 #0000; --tw-saturate: var(--tw-empty, ); --tw-sepia: var(--tw-empty, ); --tw-shadow: 0 0 #0000; animation: 10s ease 2s infinite normal none running blob; border-color: rgba(229,231,235,var(--tw-border-opacity)); border-radius: 9999px; border-style: solid; border-width: 0px; box-sizing: border-box; color: #333333; filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow); font-family: ui-sans-serif, system-ui, -apple-system, &amp;quot;system-ui&amp;quot;, &amp;quot;Segoe UI&amp;quot;, Roboto, &amp;quot;Helvetica Neue&amp;quot;, Arial, &amp;quot;Noto Sans&amp;quot;, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;, &amp;quot;Noto Color Emoji&amp;quot;; height: 8rem; margin: 0px; mix-blend-mode: multiply; opacity: 0.7; padding: 0px; position: absolute; right: 0px; top: 0px; width: 8rem;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;absolute -bottom-8 left-20 w-32 h-32 bg-pink-100 rounded-full mix-blend-multiply filter blur-xl opacity-70 animate-blob animation-delay-4000&quot; style=&quot;--tw-bg-opacity: 1; --tw-blur: blur(24px); --tw-border-opacity: 1; --tw-brightness: var(--tw-empty, ); --tw-contrast: var(--tw-empty, ); --tw-drop-shadow: var(--tw-empty, ); --tw-grayscale: var(--tw-empty, ); --tw-hue-rotate: var(--tw-empty, ); --tw-invert: var(--tw-empty, ); --tw-ring-color: rgba(59, 130, 246, 0.5); --tw-ring-inset: var(--tw-empty, ); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 #0000; --tw-saturate: var(--tw-empty, ); --tw-sepia: var(--tw-empty, ); --tw-shadow: 0 0 #0000; animation: 10s ease 4s infinite normal none running blob; border-color: rgba(229,231,235,var(--tw-border-opacity)); border-radius: 9999px; border-style: solid; border-width: 0px; bottom: -2rem; box-sizing: border-box; color: #333333; filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow); font-family: ui-sans-serif, system-ui, -apple-system, &amp;quot;system-ui&amp;quot;, &amp;quot;Segoe UI&amp;quot;, Roboto, &amp;quot;Helvetica Neue&amp;quot;, Arial, &amp;quot;Noto Sans&amp;quot;, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;, &amp;quot;Noto Color Emoji&amp;quot;; height: 8rem; left: 5rem; margin: 0px; mix-blend-mode: multiply; opacity: 0.7; padding: 0px; position: absolute; width: 8rem;&quot;&gt;&lt;/div&gt;&lt;section class=&quot;text-center relative&quot; style=&quot;--tw-border-opacity: 1; --tw-ring-color: rgba(59, 130, 246, 0.5); --tw-ring-inset: var(--tw-empty, ); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; background-color: white; border-color: rgba(229,231,235,var(--tw-border-opacity)); border-style: solid; border-width: 0px; box-sizing: border-box; color: #333333; font-family: ui-sans-serif, system-ui, -apple-system, &amp;quot;system-ui&amp;quot;, &amp;quot;Segoe UI&amp;quot;, Roboto, &amp;quot;Helvetica Neue&amp;quot;, Arial, &amp;quot;Noto Sans&amp;quot;, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;, &amp;quot;Noto Color Emoji&amp;quot;; margin: 0px; padding: 0px; position: relative; text-align: center;&quot;&gt;&lt;h1 class=&quot;text-6xl font-bold mb-6 text-shadow hero-title&quot; style=&quot;--tw-border-opacity: 1; --tw-ring-color: rgba(59, 130, 246, 0.5); --tw-ring-inset: var(--tw-empty, ); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; animation: 1s ease-out 0s 1 normal none running fadeInDown; border-color: rgba(229,231,235,var(--tw-border-opacity)); border-style: solid; border-width: 0px; box-sizing: border-box; font-size: 3.75rem; line-height: 1; margin: 0px 0px 1.5rem; padding: 0px; text-shadow: rgba(0, 0, 0, 0.1) 2px 2px 4px;&quot;&gt;Interview Assistant helps you get&lt;br style=&quot;--tw-border-opacity: 1; --tw-ring-color: rgba(59, 130, 246, 0.5); --tw-ring-inset: var(--tw-empty, ); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; border-color: rgba(229,231,235,var(--tw-border-opacity)); border-style: solid; border-width: 0px; box-sizing: border-box; margin: 0px; padding: 0px;&quot; /&gt;your dream job&lt;br style=&quot;--tw-border-opacity: 1; --tw-ring-color: rgba(59, 130, 246, 0.5); --tw-ring-inset: var(--tw-empty, ); --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; border-color: rgba(229,231,235,var(--tw-border-opacity)); border-style: solid; border-width: 0px; box-sizing: border-box; margin: 0px; padding: 0px;&quot; /&gt;using AI&lt;/h1&gt;&lt;/section&gt;&lt;br /&gt;&lt;p&gt;Check the &lt;a href=&quot;https://interview-assistant-ai.com/ &quot;&gt;Best Real-time interview assistant on the web&lt;/a&gt;. Uses OpenAI Gpt-4-o model, does live transcription and can help you during your interviews.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/9207642129027098605/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/9207642129027098605' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/9207642129027098605'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/9207642129027098605'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2024/10/interview-ai-assistant.html' title='Interview AI Assistant'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-8336104136718816668</id><published>2020-11-17T04:22:00.001-08:00</published><updated>2020-11-18T02:34:30.456-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="podcasts"/><title type='text'>Nice Ideas from Nice Discussions</title><content type='html'>&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Lusitana;&quot;&gt;Neural Plasticity&amp;nbsp;&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;&lt;span style=&quot;font-family: Lusitana;&quot;&gt;Remarkable Points&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: Lusitana;&quot;&gt;✔ In order to change or update yourself:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: Lusitana;&quot;&gt;First Act (Behavior First), then thoughts, feelings, and perceptions follow.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: Lusitana;&quot;&gt;or as a moto &quot;Mood follows Action&quot;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: Lusitana;&quot;&gt;✔ Use small rewards - punishments to move on&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: Lusitana;&quot;&gt;&lt;span&gt;✔ In the phase of a physical threat, there are 3 options:&amp;nbsp;&lt;/span&gt;&lt;span&gt;freeze, retreat, or move forward. The moving forward response actually triggers activation of a connection in the brain to the dopamine circuitry of the brain and makes it more likely that you are going to be able to move forward in the future. Also important is that the highest level of agitation and stress help us to move forward. Stopping and relaxing is not helpful at all.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: Lusitana;&quot;&gt;&lt;span&gt;✔&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;Stress is designed to move us forward!!&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: Roboto;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: Roboto;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: Lusitana;&quot;&gt;source:&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;iframe allowfullscreen=&quot;&quot; class=&quot;BLOG_video_class&quot; height=&quot;266&quot; src=&quot;https://www.youtube.com/embed/SwQhKFMxmDY&quot; width=&quot;320&quot; youtube-src-id=&quot;SwQhKFMxmDY&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/8336104136718816668/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/8336104136718816668' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/8336104136718816668'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/8336104136718816668'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2020/11/nice-ideas-from-nice-discussions.html' title='Nice Ideas from Nice Discussions'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/SwQhKFMxmDY/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-7358331797846199028</id><published>2018-10-18T02:09:00.003-07:00</published><updated>2018-10-18T02:09:32.084-07:00</updated><title type='text'>Regex to remove comments from SQL Stored Procedure</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;SQL Remove comments&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;The following regex expression&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;/\/\*[\s\S]*?\*\/|([^:]|^)--.*$/gm&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;removes following comments:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;1. Code block inside /* */&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;2. Rest of line --&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;In javascript you can simply do&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;b&gt;return sql_string.replace(/\/\*[\s\S]*?\*\/|([^:]|^)--.*$/gm,&#39;&#39;);&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrGfp6lW_kR5bzAqFrHJG_LScEHii-YQgxDG3RSdb9moZO0SxqC55Yh3RXiNy1oqRTT2EKTOl6RewcOZUUEct-wxYS088VpM04W3qwB1-jKMmToOxDVBDeqJEC_HzXzHS4sJXySXE2N2w/s1600/Screen+Shot+2018-10-18+at+12.07.23.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;443&quot; data-original-width=&quot;1199&quot; height=&quot;236&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrGfp6lW_kR5bzAqFrHJG_LScEHii-YQgxDG3RSdb9moZO0SxqC55Yh3RXiNy1oqRTT2EKTOl6RewcOZUUEct-wxYS088VpM04W3qwB1-jKMmToOxDVBDeqJEC_HzXzHS4sJXySXE2N2w/s640/Screen+Shot+2018-10-18+at+12.07.23.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/7358331797846199028/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/7358331797846199028' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/7358331797846199028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/7358331797846199028'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2018/10/regex-to-remove-comments-from-sql.html' title='Regex to remove comments from SQL Stored Procedure'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrGfp6lW_kR5bzAqFrHJG_LScEHii-YQgxDG3RSdb9moZO0SxqC55Yh3RXiNy1oqRTT2EKTOl6RewcOZUUEct-wxYS088VpM04W3qwB1-jKMmToOxDVBDeqJEC_HzXzHS4sJXySXE2N2w/s72-c/Screen+Shot+2018-10-18+at+12.07.23.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-8217176158893247284</id><published>2018-04-18T03:06:00.001-07:00</published><updated>2018-04-18T03:06:25.453-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="aws"/><category scheme="http://www.blogger.com/atom/ns#" term="node"/><category scheme="http://www.blogger.com/atom/ns#" term="s3"/><category scheme="http://www.blogger.com/atom/ns#" term="utilities"/><title type='text'>AWS S3 usefull utilities nodejs </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
AWS S3 Helpful Utilities - Helper functions using node&lt;/h2&gt;
I am using regularly the following snippets for downloading specific directory inside an S3 bucket.&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;// jshint esnext:true  
 // jshint node:true  
 &#39;use strict&#39;;  
 const AWS = require(&#39;aws-sdk&#39;);  
 const path = require(&#39;path&#39;);  
 const rimraf = require(&#39;rimraf&#39;);  
 const fs = require(&#39;fs&#39;);  
 const EventEmitter = require(&#39;events&#39;).EventEmitter;  
 exports.createClient = function(options) {  
   return new Client(options);  
 };  
 function Client(options) {  
   options = options || {};  
   this.s3 = new AWS.S3(options.s3Options);  
   this.s3RetryCount = options.s3RetryCount || 3;  
   this.s3RetryDelay = options.s3RetryDelay || 1000;  
   console.log(&#39;Client Created&#39;);  
 }  
 Client.prototype.downloadDir = function(params) {  
   return downloadDir(this, params);  
 };  
 function downloadDir(self, params) {  
   //if folder exists delete it   
   var downloader = new EventEmitter();  
   var keys;  
   if (params.localDir === undefined || params.localDir === null) {  
     downloader.emit(&#39;error&#39;, &#39;localDir cannot be empty&#39;);  
     return downloader;  
   }  
   if (params.s3Params === undefined || params.s3Params === null) {  
     downloader.emit(&#39;error&#39;, &#39;s3Params cannot be empty&#39;);  
     return downloader;  
   }  
   try {  
     initDirectorySync(params.localDir);  
   } catch (err) {  
     if (err) {  
       downloader.emit(&#39;error&#39;, err);  
       return downloader;  
     }  
   }  
   //lets get list items from S3   
   let items = [];  
   listKeys(self, params.s3Params, function(error, keys) {  
     console.log(&#39;Error = &#39; + JSON.stringify(error));  
     if (error) {  
       downloader.emit(&#39;error&#39;, error);  
       return downloader;  
     }  
     items = items.concat(keys);  
     items.forEach(function(item) {  
       var withoutPrefixKey = item.replace(params.s3Params.Prefix, &#39;&#39;);  
       //Lets check each item - key  
       //if ends in &#39;/&#39; then we have a directory  
       //else it is a file and we should get and download  
       if (withoutPrefixKey) {  
         //console.log(withoutPrefixKey);  
         if (withoutPrefixKey.slice(-1) === &#39;/&#39;) {  
           // console.log(&#39;Directory&#39;);  
           //lets create it   
           var fullpath = path.join(params.localDir, withoutPrefixKey);  
           fs.mkdirSync(fullpath);  
           console.log(&#39;Created Directory &#39; + fullpath);  
         } else {  
           downloadFile(self, params.s3Params.Bucket, item, path.join(params.localDir, withoutPrefixKey), function(err, result) {  
             if (err) {  
               console.log(&#39;Cannot create file &#39; + withoutPrefixKey);  
               console.log(err);  
             } else {  
               console.log(&#39;Created file &#39; + path.join(params.localDir, withoutPrefixKey));  
             }  
           });  
         }  
       }  
     });  
     downloader.emit(&#39;end&#39;);  
     return downloader;  
   });  
 }  
 /**  
  * List keys from the specified bucket.  
  *  
  * If providing a prefix, only keys matching the prefix will be returned.  
  *  
  * If providing a delimiter, then a set of distinct path segments will be  
  * returned from the keys to be listed. This is a way of listing &quot;folders&quot;  
  * present given the keys that are there.  
  *  
  * @param {Object} options  
  * @param {String} options.bucket - The bucket name.  
  * @param {String} [options.prefix] - If set only return keys beginning with  
  *  the prefix value.  
  * @param {String} [options.delimiter] - If set return a list of distinct  
  *  folders based on splitting keys by the delimiter.  
  * @param {Function} callback - Callback of the form function (error, string[]).  
  */  
 function listKeys(self, options, callback) {  
   var keys = [];  
   console.log(&#39;Options are &#39; + JSON.stringify(options));  
   /**  
    * Recursively list keys.  
    *  
    * @param {String|undefined} marker - A value provided by the S3 API  
    *  to enable paging of large lists of keys. The result set requested  
    *  starts from the marker. If not provided, then the list starts  
    *  from the first key.  
    */  
   function listKeysRecusively(marker) {  
     options.marker = marker;  
     listKeyPage(  
       self,  
       options,  
       function(error, nextMarker, keyset) {  
         if (error) {  
           return callback(error, keys);  
         }  
         keys = keys.concat(keyset);  
         if (nextMarker) {  
           listKeysRecusively(nextMarker);  
         } else {  
           callback(null, keys);  
         }  
       }  
     );  
   }  
   // Start the recursive listing at the beginning, with no marker.  
   listKeysRecusively();  
 }  
 /**  
    * List one page of a set of keys from the specified bucket.  
    *  
    * If providing a prefix, only keys matching the prefix will be returned.  
    *  
    * If providing a delimiter, then a set of distinct path segments will be  
    * returned from the keys to be listed. This is a way of listing &quot;folders&quot;  
    * present given the keys that are there.  
    *  
    * If providing a marker, list a page of keys starting from the marker  
    * position. Otherwise return the first page of keys.  
    *  
    * @param {Object} options  
    * @param {String} options.bucket - The bucket name.  
    * @param {String} [options.prefix] - If set only return keys beginning with  
    *  the prefix value.  
    * @param {String} [options.delimiter] - If set return a list of distinct  
    *  folders based on splitting keys by the delimiter.  
    * @param {String} [options.marker] - If set the list only a paged set of keys  
    *  starting from the marker.  
    * @param {Function} callback - Callback of the form  
     function (error, nextMarker, keys).  
    */  
 function listKeyPage(self, options, callback) { // jshint ignore:line  
   console.log(&#39;Options in listKeyPage are :&#39; + JSON.stringify(options));  
   var params = {  
     Bucket: options.Bucket,  
     Delimiter: options.delimiter,  
     Marker: options.marker,  
     MaxKeys: 1000,  
     Prefix: options.Prefix  
   };  
   self.s3.listObjects(params, function(error, response) {  
     if (error) {  
       console.log(error);  
       return callback(error);  
     } else if (response.err) {  
       console.log(response.err);  
       return callback(new Error(response.err));  
     }  
     // Convert the results into an array of key strings, or  
     // common prefixes if we&#39;re using a delimiter.  
     var keys;  
     if (options.delimiter) {  
       // Note that if you set MaxKeys to 1 you can see some interesting  
       // behavior in which the first response has no response.CommonPrefix  
       // values, and so we have to skip over that and move on to the  
       // next page.  
       keys = response.CommonPrefixes.map(function(item) {  
         return item.Prefix;  
       });  
     } else {  
       keys = response.Contents.map(function(item) {  
         return item.Key;  
       });  
     }  
     // Check to see if there are yet more keys to be obtained, and if so  
     // return the marker for use in the next request.  
     var nextMarker;  
     if (response.IsTruncated) {  
       if (options.delimiter) {  
         // If specifying a delimiter, the response.NextMarker field exists.  
         nextMarker = response.NextMarker;  
       } else {  
         // For normal listing, there is no response.NextMarker  
         // and we must use the last key instead.  
         nextMarker = keys[keys.length - 1];  
       }  
     }  
     callback(null, nextMarker, keys);  
   });  
 }  
 // If directory exists delete it and create from scratch  
 // If directory doesnot exist, create it  
 function initDirectorySync(directory) {  
   try {  
     fs.statSync(directory);  
     //if directory exists, remove it   
     cleanDir(directory);  
     //create it clean  
     fs.mkdirSync(directory);  
   } catch (e) {  
     fs.mkdirSync(directory);  
   }  
 }  
 function cleanDir(dir) {  
   rimraf.sync(dir, {  
     maxBusyTries: 1000  
   });  
 }  
 function downloadFile(self, bucket, key, localPath, callback) {  
   var params = { Bucket: bucket, Key: key };  
   var file = fs.createWriteStream(localPath);  
   file.on(&#39;close&#39;, function() {  
     callback();  
   });  
   file.on(&#39;error&#39;, function(err) {  
     callback(err);  
   });  
   self.s3.getObject(params).createReadStream().pipe(file);  
 }  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/8217176158893247284/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/8217176158893247284' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/8217176158893247284'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/8217176158893247284'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2018/04/aws-s3-usefull-utilities-nodejs.html' title='AWS S3 usefull utilities nodejs '/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-6446597067279184894</id><published>2018-03-13T03:53:00.001-07:00</published><updated>2018-03-13T05:34:25.375-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="airflow"/><category scheme="http://www.blogger.com/atom/ns#" term="apache"/><category scheme="http://www.blogger.com/atom/ns#" term="celery"/><title type='text'>Airflow with Celery Executor (MacOs)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://airflow.apache.org/_images/pin_large.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;800&quot; data-original-width=&quot;800&quot; height=&quot;200&quot; src=&quot;https://airflow.apache.org/_images/pin_large.png&quot; width=&quot;200&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Airflow - Celery Configuration&lt;/span&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;One of the best Apache projects (for me the best) is &lt;b&gt;Airflow&lt;/b&gt; Workflow Platform. The ease of use, the extending documentation and the connectivity with so many existing tools, makes it one of the best tools for creating and monitoring tasks using DAGs.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;On my first trials of the product I wanted to use &lt;a href=&quot;http://www.celeryproject.org/&quot;&gt;Celery&lt;/a&gt;&amp;nbsp;as worker machine. Airflow documentation describes the steps to do so, however I wanted to have more detailed instructions. In the following tutorial we are going to use as executor Celery. Celery will use &lt;a href=&quot;https://www.rabbitmq.com/&quot;&gt;RabbitMQ&lt;/a&gt;&amp;nbsp;as Messaging Queue for the tasks.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: xx-small;&quot;&gt;(in brief instructions are located in&amp;nbsp;https://airflow.apache.org/configuration.html?highlight=postgres#scaling-out-with-celery)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;u&gt;Install RabbitMQ&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;1. brew install rabbitmq&lt;br /&gt;(If this fails to link installed file to /usr/local/sbin, the create dir and run brew link rabbitmq)&lt;br /&gt;2. sudo nano ~/.bash_profile&lt;br /&gt;3. Add to PATH :/usr/local/sbin&lt;br /&gt;4. source ~/.bash_profile&lt;br /&gt;5. sudo rabbitmq-server -detached&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;6. sudo rabbitmqctl add_user airflow airflow&lt;br /&gt;7. Check status sudo rabbitmqctl status&lt;br /&gt;&lt;br /&gt;&lt;u&gt;Install Celery &lt;/u&gt;&lt;br /&gt;1. pip install Celery==3.1.25 // version 4 seems to have issues&lt;br /&gt;2. Check Celery installation:&amp;nbsp; celery --version&lt;/span&gt;&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #f4f4f4; background-color: #000000}
span.s1 {font-variant-ligatures: no-common-ligatures}
&lt;/style&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;u&gt;Install Postgres&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;1. brew install postgresql&lt;br /&gt;2. CREATE DATABASE airflow;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Create login user &quot;airflow&quot; with password &quot;airflow&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;4. pip install psycopg2&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Run&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;5. airflow initdb&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;u&gt;Config Airflow&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;1. nano ~/airflow/airflow.config&lt;br /&gt;Change the following lines:&lt;br /&gt;&lt;i&gt;executor = CeleryExecutor&lt;br /&gt;broker_url = amqp://airflow:airflow@localhost:5672/myvhost&lt;br /&gt;celery_result_backend = db+postgres+psycopg2://airflow:airflow@127.0.0.1:5432/airflow&lt;br /&gt;sql_alchemy_conn = postgres+psycopg2://airflow:airflow@127.0.0.1:5432/airflow&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;br /&gt;2. Run worker with &lt;br /&gt; airflow worker&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Tip.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Start scheduler and webserver&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;airflow webserver&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;airflow scheduler&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;References:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;1. https://stlong0521.github.io/20161023%20-%20Airflow.html&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;2. Setup on Ubuntu machines: https://medium.com/a-r-g-o/installing-apache-airflow-on-ubuntu-aws-6ebac15db211&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #f4f4f4; background-color: #000000}
span.s1 {font-variant-ligatures: no-common-ligatures}
&lt;/style&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/6446597067279184894/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/6446597067279184894' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/6446597067279184894'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/6446597067279184894'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2018/03/airflow-with-celery-executor-macos.html' title='Airflow with Celery Executor (MacOs)'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-8969145065458826343</id><published>2017-12-29T08:43:00.001-08:00</published><updated>2018-01-02T01:30:22.822-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="deep learning"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type='text'>Deep Learning Essentials</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Deep Learning Essentials:&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This page will become a reference page of most common used libraries when doing deep learning research in python.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Numpy&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;np.random&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;np.random.permutation&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt; np.array([123.68, 116.779, 103.939], dtype=np.float32).reshape((3,1,1))&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;helvetica neue&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;np.argmax(all_preds, axis=1)&lt;br /&gt;np.array(preds)&lt;br /&gt;np.newaxis&lt;br /&gt;np.zeros&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;Scipy&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;helvetica neue&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;helvetica neue&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;rom scipy import misc, ndimage&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;helvetica neue&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;from scipy.ndimage.interpolation import zoom&lt;br /&gt;from scipy.ndimage import imread&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;helvetica neue&amp;quot; , &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;csv&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;with open(&#39;results.csv&#39;, &#39;wb&#39;) as csv_file:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;writer = csv.writer(csv_file)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; writer.writerow&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for result in results:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for key, value in result.items():&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;writer.writerow([key, value])&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Keras&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;from keras.preprocessing import image&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;image.load_img&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Linear Model - Dense Layer (Fully Connexted: ax+b)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/8969145065458826343/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/8969145065458826343' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/8969145065458826343'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/8969145065458826343'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2017/12/deep-learning-essentials.html' title='Deep Learning Essentials'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-5125897264086350263</id><published>2017-12-28T04:02:00.000-08:00</published><updated>2018-01-09T08:18:36.372-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="deep learning"/><category scheme="http://www.blogger.com/atom/ns#" term="machine learning"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type='text'>Deep Learning in Practice</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Lately, I am following and practicing (one or two hours per day) the amazing &lt;a href=&quot;http://course.fast.ai/index.html&quot;&gt;deep learning lessons &lt;/a&gt;from Jeremy Howard and Rachel Thomas. Their teaching methodology is rather &quot;top-down&quot; than &quot;bottom up&quot; so from the first hour you will be able to run successfully image classifications.&lt;/div&gt;
&lt;br /&gt;
Jeremy has put a nice and helpful file with useful utility functions (&#39;utils.py&#39;)&lt;br /&gt;
&lt;br /&gt;
I will share here some useful scripts that maybe&amp;nbsp;you will find useful.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Lesson 1&lt;/b&gt;: &lt;a href=&quot;https://gist.github.com/alexopoulos7/272d3e7d1f57e95d53d84abf45fcccbf&quot;&gt;fast-ai-utils.py&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;a href=&quot;https://gist.githubusercontent.com/alexopoulos7/272d3e7d1f57e95d53d84abf45fcccbf/raw/a556dae82766bf3debb9109ed2c57be7863b7297/fast-ai-utils.py&quot;&gt;https://gist.githubusercontent.com/alexopoulos7/272d3e7d1f57e95d53d84abf45fcccbf/raw/a556dae82766bf3debb9109ed2c57be7863b7297/fast-ai-utils.py&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; # fast.ai Lesson 1  
 def create_validation_set(from_path, to_path, percentage = 0.2):  
   count_files_from_path = len(os.listdir(from_path))  
   validation_count = percentage * count_files_from_path  
   print(&#39;Lets copy {}/{} files for validation&#39;.format(validation_count, count_files_from_path))  
   for i in range(int(validation_count)):  
     random_path = random.choice(os.listdir(from_path))  
     os.rename(from_path+random_path, to_path+random_path)  
   
   print(&#39;Create {} Validation Set finished! &#39;.format(percentage))    
   
 # create_validation_set(&#39;/home/ec2-user/courses/deeplearning1/nbs/data/train/cat/&#39;, &#39;/home/ec2-user/courses/deeplearning1/nbs/data/validation/cat/&#39;)  
 # create_validation_set(&#39;/home/ec2-user/courses/deeplearning1/nbs/data/train/dog/&#39;, &#39;/home/ec2-user/courses/deeplearning1/nbs/data/validation/dog/&#39;)  
   
   
 def move_files_to_categories(from_directory):  
   &quot;&quot;&quot;  
   It will move labeled images to respective folders.  
   e.g. file cat_1.jpg will be moved to folder cat  
   &quot;&quot;&quot;  
   for filename in os.listdir(from_directory):  
     parts = filename.split(&#39;.&#39;)  
     if len(parts) &amp;gt; 2 and parts[2] in [&#39;jpg&#39;, &#39;jpeg&#39;, &#39;png&#39;]:  
       category = from_directory + parts[0]  
       if not os.path.exists(category):  
         os.makedirs(category)  
       print(&#39;Rename from {}&#39;.format(from_directory+filename))  
       os.rename(from_directory+filename, os.path.join(category, filename))  
       print (&#39;Moved file to {}&#39;.format(os.path.join(category, filename)))  
       
 # move_files_to_categories(&#39;/home/ec2-user/courses/deeplearning1/nbs/data/train/&#39;)  
 &lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;import shutil
def create_sample_directory(from_directory, to_dir, sample_count = 1000):  
   &quot;&quot;&quot;  
   It will create sample dir  
   &quot;&quot;&quot;  
   for d in os.listdir(from_directory):  
        for i in range(sample_count):
            target_dir = to_dir+&#39;validation/&#39;+d
            if not os.path.exists(target_dir):  
                os.makedirs(target_dir)  
            random_path = random.choice(os.listdir(from_directory+d)) 
            
            #print (&#39;Copy file from from {}&#39;.format(os.path.join(from_directory+d, random_path)))  
            #print (&#39;Copy file from to {}&#39;.format(os.path.join(target_dir, random_path)))  
            shutil.copy2(os.path.join(from_directory+d, random_path), os.path.join(target_dir, random_path))
        
        for i in range(sample_count):
            target_dir = to_dir+&#39;/train/&#39;+d
            if not os.path.exists(target_dir):  
                os.makedirs(target_dir)  
            random_path = random.choice(os.listdir(from_directory+d)) 
            
            #print (&#39;Copy file from from {}&#39;.format(os.path.join(from_directory+d, random_path)))  
            #print (&#39;Copy file from to {}&#39;.format(os.path.join(target_dir, random_path)))  
            shutil.copy2(os.path.join(from_directory+d, random_path), os.path.join(target_dir, random_path))
       
create_sample_directory(&#39;/home/ec2-user/courses/deeplearning1/nbs/images/train/&#39;,&#39;/home/ec2-user/courses/deeplearning1/nbs/images/samples/&#39;)&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;  
 def show_image(image_path):  
   import matplotlib.image as mpimg    
   img=mpimg.imread(image_path)  
   imgplot = plt.imshow(img)  
&lt;/code&gt;&lt;/pre&gt;
&lt;script src=&quot;https://gist.github.com/alexopoulos7/272d3e7d1f57e95d53d84abf45fcccbf.js?file=fast-ai-utils.py&quot;&gt;&lt;/script&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/5125897264086350263/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/5125897264086350263' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/5125897264086350263'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/5125897264086350263'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2017/12/deep-learning-in-practice_28.html' title='Deep Learning in Practice'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-1207418069985650664</id><published>2017-07-14T03:50:00.000-07:00</published><updated>2018-01-02T02:53:51.094-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="matlab"/><category scheme="http://www.blogger.com/atom/ns#" term="matrix"/><category scheme="http://www.blogger.com/atom/ns#" term="quora"/><title type='text'>Matlab Matrices</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Lately, I have been taking the amazing and very famous &lt;a href=&quot;https://www.coursera.org/learn/machine-learning/&quot;&gt;Andrews NG Machine Learning Classes on Coursera&lt;/a&gt; platform!!&lt;br /&gt;
&amp;nbsp;

&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcgEFgCJT8fY1OfdpZ06vOg6_sGo1vHol15hWJguJzwq5Yy0goYdxHfZwHZ-wr8K3QcdOuhDt0HIiEYD-XTQgxF15ckbfWjcsZDnYiYgJubKZiM07ZohLCcKUmWqb8t6B9Y6WYnyNUPj0/s1600/Screen+Shot+2017-07-14+at+13.53.07.png&quot; imageanchor=&quot;1&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;379&quot; data-original-width=&quot;1600&quot; height=&quot;152&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcgEFgCJT8fY1OfdpZ06vOg6_sGo1vHol15hWJguJzwq5Yy0goYdxHfZwHZ-wr8K3QcdOuhDt0HIiEYD-XTQgxF15ckbfWjcsZDnYiYgJubKZiM07ZohLCcKUmWqb8t6B9Y6WYnyNUPj0/s640/Screen+Shot+2017-07-14+at+13.53.07.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
I am amazed on how everything is presented easily and simplified.

The exercises and practical assignments come with a lot of code in tutorial code that we need to fill in the gaps.&lt;br /&gt;
&lt;br /&gt;
My conclusion is that in order to master Matlab you have first to master Matlab matrices and vectors. If you want speed in calculation we have first to &quot;matrixize&quot; formulas.&lt;br /&gt;
&lt;br /&gt;
Following are some of the best and most used tips on matrixes (from &lt;a href=&quot;https://www.quora.com/What-are-good-ways-to-write-matlab-code-in-matrix-way&quot;&gt;Quora question&lt;/a&gt;).&lt;br /&gt;
Always useful is Mathworks help &lt;a href=&quot;http://www.mathworks.com/help/matlab/matlab_prog/vectorization.html&quot;&gt;article&lt;/a&gt;.

&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; x = zeros(n,m);     % initialize x to all zeros  
 x = ones(n,m) * 5;    % initialize all x to 5s  
 x(4,:) = 5;       % assign 5 to all elements of row #4  
 x(:,1) = x(:,1) + x(:,2);% add column #2 to column #1  
 y = x(2:5, 1:6);     % copy inner block rows 2-5 and columns 1-6 to y  
 z = x + y;        % add all elements of x and y, store in z  
 z = x * y;        % matrix multiply x and y, store in z  
 z = x .* y;       % individually multiply elements of x and y, store in z  
 z = x .^ 2;       % set each element of z to the same element of x squared  
 w = find(x == 5);    % search x for elements == 5, store integer indices in w  
 w = (x == 5);      % create binary matrix w that has a 1 anywhere x == 5  
 x(w) = 8;        % set value of all elements found above (either case) to 8  
 z = sum(x(:) &amp;lt; 1);     % count how many elements have value &amp;lt; 1  
 x(x &amp;lt; 0) = 0;      % set all negative elements of x to zero  
 y = mean(x, 1);     % set y(1,i) to the average of each column of x  
 y = mean(x(:));     % set y to the average of all elements of x  
 y = mean2(x);      % set y to the average of all elements of x (2D only)  
 x = [y, x];       % prepend columns of y to matrix x  
 x(:,end+1) = 5;     % add a column of 5s to the right side of x  
 z = sqrt(mean(x(:).^2)); % set z to the root-mean-square of all elements in x  
 if any(x(:) == 5)    % true if any element of x == 5  
 if all(x(:) == 0)    % true if all elements of x == 0  
 if any(all(x == 0, 2))  % true if any rows are all zeros  
 x = bsxfun(@times, x, 1./sum(x));  % normalize x so each column sums to 1  
 x = (x - min(x(:))) ./ (max(x(:)) - min(x(:))); % normalize x so min==0 and max==1  
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/1207418069985650664/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/1207418069985650664' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/1207418069985650664'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/1207418069985650664'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2017/07/matlab-matrices.html' title='Matlab Matrices'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcgEFgCJT8fY1OfdpZ06vOg6_sGo1vHol15hWJguJzwq5Yy0goYdxHfZwHZ-wr8K3QcdOuhDt0HIiEYD-XTQgxF15ckbfWjcsZDnYiYgJubKZiM07ZohLCcKUmWqb8t6B9Y6WYnyNUPj0/s72-c/Screen+Shot+2017-07-14+at+13.53.07.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-6941843196891246815</id><published>2017-03-15T07:39:00.001-07:00</published><updated>2017-03-15T07:39:22.766-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="content"/><category scheme="http://www.blogger.com/atom/ns#" term="duplicate"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="search"/><category scheme="http://www.blogger.com/atom/ns#" term="tree"/><title type='text'>Search a directory tree for all files with same content</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; hashmap = {} # content signature -&amp;gt; list of matching filenames  
 for path, dirs, files in os.walk(&#39;.&#39;): # walk current directory  
   for filename in files:  
     fullname = os.path.join(path, filename)  
     contents = open(fullname).read()  
     h = hashlib.md5(contents).hexdigest()  
     hashmap.setdefault(h,[]).append(fullname)  
 pprint.pprint(hashmap)  
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/6941843196891246815/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/6941843196891246815' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/6941843196891246815'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/6941843196891246815'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2017/03/search-directory-tree-for-all-files.html' title='Search a directory tree for all files with same content'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-6460260542368690733</id><published>2017-03-15T07:02:00.000-07:00</published><updated>2017-03-15T08:10:55.217-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="apache"/><category scheme="http://www.blogger.com/atom/ns#" term="logs"/><category scheme="http://www.blogger.com/atom/ns#" term="parse"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type='text'>Parse Apache Logs</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Lets create a simple script to parse Apache Logs and print the 20 most common visited urls, I think this is a very useful script that can be easily ported in every case:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; counter = collections.Counter()  
 for filename in glob.glob(&#39;var/log/apache2/*.gz&#39;):  
   for line in gzip.open(filename):  
     mo = re.search(r&#39;GET (.*) HTTP/1&#39;, line)  
     if mo is not None:  
       url = mo.group(1)  
       counter[url] +=1  
 result = heapq.nlargest(20, counter.items(), key=lambda(url,cnt): cnt)  
 pprint result  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/6460260542368690733/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/6460260542368690733' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/6460260542368690733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/6460260542368690733'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2017/03/parse-apache-logs.html' title='Parse Apache Logs'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-220906089948627467</id><published>2017-03-14T06:20:00.000-07:00</published><updated>2017-03-16T10:21:48.815-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="advice"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="tips"/><title type='text'>Become awesome in Python!!</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Hello and welcome to my series of Python tips and tricks. I am going to list every single advice that I find interesting so that I can create a reference list.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The advice will make our Python code&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Beautiful (Beautiful is always good -- also it makes it easy maintainable)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Fast (Fast in processing, less in memory)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Pythonic (A lot of us come with different programming background, To master a language we have to go its way along)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Testable&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;1. Refactor (Extract) complex if clauses to variables to improve readibility.&lt;/b&gt;&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; if str.lower().endswith(&#39;r&#39;):  
   print (&#39;{0} ends with r&#39;.format(str)  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
can become the more readable:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; str_ends_with_r = str.lower().endswith(&#39;r&#39;)  
 if str_ends_with_r:  
   print (&#39;{0} ends with r&#39;.format(str)  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;2. Refactor (Extract) variables into classes to improve testability.&lt;/b&gt;&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;br /&gt;
Lets create our class:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; class EndsWithR(object):  
   def __init__(self,str):  
     self.str = str  
     self.r = str.lower().endswith(&#39;r&#39;)  
     self.result = str.lower().endswith(&#39;r&#39;)  
   def __bool__(self): # __nonzero__   
     return self.result  
 &lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Lets call our class&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;/pre&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;str_ends_with_r = EndsWitR(str)  
 if str_ends_with_r:   
      print (&#39;{0} ends with r&#39;.format(str)   
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
So now it is very easy to test our code&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; test = EndsWithR(&#39;some Example string that ends with r&#39;)  
 assert test  
 assert test.r  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;3. Refactor classes with a lot of properties by Splitting Classes.&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
Create a parent class and subclass.&lt;br /&gt;
Use&amp;nbsp;@Property decorator&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;4. Exit Loops fast&lt;/b&gt;&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; def search_fast(haystack, needle):   
   for item in haystack:   
     if item == needle:   
       return True   
   return False   &lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;
 def search_slow(haystack, needle):   
   return_value = False   
   for item in haystack:   
     if item == needle:   
       return_value = True   
   return return_value  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;5. Open and Write Files uniformly for Python 2 and Python 3&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We add &lt;b&gt;&#39;wb&#39; type &lt;/b&gt;to indicate &#39;Binary mode&#39;, otherwise in Python 3 opening a file defaults to reading or writing UTF-8 strings.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; with open(‘/tmp/random.bin’, ‘wb’) as f:  
   f.write(os.urandom(10))  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;6. Use &lt;i&gt;get &lt;/i&gt;method to access dictionary values&lt;/b&gt;&lt;br /&gt;
e.g. In this way we can get a default value in case dictionary key doesn&#39;t exist&lt;br /&gt;
&lt;pre class=&quot;prettyprint notranslate tryit prettyprinted&quot; style=&quot;background: url(&amp;quot;/python/images/try-it.jpg&amp;quot;) right top no-repeat rgb(238, 238, 238) !important; border-radius: 0px; border: 1px solid rgb(214, 214, 214); box-sizing: border-box; color: #313131; cursor: default; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13px; line-height: 16px; margin-bottom: 10px; min-height: 37px; overflow: auto; padding: 5px; width: 604px;&quot;&gt;&lt;span class=&quot;pln&quot; style=&quot;box-sizing: border-box;&quot;&gt;dict &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;box-sizing: border-box; color: #666600;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;box-sizing: border-box;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;box-sizing: border-box; color: #666600;&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;box-sizing: border-box; color: #008800;&quot;&gt;&#39;Name&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;box-sizing: border-box; color: #666600;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;box-sizing: border-box;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;box-sizing: border-box; color: #008800;&quot;&gt;&#39;Zabra&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;box-sizing: border-box; color: #666600;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;box-sizing: border-box;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;box-sizing: border-box; color: #008800;&quot;&gt;&#39;Age&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;box-sizing: border-box; color: #666600;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;box-sizing: border-box;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;lit&quot; style=&quot;box-sizing: border-box; color: #006666;&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;box-sizing: border-box; color: #666600;&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;box-sizing: border-box;&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;box-sizing: border-box; color: #000088;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;box-sizing: border-box;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;box-sizing: border-box; color: #008800;&quot;&gt;&quot;Value : %s&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;box-sizing: border-box;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;box-sizing: border-box; color: #666600;&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;box-sizing: border-box;&quot;&gt;  dict&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;box-sizing: border-box; color: #666600;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;box-sizing: border-box; color: #000088;&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;box-sizing: border-box; color: #666600;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;box-sizing: border-box; color: #008800;&quot;&gt;&#39;Age&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;box-sizing: border-box; color: #666600;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;box-sizing: border-box;&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;box-sizing: border-box; color: #000088;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;box-sizing: border-box;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;box-sizing: border-box; color: #008800;&quot;&gt;&quot;Value : %s&quot;&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;box-sizing: border-box;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;box-sizing: border-box; color: #666600;&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;box-sizing: border-box;&quot;&gt;  dict&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;box-sizing: border-box; color: #666600;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kwd&quot; style=&quot;box-sizing: border-box; color: #000088;&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;box-sizing: border-box; color: #666600;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;box-sizing: border-box; color: #008800;&quot;&gt;&#39;Education&#39;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;box-sizing: border-box; color: #666600;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;box-sizing: border-box;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;box-sizing: border-box; color: #008800;&quot;&gt;&quot;Never&quot;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;box-sizing: border-box; color: #666600;&quot;&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;prettyprint notranslate tryit prettyprinted&quot; style=&quot;background: url(&amp;quot;/python/images/try-it.jpg&amp;quot;) right top no-repeat rgb(238, 238, 238) !important; border-radius: 0px; border: 1px solid rgb(214, 214, 214); box-sizing: border-box; color: #313131; cursor: default; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 13px; line-height: 16px; margin-bottom: 10px; min-height: 37px; overflow: auto; padding: 5px; width: 604px;&quot;&gt;&lt;span class=&quot;pun&quot; style=&quot;box-sizing: border-box; color: #666600;&quot;&gt;&lt;pre class=&quot;result notranslate&quot; style=&quot;background-color: #f1f1f1; border-radius: 0px; border: 1px solid rgb(214, 214, 214); box-sizing: border-box; color: #313131; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; overflow: auto; padding: 5px; width: 604px;&quot;&gt;Value : 7
Value : Never&lt;/pre&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;7. &amp;nbsp;Reverse a Sequence&lt;/b&gt;&lt;br /&gt;
You can use sequence slicing [start:end:stride] with stride -1&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; x = b’mongoose’  
 y = x[::-1]  
 print(y)  
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;b’esoognom’&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Be aware though that this will not work as expected for UTF-8 strings&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;8. Prefer Generators for Large Comprehensions&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
as they have minimum memory footprint&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; it = (len(x) for x in open(‘/tmp/my_file.txt’))  
 print(it)  
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;generator genexpr=&quot;&quot; object=&quot;&quot;&gt; &amp;lt;generator object &amp;lt;genexpr&amp;gt; at 0x102b81480&amp;gt;&lt;/generator&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;9. Use enumerate() if you need index in looping or begin counting from specific index:&lt;/b&gt;&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; for &lt;b&gt;idx&lt;/b&gt;, flavor in enumerate(flavor_list, &lt;b&gt;2&lt;/b&gt;):  
     print(‘%d: %s’ % (idx, flavor))  
&lt;/code&gt;&lt;/pre&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;10. Use zip() to process iterators in parallel.&lt;/b&gt;&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;for name, count in zip(names, letters):  
    if count &amp;gt; max_letters:  
        longest_name = name  
        max_letters = count  
&lt;/code&gt;&lt;/pre&gt;
Actually zip creates a tuple for the smallest list&lt;br /&gt;
If you need to iterate to the longest list then use: &lt;b&gt;zip_longest&lt;/b&gt;&lt;br /&gt;
In Python 3 zip() is a generator function. In Python 2 it creates a new list of tuples. For python 2 we can use izip() to be more efficient.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;11. Python can return Multiple Values&lt;/b&gt;&lt;br /&gt;
This gives extreme freedom and flexibility to return a Value and a Status of execution.&lt;br /&gt;
for example following code returns result of division as long the status of execution. The returned is a tuple:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;def divide(a, b):  
    try:  
        return True, a / b  
    except ZeroDivisionError:  
        &lt;b&gt;return&lt;/b&gt; &lt;b&gt;False, None &lt;/b&gt; 
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;# And we can use them as following&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;success, result = divide(x, y)
if not success:
    print(‘Invalid inputs’)&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;12. Return Generators instead of Lists&lt;/b&gt;&lt;br /&gt;
Using the keyword &#39;&lt;i&gt;yield&#39; &lt;/i&gt;we can return Generators instead of Lists so that we can maximize performance and memory consumption&lt;br /&gt;
The transformation of code from Lists to Generators is easy:&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;def index_words(text):  
    result = []  
    if text:  
        result.append(0)  
    for index, letter in enumerate(text):  
        if letter == ‘ ‘:  
            result.append(index + 1)  
    return result  
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;b&gt;# The same code Can Become&lt;/b&gt;&lt;/pre&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; def index_words_iter(text):  
     if text:  
         &lt;b&gt;yield&lt;/b&gt; 0  
      for index, letter in enumerate(text):  
          if letter == ‘ ‘:  
              &lt;b&gt;yield&lt;/b&gt; index + 1  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;13. User repr for Classes for easier debugging&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; def __repr__(self):  
   return &#39;{0}&#39;.format(self.__class__.__name__)  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;14. Use namedtuples&lt;/b&gt;&lt;br /&gt;
Instead of&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; p = (170, 0.5, 0.6)  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
you can use namedtuples and make it much more readable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; from collections import namedtuple  
 Color = namedtuple(&#39;Color&#39;,[&#39;hue&#39;, &#39;saturation&#39;, &#39;luminosity&#39;])  
 p = Color(170, 0.5, 0.6)  
 if p.saturation &amp;gt;0.5:  
   print (&#39;That is bright&#39;)  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;References&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=D_6ybDcU5gc&quot;&gt;1. https://www.youtube.com/watch?v=D_6ybDcU5gc&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;https://www.youtube.com/watch?v=wf-BqAjZb8M&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;2. https://www.youtube.com/watch?v=wf-BqAjZb8M&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/220906089948627467/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/220906089948627467' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/220906089948627467'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/220906089948627467'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2017/03/become-awesome-in-python.html' title='Become awesome in Python!!'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-4941589636412593330</id><published>2017-02-27T00:16:00.000-08:00</published><updated>2017-02-27T00:16:01.506-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="amazon"/><category scheme="http://www.blogger.com/atom/ns#" term="aws"/><category scheme="http://www.blogger.com/atom/ns#" term="ec2"/><category scheme="http://www.blogger.com/atom/ns#" term="eip"/><category scheme="http://www.blogger.com/atom/ns#" term="elastic ip"/><category scheme="http://www.blogger.com/atom/ns#" term="instances"/><category scheme="http://www.blogger.com/atom/ns#" term="security groups"/><title type='text'>Securing AWS Instances</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blink.ucsd.edu/_images/technology-tab/aws.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;180&quot; src=&quot;https://blink.ucsd.edu/_images/technology-tab/aws.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Lately I was trying to publish a Web application to Amazon EC2 Cloud. The application had the classic approach of DB - Server Architecture. To be more specific I thought of using 2 &lt;b&gt;t2.medium&lt;/b&gt; EC2 instances, one for Web application and the other for the db. Those instances will be used for our staging environment.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;As for the &lt;i&gt;db&lt;/i&gt; we are using a PostgreSQL Server. We followed this approach and not use an Amazon RDS service as we wanted to host some other small applications in that specific machine instance. I would recommend however not to follow this approach in your cases.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;The &lt;i&gt;Application&lt;/i&gt; is served from Apache2 Server in port 80 that loads content from a django site. The Application instance is associated with an Elastic Ip, so that we give it to our client.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;The most important part for the EC2 instances is the security and how we are going to be safe from the outer world. Luckily, security groups come very handy!&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;The Application server has opened the 80 port to our clients &lt;a href=&quot;https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing&quot;&gt;CIDR&lt;/a&gt; IP and our company&#39;s IPs. We have also opened SSH Port (22) to our company&#39;s IPs.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;The difficult part was how to secure our db instance. We do not want any access from the outside, only from the Application Server. To do so at first we thought creating an Inbound Rule from Elastic IP to Port 5432. However, Amazon was not happy about this choice.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;The reason as explained from Amazon Docs:&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot; style=&quot;text-align: justify;&quot;&gt;




&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Arial; color: #242729; -webkit-text-stroke: #242729; background-color: #fff8dc}
span.s1 {font-kerning: none}
&lt;/style&gt;


&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;When you specify a security group as the source or destination for a rule, the rule affects all instances associated with the security group. For example, incoming traffic is allowed based on the private IP addresses of the instances that are associated with the source security group.&lt;/span&gt;&lt;/div&gt;
&lt;/blockquote&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Solution:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;We created a new Inbound Custom Rule using the security group name of the Application Server Instance. It worked like charm! Cheers :-)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/4941589636412593330/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/4941589636412593330' title='1 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/4941589636412593330'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/4941589636412593330'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2017/02/securing-aws-instances.html' title='Securing AWS Instances'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-6169152630343685850</id><published>2016-12-10T04:29:00.002-08:00</published><updated>2016-12-10T04:29:53.179-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hackerrank"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="js"/><category scheme="http://www.blogger.com/atom/ns#" term="solution"/><title type='text'>Greedy Florist Solution in javascript</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;




&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 36.0px &#39;Avenir Next&#39;; color: #39424e; -webkit-text-stroke: #39424e}
span.s1 {font-kerning: none}
&lt;/style&gt;


&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;Greedy Florist&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://www.hackerrank.com/challenges/greedy-florist&quot;&gt;Hackerrank&lt;/a&gt; solution in javascript&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;Problem&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;You and friends want to buy flowers. Each flower has some cost . The florist is greedy and wants to maximize his number of new customers, so he increases the sale price of flowers for repeat customers; more precisely, if a customer has already purchased flowers, price for is .&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;Find and print the minimum cost for your group to purchase flowers.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;Note:&lt;/b&gt; You can purchase the flowers in any order.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;Input Format&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;The first line contains two integers, (number of flowers to purchase) and (the size of your group of friends, including you).&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;




&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Avenir; color: #39424e; -webkit-text-stroke: #39424e}
span.s1 {font-kerning: none}
&lt;/style&gt;







&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;The second line contains space-separated positive integers describing the cost () for each flower .&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; function processData(input) {  
   input = input.split(&#39;\n&#39;);  
   let n = parseInt(input[0].split(&#39; &#39;)[0]);  
   let k = parseInt(input[0].split(&#39; &#39;)[1]);  
   let flowers = input[1].split(&#39; &#39;).map(Number).sort((a,b)=&amp;gt;{return b-a});  
   let price = 0;  
   let x =0;  
   for (let i=0; i&amp;lt;n;i++){  
     if(i%k===0 &amp;amp;&amp;amp; i!==0){  
       x++;  
     }  
     price +=((x+1)*flowers[i]);  
   }  
   //console.log(&#39;Final Price &#39;+price);  
     
   console.log(price);  
     
 }   
   
 process.stdin.resume();  
 process.stdin.setEncoding(&quot;ascii&quot;);  
 _input = &quot;&quot;;  
 process.stdin.on(&quot;data&quot;, function (input) {  
   _input += input;  
 });  
   
 process.stdin.on(&quot;end&quot;, function () {  
   processData(_input);  
 });  
   
   
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/6169152630343685850/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/6169152630343685850' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/6169152630343685850'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/6169152630343685850'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2016/12/greedy-florist-solution-in-javascript.html' title='Greedy Florist Solution in javascript'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-5871418037054470258</id><published>2016-12-10T03:05:00.002-08:00</published><updated>2016-12-10T03:05:57.471-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hackerrank"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="js"/><category scheme="http://www.blogger.com/atom/ns#" term="solution"/><title type='text'>Mark and Toys Solution in Javascript</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;




&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 36.0px &#39;Avenir Next&#39;; color: #39424e; -webkit-text-stroke: #39424e}
span.s1 {font-kerning: none}
&lt;/style&gt;


&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;Mark and Toys&lt;/b&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;Solution in Javascript&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;span class=&quot;s1&quot;&gt;problem from &lt;a href=&quot;https://www.hackerrank.com/challenges/mark-and-toys&quot;&gt;Hackerrank.com&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;Problem&lt;/span&gt;&lt;/h3&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;Mark and Jane are very happy after having their first kid. Their son is very fond of toys, so Mark wants to buy some. There are different toys lying in front of him, tagged with their prices, but he has only . He wants to maximize the number of toys he buys with this money.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;Now, you are Mark&#39;s best friend and have to help him buy as many toys as possible.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;Input Format&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;




&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Avenir; color: #39424e; -webkit-text-stroke: #39424e}
span.s1 {font-kerning: none}
&lt;/style&gt;





&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;The first line contains two integers, and , followed by a line containing space separated integers indicating the products&#39; prices&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;The key thing to the solution is just to sort toys.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; function processData(input) {  
   input = input.split(&#39;\n&#39;);  
   n = parseInt(input[0].split(&#39; &#39;)[0]);  
   money = parseInt(input[0].split(&#39; &#39;)[1]);  
   toys = input[1].split(&#39; &#39;).map(Number).sort((a,b)=&amp;gt;{return a-b});  
   //console.log(&#39;Toys sorted are &#39;+toys);  
   let countToys = 0;  
   let moneyLeft = money;  
   let i = 0;  
   while(n-- &amp;amp;&amp;amp; moneyLeft&amp;gt;0){  
     moneyLeft-=toys[i];  
     if(moneyLeft&amp;gt;=0){  
       countToys++;  
       //console.log(&#39;Buy item &#39;+i +&#39; with price &#39;+toys[i]+&#39; and moneyLeft = &#39;+moneyLeft);  
       i++;  
     }  
     else{  
       break;  
     }  
   }  
   console.log(countToys);  
 }   
   
 process.stdin.resume();  
 process.stdin.setEncoding(&quot;ascii&quot;);  
 _input = &quot;&quot;;  
 process.stdin.on(&quot;data&quot;, function (input) {  
   _input += input;  
 });  
   
 process.stdin.on(&quot;end&quot;, function () {  
   processData(_input);  
 });  
   
   
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/5871418037054470258/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/5871418037054470258' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/5871418037054470258'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/5871418037054470258'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2016/12/mark-and-toys-solution-in-javascript.html' title='Mark and Toys Solution in Javascript'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-4259794423633728144</id><published>2016-12-10T02:43:00.001-08:00</published><updated>2016-12-10T02:43:11.981-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hackerrank"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="js"/><category scheme="http://www.blogger.com/atom/ns#" term="solution"/><title type='text'>Largest Permutation Javascript Solution </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;




&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 36.0px &#39;Avenir Next&#39;; color: #39424e; -webkit-text-stroke: #39424e}
span.s1 {font-kerning: none}
&lt;/style&gt;


&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;Largest Permutation Solution&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/h3&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;a href=&quot;https://www.hackerrank.com/challenges/largest-permutation&quot;&gt;from hackerrank.com&lt;/a&gt;&lt;/h4&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Problem:&lt;/h3&gt;
&lt;div&gt;




&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Avenir; color: #39424e; -webkit-text-stroke: #39424e}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Avenir; color: #39424e; -webkit-text-stroke: #39424e; min-height: 22.0px}
span.s1 {font-kerning: none}
&lt;/style&gt;


&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;You are given an array of integers which is a permutation of the first natural numbers. You can swap any two elements of the array. You can make at most swaps. What is the largest permutation, in numerical order, you can make?&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;Input Format&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;The first line of the input contains two integers, and , the size of the input array and the maximum swaps you can make, respectively. The second line of the input contains a permutation of the first natural numbers.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;Output Format&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;Print the lexicographically largest permutation you can make with &lt;b&gt;at most&lt;/b&gt; swaps.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Solution in Javascript&lt;/h3&gt;
&lt;/div&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; function swap(list, index1,index2){  
   //console.log(&#39;SWAP &#39;+index1 +&#39; with index &#39;+index2);  
   var b = list[index2];  
   list[index2] = list[index1];  
   list[index1] = b;  
 }  
   
 function processData(input) {  
   input = input.split(&#39;\n&#39;);  
   let list = input[1].split(&#39; &#39;).map(Number);  
   let n = parseInt(input[0].split(&#39; &#39;)[0]);  
   let k = parseInt(input[0].split(&#39; &#39;)[1]);  
   let result_list = [];  
   let j = 0;  
   let list_index = [];  
   //console.log(&#39;List is &#39;+list);  
   for(let i=0; i&amp;lt;n; i++){  
     //console.log(i, list[i]);  
     list_index[list[i]] = i;  
   }  
   let exitMainLoop = false;  
   // console.log(&#39;List Index is &#39;+list_index);  
   while (k--) {  
     //console.log(&#39;K is &#39;+k);  
     for(let i=j;i&amp;lt;n;i++){  
       //console.log(&#39;i = &#39;+i+&#39; j= &#39;+j);  
       //console.log(&#39;List[i] = &#39;+list[i]);  
       //console.log(&#39;n-i =&#39;+(n-i));  
      if(list[i]!==n-i){  
        let temp = list_index[n-i];  
        //console.log(&#39;Temp is &#39;+temp);  
        let t = list_index[list[i]];  
        //console.log(&#39;list_index before swapping is &#39;+list_index);  
        swap(list_index,list[i],list[temp]);  
        //console.log(&#39;list_index after swapping is &#39;+list_index);  
        //console.log(&#39;list before swapping is &#39;+list);  
        swap(list,i,temp);  
        //console.log(&#39;list after swapping is &#39;+list);  
          
        break;  
      }  
       // console.log(&#39;In order to avoid timeouts we should exit main While loop as soon we have finished swapping all elements&#39;);  
       if(i&amp;gt;n-2){  
          exitMainLoop = true;  
        }  
         
     }  
     if(exitMainLoop){  
       break;  
     }  
     j++;  
   }  
     
   console.log(list.join(&#39; &#39;));  
     
 }   
   
 process.stdin.resume();  
 process.stdin.setEncoding(&quot;ascii&quot;);  
 _input = &quot;&quot;;  
 process.stdin.on(&quot;data&quot;, function (input) {  
   _input += input;  
 });  
   
 process.stdin.on(&quot;end&quot;, function () {  
   processData(_input);  
 });  
   
   
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/4259794423633728144/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/4259794423633728144' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/4259794423633728144'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/4259794423633728144'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2016/12/largest-permutation-javascript-solution.html' title='Largest Permutation Javascript Solution '/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-7038382434451267350</id><published>2016-12-09T04:54:00.002-08:00</published><updated>2016-12-09T04:54:19.844-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="beautiful soup"/><category scheme="http://www.blogger.com/atom/ns#" term="crawler"/><category scheme="http://www.blogger.com/atom/ns#" term="multiprocessing"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="spider"/><title type='text'>Spidering the Web</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: x-large;&quot;&gt;Spidering the Web &amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjf_3gCM_Shgw-lDv8qs56sSxIImAbSgt5fMNX7wSAeUVG-ME2uGMjHnQfXq5YYdTDvJd9OyotTuBhwO4GWESC7vonVNQ3daJt9qEhM9_t2lrgq6Lgru5eSBAWw5OeBriQ9MRdSdxPXl4g/s1600/spider-monkey-clip-art-cartoon-spider-hi.png&quot; imageanchor=&quot;1&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;145&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjf_3gCM_Shgw-lDv8qs56sSxIImAbSgt5fMNX7wSAeUVG-ME2uGMjHnQfXq5YYdTDvJd9OyotTuBhwO4GWESC7vonVNQ3daJt9qEhM9_t2lrgq6Lgru5eSBAWw5OeBriQ9MRdSdxPXl4g/s200/spider-monkey-clip-art-cartoon-spider-hi.png&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Spidering (or better crawling) the Web is such a common task for crawlers that a lot of ready to use good quality tools are already available in the web. For example check this page of &lt;a href=&quot;http://bigdata-madesimple.com/top-50-open-source-web-crawlers-for-data-mining/&quot;&gt;Top 50 crawlers&lt;/a&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;If you are interested on what these programs do in their core as me, you can find a simple spider in my&lt;a href=&quot;https://github.com/alexopoulos7/web-spider-example/blob/master/README.md&quot;&gt; git hub account&lt;/a&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;As you can see in code with Python and only in a few lines you can have an honest spider that saves a list of urls links in a text file using all cores of your pc. Parsing a page is a kind of cpu intensive process so spawing this process to all cores we can have production performance.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;As a reference check code and comments below:&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; from multiprocessing import Pool  
 import bs4 as bs  
 import requests  
   
   
 urls = [&#39;http://martinfowler.com&#39;, &#39;https://www.tutorialspoint.com&#39;]  
   
   
 def handle_local_links(url, link):  
   print(&#39;Url:{}, Link {}&#39;.format(url,link))  
   if link.startswith(&#39;//&#39;):  
     return url  
   elif link.startswith(&#39;/&#39;):  
     return &#39;&#39;.join([url, link])  
   elif link.startswith(&#39;http&#39;):  
     return link  
   elif link.startswith(&#39;#&#39;):  
     return &#39;&#39;  
   else:  
     return &#39;&#39;.join([url, link])  
   
   
 def get_links(url):  
   try:  
     print(&#39;Start parsing URL: {}&#39;.format(url))  
     response = requests.get(url)  
     soup = bs.BeautifulSoup(response.text, &#39;lxml&#39;)  
     body = soup.body  
     links = [link.get(&#39;href&#39;) for link in body.find_all(&#39;a&#39;)]  
     links = [handle_local_links(url, link) for link in links]  
     # Encode  
     links = [str(link.encode(&#39;ascii&#39;)) for link in links]  
     return links  
   except TypeError as type_error:  
     # Iterate over None  
     print (type_error)  
     print (&#39;Got a Type Error, probably a None that we tried to iterate&#39;)  
     return []  
   except IndexError as index_error:  
     print (index_error)  
     print (&#39;We probably did not find any useful links, returning empty list&#39;)  
     return []  
   except AttributeError as attribute_error:  
     print (attribute_error)  
     print (&#39;Probably we got None for links, so we return empty list&#39;)  
     return []  
   except Exception as exception:  
     print (str(exception))  
     return []  
   
   
 def main():  
   how_many = 100  
   p = Pool(processes=how_many)  
   data = p.map(get_links, [link for link in urls])  
   print (&#39;Data after multiprocessing {}&#39;.format(data))  
   # data is now a list of lists  
   # lets flatten it to a list  
   data = [url for url_list in data for url in url_list]  
   print (&#39;Data is {}&#39;.format(data))  
   sorted_list = sorted(data)  
   print (&#39;Sorted List is {}&#39;.format(sorted_list))  
   p.close()  
   with open(&#39;urls.txt&#39;, &#39;w&#39;) as f:  
     f.write(&#39;\n&#39;.join(sorted_list))  
   
   
 if __name__ == &#39;__main__&#39;:  
   main()  
   
&lt;/code&gt;&lt;/pre&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/7038382434451267350/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/7038382434451267350' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/7038382434451267350'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/7038382434451267350'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2016/12/spidering-web.html' title='Spidering the Web'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjf_3gCM_Shgw-lDv8qs56sSxIImAbSgt5fMNX7wSAeUVG-ME2uGMjHnQfXq5YYdTDvJd9OyotTuBhwO4GWESC7vonVNQ3daJt9qEhM9_t2lrgq6Lgru5eSBAWw5OeBriQ9MRdSdxPXl4g/s72-c/spider-monkey-clip-art-cartoon-spider-hi.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-3836084725483649153</id><published>2016-12-08T14:33:00.004-08:00</published><updated>2016-12-08T14:33:57.529-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hackerrank"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="js"/><category scheme="http://www.blogger.com/atom/ns#" term="solution"/><title type='text'>Priyanka and Toys Solution in JS</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;style type=&quot;text/css&quot;&gt;
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 36.0px &#39;Avenir Next&#39;; color: #39424e; -webkit-text-stroke: #39424e}
span.s1 {font-kerning: none}
&lt;/style&gt;


&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;Priyanka and Toys Solution&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;Hackerrank.com&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;b&gt;solution in Javascript&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;function processData(input) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; input = input.split(&#39;\n&#39;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; let n = parseInt(input[0]);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; let toys = input[1].split(&#39; &#39;).map(Number).sort((a,b)=&amp;gt;{return a-b;});&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; toys = [...new Set(toys)]; // unique items&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;n = toys.length;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; var i =0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; var buckets=1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; curBucket = toys[0];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; for( var i=1; i&amp;lt;n; i++){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;if(curBucket+4&amp;lt;toys[i]){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;buckets++;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; curBucket = toys[i];&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; console.log(buckets);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;}&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;process.stdin.resume();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;process.stdin.setEncoding(&quot;ascii&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;_input = &quot;&quot;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;process.stdin.on(&quot;data&quot;, function (input) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; _input += input;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;});&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;process.stdin.on(&quot;end&quot;, function () {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;processData(_input);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;});&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/3836084725483649153/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/3836084725483649153' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/3836084725483649153'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/3836084725483649153'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2016/12/priyanka-and-toys-solution-in-js.html' title='Priyanka and Toys Solution in JS'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-5961842173215064060</id><published>2016-12-02T03:58:00.000-08:00</published><updated>2016-12-02T03:58:00.735-08:00</updated><title type='text'>Hierarchical Clustering Algorithms Work!!</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Today I was playing with Hierarchical Clustering Algorithms. Hierarchical Clustering Algorithms belongs to Unsupervised Learning algorithms. It creates clusters of similar objects.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;So I tried to create clusters of the following blog sites:&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #2b2b2b; color: #a9b7c6; font-size: 9pt;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;http://feeds.feedburner.com/37signals/beMH
http://feeds.feedburner.com/blogspot/bRuz
http://battellemedia.com/index.xml
http://blog.guykawasaki.com/index.rdf
http://blog.outer-court.com/rss.xml
http://feeds.searchenginewatch.com/sewblog
http://blog.topix.net/index.rdf
http://blogs.abcnews.com/theblotter/index.rdf
http://feeds.feedburner.com/ConsumingExperienceFull
http://flagrantdisregard.com/index.php/feed/
http://featured.gigaom.com/feed/
http://gizmodo.com/index.xml
http://gofugyourself.typepad.com/go_fug_yourself/index.rdf
http://googleblog.blogspot.com/rss.xml
http://feeds.feedburner.com/GoogleOperatingSystem
http://headrush.typepad.com/creating_passionate_users/index.rdf
http://feeds.feedburner.com/hotair/main
http://feeds.feedburner.com/instapundit/main
http://jeremy.zawodny.com/blog/rss2.xml
http://joi.ito.com/index.rdf
http://journals.aol.com/thecoolerblog/AOLNewsCooler/rss.xml
http://feeds.feedburner.com/Mashable
http://michellemalkin.com/index.rdf
http://moblogsmoproblems.blogspot.com/rss.xml
http://newsbusters.org/node/feed
http://beta.blogger.com/feeds/27154654/posts/full?alt=rss
http://feeds.feedburner.com/paulstamatiou
http://powerlineblog.com/index.rdf
http://feeds.feedburner.com/Publishing20
http://radar.oreilly.com/index.rdf
http://scienceblogs.com/pharyngula/index.xml
http://scobleizer.wordpress.com/feed/
http://sethgodin.typepad.com/seths_blog/index.rdf
http://rss.slashdot.org/Slashdot/slashdot
http://thinkprogress.org/feed/
http://feeds.feedburner.com/andrewsullivan/rApM
http://wilwheaton.typepad.com/wwdnbackup/index.rdf
http://www.43folders.com/feed/
http://www.456bereastreet.com/feed.xml
http://www.autoblog.com/rss.xml
http://www.bloggersblog.com/rss.xml
http://www.bloglines.com/rss/about/news
http://www.blogmaverick.com/rss.xml
http://www.boingboing.net/index.rdf
http://www.buzzmachine.com/index.xml
http://www.captainsquartersblog.com/mt/index.rdf
http://www.coolhunting.com/index.rdf
http://feeds.copyblogger.com/Copyblogger
http://feeds.feedburner.com/crooksandliars/YaCP
http://feeds.dailykos.com/dailykos/index.xml
http://www.deadspin.com/index.xml
http://www.downloadsquad.com/rss.xml
http://www.engadget.com/rss.xml
http://www.gapingvoid.com/index.rdf
http://www.gawker.com/index.xml
http://www.gothamist.com/index.rdf
http://www.huffingtonpost.com/raw_feed_index.rdf
http://www.hyperorg.com/blogger/index.rdf
http://www.joelonsoftware.com/rss.xml
http://www.joystiq.com/rss.xml
http://www.kotaku.com/index.xml
http://feeds.kottke.org/main
http://www.lifehack.org/feed/
http://www.lifehacker.com/index.xml
http://littlegreenfootballs.com/weblog/lgf-rss.php
http://www.makezine.com/blog/index.xml
http://www.mattcutts.com/blog/feed/
http://xml.metafilter.com/rss.xml
http://www.mezzoblue.com/rss/index.xml
http://www.micropersuasion.com/index.rdf
http://www.neilgaiman.com/journal/feed/rss.xml
http://www.oilman.ca/feed/
http://www.perezhilton.com/index.xml
http://www.plasticbag.org/index.rdf
http://www.powazek.com/rss.xml
http://www.problogger.net/feed/
http://feeds.feedburner.com/QuickOnlineTips
http://www.readwriteweb.com/rss.xml
http://www.schneier.com/blog/index.rdf
http://scienceblogs.com/sample/combined.xml
http://www.seroundtable.com/index.rdf
http://www.shoemoney.com/feed/
http://www.sifry.com/alerts/index.rdf
http://www.simplebits.com/xml/rss.xml
http://feeds.feedburner.com/Spikedhumor
http://www.stevepavlina.com/blog/feed
http://www.talkingpointsmemo.com/index.xml
http://www.tbray.org/ongoing/ongoing.rss
http://feeds.feedburner.com/TechCrunch
http://www.techdirt.com/techdirt_rss.xml
http://www.techeblog.com/index.php/feed/
http://www.thesuperficial.com/index.xml
http://www.tmz.com/rss.xml
http://www.treehugger.com/index.rdf
http://www.tuaw.com/rss.xml
http://www.valleywag.com/index.xml
http://www.we-make-money-not-art.com/index.rdf
http://www.wired.com/rss/index.xml
http://www.wonkette.com/index.xml
http://feeds.feedburner.com/blogspot/eXYjt&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Using Pythons PIL Library I have created the dendogram for the clusters created:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpWzodlVK3F-ch9S6QeA0kIL7VLwt5cEO1uK6Lu_Dr4jslQgOqPf5gLKlX_rBQqbhAmALVAFxdv4RWwEn6s0Y28ECn8Pn0LvRNXwCl-T1HvgvmedZT0iquyZVGovBeoRqQBD8A-Q2RNzw/s1600/blog_cluster.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpWzodlVK3F-ch9S6QeA0kIL7VLwt5cEO1uK6Lu_Dr4jslQgOqPf5gLKlX_rBQqbhAmALVAFxdv4RWwEn6s0Y28ECn8Pn0LvRNXwCl-T1HvgvmedZT0iquyZVGovBeoRqQBD8A-Q2RNzw/s640/blog_cluster.jpg&quot; width=&quot;600&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Another interesting thing is the Word Clustering Dendogram:

&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7T1xD61h81E1J7ZjsO6buONpqZKwA0gZdkQZhE-I3ihTE8pvkw5K25EPJ4P5t21mc5AVIL-0uBn3L5QlWKQV8ApNb6ivu3W-EMpGR_m_6kbQlyFG1Eu3SKebkByspkqseNG6g-xqmP1E/s1600/word_cluster.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7T1xD61h81E1J7ZjsO6buONpqZKwA0gZdkQZhE-I3ihTE8pvkw5K25EPJ4P5t21mc5AVIL-0uBn3L5QlWKQV8ApNb6ivu3W-EMpGR_m_6kbQlyFG1Eu3SKebkByspkqseNG6g-xqmP1E/s1600/word_cluster.jpg&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Lets zoom in a small sub cluster to get a better idea:

&lt;/span&gt;&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhUG_rksAvmfrJWsmq-QKDfMRi7J9OIIwZR3SFCyeUYIq1bJdE4izEmn0YzQf5mgeZJhvAygXAZAfk-Alhrl7-gqDLgBfV5Nh6QVxMftt0Sl_SEFHWBzTA2TeyRZiSESK1rpWHLuzqfLo/s1600/sub_cluster1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhUG_rksAvmfrJWsmq-QKDfMRi7J9OIIwZR3SFCyeUYIq1bJdE4izEmn0YzQf5mgeZJhvAygXAZAfk-Alhrl7-gqDLgBfV5Nh6QVxMftt0Sl_SEFHWBzTA2TeyRZiSESK1rpWHLuzqfLo/s1600/sub_cluster1.png&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Trump and Elections&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;Now if you want to see for yourself or play with the code, please visit my git hub account here:&lt;a href=&quot;https://github.com/alexopoulos7/collective-intelligence/tree/master/CollectiveIntelligence/Unsupervised%20Learning/Word%20Vectors&quot;&gt;&amp;nbsp;https://github.com/alexopoulos7/collective-intelligence/tree/master/CollectiveIntelligence/Unsupervised%20Learning/Word%20Vectors&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/5961842173215064060/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/5961842173215064060' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/5961842173215064060'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/5961842173215064060'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2016/12/hierarchical-clustering-algorithms-work.html' title='Hierarchical Clustering Algorithms Work!!'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpWzodlVK3F-ch9S6QeA0kIL7VLwt5cEO1uK6Lu_Dr4jslQgOqPf5gLKlX_rBQqbhAmALVAFxdv4RWwEn6s0Y28ECn8Pn0LvRNXwCl-T1HvgvmedZT0iquyZVGovBeoRqQBD8A-Q2RNzw/s72-c/blog_cluster.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-7156730203190436747</id><published>2016-11-28T23:55:00.004-08:00</published><updated>2016-11-29T00:04:10.868-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="benchmark"/><category scheme="http://www.blogger.com/atom/ns#" term="cosine"/><category scheme="http://www.blogger.com/atom/ns#" term="euclidean distance"/><category scheme="http://www.blogger.com/atom/ns#" term="pearson"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="similarity"/><category scheme="http://www.blogger.com/atom/ns#" term="tanimoto"/><title type='text'>Similarity Functions Benchmark in Python</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Lets create a benchmark between 4 of the most common similarity formulas used in recommendations&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Euclidean Distance&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Pearson Coefficients&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Tanimoto&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Cosine&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The data we are going to use is this simple dictionary of user ratings of movies (sample data is taken from&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://shop.oreilly.com/product/9780596529321.do&quot; style=&quot;font-family: verdana, sans-serif;&quot;&gt;&quot;Programming Collective Intelligence&quot;&amp;nbsp;&lt;/a&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;book by&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;byLineLink&quot; href=&quot;http://shop.oreilly.com/product/9780596529321.do#tab_04_2&quot; style=&quot;background-color: white; color: #207cc1; font-family: verdana, sans-serif; font-size: 12px; text-decoration: none;&quot;&gt;Toby Segaran&lt;/a&gt;)&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;

&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; # Load a dictionary of movie critics and their ratings of a small set of movies  
 critics = {  
   &#39;Lisa Rose&#39;: {  
     &#39;Lady in the Water&#39;: 2.5,  
     &#39;Snakes on a Plane&#39;: 3.5,  
     &#39;Just My Luck&#39;: 3.0,  
     &#39;Superman Returns&#39;: 3.5,  
     &#39;You, Me and Dupree&#39;: 2.5,  
     &#39;The Night Listener&#39;: 3.0  
   },  
   &#39;Gene Seymour&#39;: {  
     &#39;Snakes on a Plane&#39;: 3.5,  
     &#39;Lady in the Water&#39;: 3.0,  
     &#39;Just My Luck&#39;: 1.5,  
     &#39;Superman Returns&#39;: 5.0,  
     &#39;You, Me and Dupree&#39;: 3.5,  
     &#39;The Night Listener&#39;: 3.0  
   },  
   &#39;Michael Philips&#39;: {  
     &#39;Snakes on a Plane&#39;: 3.0,  
     &#39;Lady in the Water&#39;: 2.5,  
     &#39;Superman Returns&#39;: 3.5,  
     &#39;The Night Listener&#39;: 4.5  
   },  
   &#39;Claudia Puig&#39;: {  
     &#39;Snakes on a Plane&#39;: 3.5,  
     &#39;Just My Luck&#39;: 3.0,  
     &#39;Superman Returns&#39;: 4.0,  
     &#39;You, Me and Dupree&#39;: 2.5,  
     &#39;The Night Listener&#39;: 4.5  
   },  
   &#39;Mick LaSalle&#39;: {  
     &#39;Snakes on a Plane&#39;: 4.0,  
     &#39;Lady in the Water&#39;: 3.0,  
     &#39;Just My Luck&#39;: 1.5,  
     &#39;Superman Returns&#39;: 3.0,  
     &#39;You, Me and Dupree&#39;: 2.0,  
     &#39;The Night Listener&#39;: 3.0  
   },  
   &#39;Jack Matthews&#39;: {  
     &#39;Snakes on a Plane&#39;: 4.0,  
     &#39;Lady in the Water&#39;: 3.0,  
     &#39;Superman Returns&#39;: 5.0,  
     &#39;You, Me and Dupree&#39;: 3.5,  
     &#39;The Night Listener&#39;: 3.0  
   },  
   &#39;Toby&#39;: {  
     &#39;Snakes on a Plane&#39;: 4.5,  
     &#39;Superman Returns&#39;: 4.0,  
     &#39;You, Me and Dupree&#39;: 1.0  
   }  
 }  
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #2b2b2b; color: #a9b7c6; font-family: &#39;Menlo&#39;; font-size: 9.0pt;&quot;&gt;&lt;b style=&quot;font-size: 9pt;&quot;&gt;OUTPUT BENCHMARK&lt;/b&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-small;&quot;&gt;Lisa Rose:&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-small;&quot;&gt;[2.5, 3.5, 3.5, 3.0]&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-small;&quot;&gt;Michael Philips:&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-small;&quot;&gt;[2.5, 3.0, 3.5, 4.5]&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-small;&quot;&gt;&lt;u&gt;Euclidean Distance&lt;/u&gt; Score between Lisa Rose and Michael Philips is &lt;b&gt;0.387425886723&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-small;&quot;&gt;&lt;u&gt;Pearson Correlation Coefficient&lt;/u&gt; Score between Lisa Rose and Michael Philips is &lt;b&gt;0.254823595719&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-small;&quot;&gt;&lt;u&gt;Tanimoto Correlation Coefficient Score&lt;/u&gt; between Lisa Rose and Michael Philips is &lt;b&gt;0.666666666667&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: x-small;&quot;&gt;&lt;u&gt;Cosine Similarity Score &lt;/u&gt;between Lisa Rose and Michael Philips is &lt;/span&gt;&lt;b style=&quot;font-family: verdana, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;0.975&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b style=&quot;font-family: Verdana, sans-serif; font-size: small;&quot;&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b style=&quot;font-family: Verdana, sans-serif; font-size: small;&quot;&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre style=&quot;background-color: #2b2b2b; color: #a9b7c6; font-family: &#39;Menlo&#39;; font-size: 9.0pt;&quot;&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/7156730203190436747/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/7156730203190436747' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/7156730203190436747'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/7156730203190436747'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2016/11/similarity-functions-benchmark-in-python.html' title='Similarity Functions Benchmark in Python'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-5164372393602132684</id><published>2016-11-28T07:33:00.001-08:00</published><updated>2016-11-28T23:56:19.053-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="collaborative"/><category scheme="http://www.blogger.com/atom/ns#" term="cosine"/><category scheme="http://www.blogger.com/atom/ns#" term="euclidean"/><category scheme="http://www.blogger.com/atom/ns#" term="filtering"/><category scheme="http://www.blogger.com/atom/ns#" term="pearson"/><category scheme="http://www.blogger.com/atom/ns#" term="similarity"/><category scheme="http://www.blogger.com/atom/ns#" term="tanimoto"/><title type='text'>Programming Collective Intelligence</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH5Mr2irupUvgGHzfLM0nRPPzss0b8ZA1rwoD2J3VsMSk9nXXi0qAwojvzwrGxYnOQ2NvLE2zjrR9DjP_xScDl2db5Kb6i6OhwI0U60gVhEesmoYouCdEYmw5Y2Cnm7b8gqPy45xJnodQ/s1600/intelligence.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;260&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH5Mr2irupUvgGHzfLM0nRPPzss0b8ZA1rwoD2J3VsMSk9nXXi0qAwojvzwrGxYnOQ2NvLE2zjrR9DjP_xScDl2db5Kb6i6OhwI0U60gVhEesmoYouCdEYmw5Y2Cnm7b8gqPy45xJnodQ/s400/intelligence.jpg&quot; width=&quot;400&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Lately I have been reading the amazing book &lt;a href=&quot;http://shop.oreilly.com/product/9780596529321.do&quot;&gt;&quot;Programming Collective Intelligence&quot;&lt;/a&gt;&amp;nbsp;book by&amp;nbsp;&lt;a class=&quot;byLineLink&quot; href=&quot;http://shop.oreilly.com/product/9780596529321.do#tab_04_2&quot; style=&quot;background-color: white; color: #207cc1; font-size: 12px; text-decoration: none;&quot;&gt;Toby Segaran&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Its a fascinating book if you are trying to understand Machine Learning Algorithms using Python from the scratch.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;I have been playing with the code so I am publishing to my &lt;a href=&quot;https://github.com/alexopoulos7/collective-intelligence&quot;&gt;git account&lt;/a&gt; code examples that I have used from the book.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;For the moment I have posted code in one big recommendations.py file algorithms for&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;user-based&lt;/b&gt; and &lt;b&gt;item-based&lt;/b&gt; filtering&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;using&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Euclidean Distance&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Pearson Approach&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Tanimoto&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Cosine Similarity&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;You can simple download or clone repo. Afterwards just run python recommendations.py&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Please enjoy&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/5164372393602132684/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/5164372393602132684' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/5164372393602132684'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/5164372393602132684'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2016/11/programming-collective-intelligence.html' title='Programming Collective Intelligence'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH5Mr2irupUvgGHzfLM0nRPPzss0b8ZA1rwoD2J3VsMSk9nXXi0qAwojvzwrGxYnOQ2NvLE2zjrR9DjP_xScDl2db5Kb6i6OhwI0U60gVhEesmoYouCdEYmw5Y2Cnm7b8gqPy45xJnodQ/s72-c/intelligence.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-6945845000372939154</id><published>2016-11-23T08:34:00.002-08:00</published><updated>2016-11-23T08:34:08.142-08:00</updated><title type='text'>iphone PhotoStream</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;a href=&quot;https://flic.kr/ps/2X5PvQ&quot;&gt;https://flic.kr/ps/2X5PvQ&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/6945845000372939154/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/6945845000372939154' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/6945845000372939154'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/6945845000372939154'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2016/11/iphone-photostream.html' title='iphone PhotoStream'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-7332575057885191850</id><published>2016-11-23T04:27:00.006-08:00</published><updated>2016-11-23T04:27:43.656-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="combobox"/><category scheme="http://www.blogger.com/atom/ns#" term="Djanog"/><category scheme="http://www.blogger.com/atom/ns#" term="models"/><title type='text'>Django Forms Choice Tutorial Sample Code</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Lately I have been playing with &lt;a href=&quot;https://www.djangoproject.com/&quot;&gt;Django&lt;/a&gt;!! Its a really amazing Python Web Framework that can help anybody with small experience in web frameworks and python language to create amazing web sites.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;One of the biggest advantages of using Django is the really detailed documentation. Please check yourself at&amp;nbsp;&lt;a href=&quot;https://docs.djangoproject.com/en/1.10/&quot;&gt;https://docs.djangoproject.com/en/1.10/&lt;/a&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In this tutorial I am going to show a quick example of creating a simple form with 3 comboboxes that will take some data from 3 tables and save the choices to a 4th table. The sample output will be as following:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSWibZi6wh3RAM2mVrlAX58mZhSdqtFK2SuQj_hMtdJN4ZXuKrgd5e3oYH_DEVvimbw_TWScJ_TcI0UkIqIau10LOOqOUyEsMvuk6mgvZNI1rkAIR9tidPHLGy_x2PuDOP5HRTt8hFnOg/s1600/Untitled+drawing.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;305&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSWibZi6wh3RAM2mVrlAX58mZhSdqtFK2SuQj_hMtdJN4ZXuKrgd5e3oYH_DEVvimbw_TWScJ_TcI0UkIqIau10LOOqOUyEsMvuk6mgvZNI1rkAIR9tidPHLGy_x2PuDOP5HRTt8hFnOg/s640/Untitled+drawing.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Before we start:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;For the above scenario we are going to have 3 simple models - tables: Category, Service, Criteria and a more complex one which will store 3 foreign keys for those 3 tables.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Implementation:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;1. models.py&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;The trick here is to have __unicode__ function defined. This will help our comboboxes to populate a unicode string representation of our model.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;The __str__ function is used by our Django Admin site&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;I usually add created_at and updated_at fields for every model I create. I have found it usefull in many cases.&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;pre style=&quot;background-color: #2b2b2b; color: #a9b7c6; font-family: &#39;Menlo&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;from &lt;/span&gt;django.db &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;import &lt;/span&gt;models


&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Service&lt;/span&gt;(models.Model):
    &lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    Service Model. &lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    &lt;/span&gt;name = models.TextField(&lt;span style=&quot;color: #aa4926;&quot;&gt;max_length&lt;/span&gt;=&lt;span style=&quot;color: #6897bb;&quot;&gt;200&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;help_text&lt;/span&gt;=&lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;Service Name&#39;&lt;/span&gt;)
    short_code = models.TextField(&lt;span style=&quot;color: #aa4926;&quot;&gt;max_length&lt;/span&gt;=&lt;span style=&quot;color: #6897bb;&quot;&gt;15&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;help_text&lt;/span&gt;=&lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;Service Short Code&#39;&lt;/span&gt;) 
    created_at = models.DateTimeField(&lt;span style=&quot;color: #aa4926;&quot;&gt;auto_now_add&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;editable&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;False&lt;/span&gt;)
    updated_at = models.DateTimeField(&lt;span style=&quot;color: #aa4926;&quot;&gt;auto_now&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;editable&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;False&lt;/span&gt;)

    &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;def &lt;/span&gt;&lt;span style=&quot;color: #b200b2;&quot;&gt;__str__&lt;/span&gt;(&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;):
        &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;.name + &lt;span style=&quot;color: #a5c261;&quot;&gt;&#39; code: &#39; &lt;/span&gt;+ &lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;.short_code  

    &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;def &lt;/span&gt;&lt;span style=&quot;color: #b200b2;&quot;&gt;__unicode__&lt;/span&gt;(&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;):
        &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;.name + &lt;span style=&quot;color: #a5c261;&quot;&gt;&#39; code: &#39; &lt;/span&gt;+ &lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;.short_code  


&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Category&lt;/span&gt;(models.Model):
    &lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    # Template Messages Categories (e.g. Help, Bulk, etc&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    &lt;/span&gt;name = models.TextField(&lt;span style=&quot;color: #aa4926;&quot;&gt;max_length&lt;/span&gt;=&lt;span style=&quot;color: #6897bb;&quot;&gt;200&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;help_text&lt;/span&gt;=&lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;Template Message Category. e.g. HELP, STOP, etc&#39;&lt;/span&gt;)
    description = models.TextField(&lt;span style=&quot;color: #aa4926;&quot;&gt;max_length&lt;/span&gt;=&lt;span style=&quot;color: #6897bb;&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;help_text&lt;/span&gt;=&lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;Template Message Category Description&#39;&lt;/span&gt;)
    created_at = models.DateTimeField(&lt;span style=&quot;color: #aa4926;&quot;&gt;auto_now_add&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;editable&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;False&lt;/span&gt;)
    updated_at = models.DateTimeField(&lt;span style=&quot;color: #aa4926;&quot;&gt;auto_now&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;editable&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;False&lt;/span&gt;)

    &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;def &lt;/span&gt;&lt;span style=&quot;color: #b200b2;&quot;&gt;__str__&lt;/span&gt;(&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;):
        &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;.name

    &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;def &lt;/span&gt;&lt;span style=&quot;color: #b200b2;&quot;&gt;__unicode__&lt;/span&gt;(&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;):
        &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;.name


&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;SubscriptionCriteria&lt;/span&gt;(models.Model):
    &lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    Criteria for Selecting Users to bulk&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    &lt;/span&gt;name = models.CharField(&lt;span style=&quot;color: #aa4926;&quot;&gt;max_length&lt;/span&gt;=&lt;span style=&quot;color: #6897bb;&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;help_text&lt;/span&gt;=&lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;Name your Subscription Criteria&#39;&lt;/span&gt;)
    description = models.TextField(&lt;span style=&quot;color: #aa4926;&quot;&gt;max_length&lt;/span&gt;=&lt;span style=&quot;color: #6897bb;&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;help_text&lt;/span&gt;=&lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;Describe your Subscription Criteria&#39;&lt;/span&gt;)
    created_at = models.DateTimeField(&lt;span style=&quot;color: #aa4926;&quot;&gt;auto_now_add&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;editable&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;False&lt;/span&gt;)
    updated_at = models.DateTimeField(&lt;span style=&quot;color: #aa4926;&quot;&gt;auto_now&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;editable&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;False&lt;/span&gt;)

    &lt;span style=&quot;color: #8888c6;&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: #bbb529;&quot;&gt;property&lt;/span&gt;&lt;span style=&quot;color: #bbb529;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;def &lt;/span&gt;&lt;span style=&quot;color: #b200b2;&quot;&gt;__str__&lt;/span&gt;(&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;):
        &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;.name

    &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;def &lt;/span&gt;&lt;span style=&quot;color: #b200b2;&quot;&gt;__unicode__&lt;/span&gt;(&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;):
        &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;.name
    
    
&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;BulkWorker&lt;/span&gt;(models.Model):
    &lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    A Bulk Worker saves the progress of a worker ..... &lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    &lt;/span&gt;task_id = models.TextField(&lt;span style=&quot;color: #aa4926;&quot;&gt;primary_key&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;max_length&lt;/span&gt;=&lt;span style=&quot;color: #6897bb;&quot;&gt;150&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;help_text&lt;/span&gt;=&lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;Celery task Id&#39;&lt;/span&gt;)
    launched_at = models.DateTimeField(&lt;span style=&quot;color: #aa4926;&quot;&gt;auto_now_add&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;editable&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;False&lt;/span&gt;)
    charged_at = models.DateTimeField(&lt;span style=&quot;color: #aa4926;&quot;&gt;editable&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;default&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;None&lt;/span&gt;)
    state = models.TextField(&lt;span style=&quot;color: #aa4926;&quot;&gt;max_length&lt;/span&gt;=&lt;span style=&quot;color: #6897bb;&quot;&gt;1000&lt;/span&gt;)  &lt;span style=&quot;color: grey;&quot;&gt;# TO ADD Exceptions&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;    &lt;/span&gt;percent = models.IntegerField(&lt;span style=&quot;color: #aa4926;&quot;&gt;default&lt;/span&gt;=&lt;span style=&quot;color: #6897bb;&quot;&gt;0&lt;/span&gt;)
    service = models.ForeignKey(Service)
    message_category = models.ForeignKey(Category&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;default&lt;/span&gt;=&lt;span style=&quot;color: #6897bb;&quot;&gt;1&lt;/span&gt;)
    criteria = models.ForeignKey(SubscriptionCriteria&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;default&lt;/span&gt;=&lt;span style=&quot;color: #6897bb;&quot;&gt;1&lt;/span&gt;)
    created_at = models.DateTimeField(&lt;span style=&quot;color: #aa4926;&quot;&gt;auto_now_add&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;editable&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;False&lt;/span&gt;)
    updated_at = models.DateTimeField(&lt;span style=&quot;color: #aa4926;&quot;&gt;auto_now&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;editable&lt;/span&gt;=&lt;span style=&quot;color: #8888c6;&quot;&gt;False&lt;/span&gt;)

    &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;def &lt;/span&gt;&lt;span style=&quot;color: #b200b2;&quot;&gt;__str__&lt;/span&gt;(&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;):
        &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color: #a5c261;&quot;&gt;&quot;Worker started at &quot; &lt;/span&gt;+ &lt;span style=&quot;color: #8888c6;&quot;&gt;str&lt;/span&gt;(&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;.launched_at) + &lt;span style=&quot;color: #a5c261;&quot;&gt;&quot; for service &quot; &lt;/span&gt;+ &lt;span style=&quot;color: #8888c6;&quot;&gt;str&lt;/span&gt;(&lt;span style=&quot;color: #94558d;&quot;&gt;self&lt;/span&gt;.service)
&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;2. views.py&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Now that we have our models we can create the views.py.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;In home view we just load an empty BulkForm. BulkForm is created below in forms.py&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;We also add bulk Task to save form data&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: #2b2b2b; color: #a9b7c6; font-family: &#39;Menlo&#39;; font-size: 9.0pt;&quot;&gt;&lt;pre style=&quot;font-family: Menlo; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: grey;&quot;&gt;# coding=utf-8# Create your views here.&lt;/span&gt;&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;from &lt;/span&gt;__future__ &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;import &lt;/span&gt;print_function

&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;from &lt;/span&gt;django.contrib.auth.decorators &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;import &lt;/span&gt;user_passes_test
&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;from &lt;/span&gt;django.shortcuts &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;import &lt;/span&gt;render_to_response
&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;from &lt;/span&gt;django.template &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;import &lt;/span&gt;RequestContext
&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;from &lt;/span&gt;django.views.decorators.csrf &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;import &lt;/span&gt;csrf_exempt

&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;from &lt;/span&gt;.forms &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;import &lt;/span&gt;BulkForm


@&lt;span style=&quot;color: #bbb529;&quot;&gt;user_passes_test&lt;/span&gt;(&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;lambda &lt;/span&gt;u: u.is_superuser)
@&lt;span style=&quot;color: #bbb529;&quot;&gt;csrf_exemptdef &lt;/span&gt;home(request):
    &lt;span style=&quot;color: #a5c261;&quot;&gt;&quot;&quot;&quot;    Main View Page for Bulk Tasks    :param request:    :return:    &quot;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color: #a5c261;&quot;&gt;    &lt;/span&gt;form = BulkForm()
    &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;return &lt;/span&gt;render_to_response(&lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;bulk.html&#39;&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;{&lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;form&#39;&lt;/span&gt;: form}&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;context_instance=RequestContext(request))


&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;def &lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;add_bulk_task&lt;/span&gt;(request):
    &lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    Add in db a bulk task&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    Send to start task&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic; font-weight: bold;&quot;&gt;:param&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt; request: POST object should be a Request object&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic; font-weight: bold;&quot;&gt;:return&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;: HttpResponse&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;context &lt;/span&gt;= RequestContext(request)

    &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;if &lt;/span&gt;request.method == &lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;POST&#39;&lt;/span&gt;:
        form = BulkForm(request.POST)

        &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;if &lt;/span&gt;form.is_valid():
            form.save() &lt;span style=&quot;color: grey;&quot;&gt;# commit = True by default&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;            &lt;/span&gt;json_data = &lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;Bulk Task saved fine&#39;&lt;/span&gt;&lt;span style=&quot;color: #a5c261;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;else&lt;/span&gt;:
            json_data = &lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;Form is not valid&#39;&lt;/span&gt;&lt;span style=&quot;color: #a5c261;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;else&lt;/span&gt;:
        json_data = &lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;Only POST requests are allowed&#39;&lt;/span&gt;&lt;span style=&quot;color: #a5c261;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;return &lt;/span&gt;HttpResponse(json_data&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;content_type&lt;/span&gt;=&lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;application/json&#39;&lt;/span&gt;)&lt;/pre&gt;
&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;3. forms.py&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;In our forms.py we use ModelChoiseField to load the foreign keys. As widget we use forms.Select as we only want to select one value. We query and get all objects populated for all referenced tables in queryset&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: #2b2b2b; color: #a9b7c6; font-family: &#39;Menlo&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;from &lt;/span&gt;django &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;import &lt;/span&gt;forms
&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;from &lt;/span&gt;.models &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;import &lt;/span&gt;BulkWorker&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;Service&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;SubscriptionCriteria&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;Category


&lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;BulkForm&lt;/span&gt;(forms.ModelForm):
    &lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    Create Form for Sending Bulk Requests&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color: #629755; font-style: italic;&quot;&gt;    &lt;/span&gt;service = forms.ModelChoiceField(&lt;span style=&quot;color: #aa4926;&quot;&gt;widget&lt;/span&gt;=forms.Select&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;queryset&lt;/span&gt;=Service.objects.all())
    message_category = forms.ModelChoiceField(&lt;span style=&quot;color: #aa4926;&quot;&gt;widget &lt;/span&gt;= forms.Select&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;queryset&lt;/span&gt;=Category.objects.all())
    criteria = forms.ModelChoiceField(&lt;span style=&quot;color: #aa4926;&quot;&gt;widget &lt;/span&gt;= forms.Select&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;queryset&lt;/span&gt;=SubscriptionCriteria.objects.all())

    &lt;span style=&quot;color: #cc7832; font-weight: bold;&quot;&gt;class &lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Meta&lt;/span&gt;:
        model = BulkWorker&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;4. templates/bulk.html&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Lastly we should add the template code so that django will replace data from view.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;With Django its the easiest thing to do!&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;We just need 5 lines of code.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Note: csrf_token is used to prevent cross site forgery attacks&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;so the line that does all the work is {{form.as_p}}&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;we cound have used of course the simple {{form}} with the same results, I just wanted to put the form in a paragraph (&amp;lt;p&amp;gt; element)&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: #2b2b2b; color: #a9b7c6; font-family: &#39;Menlo&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: #e8bf6a;&quot;&gt;&amp;lt;div &lt;/span&gt;&lt;span style=&quot;color: #bababa;&quot;&gt;id=&lt;/span&gt;&lt;span style=&quot;color: #a5c261;&quot;&gt;&quot;bulk-form&quot;&lt;/span&gt;&lt;span style=&quot;color: #e8bf6a;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #e8bf6a;&quot;&gt;    &amp;lt;form &lt;/span&gt;&lt;span style=&quot;color: #bababa;&quot;&gt;id=&lt;/span&gt;&lt;span style=&quot;color: #a5c261;&quot;&gt;&quot;BulkForm&quot; &lt;/span&gt;&lt;span style=&quot;color: #bababa;&quot;&gt;action=&lt;/span&gt;&lt;span style=&quot;color: #a5c261;&quot;&gt;&quot;save_bulk&quot; &lt;/span&gt;&lt;span style=&quot;color: #bababa;&quot;&gt;method=&lt;/span&gt;&lt;span style=&quot;color: #a5c261;&quot;&gt;&quot;post&quot;&lt;/span&gt;&lt;span style=&quot;color: #e8bf6a;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #e8bf6a;&quot;&gt;        &lt;/span&gt;{% csrf_token %}
        {{ form.as_p }}
     &lt;span style=&quot;color: #e8bf6a;&quot;&gt;&amp;lt;input &lt;/span&gt;&lt;span style=&quot;color: #bababa;&quot;&gt;type=&lt;/span&gt;&lt;span style=&quot;color: #a5c261;&quot;&gt;&quot;submit&quot; &lt;/span&gt;&lt;span style=&quot;color: #bababa;&quot;&gt;name=&lt;/span&gt;&lt;span style=&quot;color: #a5c261;&quot;&gt;&quot;submit&quot; &lt;/span&gt;&lt;span style=&quot;color: #bababa;&quot;&gt;value=&lt;/span&gt;&lt;span style=&quot;color: #a5c261;&quot;&gt;&quot;Create BULK Task&quot; &lt;/span&gt;&lt;span style=&quot;color: #e8bf6a;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #e8bf6a;&quot;&gt;    &amp;lt;/form&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #e8bf6a;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #2b2b2b; color: #a9b7c6; font-family: &#39;Menlo&#39;; font-size: 9.0pt;&quot;&gt;&lt;span style=&quot;color: #e8bf6a;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;5. urs.py&lt;/b&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Lastly we should add our page in urls.py as simple as following&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: #2b2b2b; color: #a9b7c6; font-family: &#39;Menlo&#39;; font-size: 9.0pt;&quot;&gt;url(&lt;span style=&quot;color: #a5c261;&quot;&gt;r&#39;^bulk$&#39;&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;amusely.views.home&#39;&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;bulk&#39;&lt;/span&gt;)&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #2b2b2b; color: #a9b7c6; font-family: &#39;Menlo&#39;; font-size: 9.0pt;&quot;&gt;url(&lt;span style=&quot;color: #a5c261;&quot;&gt;r&#39;^save_bulk$&#39;&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;amusely.views.add_bulk_task&#39;&lt;/span&gt;&lt;span style=&quot;color: #cc7832;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #aa4926;&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: #a5c261;&quot;&gt;&#39;save_task&#39;&lt;/span&gt;)&lt;span style=&quot;color: #cc7832;&quot;&gt;,&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #2b2b2b; color: #a9b7c6; font-family: &#39;Menlo&#39;; font-size: 9.0pt;&quot;&gt;&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;As always comments are welcomed. I would be glad to see what you think or help you. CU next time&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/7332575057885191850/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/7332575057885191850' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/7332575057885191850'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/7332575057885191850'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2016/11/django-forms-choice-tutorial-sample-code.html' title='Django Forms Choice Tutorial Sample Code'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSWibZi6wh3RAM2mVrlAX58mZhSdqtFK2SuQj_hMtdJN4ZXuKrgd5e3oYH_DEVvimbw_TWScJ_TcI0UkIqIau10LOOqOUyEsMvuk6mgvZNI1rkAIR9tidPHLGy_x2PuDOP5HRTt8hFnOg/s72-c/Untitled+drawing.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-8162613395400839567</id><published>2016-05-20T09:35:00.001-07:00</published><updated>2016-05-20T09:35:22.925-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="greece"/><category scheme="http://www.blogger.com/atom/ns#" term="hotspot"/><category scheme="http://www.blogger.com/atom/ns#" term="hotspotonthego"/><category scheme="http://www.blogger.com/atom/ns#" term="internet"/><category scheme="http://www.blogger.com/atom/ns#" term="wifi"/><title type='text'>Internet in Greece</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Stay connected during your vacations in Greece with portable wifi hotspot.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;Connect up to 10 devices without extreme fees!!!&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Visit&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;a href=&quot;http://www.hotspotonthego.com/&quot;&gt;http://www.hotspotonthego.com&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP2ggKNTpq6euMBPrdxxJCJtbPzQg8k-zxq-u79ExS-M9O5by7I6t9o5x-duwl2DlhXxGZZ9k17aVepdhwlCjhTHlUHezUjJ6PfMOU3XfY18LRwXyyBM3PGEFh8gWqLUoKF_YSXH4Lbxo/s1600/greece.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP2ggKNTpq6euMBPrdxxJCJtbPzQg8k-zxq-u79ExS-M9O5by7I6t9o5x-duwl2DlhXxGZZ9k17aVepdhwlCjhTHlUHezUjJ6PfMOU3XfY18LRwXyyBM3PGEFh8gWqLUoKF_YSXH4Lbxo/s320/greece.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Welcome and Enjoy..&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/8162613395400839567/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/8162613395400839567' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/8162613395400839567'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/8162613395400839567'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2016/05/internet-in-greece.html' title='Internet in Greece'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP2ggKNTpq6euMBPrdxxJCJtbPzQg8k-zxq-u79ExS-M9O5by7I6t9o5x-duwl2DlhXxGZZ9k17aVepdhwlCjhTHlUHezUjJ6PfMOU3XfY18LRwXyyBM3PGEFh8gWqLUoKF_YSXH4Lbxo/s72-c/greece.jpg" height="72" width="72"/><thr:total>0</thr:total><georss:featurename>Πάτρα, Ελλάδα</georss:featurename><georss:point>38.2466395 21.734574000000066</georss:point><georss:box>38.14688 21.573212500000064 38.346399 21.895935500000068</georss:box></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-436183227283734801</id><published>2013-01-31T11:34:00.001-08:00</published><updated>2013-01-31T11:34:02.668-08:00</updated><title type='text'>Homework Feedback | Algorithms: Design and Analysis, Part I</title><content type='html'>&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;a href=&quot;https://class.coursera.org/algo-003/quiz/feedback?submission_id=16488&quot;&gt;Homework Feedback | Algorithms: Design and Analysis, Part I&lt;/a&gt;: &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;box-sizing: border-box; color: #333333; font-size: 24px; line-height: 42px; margin: 10.5px 0px; text-rendering: optimizelegibility;&quot;&gt;&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;Feedback — Programming Question-1&lt;/span&gt;&lt;/h2&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;The answer of the 1st programming question is ... &amp;nbsp;&lt;span style=&quot;background-color: #fafafa; color: #333333; font-size: 14.44444465637207px; line-height: 20.98958396911621px;&quot;&gt;&lt;b&gt;2407905288&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/436183227283734801/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/436183227283734801' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/436183227283734801'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/436183227283734801'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2013/01/homework-feedback-algorithms-design-and.html' title='Homework Feedback | Algorithms: Design and Analysis, Part I'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4746658946889574209.post-207817087036888212</id><published>2012-02-13T09:59:00.000-08:00</published><updated>2012-02-13T09:59:55.581-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="administration"/><category scheme="http://www.blogger.com/atom/ns#" term="application"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><title type='text'>Web Site Performance Test</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;At last! You have finished that project that made you loose your sleep, friends, or I don&#39;t know what else... A really &quot;boring&quot; and very time consuming step is ... yes you know... &lt;b&gt;Testing&lt;/b&gt;!&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;There are a lot of things that you want to test. I will complete the list through time... But now I would like to notice 2 very important tests:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;1.&lt;/b&gt; Put your enemies to test your site. Make them find whatever bug, fault anything that they don&#39;t like. Make sure you Thank them then.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;b&gt;2.&lt;/b&gt; MAKE a performance test:&amp;nbsp;If you&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;want to start with the big picture—how well the server copes with&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;demand—software like &lt;a href=&quot;http://httpd.apache.org/&quot;&gt;ApacheBench&lt;/a&gt;&amp;nbsp; &amp;nbsp;and &lt;a href=&quot;http://www.joedog.org/index/siege-home&quot;&gt;Siege&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; will run benchmarks on your Web&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;server, reporting on how many requests can be handled per second, which is&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;the standard measuring tool for a site’s performance. Once you start checking&amp;nbsp;your site’s performance, you will fi nd that big, systemwide changes you make&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;will have the greatest impact. These include:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;■ Changing the server hardware: increasing memory, installing faster hard&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;drives, and using faster processors&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;■ Changing the demands on the server: disabling unnecessary features,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;putting fewer users or sites on a single server, and balancing loads across&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;multiple servers&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;■ Caching the PHP output&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;■ Caching the PHP execution&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;■ Caching the database results&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;If you think about the process involved for handling the request of a PHPMySQL&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;based page, you’ll see three areas where caching can be applied&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;(Figure 1.4). First, if the database or PHP is caching the results of a database&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;query, then that query will not need to be executed with each request.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Second, by default, each request of a PHP script requires that the PHP code&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;be executed as if it had never been run before. By applying an opcode cache&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;such as the Alternative PHP Cache (&lt;a href=&quot;http://www.php.net/apc&quot;&gt;APC&lt;/a&gt;), the PHP code&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;itself is cached by the system, making that execution faster. Finally, the end&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;result is that HTML is sent to the Web browser. If you can cache the dynamically&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;generated HTML, then no PHP code will be executed at all, no database&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;queries are required, and the request itself becomes as fast as a request for&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;a static HTML page.&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://alexopoulos7.blogspot.com/feeds/207817087036888212/comments/default' title='Σχόλια ανάρτησης'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4746658946889574209/207817087036888212' title='0 σχόλια'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/207817087036888212'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4746658946889574209/posts/default/207817087036888212'/><link rel='alternate' type='text/html' href='http://alexopoulos7.blogspot.com/2012/02/web-site-performance-test.html' title='Web Site Performance Test'/><author><name>Άγγελος Α. Αλεξόπουλος</name><uri>http://www.blogger.com/profile/07489820811348794001</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='20' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikjsI5ANtLuYIwy--WhWzXL9xhFXTjANY6Vi-5OiWrtsvxrGv8raRyVYhIgXNv6P1eJmgHcgpYXXvyGjDZ5x_AdZgfzjaCF36PWn2MZApxpaV3GxY9uNUyyyjst05PjA/s220/Rainbow-Paint-Splatter.jpg'/></author><thr:total>0</thr:total></entry></feed>