<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[kblog - Medium]]></title>
        <description><![CDATA[A personal blog of Amr Gawish - Medium]]></description>
        <link>https://blog.amr-gawish.com?source=rss----c602104e17b6---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>kblog - Medium</title>
            <link>https://blog.amr-gawish.com?source=rss----c602104e17b6---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 13 Jun 2026 13:43:04 GMT</lastBuildDate>
        <atom:link href="https://blog.amr-gawish.com/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Google vs Apple — Which AI to choose!]]></title>
            <link>https://blog.amr-gawish.com/google-vs-apple-which-ai-to-choose-bd1ac8e66e25?source=rss----c602104e17b6---4</link>
            <guid isPermaLink="false">https://medium.com/p/bd1ac8e66e25</guid>
            <category><![CDATA[thoughts]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[musings]]></category>
            <dc:creator><![CDATA[Amr Gawish]]></dc:creator>
            <pubDate>Thu, 13 Jun 2024 10:59:12 GMT</pubDate>
            <atom:updated>2024-06-13T10:59:12.258Z</atom:updated>
            <content:encoded><![CDATA[<h3>Google vs Apple — Which AI to choose!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cKJHs6J6mJ5_4gYX" /><figcaption>Photo by <a href="https://unsplash.com/@wacalke?utm_source=medium&amp;utm_medium=referral">Mateusz Wacławek</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>TL;DR:</h3><p>Apple announced their AI system, Apple Intelligence, at WWDC. As an Android user and a Google services user, I’m intrigued by Apple’s focus on privacy but prefers my Pixel due to habit. While Google’s AI might be better, their ad-based model raises privacy concerns. Apple’s hardware focus and privacy emphasis might be a better fit in the future, but switching to iPhone requires a whole ecosystem shift.</p><p>Apple WWDC 2024 launched with a slew of Apple Intelligence — Apple’s own AI brand! — that work tightly with Apple’s echo systems and service.</p><p>I’ve had a lot of thoughts, but Dave 2D on <a href="https://www.youtube.com/watch?v=cy9b2v8Rhvs">youtube</a> echoed similar sentiments and trains of thought that I have, and I thought I’d try to put them into words here.</p><p>In his video, Dave said the company behind your phone’s operating system will likely win the AI race. I agree, at least until something totally new comes along for phones. This isn’t going to change anytime soon.</p><p>I’m not an iPhone user, I only use my work iPhone for work. I did use it exclusively when my Android phone died a few years back, but I still prefer Google Pixels over an iPhone just because I’m more used to Google’s operating systems.</p><p>I’m lucky that I live in the UK, so the iMessage drama doesn’t impact me in the slightest. My family and I use WhatsApp and it works well.</p><p>Overall, I use Google services more. I even have Google One for my Nest cameras and more Google Drive storage.</p><p>However, looking overall at Google, their main business focus is Ads. When you combine that with whatever AI offering they’re going to put on the table, you have to feel worried. Even if Google’s AI functionality is better, it’s because my data is likely used to fuel ad campaigns for other companies thriving on Google Ads.</p><p>On the other hand, Apple’s main business focus is selling hardware, and they don’t care as much about selling Ads — correct me if I’m wrong — . In their keynote, they’ve put a lot of emphasis on AI privacy and even went the extra mile to notify you every time you interact with ChatGPT. This level of commitment and openness may allow you to use your iPhone with Gemini in the future — if Apple decides it, that is — if you really want to use Google’s Gemini over ChatGPT.</p><p>However, switching to an iPhone involves more than just purchasing a new phone, as the ecosystem kind of forces you towards additional purchases to “complement” your iPhone, but it is definetly a strong option.</p><p>It’s an interesting time to be alive, and the competition is only going to get fiercer as time goes by.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd1ac8e66e25" width="1" height="1" alt=""><hr><p><a href="https://blog.amr-gawish.com/google-vs-apple-which-ai-to-choose-bd1ac8e66e25">Google vs Apple — Which AI to choose!</a> was originally published in <a href="https://blog.amr-gawish.com">kblog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Feeling old]]></title>
            <link>https://blog.amr-gawish.com/feeling-old-1b4b5beb2ab0?source=rss----c602104e17b6---4</link>
            <guid isPermaLink="false">https://medium.com/p/1b4b5beb2ab0</guid>
            <category><![CDATA[random-thoughts]]></category>
            <category><![CDATA[ramblings]]></category>
            <category><![CDATA[random-musings]]></category>
            <dc:creator><![CDATA[Amr Gawish]]></dc:creator>
            <pubDate>Tue, 30 Jan 2024 15:51:59 GMT</pubDate>
            <atom:updated>2024-01-30T15:51:01.298Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DDa4Z1_ends3myDh" /><figcaption>Photo by <a href="https://unsplash.com/@polarmermaid?utm_source=medium&amp;utm_medium=referral">Anne Nygård</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><ul><li><em>“Why are we running?”</em></li><li>“Because…um…we need to”</li><li><em>“Why?”</em></li><li>“Because we don’t want to be late”</li><li><em>“Why can’t we be late?”</em></li><li>“Because it is not a good thing to be, I don’t like being late.”</li><li><em>“But you didn’t do anything wrong!”</em></li><li>“…”</li></ul><p>A conversation with my son.</p><p><strong>38th </strong>birthday was the day I felt, truly felt it. It hit me like a cold water on the winter, it suffocated and crushed my soul like a nut by a nutcracker, I could no longer breathe, and I lost the will and the drive for, well everything!</p><p>I stopped running. My lungs burned, but it was the hollowness inside that made me stumble to a halt. I’ve always cringed when people say that being old is a mindset, they were right. I didn’t feel it when I was 30 nor did it wait for me to hit 40, nope, 38 was the year I truly felt ancient.</p><p>For the past five years, I’ve been running. Just living as a sideline character, reacting but not truly acting. It caught up with me when I stopped. Five years of running drained my energy and left me feeling exhausted, my legs spasmed uncontrollably.</p><p>For a week, I hunkered down, weathering the self-inflicted storm of doubt and loathing. A cold, sucking feeling drained the colour from my world, leaving everything muted and meaningless, urging me to find purpose, an anchor in the swirling chaos. So, I took a step back, a deep breath, and began rebuilding. As a software engineer, my comfort zone had been logic, the clean lines of code. I knew I would find solace in a new project, a fledgling flame to reignite the embers of my passion. But warmth alone wouldn’t conquer the biting economic winds. My finances, already shaky from neglect, shuddered under the strain of the economical inflation rise. Action was imperative. I needed to shore up my crumbling foundation, brick by solid brick, forging a resilient fortress against future financial turmoils.</p><p>My gnawing unease demanded action, but I wouldn’t settle for anything mediocre. I craved genuine passion, something that fuelled me and brought value to others. So, I took a step back, brainstorming possibilities for sometime. I envisioned hobbies that brought joy, alongside income streams that could ease financial burdens and secure our well-being. It was a slow, careful process, but I was determined to enjoy it as much as I could.</p><p>While waiting for my side project idea to simmer, I tackled my finances head-on, slashing unnecessary costs that offered little to no joy. While the savings weren’t as significant as I’d hoped, the process itself was empowering. For the first time in a long while, I felt in control, like I was actively building a brighter financial future for myself and my family. This brought a sense of hope and resilience I hadn’t felt in years.</p><p>At first, I couldn’t grasp my wife’s urge to move furniture and shift the bed around. But seeing the living room through fresh eyes, the sunlight bathing new corners, brought it all home. It is fine to seek change for its own sake. We do need occasional jolts to truly appreciate what we have, to slow down and admire the life we’ve built together. Maybe some wrinkles have appeared, but that just adds character to an old fella who’s still learning to savour the moments.</p><p>— Amr</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b4b5beb2ab0" width="1" height="1" alt=""><hr><p><a href="https://blog.amr-gawish.com/feeling-old-1b4b5beb2ab0">Feeling old</a> was originally published in <a href="https://blog.amr-gawish.com">kblog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How listening to books made me a better reader without giving up listening!]]></title>
            <link>https://blog.amr-gawish.com/how-listening-to-books-made-me-a-book-reader-without-giving-up-listening-416560d3dcac?source=rss----c602104e17b6---4</link>
            <guid isPermaLink="false">https://medium.com/p/416560d3dcac</guid>
            <category><![CDATA[books]]></category>
            <category><![CDATA[reading]]></category>
            <category><![CDATA[new-year-resolution]]></category>
            <category><![CDATA[audiobooks]]></category>
            <category><![CDATA[listening]]></category>
            <dc:creator><![CDATA[Amr Gawish]]></dc:creator>
            <pubDate>Thu, 02 Jan 2020 10:51:01 GMT</pubDate>
            <atom:updated>2020-01-03T13:22:22.796Z</atom:updated>
            <content:encoded><![CDATA[<p>An in-depth look at my three years journey to enjoy both listening and reading books!</p><figure><img alt="The wonder of reading a book and getting into it." src="https://cdn-images-1.medium.com/max/1024/0*HYc3WWAP-04pQ5w0" /><figcaption>Photo by <a href="https://unsplash.com/@californong?utm_source=medium&amp;utm_medium=referral">Nong Vang</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>tl;dr</strong> You can enjoy both listening and reading without having to sacrifice either, if you want to take a look of my experience starting at listening and ending at doing both continue reading. Or you can go straight to the Lessons Learned section and know that listening and reading are not mutually exclusive. Enjoy what makes sense and is more comfortable for you!</p><h3>Listening is not the same as reading!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NXo9wK_xIcnCxaxH9Bf97A.jpeg" /><figcaption>Photo by <a href="https://pixabay.com/users/maylai-7058946/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=3662442">may lai</a> on <a href="https://pixabay.com/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=3662442">Pixabay</a></figcaption></figure><blockquote><strong>Listening is not the same as reading, but really who cares!</strong></blockquote><p>There is always this debate going on between two groups of people. People who cherish reading physical hard/soft copy books, and those who choose to use other digital media to consume book’s content, whether it is reading from a kindle or using audiobooks or other methods.</p><p>This debate, in my opinion, is meaningless and counterproductive, that’s why I wanted to get it out of the way as the first part of this article to say that whatever suits you go for it. In my opinion, there is no right or wrong way to consume a book. If a person doesn’t have time to sit and read, then other consumption methods are a good use of time, but if someone enjoys the physical sensation that accompanies carrying a book, then they should embrace it.</p><p>I’m proud of my journey that started back at the beginning of 2017 when I decided to purchase an Audible subscription, and I consider this subscription the best investment I’ve made for myself in the last 10 years — I know I should be more embarrassed about this! — and until now, I’m still enjoying listening to books on my walks.</p><p>Listening to books was handy plenty of times as I can get motion sickness on car/boat/train/plane trips, but audiobooks keep me occupied into the book’s world for the entirety of those long trips!</p><p>I can understand the argument that says the author intended for the book to be imagined by the reader and the execution of the narrator can mess it up. Not to mention that some books — mostly non-fictional books — have diagrams/figures that would require a reader, not a listener. But then there are audiobooks like <a href="https://www.audible.com/pd/Sherlock-Holmes-Audiobook/B06WLMWF2S">Sherlock Holmes</a> narrated by the fantastic Stephen Fry that can outperform the Sherlock Holmes BBC show by a vast distance!<br>I can understand both arguments, and I appreciate both of them.</p><blockquote>However, I’m still going to enjoy that book for what it is regardless of the medium of consumption.</blockquote><p>With that debate out of the way, if you want to make a habit of consuming books as maybe one of the new year resolution, I believe listening can be a great introduction into this magnificent world. By the end of the year — no promises! — you should appreciate both listening and also reading and maybe even become more like me enjoy doing both at the same time!</p><h3>Getting started with your listening experience</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zUAMgJg9Rwzg9zxx" /><figcaption>Photo by <a href="https://unsplash.com/@maltewingen?utm_source=medium&amp;utm_medium=referral">Malte Wingen</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Before we start talking about starting your experience, one golden rule you should always follow: <strong><em>NEVER</em></strong> listen — or read for that matter — to a book that you don’t like!<br>The main point is to lose yourself to the world the author created for you, to get entangled with its characters and emotionally advance as events progress within the book.<br>If you are engaging with a book because you <strong><em>have to</em></strong> then nothing I’m going to discuss here is going to make any lasting effect, just be aware of that!</p><p>1st thing you want to do is to <strong><em>choose a</em></strong> <strong><em>subscription plan</em></strong>. It is a commitment, so make sure you — cough — commit to it! <br>Make sure it has books you like, browse its catalogue before making your decision.</p><p>2nd you should <strong><em>select at least 3 to 5 books</em></strong> you want to start straight away (put them in your wishlist if that feature exist). In 2017 I completed my goal to finish <strong><em>12 books a year</em></strong>, which is entirely feasible, and if you can choose the 12 books you like from the get-go, go for it, but I’m quite sure plans will change midway!</p><p>3rd you need to <strong><em>dedicate a commute to your book</em></strong>. A daily commute would be best. Listen the whole time in this commute, and make an effort to focus on the listening without drifting in thoughts.</p><p>4th optionally <strong><em>make excuses to commute more</em></strong>. To finish that chapter, or to know how the main character narrowly escaped, or how the villain controlled the dragon! <br>Capitalise on the urge of wanting to listen more and don’t quill it, embrace it!</p><h3>My journey and how I ended up reading again!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FlxN6A9TNwUbyGva" /><figcaption>Photo by <a href="https://unsplash.com/@danielcv_93?utm_source=medium&amp;utm_medium=referral">Daniel Cartin</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When I started listening, my goal was simple, develop a reading habit so that I would always have something to occupy my time in a meaningful way. I got frustrated amidst failing to commit, and on a whim, I decided to purchase an Audible subscription plan that had a good deal for three months.</p><p>I purchased the same audiobook that I was trying — and failing — to read at the time: <a href="https://www.amazon.co.uk/Algorithms-Live-Computer-Science-Decisions-dp-1250118360/dp/1250118360">Algorithms to live by</a>; it was <strong><em>not</em></strong> a great experience to listen! <br>Don’t get me wrong, the book itself was great, but if I started this journey all over again, I would begin it differently!</p><p>The reason being that non-fictional books can be quite tricky to follow without drifting in thoughts, especially if you’re starting your listening experience since the narrator usually have a monotone voice that can get boring quite quickly. Non-fictional books typically focus on the added-value — generally in the shape of advice — rather than the story and its narrative, not to mention that there are no characters to be invested in, which makes it a horrible first-time listening experience!</p><blockquote>Thankfully I had quite a long commute, and I was bored with my music library, so I kept on it until I managed to give ~90% of my attention to my audiobook.</blockquote><p>Even though I wouldn’t recommend starting with non-fictional books, I’m thankful for the time I spent on it, which taught me a lot and took a little over a year to shape up. However, I ended up finishing a total of 14 books by the end of February 2018.</p><p>Then my real enjoyment began with <a href="https://www.audible.com/pd/Nineteen-Eighty-Four-Audiobook/B016E9QOP0">1984 by George Orwell</a> and the fantastic <a href="https://www.audible.com/search?searchNarrator=Andrew+Wincott&amp;pf_rd_p=52918805-f7fc-40f4-a76b-cf1c79f7d10a&amp;pf_rd_r=BMTEYX1RT5EYRA1CB6XR&amp;ref=a_pd_Ninete_c1_narrator_1">Andrew Wincott</a> as a narrator!</p><blockquote>It was like wandering in the sand for so long that you thought everything is a shade of yellow until you see a colourful forest with its deep green and multicoloured birds flying and singing!</blockquote><p>From that point on, I upgraded my subscription to three credits per month. I started consuming a lot of fictional books, including sagas like <a href="https://www.audible.com/author/Pierce-Brown/B00EDBZVNI">Pierce Brown</a>’s <a href="https://www.audible.com/series/Red-Rising-Audiobooks/B00U1UJCU8">Red Rising</a> and trilogies like <a href="https://www.audible.com/series/Chronicle-of-the-Unhewn-Throne-Audiobooks/B00HCMSP1K">Chronicle of the Unhewn Throne</a> by <a href="https://www.audible.com/author/Brian-Staveley/B00D0GLPAK?">Brian Stavely</a> among many more. Up until recently, when I switched back to one credit to give me some time for my reading endeavour along with my listening with 60 books finished in my Audible library!</p><p>During 2017 towards the end, I started to realise that I achieved my goal when I began criticising books without really hating it, and when I was looking forward to 15th of the month when I get my credit to choose a new book!</p><blockquote>Criticising a book was a massive milestone for me, as when I started consuming books, I was like a child, happy with whatever sweets I eat. To be able to criticise is to have the maturity to compare and dissect content and come up with counter-arguments and alternative scenarios, and that is just a wonderful feeling!</blockquote><p>In August of 2019, I started reading again, and it felt like all the listening time has added something, books had taken a different shape in my head than when I started in 2017, and my love for books has taken a new turn for the better.</p><p>The reason I turned back to reading was simple. I wanted to enjoy my non-fictional books again without leaving my colourful forest! <br>I thought I would rather experience them with reading while focusing my listening experience on fictional novels, and this way, I can keep on reading without sacrificing my listening time!</p><p>The decision was easy as my commute was combining transporting by a slow train, a good time for a book without motion sickness, and then a lengthy walk to work, an excellent time for listening, and with that the two-books strategy was born!<br>So far, I’ve read around five books of different sizes, and I found myself sneaking some time to go to a coffee shop to steal more reading time, which is exciting.</p><h3>Lessons learned</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NKHRNuCWV3bl3ENUrHtZzw.jpeg" /><figcaption>Photo by <a href="https://pixabay.com/users/harishs-3407954">Harish Sharma</a> on <a href="https://pixabay.com">Pixabay</a></figcaption></figure><p>The journey turned into a habit, and for the last few months, I kept thinking about what I learned from it and how I can help others going through the same. Below are some of the lessons I accumulated from my mistakes and my accomplishments throughout my journey.</p><h4>Suggestions for choosing a new book to listen to</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G69aYGaFv7Z1qUei" /><figcaption>Photo by <a href="https://unsplash.com/@soymeraki?utm_source=medium&amp;utm_medium=referral">Javier Allegue Barros</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If you don’t have any books in mind, here are some tips that helped me when choosing a new book to listen to:</p><ol><li>Search books in the genre you like, I would suggest going for fictional genres if you’re getting started.</li><li>Check smaller books first, don’t go for the big 30+ hours books, it can get overwhelming. A good starting range would be between 4 to 13 hours long.</li><li>Listen carefully to the book’s sample and its narrator’s performance, preferably on the device and headphones you’re going to use in your commute. Make sure you’re comfortable with it.</li><li>Check the rating but don’t read into it too much! A good rule of thumb: if a book has 4+ stars with more than 1k+ reviews, you probably going to have a great experience!</li><li>Start with stand-alone fictions, and slowly move into big trilogies and sagas, seeing the story’s ending is remarkably satisfactory.</li></ol><h4>Tips for focusing on listening</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*msuOP_qLSOXb61T-" /><figcaption>Photo by <a href="https://unsplash.com/@stefanbc?utm_source=medium&amp;utm_medium=referral">Stefan Cosma</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If you always drift in thought or itch to check your mobile every 5 seconds, here are some pointers that I learned to develop, which helped me focus on listening, even when listening to non-fictional books!</p><ol><li>Don’t stress it. It can take time, but it will come naturally. Just don’t stress about it too much. Trust me on this one.</li><li>Maintain a loose focus; a sharp focus can and will be tiring in the long run.</li><li>Put your phone in your pocket at all times!</li><li>Use a wireless headset for the best experience and less entanglement.</li><li>Put your phone on silent mode without vibration. If you have to read something on your mobile, pause your listening before doing so.</li><li>If you want to take notes, stop the audiobook first.</li><li>Treat it like reading and give it your full attention without losing your surroundings.</li></ol><h3>Taking it a step further</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gWQ7ZhSu4vnvWb7Q" /><figcaption>Photo by <a href="https://unsplash.com/@cerstrand?utm_source=medium&amp;utm_medium=referral">Carl Cerstrand</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The strategy of reading and listening at the same time is good enough for the time being. Still, I’m already foreseeing a problem with long-running series, how can I refresh my memory of what happened in the last <strong><em>n</em></strong> books before reading the <strong><em>n+1</em></strong>&#39;s!</p><p>My <em>work in progress</em> solution would be to incorporate writing into my strategy and start to have a recap with some template so that I can remember the story’s events, characters and their relationships. Then I can just skim through it within a few hours to get back on track whenever a series adds a new book!</p><p>The reason I think writing something myself is better than going to Wikipedia or Reddit for reference is that writing adds another level of intimacy between me and the book, and increase the critique mental model that I love so much.</p><h3>In conclusion</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LPLhGJZDybEzYO-0oyjL3Q.jpeg" /><figcaption>Photo by <a href="https://pixabay.com/users/ulleo-1834854/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=3755516">Ulrike Leone</a> on <a href="https://pixabay.com/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=3755516">Pixabay</a></figcaption></figure><p>Making a habit of reading books is a worthy goal, and if you’re struggling to get started like I was, I hope you found my journey insightful and the Lessons learned helpful. I’m also hopeful that you can see that the consumption method of a book is less important than the book’s content. <strong><em>That is what truly matters!</em></strong></p><p>If you liked this article, consider following me for more. If you loved it, then don’t forget to click on the green hands right below this text. 👏👏👏</p><p>Also, follow me on <a href="https://twitter.com/agawish">Twitter</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=416560d3dcac" width="1" height="1" alt=""><hr><p><a href="https://blog.amr-gawish.com/how-listening-to-books-made-me-a-book-reader-without-giving-up-listening-416560d3dcac">How listening to books made me a better reader without giving up listening!</a> was originally published in <a href="https://blog.amr-gawish.com">kblog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gamification & Progression-Driven Development — Agile Tour London 2018]]></title>
            <link>https://blog.amr-gawish.com/gamification-progression-driven-development-agile-tour-london-2018-c2ea645407df?source=rss----c602104e17b6---4</link>
            <guid isPermaLink="false">https://medium.com/p/c2ea645407df</guid>
            <category><![CDATA[conference]]></category>
            <category><![CDATA[gamification]]></category>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[craftsmanship]]></category>
            <dc:creator><![CDATA[Amr Gawish]]></dc:creator>
            <pubDate>Fri, 05 Oct 2018 11:30:24 GMT</pubDate>
            <atom:updated>2018-10-05T11:30:24.095Z</atom:updated>
            <content:encoded><![CDATA[<h3>Gamification &amp; Progression-Driven Development — Agile Tour London 2018</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5ujwiZVoR2lF_JFM" /><figcaption>“MacBook beside headphones” by <a href="https://unsplash.com/@frankievalentine?utm_source=medium&amp;utm_medium=referral">Frankie Valentine</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I’ve been quite busy lately and currently preparing for my presentation <a href="https://twitter.com/agiletourlondon">@agiletourlondon</a> which takes place on October 19th, so if you want to meet me in person and you happen to be in London, come to say Hi :)</p><blockquote>The session is about the use of <a href="http://2018.agiletourlondon.co.uk/Session/bringing-gamification-techniques-to-agility-and-the-rise-of-progression-driven-development/">Gamification elements into an Agile process</a>, and how would that can make a fun and enjoyable environment for the whole team.</blockquote><p>This topic is quite close to my heart as it combines Agility, Gamification and software engineering &amp; craftsmanship.</p><p>This session will also debut my Progression-Driven Development (PDD) Framework, and I will follow up with more details in this blog about the framework after the 19th of October.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sc9Bj8TTM-d7preQc9ON_g.jpeg" /><figcaption>Come to join me on the 19th of October for an exciting Journey through one of PDD worlds 😉</figcaption></figure><p>PS: I have a discount code <strong>SAG15</strong> for 15% at checkout if you want!</p><p>If you liked this article, consider following me for more. If you loved it, then don’t forget to click on the green hands right below this text. 👏👏👏</p><p>Also, follow me on <a href="https://twitter.com/agawish">Twitter</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2ea645407df" width="1" height="1" alt=""><hr><p><a href="https://blog.amr-gawish.com/gamification-progression-driven-development-agile-tour-london-2018-c2ea645407df">Gamification &amp; Progression-Driven Development — Agile Tour London 2018</a> was originally published in <a href="https://blog.amr-gawish.com">kblog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Challenge UK: a gamified challenge for Java students and professionals]]></title>
            <link>https://blog.amr-gawish.com/java-challenge-uk-a-gamified-challenge-for-java-students-and-professionals-3fcb1c16d93f?source=rss----c602104e17b6---4</link>
            <guid isPermaLink="false">https://medium.com/p/3fcb1c16d93f</guid>
            <category><![CDATA[uk]]></category>
            <category><![CDATA[students]]></category>
            <category><![CDATA[gamification]]></category>
            <category><![CDATA[challenge]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Amr Gawish]]></dc:creator>
            <pubDate>Mon, 23 Apr 2018 11:31:02 GMT</pubDate>
            <atom:updated>2018-04-23T11:54:33.599Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cHivTXox3q_BhT3N." /><figcaption>Take the challenge! (Photo by <a href="https://unsplash.com/@doran_erickson?utm_source=medium&amp;utm_medium=referral">Doran Erickson</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a>)</figcaption></figure><p>I’m writing this post to give a heads-up about a UK-wide Java competition, for professionals and students, that’s happening right now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*vY15TYjWNc5v1A1m0-UEyw.jpeg" /><figcaption>50% chance with your jokers</figcaption></figure><p>The Java Challenge UK is a gamified online challenge, running over six weeks.<br>It works like this: you get 15 minutes to answer a maximum of 17 multiple-choice questions. If you run into trouble, you get three “jokers”, giving you a 50/50 chance of picking the right answer, you can choose to see what the other contestants answered, or you get to call a friend to help you out!</p><p>So, it’s a fun chance to test your skills and to compete against other Java lovers to become the champion. What’s also fun, though, is that you get the chance to fight for some quality prizes; the first prize, for example, is a £800 flight voucher, valid on over 300 different airlines</p><p>You can enter the challenge, and get more information on the awards and rules, on <a href="https://editx.eu/it-challenge/java-challenge-uk-infomentum">the official challenge page</a>.</p><p>If you liked this article, consider following me for more. If you loved it, then don’t forget to click on the green hands right below this text. 👏👏👏</p><p>Also, follow me on <a href="https://twitter.com/agawish">Twitter</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fcb1c16d93f" width="1" height="1" alt=""><hr><p><a href="https://blog.amr-gawish.com/java-challenge-uk-a-gamified-challenge-for-java-students-and-professionals-3fcb1c16d93f">Java Challenge UK: a gamified challenge for Java students and professionals</a> was originally published in <a href="https://blog.amr-gawish.com">kblog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a production-ready Ethereum DApp from idea to final product — The smart-contract (pt. 3)]]></title>
            <link>https://blog.amr-gawish.com/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-the-smart-contract-pt-3-2e117c74e61e?source=rss----c602104e17b6---4</link>
            <guid isPermaLink="false">https://medium.com/p/2e117c74e61e</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[solidity]]></category>
            <dc:creator><![CDATA[Amr Gawish]]></dc:creator>
            <pubDate>Wed, 21 Mar 2018 11:01:01 GMT</pubDate>
            <atom:updated>2018-03-21T11:01:01.187Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a production-ready Ethereum DApp from idea to final product — The smart-contract (Part 3)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V61RihtAuGzwcFpSolI0Ag.png" /><figcaption>Always run your tests!</figcaption></figure><p>In the <a href="https://blog.amr-gawish.com/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-the-smart-contract-pt-2-97e8220e2e2c">previous post</a>, we built the application structure for our solidity code. In this article, we are going to develop our smart-contract (business logic) for the Survey DApp.</p><h3>Table of content</h3><p>This series is separated into 3 sections:</p><ol><li><strong>The smart-contract — Create the Survey smart-contract</strong> (You’re here)<br>1.1. <a href="https://blog.amr-gawish.com/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-first-section-the-3b9975a226c">From Idea to a business plan</a><br>1.2. <a href="https://blog.amr-gawish.com/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-the-smart-contract-pt-2-97e8220e2e2c">Setting up development environment with Truffle </a><br>1.3. Creating the smart-contract the TDD way — You’re here<br>1.4. Testing Solidity Code on TestRPC, Local Ethereum chain and Testnet</li><li><strong>The Backend — Server side Ethereum development</strong></li><li><strong>The Frontend — Client side user interface and wallet integration</strong></li></ol><h3>Incremental updates the TDD way</h3><p>I’m a big fan when it comes to TDD and BDD, and one thing that TDD does best is to minimise the process of thinking about your code and approach the source code in a more functional approach.</p><p>BDD is using the same concepts as TDD but communicates it using examples instead; for example:</p><blockquote>“Given that I’m a [ROLE]<br>When I [CONDITION]<br>Then [RESULT]”</blockquote><p>In this article you will see the above format used for clarity purposes.</p><p>We can also create Solidity Mocks, but it will not allow certain test cases to be executed since we cannot control the msg.sender and the msg.value variables, so I will preferably work with Truffle’s Mocha test suits.</p><p>We are going to extend Mocha test suit and use it with <a href="http://www.chaijs.com/">ChaiJS </a>to make a better quality code for my contract.</p><blockquote>I also included <a href="http://www.chaijs.com/">ChaiJS</a> and some of its plugins as part of my dependencies using npm install --save-dev chai chai-as-promised chai-bignumber</blockquote><h3>Creating the Contracts Shell</h3><p>The first thing we need to create is the shell for our smart-contract, in this Simple DApp, we only need to create two solidity contracts.</p><ol><li><strong><em>SurveyFactory.sol</em></strong> — The solidity contract that creates the survey to keep track of the survey’s owner and optionally charge fees from Survey Makers to run the service.</li><li><strong><em>Survey.sol</em></strong><em> — </em>The solidity contract that works with the survey itself like adding participants, removing participants, finishing survey and more.</li></ol><p>In the contracts folder, create two files SurveyFactory.sol and Survey.sol and write the minimal code for a valid solidity contract, such as:</p><pre>pragma solidity ^0.4.19;</pre><pre>/// <a href="http://twitter.com/title">@title</a> SurveyFactory <em>—</em> Creates surveys and charge users<br>/// <a href="http://twitter.com/author">@author</a> {YOUR NAME HERE}<em>—</em> &lt;{YOUR EMAIL HERE}&gt;<br>contract SurveyFactory {<br> //Just a shell...for now!</pre><pre>}</pre><p>And do the exact same thing for Survey.sol as well.</p><pre>pragma solidity ^0.4.19;</pre><pre>/// <a href="http://twitter.com/title">@title</a> Survey <em>—</em> Work with a Survey to add participants finish survey <br>/// <a href="http://twitter.com/author">@author</a> {YOUR NAME HERE}<em>—</em> &lt;{YOUR EMAIL HERE}&gt;<br>contract Survey{<br> //Just a shell...for now!</pre><pre>}</pre><blockquote>If you installed Truffle globally, you can create the contracts by simply running the command <em>truffle create contract SurveyFactory</em> and <em>truffle create contract Survey</em>. However, you will have to change the default solidity compiler version.</blockquote><h3>Creating the Test Suits</h3><p>Now we need to create the same for our tests, we need to have two test suits, one for <em>SurveyFactory </em>and the other for <em>Survey</em>.</p><p>In the test folder, create two files survey_factory.js and survey.js and write the minimal code for a valid solidity contract, such as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92f2d797e99e5351db527e16df38f68f/href">https://medium.com/media/92f2d797e99e5351db527e16df38f68f/href</a></iframe><blockquote>If you installed Truffle globally, you can create test files by simply running the command <em>truffle create test SurveyFactory</em> and <em>truffle create test Survey</em>. This will create the same identical files.</blockquote><h3>Preparing the test suits</h3><p>Before we start with the test cases, we need to figure out how we want to work with specific common variables and patterns throughout your test cases; it is usually a good practice to separate those in helper classes and make yourself <a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a> from the beginning.</p><h4>Error Helpers</h4><p>The first helper is to work with Solidity errors. Since the most common exception is going to appear from a require statement, then we need to figure out a way in which we can detect that. Luckily Solidity throws the code “revert” to that error, and we can try to see if the error contains the “revert” keyword or it is a different error.</p><blockquote>This helper is using the same concepts as the <a href="https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/test/helpers/assertRevert.js">assertRevert.js</a> from zeppelin-solidity library.</blockquote><p>Create a folder inside the test directory named helpers and add the following file inside of it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f883db9260ee274ef2a6fdb80db1f72/href">https://medium.com/media/1f883db9260ee274ef2a6fdb80db1f72/href</a></iframe><h4>Packages and Common Variables helper</h4><p>Another essential helper is to group all the variables that we think is going to be utilised by our test cases together so that we DRY.</p><p>We first need to think about the Survey DApp roles; we have three roles in our DApp:</p><ol><li>Survey DApp Owner</li><li>Survey Maker</li><li>Participants</li></ol><p>It makes sense to create variables for these accounts, also set other shared variables, for example, the Survey DApp Creation Fee or different constants.</p><p>Inside helpers directory, add the following file :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48865a95118a8647628b2ed5c9c6a7ff/href">https://medium.com/media/48865a95118a8647628b2ed5c9c6a7ff/href</a></iframe><p>With that in mind, we can go back to our test files survey_factory.js and survey.js and use the helpers we created, it should looks something similar to the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22325f6cf3b6c0d7cf79a4d2d0193ea3/href">https://medium.com/media/22325f6cf3b6c0d7cf79a4d2d0193ea3/href</a></iframe><blockquote>Note that I did repeat some code twice (initialization code), that is for readability purposes, and ease of access!</blockquote><p>Now, we first need to run ganache-cli, just execute npm run testrpc in a command-line and open a new command line to prepare for testing.</p><p>With the above, we are ready to work on our test cases and start coding some solidity.</p><h3>Starting the TDD Cycle</h3><p>1 <strong>Adding Test Case(s) — </strong>Adding the test case(s) by creating a logical group using describe and add various test case examples underneath it, for example, we need to cover test cases for “<strong><em>Create Survey</em></strong>” functionality, so we can build our test cases to cover all examples of this requirements. Such as:</p><h4>Example #1</h4><ol><li>Given that I’m the Survey Maker</li><li>When I try to create a new Survey and included the survey creation costs and survey reward</li><li>Then I should be able to get the created survey reference number and address</li></ol><h4>Example #2</h4><ol><li>Given that I’m the Survey Maker</li><li>When I try to create a new Survey and included the survey creation costs and survey reward</li><li>Then I should be assigned as the owner of the newly created survey</li></ol><h4>Example #3</h4><ol><li>Given that I’m the Survey Maker</li><li>When I try to create a new survey without including the survey creation cost.</li><li>Then I should receive an Error</li></ol><h4>Example #4</h4><ol><li>Given that I’m the Survey App Owner</li><li>When I try to create a new Survey</li><li>Then I should receive an Error</li></ol><p>Below is the code that covers all four examples:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/796a038df9d6085c2deb651ecd7d5682/href">https://medium.com/media/796a038df9d6085c2deb651ecd7d5682/href</a></iframe><p>Two things to note from the code above:</p><ol><li>I didn’t use async/await and used it only in the beforeEach override, this is just a style preference, I usually depend on using chai-as-promised library, but you can still use it as you please.</li><li>In the second test case, I invoked the method createSurvey first with .call and then without it, the first one is meant to get the result and the second one executes the transaction to be mined by the Ethereum Blockchain (returns a transaction receipt).</li></ol><p>2 <strong>Update Solidity Code to add enough logic for the test to succeed — </strong>Now that we created the test cases we need to make sure the solidity code can make those test cases succeed.</p><p>I changed both Solidity contracts to make my test passes, the solidity code now looks like the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f08ba4e72b15e5788d098147459f70c0/href">https://medium.com/media/f08ba4e72b15e5788d098147459f70c0/href</a></iframe><p>Things to note here:</p><ol><li>I might have created more than what the test cases need to pass; this is because I have an architecture and I know specific variables/modifiers would be handy in the future.</li><li>When you have public/external methods, make sure they emit an event, always!</li><li>Always be paranoid and do your checks (usually using require) to make sure the method is not continuing with any corrupt state.</li><li>Also use SafeMath for any arithmetic operations, always!</li><li>If the contract has Ownership logic, import zeppelin Ownable contract!</li></ol><p>3 <strong>Test &amp; Repeat — </strong>Test the above code by running npm run test to make sure it passes all test cases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*X4h4uvdHFQd-GK0JH-ahHQ.png" /><figcaption>It worked!</figcaption></figure><p>Then repeat the above two steps for another requirement, until we cover all our cases, and our application is ready!</p><p>In the Survey DApp, there are four other significant functionalities to test like:</p><ol><li>Adding Participants</li><li>Increasing the survey reward</li><li>Finishing Survey and Draw Winner Randomly</li><li>Invalidate Survey and pull money out</li></ol><h3>In the next part</h3><p>With what we’ve covered in this post, we have successfully looked at how to build the main business logic for the application in a TDD/BDD fashion. We can now deploy the contract and tested it.</p><blockquote>The Git repository doesn’t have all test cases covered yet; it would be great if you want to help include it by creating a PR and add the new test-cases and solidity code. However, the full source code with test cases should be available before the next blog post.</blockquote><p><a href="https://github.com/agawish/survey-reward-dapp">agawish/survey-reward-dapp</a></p><p>If you liked this article, consider checking it on <a href="https://steemit.com/blockchain/@agawish/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-the-smart-contract-part-3">steemit</a>, and follow me for more. If you loved it, then don’t forget to click on the green hands right below this text. 👏👏👏</p><p>Also, follow me on <a href="https://twitter.com/agawish">Twitter</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e117c74e61e" width="1" height="1" alt=""><hr><p><a href="https://blog.amr-gawish.com/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-the-smart-contract-pt-3-2e117c74e61e">Building a production-ready Ethereum DApp from idea to final product — The smart-contract (pt. 3)</a> was originally published in <a href="https://blog.amr-gawish.com">kblog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a production-ready Ethereum DApp from idea to final product — The smart-contract (pt. 2)]]></title>
            <link>https://blog.amr-gawish.com/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-the-smart-contract-pt-2-97e8220e2e2c?source=rss----c602104e17b6---4</link>
            <guid isPermaLink="false">https://medium.com/p/97e8220e2e2c</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[truffle]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[web3]]></category>
            <dc:creator><![CDATA[Amr Gawish]]></dc:creator>
            <pubDate>Mon, 19 Feb 2018 17:01:01 GMT</pubDate>
            <atom:updated>2018-03-21T22:17:07.108Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a production-ready Ethereum DApp from idea to final product — The smart-contract (Part 2)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_TH_MQXXVf-bcfKzR1ZLZQ.png" /><figcaption>Know your tools</figcaption></figure><p>In the <a href="https://blog.amr-gawish.com/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-first-section-the-3b9975a226c">previous post</a>, I discussed the idea behind the survey DApp, the primary focus of this series. By now you should have a fair understanding of how the interaction between the DApp, the survey taker and survey owner is going to look like — roughly — and now it is time to get started.</p><p>But before we dig into the smart contract code we need to understand the tools that we are going to use to set up our development environment.</p><h3>Table of content</h3><p>This series is separated into 3 sections:</p><ol><li><strong>The smart-contract — Create the Survey smart-contract</strong> (You’re here)<br>1.1. <a href="https://blog.amr-gawish.com/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-first-section-the-3b9975a226c">From Idea to a business plan</a><br>1.2. Setting up development environment with Truffle — You’re here<br>1.3. <a href="https://blog.amr-gawish.com/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-the-smart-contract-pt-3-2e117c74e61e">Creating the smart-contract the TDD way</a><br>1.4. Testing Solidity Code on TestRPC, Local Ethereum chain and Testnet</li><li><strong>The Backend — Server side Ethereum development</strong></li><li><strong>The Frontend — Client side user interface and wallet integration</strong></li></ol><h3>The smart-contract role of the DApp</h3><p>We need first to understand how we are going to develop our DApp, the application design is a significant step, as we need to architect application stages properly to avoid <a href="https://en.wikipedia.org/wiki/Code_smell">code smells</a> in the long run.</p><p>The smart-contract is the core module of our DApp, but if we’re part of a team, then the design of the DApp should allow all modules to be loosely coupled, to enable rapid development.</p><p>While other parts of the DApp are essential, the smart-contract serves as our business logic, the main point of truth (don’t like to say it is a database!). While validations will exist on both the backend and the frontend, we still want to ensure our data is not corrupted, especially that anyone with the smart-contract address can call its functionality straight away, and that’s why the security of the smart-contract is a keystone to a successful DApp.</p><h3>Truffle and Web3</h3><p>Since DApps are literally in their infancy, there are not a lot of frameworks to work with in here, not to mention that the community is currently pushing one specific structure to use, that becomes the defacto nowadays, that is Truffle.</p><p>Truffle eases up the development tasks from compiling, testing, migrating/deploying and provide a quick and handy Command Line Interface (CLI) to do all these stuff with ease.</p><p>It also provides <a href="http://truffleframework.com/boxes/">Truffle Boxes</a>, a prepackaged folder structure that eases up development work with other frameworks like react, uPort and more.</p><blockquote>Some of these boxes don’t use the latest versions, so be careful and read your package.json file for dependencies</blockquote><p>Unfortunately, Truffle is not a one-size-fits-all framework and therefore is not sufficient. We would still need to work with accounts, BigNumbers, transactions, providers — such as Metamask and Mist — and more, and this is where Web3 comes into the picture.</p><p>Web3 simplifies working with all that is Ethereum such as accounts, transactions, different providers, Blockchain blocks, gas and much more.</p><h3>Setting up the environment</h3><p>Enough talk, lets get coding…</p><p>1we need to have the latest version of <a href="https://nodejs.org/en/">Node</a> (if you have a non-upgraded Node, you can upgrade it by following <a href="https://davidwalsh.name/nvm">this guide</a>).</p><p>2download geth(Go Ethereum) as we will need to use in Part 4 (instructions <a href="https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum">here</a>)</p><p>3create the application’s folder structure by below commands (assuming Unix-based platforms)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/badd9e1c5eecc93a3bff82defbd16500/href">https://medium.com/media/badd9e1c5eecc93a3bff82defbd16500/href</a></iframe><blockquote>I installed everything locally (not globally), it is a good practice if you want to distribute your project without having to worry about individual modules availability. However, you might find it useful to install some of these npm modules globally.</blockquote><p>After you finish, you should end up with the below structure (Minus the LICENSE, .env-sample and .gitignore files)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*HUXLVzGp4nD4YsSa4ndHeA.png" /><figcaption>Folder structure in Visual Studio Code</figcaption></figure><p>Now time to configure some of these modules to be ready.</p><h3>Additional npm modules configuration</h3><p>Now that we sat up the application folder structure, it is good to go through some of these modules to understand their role in the DApp and add its specific configurations.</p><h4>zeppelin-solidity</h4><p><a href="https://github.com/OpenZeppelin/zeppelin-solidity">zeppelin-solidity</a> is a fantastic npm module that helps with common solidity patterns, not to mention that these contracts have been audited for security so you can safely depend on them. We are going to see how to use these contracts in the next part.</p><h4><strong>solium</strong></h4><p><a href="https://github.com/duaraghav8/Solium">solium</a> is another excellent npm module as it provides lint and preliminary security for solidity code and can also — sometimes — fix these problems, it also helps if you’re working with teams and want to force particular style format.</p><p>One thing we don’t want it to analyse is the <em>Migrations.sol</em> contract that comes with Truffle. To ignore it, we need to add the solium ignore list. We can do that by easily open <em>.soliumignore</em> file and add the following line at the end.</p><pre>contracts/Migrations.sol</pre><p>We also need to be able to run Solium a lot; it is a good practice to add a script to it inside package.json file like so</p><pre>&quot;lint&quot;: &quot;./node_modules/.bin/solium -d contracts --fix&quot;</pre><h4>solidity-coverage</h4><p><a href="https://github.com/sc-forks/solidity-coverage">solidity-coverage</a> is yet another excellent npm module that works in tandem with truffle test command; it generates test coverage report which can be useful, especially if you’re following TDD practices.</p><p>First, we need to create the configuration file for solidity-coverage, namely .solcover.js and add the following inside of it</p><pre>module.exports = {</pre><pre>//Make sure that all open zeppelin contracts are included as a dependency</pre><pre>copyPackages: [&#39;zeppelin-solidity&#39;],</pre><pre>//If we want to skip files</pre><pre>skipFiles: []</pre><pre>};</pre><p>It is also useful to add solidity-coverage as a script into package.json like so:</p><pre>&quot;coverage&quot;: &quot;./node_modules/.bin/solidity-coverage&quot;</pre><h4>dotenv</h4><p><a href="https://github.com/motdotla/dotenv">dotenv</a> is simply a .env file that load all the properties inside of it into an environment variables, which can be handy especially when we develop server-side code.</p><h4>ganache-cli</h4><p><a href="https://github.com/trufflesuite/ganache-cli">ganache-cli</a> is part of the Truffle suite; it is JavaScript-based Ethereum Blockchain simulator that runs locally which is useful to run different tests and make sure that everything is working as intended.</p><p>It is also essential to add ganache-cli as a script into package.json like so:</p><pre>&quot;testrpc&quot;: &quot;./node_modules/.bin/ganache-cli --accounts 30&quot;</pre><blockquote>In the above command, I’ve changed the default number of generated accounts from 10 to 30.</blockquote><h4>Truffle</h4><p><a href="http://truffleframework.com/">Truffle</a> is the main framework to compile, migrate and test different solidity contracts, we are going to depend on a lot of its functionality throughout this series, but first, we must prepare its configuration.</p><p>First, we need to add our the development configuration into truffle.js configuration file.</p><blockquote>For windows user, if you have problems with configuration, it would be better to use truffle-config.js file and delete truffle.js file.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e87817a29101cfd7c4d666e1a43caee5/href">https://medium.com/media/e87817a29101cfd7c4d666e1a43caee5/href</a></iframe><p>The above file is going to grow as we utilise <em>dotenv</em> and test other networks as we move on.</p><p>And again it is good to add different truffle commands as a script into package.json like so:</p><pre>&quot;compile&quot;: &quot;./node_modules/.bin/truffle compile&quot;,</pre><pre>&quot;test&quot;: &quot;./node_modules/.bin/truffle test&quot;,</pre><pre>&quot;migrate&quot;: &quot;./node_modules/.bin/truffle migrate&quot;</pre><p>You should finally end up with something similar to the below screen in your package.json file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*l7apJvJW_NI00d4JgjhYxQ.png" /><figcaption>Scripts object in package.json</figcaption></figure><h3>In the next part</h3><p>With what we’ve covered in this post, we are ready to start working on the DApp solidity code; if you found the above too long to follow, you can grab the code from below GitHub repository (make sure you check out the right branch!)</p><p><a href="https://github.com/agawish/survey-reward-dapp">agawish/survey-reward-dapp</a></p><p>If you liked this article, consider checking it on <a href="https://steemit.com/blockchain/@agawish/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-the-smart-contract-part-2">steemit</a>, and follow me for more. If you loved it, then don’t forget to click on the green hands right below this text. 👏👏👏</p><p>Also follow me on <a href="https://twitter.com/agawish">Twitter</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97e8220e2e2c" width="1" height="1" alt=""><hr><p><a href="https://blog.amr-gawish.com/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-the-smart-contract-pt-2-97e8220e2e2c">Building a production-ready Ethereum DApp from idea to final product — The smart-contract (pt. 2)</a> was originally published in <a href="https://blog.amr-gawish.com">kblog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a production-ready Ethereum DApp from idea to final product — The smart-contract (pt. 1)]]></title>
            <link>https://blog.amr-gawish.com/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-first-section-the-3b9975a226c?source=rss----c602104e17b6---4</link>
            <guid isPermaLink="false">https://medium.com/p/3b9975a226c</guid>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[truffle]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Amr Gawish]]></dc:creator>
            <pubDate>Mon, 05 Feb 2018 18:50:04 GMT</pubDate>
            <atom:updated>2018-03-21T22:18:02.546Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a production-ready Ethereum DApp from idea to final product — The smart-contract (Part 1)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*On7BznIa_jNWrZmT4tGa5A.png" /><figcaption>Approach the Blockchain light!</figcaption></figure><h3>Introduction</h3><p>This series is targeting seasoned developers who want a series of articles that revolve around coding best practice to create a production-ready DApps. The developer who has a good understanding of what Blockchain is and how Ethereum smart contract works.</p><blockquote>If you need to gain more knowledge about Ethereum and blockchain, check the following <a href="https://medium.com/@ConsenSys/a-101-noob-intro-to-programming-smart-contracts-on-ethereum-695d15c1dab4">post</a> and familiarize yourself with the concept thoroughly.</blockquote><p>There are a lot of fantastic guides out there that talks about Ethereum development but usually fall short to show the full picture from the idea all the way to the front-end, back-end and Smart Contract with all of them working together, and all settings and configurations around all that.</p><p>Even though I’m targeting a production-ready Ethereum DApp, this tutorial is in no mean the full picture, and won’t guarantee to create a secure app as a security audit would still be needed, and you also need to do your research. But at least I hope to give you enough pointers to know where to go afterwards.</p><blockquote>If you care about getting more solidity code and you’re comfortable with the rest, then head to <a href="https://cryptozombies.io/">Cyrptozombies.io</a> or follow <a href="https://hackernoon.com/ethereum-development-walkthrough-part-1-smart-contracts-b3979e6e573e">this guide</a> or <a href="https://blog.zeppelin.solutions/the-hitchhikers-guide-to-smart-contracts-in-ethereum-848f08001f05">that guide</a>, these give an excellent idea of what you need to do.</blockquote><p>This series is not going to dig into the specific details of Solidity language or deep dive into the JavaScript and Node.js code, but instead on how to take an idea from the origin and orchestrate the work needed to make everything work. However, if you need any help or more explanation, you can let me know in a comment below.</p><p>These posts are going to be short and sweet. It will also be progressive with things getting added as the series goes on. If it attracts enough audience, I can create another series of standard applications like ICOs, Sidechains and more…</p><h3>Table of contents</h3><p>This series is separated into 3 layers:</p><ol><li><strong>The smart-contract — Create the Survey smart-contract</strong> <br>1.1. From Idea to a business plan — (You’re here)<br>1.2. <a href="https://blog.amr-gawish.com/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-the-smart-contract-pt-2-97e8220e2e2c">Setting up development environment with Truffle</a><br>1.3. <a href="https://blog.amr-gawish.com/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-the-smart-contract-pt-3-2e117c74e61e">Creating the smart-contract the TDD way</a><br>1.4. Testing Solidity Code on TestRPC, Local Ethereum chain and Testnet</li><li><strong>The Backend — Server side Ethereum development</strong></li><li><strong>The Frontend — Client side user interface and wallet integration</strong></li></ol><h3>The idea</h3><p>As part of my dissertation, I need to conduct a survey to collect information, and I always hit the problem that people would like to be incentivized for the time they spent — wasted — filling that survey. It would be good if you can compensate them. But wait you’re looking to pay 10s or 100s or even 1000s of people, that would cost a lot of money, wouldn’t it!</p><p>Then it hits you…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*5OCOH3fMsFqdw69R6zsi8A.jpeg" /><figcaption>A raffle — What a brilliant idea!</figcaption></figure><p>A raffle, a raffle is a good option, but then people will start question the authenticity and randomness of that raffle and whether or not you’ve given it to someone you know to save yourself this few bucks!</p><p>To solve that problem, you design an excellent survey rewarding DApp to assure authenticity to participants and also to deter away people who don’t understand what Ethereum wallet mean ;)</p><h3>The user(s) journey</h3><p>The user journey can all be elaborated in the following sequence diagram</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*PCl_sDwR3XIz3I-aWQGK_w.png" /><figcaption>Survey DApp Actors and Flow Sequence</figcaption></figure><p>There are 3 actors of this DApp:</p><ol><li>Survey Creator</li><li>Survey Participant</li><li>Survey DApp (The connection between both parties)</li></ol><h4>Survey Creator’s perspective</h4><ol><li>The user Goes to the DApp</li><li>The user Enters the reward and on clicks on Create Survey Link</li><li>The user is Prompted from Metamask to confirm Transaction (Creates smart-contract instance)</li><li>The user is filling the survey link and add integration to survey monkey (out-of-scope)</li></ol><p>After the survey is done, the Survey creator can close — announce it is finished — and receive the winner’s details.</p><h4>Survey Participant’s perspective</h4><ol><li>The user navigates to the Survey DApp.</li><li>The user clicks on to take the survey link.</li><li>The user fills in the survey.</li><li>The user clicks on Finish survey.</li><li>A popup comes that prompt the user to enter his ETH account address to claim his/her reward later.</li><li>The user puts his address.</li><li>A few seconds later the user gets a number to save.</li></ol><p>If the participant is the lucky winner, then the participant gets notified, which he/she can withdraw their money into their wallet.</p><h3>In the next part</h3><p>With the above you hopefully got the idea of how the DApp is going to look like, in the <a href="https://blog.amr-gawish.com/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-the-smart-contract-pt-2-97e8220e2e2c">next part</a> we will see how to create your development environment and what kind of problems you’d usually face setting it up on different Operating Systems, and how to overcome them.</p><p>If you liked this article, consider checking it on <a href="https://steemit.com/blockchain/@agawish/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-the-smart-contract-part-1">steemit</a>, and follow me for more. If you loved it, then don’t forget to click on the green hands right below this text. 👏👏👏</p><p>Also follow me on <a href="https://twitter.com/agawish">Twitter</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b9975a226c" width="1" height="1" alt=""><hr><p><a href="https://blog.amr-gawish.com/building-a-production-ready-ethereum-dapp-from-idea-to-final-product-first-section-the-3b9975a226c">Building a production-ready Ethereum DApp from idea to final product — The smart-contract (pt. 1)</a> was originally published in <a href="https://blog.amr-gawish.com">kblog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My journey with Discord bots from Java to Node.js — Part 3 (Final) Deploying the bot to Heroku]]></title>
            <link>https://blog.amr-gawish.com/my-journey-with-discord-bots-from-java-to-node-js-part-3-final-deploying-the-bot-to-heroku-23abc84d9bae?source=rss----c602104e17b6---4</link>
            <guid isPermaLink="false">https://medium.com/p/23abc84d9bae</guid>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[discord]]></category>
            <category><![CDATA[bots]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Amr Gawish]]></dc:creator>
            <pubDate>Wed, 03 May 2017 13:10:19 GMT</pubDate>
            <atom:updated>2017-05-03T13:10:18.537Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oPfNrSzGKxzc-5AJ3n-lRQ.jpeg" /><figcaption>Courtesy of <a href="https://pixabay.com">https://pixabay.com</a></figcaption></figure><p>Continuing my journey after finishing <a href="https://blog.amr-gawish.com/my-journey-with-discord-bots-from-java-to-node-js-part-2-developing-the-bot-57fe3f9ac89a">Part 2</a>, now that everything in place I want a good place to host my bot and monitor its progress.</p><h3>Table of Content</h3><ul><li><a href="https://blog.amr-gawish.com/my-journey-with-discord-bots-from-java-to-nodejs-part-0-the-setup-671243c768a6">Part 0 — The Setup</a></li><li><a href="https://blog.amr-gawish.com/my-journey-with-discord-bots-from-java-to-node-js-part-1-the-project-structure-4d368cc6fcff">Part 1 — The Project structure</a></li><li><a href="https://blog.amr-gawish.com/my-journey-with-discord-bots-from-java-to-node-js-part-2-developing-the-bot-57fe3f9ac89a">Part 2 — Developing the bot</a></li><li>Part 3 — Deploying the bot to Heroku (You are here)</li></ul><h3>The first rule about Discord bots</h3><blockquote>The first rule about Disrcord bot, we don’t talk about Discord bots!</blockquote><p>The truth about Chat bots, especially the Discord User Bots — not webhook bots — is that you don’t need to deploy them. You just need a computer that is connected to the internet and your bot listening to the socket connection, and you should be good to go.</p><p>But since we are in the cloud era, it makes sense to host your bot elsewhere and <a href="https://www.heroku.com/">Heroku</a> is a great place to host your Node.js application.</p><p>I first ran my bot on my private server, even when the internet connection was always there, I had a lot of trouble with web socket connection going down periodically, and connecting via VNC or SSH to my server and restarting it was troublesome, even with solutions like <a href="https://github.com/foreverjs/forever">Forever</a>, the connection were never stable, so I decided to go for Heroku and it was a great decision!</p><h3>Pros and Cons of deploying to Heroku</h3><p>There are multiple things you need to worry about when deploying to Heroku or any other cloud provider:</p><ol><li>Bots don’t have any UI Interface, so you have to check the log or have a monitoring dyno in order to track your application health.</li><li>Free dynos may not suitable for your bot, since your bot is going to be idle a lot of the times, and Heroku automatically put them into an idle state when they are not used — This is useful in a web interface, not so much for a bot! — which stops all socket connections!</li><li>Unless you have a robust Error Handling built in, Heroku won’t be able to tell you if things are not working!</li></ol><p>However there are a good news in here, some of them are:</p><ol><li>Heroku provides you with a public URL, which can be used for webhooks and integration with other messaging platforms like Facebook messanger, Line and others.</li><li>Heroku has a lot of integrations between different AI/ML engines that can make your bot a lot smarter.</li><li>You get Continuous Integration for Free, just push your code and everything is redeployed and updated!</li></ol><h3>Deploying to Heroku</h3><p>Everything is ready for Heroku, just hook it to my Github repository or use the <a href="https://devcenter.heroku.com/articles/getting-started-with-nodejs">Heroku CLI</a> and you should be good to go.</p><p>Heroku also uses <a href="https://www.npmjs.com/package/foreman">Foreman</a> to load your Environment variables and you can utilise that in your bot to save the API Keys and token in these environment variables — good if you open source your project — instead of your config file.</p><p>In my case I just needed to add a start script to my package.json— since my main entry point is not “server.js” — and I’m good to go!</p><p>So my <em>package.json</em> becomes something like this:</p><pre>{</pre><pre>&quot;name&quot;: &quot;trials-bot&quot;,</pre><pre>&quot;version&quot;: &quot;1.0.0&quot;,</pre><pre>&quot;description&quot;: &quot;Trials of Osiris Discrod Bot&quot;,</pre><pre>&quot;main&quot;: &quot;app.js&quot;,</pre><pre>&quot;scripts&quot;: {</pre><pre><strong>&quot;start&quot;: &quot;node app.js&quot;,</strong></pre><pre>&quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;</pre><pre>},</pre><pre>&quot;keywords&quot;: [],</pre><pre>...<br>}</pre><p>And we are done, now you have our bot hosted in Heroku and working with Discord.js!</p><h3>Taking your bot a step further</h3><p>Since you have a public URL for your bot, why not utilise it!</p><p>Just creating a static HTML page with a minimal bootstrap template to show case your bots commands and maybe a screenshot can be useful right!</p><p>And that is exactly what I did, I didn’t want to do anything fancy, just a static HTML page describing the bot and that is it.</p><p>First I added express as a dependency.</p><pre>npm install express --save</pre><p>I downloaded <a href="http://getbootstrap.com/">Bootstrap</a> template — I went for the cover theme — and put everything in “public” folder, so my structure became something like this:</p><pre>├───lib/<br>│    └───services/<br>│          └───bungie.service.js<br>│    └───commands/<br>│          └───command.js<br>│          └───command.registry.js<br>│          └───help.command.js<br>├───conf/<br>│    └───config.js<br>├───public/<br>│    └───js/*<br>│    └───css/*<br>│    └───img/*<br>│    └───index.html<br>├───app.js<br>├───package.jso</pre><p>I made sure my index.html looks nice offline, and I added the below code to my app.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/287c151e0a5b6f9fd9c1ac697af74a42/href">https://medium.com/media/287c151e0a5b6f9fd9c1ac697af74a42/href</a></iframe><p>And voila, now I can see my bot website in action, and the bot is secretly running in the background, here is how it looks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2PQS4whHeHi-qBu-1kc9zg.png" /><figcaption>You can try it out yourself from <a href="https://too-ketf-chatbot.herokuapp.com/">here</a>!</figcaption></figure><h3>Marketing your bot</h3><p>The bot is there, but you still need to tell the people what it is and how to use it through different commands.</p><p>The perfect place to market your Discord bot is by adding it to the <a href="https://bots.discord.pw/">unofficial Discord bot marketplace</a>.</p><p>This way users can search what it is, check the website, and even know the technology behind it. The portal makes it really easy for Server/Guild admins to search and add your bot to their channels, just make sure you add the important searchable keywords in your bot description.</p><h3><strong>Final words</strong></h3><p>Hope you liked this series of posts about the journey I went through from converting this bot from Java to Node.js, I’ll open source the project soon so check back later.</p><p>Overall I’m glad that I made the switch, Node.js community is very vibrant and it is a great match for such projects. All my bots are going to be developed with Node.js from now on!</p><p>If you have any questions, please don’t hesitate to ask in the comment section, and leave a ❤ if you liked this post.</p><p>Thanks, Amr.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23abc84d9bae" width="1" height="1" alt=""><hr><p><a href="https://blog.amr-gawish.com/my-journey-with-discord-bots-from-java-to-node-js-part-3-final-deploying-the-bot-to-heroku-23abc84d9bae">My journey with Discord bots from Java to Node.js — Part 3 (Final) Deploying the bot to Heroku</a> was originally published in <a href="https://blog.amr-gawish.com">kblog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My journey with Discord bots from Java to Node.js — Part 2 Developing the bot]]></title>
            <link>https://blog.amr-gawish.com/my-journey-with-discord-bots-from-java-to-node-js-part-2-developing-the-bot-57fe3f9ac89a?source=rss----c602104e17b6---4</link>
            <guid isPermaLink="false">https://medium.com/p/57fe3f9ac89a</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[discord]]></category>
            <dc:creator><![CDATA[Amr Gawish]]></dc:creator>
            <pubDate>Thu, 27 Apr 2017 14:10:04 GMT</pubDate>
            <atom:updated>2017-05-03T13:10:48.037Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YKkbE3b2JgMDHCMwj5oCwA.jpeg" /><figcaption>Courtesy of <a href="https://pixabay.com">https://pixabay.com</a></figcaption></figure><p>Continuing my journey from <a href="https://blog.amr-gawish.com/my-journey-with-discord-bots-from-java-to-node-js-part-1-the-project-structure-4d368cc6fcff">Part 1</a>, after having a not-so-bad project structure, I needed to make sure I’m being totally <a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a> and using the best practice of Node.JS!</p><h3>Table of Content</h3><ul><li><a href="https://blog.amr-gawish.com/my-journey-with-discord-bots-from-java-to-nodejs-part-0-the-setup-671243c768a6">Part 0 — The Setup</a></li><li><a href="https://blog.amr-gawish.com/my-journey-with-discord-bots-from-java-to-node-js-part-1-the-project-structure-4d368cc6fcff">Part 1 — The Project structure</a></li><li>Part 2 — Developing the bot (You are here)</li><li><a href="https://blog.amr-gawish.com/my-journey-with-discord-bots-from-java-to-node-js-part-3-final-deploying-the-bot-to-heroku-23abc84d9bae">Part 3 — Deploying the bot to Heroku</a></li></ul><h3>Defining the Service Layer</h3><p>In my previous article I decided to create a service layer, each service would consume a specific RESTful APIs source. I used 3 services: <a href="https://www.bungie.net/platform/destiny/help/">Bungie</a>, <a href="http://guardian.gg/">GuardianGG</a> and <a href="https://destinytrialsreport.com">DestinyTrialsReport</a>.</p><p>So I created 3 service files, since I’m using Node.JS version 6, I opted to use the best practice for ES6, which has definition for Classes and has a much cleaner syntax.</p><p>I also <a href="https://medium.com/javascript-scene/javascript-es6-var-let-or-const-ba58b8dcde75">avoided using var and opted to use let and const instead</a>, this made my life a little bit easier.</p><p>Here is how my Bungie Service looks</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fcde36916a708f13a336daef936044a/href">https://medium.com/media/3fcde36916a708f13a336daef936044a/href</a></iframe><p>As you can notice, I felt right at home with that new structure, since Classes is the main construct in Java and this structure looks very familiar.</p><h3>Organising different Bot commands</h3><p>In order to optimize the registry of different commands for my bot, I used a CommandRegistry to register different commands — I later discovered that it exist as part of core Discord.js library — so I can do something like the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f584c07c961bca1855fae5e0e1f45fb3/href">https://medium.com/media/f584c07c961bca1855fae5e0e1f45fb3/href</a></iframe><p>The registry is a simple regex — It can capture spaces within quotes as a single entity — and calls the callback method (second-argument) when the message issued a command. It also works on Mention only, so you need to mention the bot in Discord for this to trigger, which was my use case.</p><p>My CommandRegistry class was following the below structure:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee35f4e303e5b939285449429fb0e3fa/href">https://medium.com/media/ee35f4e303e5b939285449429fb0e3fa/href</a></iframe><p>I also had a list of commands since I can listen to the wildcard, but needed to make sure it’s not being called when another command is there.</p><p>Also I replaced the previous structure from Listeners to Commands and opted for the below structure:</p><pre>├───lib/<br>│    └───services/<br>│          └───bungie.service.js<br>│    └───commands/<br>│          └───command.js<br>│          └───command.registry.js<br>│          └───help.command.js<br>├───conf/<br>│    └───config.js<br>├───app.js<br>├───package.json</pre><p>So the last piece of work I needed to do is to create my commands, so for Instance the help.command.js looked like</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d506d8b6e1d9a30f5c13a3f8d5299522/href">https://medium.com/media/d506d8b6e1d9a30f5c13a3f8d5299522/href</a></iframe><p>Note that I used inheritance here, since I have multiple commands, and I wanted to reuse as much parts as I can.</p><h3>Conclusion</h3><p>I was pretty happy with the architecture and everything worked out pretty well for me, and I think it can be easily understood and navigated.</p><p>The only thing missing for me is to actually deploy the application and see its fruit in action.</p><p>In the next and final article I’m going to talk about that process.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57fe3f9ac89a" width="1" height="1" alt=""><hr><p><a href="https://blog.amr-gawish.com/my-journey-with-discord-bots-from-java-to-node-js-part-2-developing-the-bot-57fe3f9ac89a">My journey with Discord bots from Java to Node.js — Part 2 Developing the bot</a> was originally published in <a href="https://blog.amr-gawish.com">kblog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>