<?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[Stories by Mark Feng on Medium]]></title>
        <description><![CDATA[Stories by Mark Feng on Medium]]></description>
        <link>https://medium.com/@markselby9?source=rss-79f79d2d5991------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Mu6WSeBUffwhviLWv0r4LQ.jpeg</url>
            <title>Stories by Mark Feng on Medium</title>
            <link>https://medium.com/@markselby9?source=rss-79f79d2d5991------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 08 Apr 2026 08:27:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@markselby9/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[Think Again: the art of rethinking in both career and life]]></title>
            <link>https://markselby9.medium.com/think-again-the-art-of-rethinking-in-both-career-and-life-a7a78a660d76?source=rss-79f79d2d5991------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7a78a660d76</guid>
            <category><![CDATA[reading]]></category>
            <category><![CDATA[think-again]]></category>
            <category><![CDATA[book-recommendations]]></category>
            <category><![CDATA[book-review]]></category>
            <category><![CDATA[adam-grant]]></category>
            <dc:creator><![CDATA[Mark Feng]]></dc:creator>
            <pubDate>Mon, 08 Aug 2022 16:59:07 GMT</pubDate>
            <atom:updated>2022-08-08T16:59:07.576Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Think Again</em> is one of the books that talk about thoughts with abundant examples, and will keep me reminded to practice rethinking skills in both my career and life. I expect rethinking could eventually become part of my thinking strategies.</p><h3>Individual Rethinking: Updating Our Views</h3><p>Starts by talking about individual rethinking, The author listed four modes of thinking:</p><ul><li>Preacher: We’re convinced we’re right</li><li>Prosecutor: We’re trying to prove someone else wrong</li><li>Politician: We’re trying to win the approval of our audience</li><li>Scientist: You favor humility over pride and curiosity over conviction. You look for reasons why you might be wrong, not just reasons why you must be right.</li></ul><p>It looks obvious that the scientist thinking mode is the most “mature” way of thinking, but I can easily come up with cases that I’ve behaved as the other modes. It’s hard to maintain an open mind and research why we might be wrong instead of thinking about why we must be right. The author listed several stories about how rethinking has helped start-up revenues, or how intelligence became a curse for Blackberry’s failure in the competition with Apple.</p><p>“If knowledge is power, knowing what we don’t know is wisdom.”. I’m confident that I would stay in the rethinking cycle of Humility -&gt; Doubt -&gt; Curiosity -&gt; Discovery -&gt; Humility when learning new things, but it’s so easy to get into the overconfidence cycle when talking about some topics tech stack that (I believe) I’m fairly familiar with and know much more than average: Pride -&gt; Conviction -&gt; Confirmation &amp; Desirability Biases -&gt; Validation -&gt; Pride. Especially on the validation part, when I got lucky in several discussions or even debates, it’s easy to tend to become conceited or even condescending. The curse of knowledge is we could close our minds to what we don’t know, and stand on the “summit of mount stupid”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/0*MOrhf4taB-KEUkj6.png" /></figure><p>The ideal position to be both high in confidence and humility, or the “Confident Humility Zone”, which I believe I’m still seeking. To possess faith in my strengths while being aware of my weaknesses, I need to get an accurate picture of my knowledge and skills in the scientist mode. Although the author mentioned he somehow believes “we’re sometimes better off underestimating ourselves”, which I also agree with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V_FPtW64pi-V2jEJ.png" /></figure><h3>Interpersonal Rethinking: Opening Other People’s Minds</h3><p>I’m not that passionate about winning debates and influencing other people, but it’s possible that when I think things are personal I lose passion/temper/whatever and ended up in at least one person in the debate becoming unhappy and nothing working out. One way to improve is by listening and finding common ground.</p><p>The book listed the debate between <a href="https://www.youtube.com/watch?v=-d4Uj9ViP9o">Harish and Debra debating</a>, where the audience’s mind shifted several times when the debaters convinced people to rethink. The key points from Harish are: drawing attention to common ground and avoiding defend-attack spirals. Also, don’t step on people’s toes by throwing more reasons as preaching or prosecuting, as that would shut people’s minds as audience shielding against persuasions, and maybe even backfire. Instead, pose more questions, and open audiences’ minds that they might be wrong.</p><p>One thing to notice is “less is more”, when we put on several reasons on the table, the weakest one would be the easiest loophole to let people dismiss the entire case. “A weak argument generally dilutes a strong one”. This also applies when we’re writing a list of reasons for performance reviews :P</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*N7VQi16jBtnY02rA.png" /></figure><h3>Collective Rethinking: Creating Communities of Lifelong Learners</h3><p>It’s a basic human tendency to seek binary bias by simplifying a complex continuum into two categories, like good or bad, gun control or gun freedom, abortion or anti-abortion, Democrats or Republicans, Zero Covid or Living with Covid, or “those who divide the world into two kinds of people, and those who don’t”. It’s important to <strong>resist the impulse to simplify things</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qumZsvcXd6c449vz.png" /></figure><p>The author also talked about the so-called life plans, by not setting boundaries by making plans. We should be mindful of the “tunnel vision” of plans that prevent us from seeing better possibilities.</p><p>Collective rethinking is also about changing organizational cultures, for example, a team that is agile in changing its mind collectively based on rethinking, although I wouldn’t want this agility to go too far either. One interesting point is “avoid best practice”, as best practice assumes the team has arrived at an optimal solution. I understand this belief will prevent effective rethinking, but since I’m a fan of “best practice” myself and believe it has more benefits, I would prefer stating this as “update best practice frequently”.</p><p>It’s also very normal for the plan to not work out, we should keep an open mind and spend time rethink about the plan on the way. To question your plan instead of executing it at any cost is the essence of rethinking, and this is something I’m also not very aware of. We always heard about determination but rarely about the direction that would lead to undesirable results.</p><p><em>Originally published at </em><a href="https://www.usegitflow.com/posts/think-again/"><em>https://www.usegitflow.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7a78a660d76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What I learned from <How to Avoid a Climate Disaster>]]></title>
            <link>https://markselby9.medium.com/what-i-learned-from-how-to-avoid-a-climate-disaster-a60471e47f46?source=rss-79f79d2d5991------2</link>
            <guid isPermaLink="false">https://medium.com/p/a60471e47f46</guid>
            <category><![CDATA[book-review]]></category>
            <category><![CDATA[climate-change]]></category>
            <dc:creator><![CDATA[Mark Feng]]></dc:creator>
            <pubDate>Thu, 06 May 2021 12:06:51 GMT</pubDate>
            <atom:updated>2021-05-06T12:06:51.824Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6e-smJ7czcz1m1j3.jpg" /></figure><p>Bill Gates explains his thoughts about a potential future crisis, clearly and thoroughly in the book &lt;How to Avoid a Climate Disaster: The Solutions We Have and the Breakthroughs We Need&gt;</p><h3>The importance of “getting to zero”</h3><p>We’ve heard the word “zero greenhouse gas commission” many times in the news or magazines because greenhouse gases absorb heat, trap it in the atmosphere, and cause global warming and rising temperature. We already know that if we don’t reduce emissions, the temperature would still grow between 4 to 8 degrees Celsius in this century. But apart from the direct effect of days becoming hotter and sea levels go up (which is already horrible), there are some efforts that I didn’t think about before reading this book.</p><p>The first trouble from a hotter climate is more extreme natural disasters like hurricanes and floods that destroy infrastructures and cause disasters. Hotter weather means droughts in the river or soil lands and more frequent and destructive wildfires in California and Australia in the year 2020. Rising sea levels because of melting polar ice and expanding seawater size as it’s warmer is that some cities are shrinking because of higher coastlines. <a href="https://www.nccs.gov.sg/faqs/impact-of-climate-change-and-adaptation-measures/">Singapore is taking some steps</a> to prepare itself for future issues caused by climate change.</p><p>When the weather is getting hotter, animals and plants would be affected. Some would suffer when some thrive, affecting essential businesses like farming significantly. With seawater getting warmer, even only 2 degrees, some seafood would be wiped out.</p><p>And these effects are not working individually but on top of the others. According to Bill, climate change can be just as deadly as COVID-19 by mid-century and five times as fatal by 2100. Economic damage caused by climate change would be equally enormous.</p><p>To answer the question “why should we (as a country) deal with this issue?” the most persuasive answer is that countries that build great zero-carbon industries will be leading the global economy in the coming decades. Big energy breakthroughs would be significant and welcomed by the world.</p><h3>Significant topics to consider about Climate Change</h3><p>According to the data in the book, greenhouse gas is emitted by these five categories as a proportion of:</p><ol><li>Making things (cement, steel, plastic): 31%</li><li>Electricity: 27%</li><li>Growing plants and animals: 19%</li><li>Traffic (planes, trucks, ships): 16%</li><li>Keeping warm and cool (heating, cooling, refrigeration): 7%</li></ol><p>Although electricity only accounts for just a quarter here, I think clean energy is the most important topic and can help with the other categories, like how electric cars help reduce carbon emissions. In the book, Bill talked about how to help with “zero greenhouse gas commission” for each category in different chapters.</p><p><strong>Electricity</strong> One interesting new name I learned is “power density,” about how much power we can get from a square meter’s land. It turns out we can generate fossil fuels 500–10000 Watts per square meter, and for Nuclear, the number is 500–1000, when for Solar, it is 5–20, and for Wind, we can only generate 1–2 Watts per square meter. The author uses the word <a href="https://www.gatesnotes.com/Energy/Introducing-the-Green-Premiums">“Green Premium”</a> to describe the extra cost we would need for switching to a zero-carbon option, and we need to find a new energy source that we can widely deploy with low or no Green Premium.</p><p>Today, natural gas and coal make up two-thirds of our electricity source because fossil fuels are cheap-fun fact: oil is more affordable than a soft drink. Bill discussed several other options that are possible to replace fossil fuels. Apart from the too much land needed problem, the sun and the wind are intermittent sources affected by weather, storing excessive electricity in batteries is super expensive, and hard to reduce the cost. If we want to use renewables for electricity sources, much faster innovations and more breakthroughs are needed about deploying renewables and improving transmission. According to <a href="https://www.nytimes.com/2021/02/15/books/review/bill-gates-how-to-avoid-a-climate-disaster.html">this NYTimes review</a>, the progress about batteries, solar, and wind energy is more optimistic than Bill thinks.</p><p>Other options include nuclear power (fission and fusion), the only carbon-free and reliable energy source. France is already getting 70 percent of electricity from nuclear, while the US around 20 percent. The significant shortage is that it’s costly to build, and human error caused several nuclear accidents or disasters in history. In the book, Bill compared Nuclear power with Coal and Oil and said deaths caused per unit of Nuclear electricity are far less, and safety concerns shouldn’t block people from using it. Of course, the world needs to improve on Nuclear safety.</p><p><strong>Materials</strong> Cement, concrete, and steel are the materials being used worldwide at a faster speed, and they generate much more greenhouse gases than plastics when plastics have the worst reputation for climate change recently. We manufacture enormous materials, resulting in copious amounts of greenhouse gases, nearly a third of the 51 billion tons per year. We need to get those emissions down to zero, but it’s not an option to stop making things. Instead, Bill discussed several ways to drive the premiums down when adopting the zero-emissions approach.</p><p><strong>Farming</strong> As people get richer, they eat more calories, particularly more meat and dairy. The more meat we consume, the more plants we need to grow, as six calories of feed for every calorie of beef. When we need to produce more food, we need to reduce the emissions during producing the foods when farmlands are already being infected from climate change. Artificial plant-based meat is a popular alternative for real meat, and the author highly recommends this approach (as an investor in plant-based meat companies).</p><p>Planting trees has been viewed as a popular forest-related solution for climate change, as trees capture carbon dioxide from the atmosphere. However, it’s not as simple as I consider it before. A tree absorbs carbon dioxide in rather a low efficiency, and if the tree dies, it will release all the carbon dioxide it stored back into the atmosphere. If we eliminate a farm for a forest, that may lead to somewhere else trees being cut down, and the benefits are offset. The most effective tree strategy for climate change is to <strong>stop cutting down</strong> trees we already have.</p><p><strong>Traffic</strong> 8.2 billion tons of carbon is being produced from transportation today. During Covid-19, travel and trade have been limited, but even this reduction is not enough for the zero-emission target by 2050. And stop people from moving is also not a valid option. Passager vehicles are the source of half transportation-related emissions. Electric vehicles are already trendy, and the Green Premium of EV is coming down. But the main concern is that if the electricity is not coming from a clean resource, we’re not reducing the emissions, as it’s equal to moving gasoline around.</p><p>In the last three chapters, the author suggested the specific steps we can do, from government policies and world leaders to companies and investors to every individual of us.</p><h3>COVID-19 and Climate Change</h3><p><a href="https://www.geekwire.com/2020/bill-gates-warned-us-covid-19-like-pandemic-watch-ted-talk-2015/">Bill Gates warned us of a COVID-19-like pandemic — watch his TED Talk from 2015</a>. Now he wrote this book to warn people about climate change. Still, he’s being optimistic, pragmatic and thinks the world can avoid a disaster, as countries are making real progress. The world becomes more committed after Covid to solve a global problem. In the next decade, Bill thinks that the world should focus on the technologies, policies, and market structures that will put us on the path to eliminating greenhouse gases by 2050.</p><p><a href="https://www.theguardian.com/books/2021/feb/17/how-to-avoid-a-climate-disaster-by-bill-gates-review-why-science-isnt-enough">Book review by the Guardian: How to Avoid a Climate Disaster by Bill Gates review — why science isn’t enough</a></p><p><em>Originally published at </em><a href="https://www.usegitflow.com/posts/climate-change/"><em>https://www.usegitflow.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a60471e47f46" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Japanese learning path from Zero to JLPT N3, in seven months]]></title>
            <link>https://markselby9.medium.com/my-japanese-learning-path-from-zero-to-jlpt-n3-in-seven-months-c61e5df0934c?source=rss-79f79d2d5991------2</link>
            <guid isPermaLink="false">https://medium.com/p/c61e5df0934c</guid>
            <category><![CDATA[language-learning]]></category>
            <category><![CDATA[jlpt]]></category>
            <category><![CDATA[japanese-culture]]></category>
            <category><![CDATA[japanese]]></category>
            <dc:creator><![CDATA[Mark Feng]]></dc:creator>
            <pubDate>Wed, 27 Jan 2021 10:38:46 GMT</pubDate>
            <atom:updated>2021-01-27T12:21:53.414Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m writing to share my Japanese learning path last year, from Zero to JLPT N3, in seven months. It’s achievable and practical.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/0*bPeJVyssS7YrG73l.jpeg" /><figcaption>My friends during the journey</figcaption></figure><h3>My experience</h3><p>2020 has been, no wonder, a strange and challenging year almost for most people. We are isolated from the world where nearly no good news is going on, working from home and away from the office, colleagues, and friends since March, getting used to facing people under masks.</p><p>Being bored of the daily routine of WFH, I found out that there have been more chunks of spare time to spend, and because of my long-lasting curiosity towards Japan and Japanese, in May, I decide to try learning Japanese and see how far I could go. The target I made for myself is passing the 2020.12 JLPT N3 exams (the July exam happened to be canceled).</p><p>My motivation to learn Japanese is relatively straightforward:</p><ul><li>It’s an influential language in the world, especially in Asia and Singapore.</li><li>Learning a new language is always pretty cool, and it can equip me with a new angle on the world.</li><li>It’s close to Chinese. Two languages are similar concerning lexical similarity, and I can save some effort reading Kanji (but not reading). Japanese culture is influential to almost everyone around me. I watched several Japanese dramas and movies, including several times of Legal High.</li><li>If I have time, effort, and interest, why not?</li></ul><p>After seven months of learning, I took <strong>the JLPT N3 test </strong>in December 2020 at the Japanese Cultural Society of Singapore. Seven months of part-time study is not sufficient to master the language, and I met some difficulties during the text. Luckily the result turned out well. I got an A in both Vocabulary and Grammar, and a 60/60 for reading.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/0*pzDRJtGu_QbKGAMJ.jpeg" /><figcaption>My test results</figcaption></figure><h3>Learning path</h3><p>I want to introduce my <strong>reference books, textbooks, exam books</strong>, and how I used them. I hope it can help somebody to start their journey of learning Japanese.</p><p>For reference books, I only bought three books, and these are more than enough for me.</p><ul><li><a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwiXkuDP6rvuAhUl7XMBHRr-BvMQFjACegQIAhAC&amp;url=http%3A%2F%2Fwww.randomhousebooks.com%2Fbooks%2F40690%2F&amp;usg=AOvVaw1NTcJrUicI0qCnXo-psjae"><strong>Random House Japanese-English Dictionary</strong></a></li><li><a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwj2puni6rvuAhX0juYKHbyvDPQQFjABegQIAxAC&amp;url=https%3A%2F%2Fwww.tofugu.com%2Freviews%2Fdictionary-of-basic-japanese-grammar%2F&amp;usg=AOvVaw3zo13CK21k8mJxPR7e8LS6"><strong>A Dictionary of Japanese Grammar</strong></a>, buy the Basic and Intermediate if you’re aiming N3. It may seem a bit pricey, but worth every penny.</li></ul><p>The only textbooks I used is the complete set of <strong>『みんなの日本語初級』</strong> including Textbook and several workbooks, as <a href="https://omgjapan.com/products/minna-no-nihongo-shokyu-1-bundle">this link</a> shows. As I’m studying part-time, I spent around 1–2 hours learning these textbooks every day.</p><p>My steps of using 『みんなの日本語初級』 are:</p><ol><li>Read the words following recordings.</li><li>Memorize the words through <a href="https://ankiweb.net/about"><strong>Anki</strong></a> iOS and Mac apps. It is an excellent app for memorizing Japanese words. I strongly recommend using it. We can easily find the vocabulary set of みんなの日本語 in shared decks.</li><li>Listen to the main text and <strong>shadow</strong> it. By shadow, I mean doing dictation as much as possible. I used my iPad Pro Notability app to write the texts down after repeating them several times. Of course, there would be words I don’t understand and Kanji I can’t remember. It’s totally fine.</li><li>Compare with the main text and correct my dictation.</li><li>Reread the text following the audio for pronunciation.</li><li>Read the grammar part. There are plenty of great Youtube videos explaining grammars in みんなの日本語. I attached my link in the next section.</li><li>Look up the grammar I don’t understand in ‘A dictionary of Basic Japanese Grammar’ or search it online.</li><li>Finish all the exercises and workbooks. And then I’ll give myself some rewards after the hard work. No more practices are required as the workbooks contain reviewing sections already.</li></ol><p>I think after finishing 『みんなの日本語初級』textbook, you can just pass JLPT N4 exams easily without anything else. However, I need to fill in the gap as I signed up for the N3 exams.</p><p>After I finish 『みんなの日本語初級』textbook, it’s already October, two months before my JLPT N3 exam. In these two months, I’m focusing on only one set of books, <a href="https://omgjapan.com/products/nihongo-so-matome-jlpt-n3-bundle"><strong>Nihongo So-Matome JLPT N3 Complete Set</strong></a>. By finishing one section within five books every day, the timeline just matches well, and the book helped a lot for me to fill in the gap between 『みんなの日本語初級』 and JLPT N3. Vocabulary, Grammar, and Listening are the most critical parts, in my opinion, as test preparation somehow requires specific techniques and experience. I definitely didn’t memorize everything down, but I think by completing <a href="https://omgjapan.com/products/nihongo-so-matome-jlpt-n3-bundle">Nihongo So-Matome JLPT N3 Complete Set</a>, it’s enough for me to pass the N3 exams. Things turned out well.</p><h3>Some useful online resources</h3><ol><li><a href="https://www.tofugu.com/learn-japanese/">Learn Japanese: A Ridiculously Detailed Guide — Tofugu</a></li><li><a href="https://www.youtube.com/watch?v=U8wniu_c_zc">出口日語 【改訂版】大家的日本語文法解說</a> for grammar explanation</li><li><a href="https://www.udemy.com/course/japanese-n3-course/">Online Japanese N3 Course(All 10 lessons)</a> I think the series by Attain Corp. on Udemy are all well-made. You can buy all courses if you prefer learning through videos. It would take no less effort for sure. I think it can be suitable supplemental materials for 『みんなの日本語初級』</li><li><strong>Siri</strong> :) I changed my Siri language settings to Japanese and talk to it sometimes. It’s quite helpful to practice my Japanese communication, especially during the lockdown period.</li></ol><p>Hope this post can help some friends as a reference to reach the N3 level. I’m continuing my self-learning journey this year, hope I can share some N3 -&gt; N2 experience some time :)</p><p><em>Originally published at </em><a href="https://www.usegitflow.com/posts/japanese-n3/"><em>https://www.usegitflow.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c61e5df0934c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Some pragmatic notes for programmers]]></title>
            <link>https://markselby9.medium.com/some-pragmatic-notes-for-programmers-c8c861e0898e?source=rss-79f79d2d5991------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8c861e0898e</guid>
            <category><![CDATA[book-highlights]]></category>
            <category><![CDATA[programmer]]></category>
            <category><![CDATA[programmers-life]]></category>
            <dc:creator><![CDATA[Mark Feng]]></dc:creator>
            <pubDate>Tue, 28 Jan 2020 14:14:36 GMT</pubDate>
            <atom:updated>2020-01-28T14:14:36.583Z</atom:updated>
            <content:encoded><![CDATA[<p>Keep a record of some highlights from the book <a href="https://www.amazon.com/gp/product/0135957052">“The Pragmatic Programmer: your journey to mastery, 20th Anniversary Edition, 2nd Edition”</a> which might be useful to me, or your Software Engineer career path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/0*ym0qdrB6xaYzLmp_.jpg" /></figure><h3>What makes a pragmatic programmer?</h3><ol><li>Over the long term, your time investment will be repaid as you and your team become more efficient, write code that’s easier to maintain, and spend less time in meetings.</li><li>You rarely take things as given without first getting the facts. When colleagues say “because that’s the way it’s done,” or a vendor promises the solution to all your problems, you smell a challenge.</li><li><strong>We who cut mere stones must always be envisioning cathedrals.</strong></li><li>Every day, work to refine the skills you have and to add new tools to your repertoire.</li></ol><h3>1. A Pragmatic Philosophy &amp;&amp; Software Entropy</h3><ol><li>When you find yourself saying, “I don’t know,” be sure to follow it up with “-but I’ll find out.” It’s a great way to admit what you don’t know, but then take responsibility like a pro.</li><li>Before you approach anyone to tell them why something can’t be done, is late, or is broken, stop and listen to yourself. Talk to the rubber duck on your monitor, or the cat.</li><li><strong>Don’t leave “broken windows’’ (bad designs, wrong decisions, or poor code) unrepaired. Fix each one as soon as it is discovered. If there is insufficient time to fix it properly, then board it up.</strong></li><li>It’s time to bring out the stones. Work out what you can reasonably ask for. Develop it well. Once you’ve got it, show people, and let them marvel. Then say “of course, it would be better if we added…’’ Pretend it’s not important. Sit back and wait for them to start asking you to add the functionality you originally wanted. People find it easier to join an ongoing success. Show them a glimpse of the future and you’ll get them to rally around.</li><li>If you give your users something to play with early, their feedback will often lead you to a better eventual solution.</li><li>Talking to other people will help build your personal network, and you may surprise yourself by finding solutions to other, unrelated problems along the way. And that old portfolio just keeps getting bigger.</li><li><strong>The more different things you know, the more valuable you are.</strong></li><li>Know what you want to say. Know your audience. Choose your moment. Choose a style. Make it look good. Involve your audience. Be a listener. Get back to people. Keep code and documentation together.</li><li><strong>if you don’t listen to them, they won’t listen to you.</strong></li><li>Treat English (or whatever your native tongue may be) as just another programming language. Write natural language as you would write code: honor the DRY principle, ETC, automation, and so on.</li><li>A good idea is an orphan without effective communication.</li></ol><h3>2. A Pragmatic Approach</h3><ol><li>In the modern world, it’s critical to test ideas and get feedback before you commit to them whole-heartedly.</li><li>We feel that the only way to develop software reliably, and to make our developments easier to understand and maintain, is to follow what we call the DRY principle: <strong>Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.</strong></li><li>Don’t rely on the properties of things you can’t control.</li><li>Requirements, users, and hardware change faster than we can get the software developed.</li><li>The distinction is important enough to warrant repeating. Prototyping generates disposable code. Tracer code is lean but complete, and forms part of the skeleton of the final system. Think of prototyping as the reconnaissance and intelligence gathering that takes place before a single tracer bullet is fired.</li><li>Our suggestion is fairly simple: don’t spend more effort than you save. Writing a domain language adds some cost to your project, and you’ll need to be convinced that there are offsetting savings (potentially in the long term).</li><li>Use paper, not a file or a wiki: there’s something special about the act of writing compared to typing. Give it a month, and see if you’re getting any benefits.</li></ol><h3>3. Pragmatic Paranoia</h3><ol><li>But Pragmatic Programmers take this a step further. They don’t trust themselves, either. Knowing that no one writes perfect code, including themselves, Pragmatic Programmers build in defenses against their own mistakes.</li><li>The finish what you start tip tells us that, ideally, the routine that allocates a resource should also free it.</li><li>Much of the time, tomorrow looks a lot like today. But don’t count on it.</li><li>Let’s look at four strategies that help: Finite State Machines, The Observer Pattern, Publish/Subscribe, Reactive Programming and Streams</li><li>Let us suggest three techniques that mean you should never need to use inheritance again: Interfaces and protocols, Delegation, Mixins and traits</li><li>We still want configuration data kept external to the application, but rather than in a flat file or database, we’d like to see it stored behind a service API.</li></ol><p><em>Originally published at </em><a href="https://www.usegitflow.com/posts/some-pragmatic-notes/"><em>https://www.usegitflow.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8c861e0898e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Some LeetCode Contest in Rust ️]]></title>
            <link>https://markselby9.medium.com/some-leetcode-contest-in-rust-%EF%B8%8F-bbdb8f59e0e4?source=rss-79f79d2d5991------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbdb8f59e0e4</guid>
            <category><![CDATA[rustlang]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Mark Feng]]></dc:creator>
            <pubDate>Sun, 27 Oct 2019 07:50:17 GMT</pubDate>
            <atom:updated>2019-11-06T10:28:45.300Z</atom:updated>
            <content:encoded><![CDATA[<h3>Some LeetCode Contest solution, in Rust 🦀️</h3><p>As I’m learning Rust language recently, LeetCode becomes a good place to write some small programs and to get familiar with Rust grammar and syntax. In the recent contests, I tried using Rust to solve some problems however it took a much longer time than I expected, to deal with the strict compiler. Pretty fun though, and I think it did help me getting hands dirty.</p><p>However, personally I won’t suggest using Rust in LeetCode contests or in real interviews as Python/Ruby would be a much better choice. Rust could be useful in some other aspects which I’ll check later. (safety, speed, and concurrency? + WebAssembly) 🦀️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*sHAPf_FezdWW5y_loeRjeA.png" /><figcaption>Let’s do some LeetCode in Rust!</figcaption></figure><h3><a href="https://leetcode.com/contest/weekly-contest-159/problems/replace-the-substring-for-balanced-string/">1234. Replace the Substring for Balanced String</a></h3><p>Keyword: <strong>Sliding window</strong></p><p>Use a counter to keep track of the appearances <strong>outside</strong> of the sliding window, and try to narrow the window as small as possible.</p><p>Rust solution:</p><pre>use std::cmp;<br>use std::collections::HashMap;<br><br>struct Solution {}<br><br>impl Solution {<br>    pub fn balanced_string(s: String) -&gt; i32 {<br>        let mut counter: HashMap&lt;char, i32&gt; = HashMap::new();<br>        for c in [&#39;Q&#39;, &#39;W&#39;, &#39;E&#39;, &#39;R&#39;].iter() {<br>            counter.insert(*c, 0);<br>        }<br>        for c in s.chars() {<br>            let new_count = match counter.get(&amp;c) {<br>                Some(&amp;val) =&gt; val + 1,<br>                None =&gt; 1,<br>            };<br>            counter.insert(c, new_count);<br>        }<br>        let length = s.len() as i32;<br>        let mut result = length;<br>        let expected = length / 4;<br><br>        let (mut j, mut i) = (0_i32, 0_i32);<br>        while j &lt; length {<br>            let char_j = s.chars().nth(j as usize).unwrap();<br>            counter.insert(char_j, counter.get(&amp;char_j).unwrap() - 1);<br><br>            // sliding window<br>            while i &lt; length<br>                &amp;&amp; counter[&amp;&#39;Q&#39;] &lt;= expected<br>                &amp;&amp; counter[&amp;&#39;W&#39;] &lt;= expected<br>                &amp;&amp; counter[&amp;&#39;E&#39;] &lt;= expected<br>                &amp;&amp; counter[&amp;&#39;R&#39;] &lt;= expected<br>                {<br>                    result = cmp::min(result, j - i + 1);<br><br>                    let char_i = s.chars().nth(i as usize).unwrap();<br>                    counter.insert(char_i, counter.get(&amp;char_i).unwrap() + 1);<br>                    i += 1;<br>                }<br>            j += 1;<br>        }<br><br>        result<br>    }<br>}<br><br>#[cfg(test)]<br>mod tests {<br>    use super::*;<br><br>    #[test]<br>    fn test() {<br>        let s = &quot;QWER&quot;.to_string();<br>        assert_eq!(Solution::balanced_string(s), 0);<br><br>        let s = &quot;QQWE&quot;.to_string();<br>        assert_eq!(Solution::balanced_string(s), 1);<br>    }<br>}</pre><p>Some places in the code may be not necessary:</p><ol><li>Update a counter’s value for a character, I’m using: let char_j = s.chars().nth(j as usize).unwrap(); counter.insert(char_j, counter.get(&amp;char_j).unwrap() - 1); which is actually the same as counter[c] += 1 in Python. It seems too long in Rust.</li><li>For the place while i &lt; length &amp;&amp; counter[&amp;&#39;Q&#39;] &lt;= expected &amp;&amp; counter[&amp;&#39;W&#39;] &lt;= expected &amp;&amp; counter[&amp;&#39;E&#39;] &lt;= expected &amp;&amp; counter[&amp;&#39;R&#39;] &lt;= expected, it would be all([counter[x] &lt;= expected for x in &#39;QWER&#39;]) in Python 😅</li></ol><h3><a href="https://leetcode.com/contest/weekly-contest-159/problems/maximum-profit-in-job-scheduling/">1235. Maximum Profit in Job Scheduling</a></h3><p>Keyword: <strong>DP</strong></p><p>Use [(ending <em>time, max</em>profit)] to keep track of possible best profit for each end time. For new job, use <strong>binary search</strong> to find the possible previous ending time for last job, and calculate whether the profit would be better than the current best(last element in DP record), if so append it to the end of DP record vector.</p><pre>struct Solution{}<br><br>impl Solution {<br>    pub fn job_scheduling(start_time: Vec&lt;i32&gt;, end_time: Vec&lt;i32&gt;, profit: Vec&lt;i32&gt;) -&gt; i32 {<br>        let mut jobs = Vec::new();<br>        let length = start_time.len();<br>        for i in 0..length {<br>            jobs.push((start_time[i], end_time[i], profit[i]))<br>        }<br>        jobs.sort_by_key(|t1| t1.1);<br>        println!(&quot;{:?}&quot;, jobs);<br><br>        let mut record = vec![(0, 0)];  // (ending, max_profit)<br>        for (s, e, p) in jobs {<br>            let last_job_index = match record.binary_search_by_key(&amp;s, |&amp;t| t.0) {<br>                Ok(i) =&gt; i,<br>                Err(i) =&gt; i-1,<br>            };<br>            println!(&quot;{}, {:?}, {}&quot;, s, record, last_job_index);<br>            if record[last_job_index].1 + p &gt; record.last().unwrap().1 {<br>                record.push((e, record[last_job_index].1 + p))<br>            }<br>        }<br>        record.last().unwrap().1<br>    }<br>}<br><br>#[cfg(test)]<br>mod tests {<br>    use super::*;<br><br>    #[test]<br>    fn test1 () {<br>        let starts = vec![1,2,3,4,6];<br>        let ends = vec![3,5,10,6,9];<br>        let profit = vec![20,20,100,70,60];<br><br>        assert_eq!(Solution::job_scheduling(starts, ends, profit), 150);<br>    }<br>}</pre><h3><a href="https://leetcode.com/contest/weekly-contest-158/problems/dice-roll-simulation/">1223. Dice Roll Simulation</a></h3><p>Keyword: <strong>Cache</strong></p><p>To make it not TLE we use a cache to reduce time cost. However in Rust it happened to be the very first HashMap I used and cost me some time to deal with compiler…finally made it pass with this code below. The &lt;&#39;a&gt; is explicit lifetime which could be implicit.</p><pre>use std::collections::HashMap;<br><br>// struct Solution {}<br><br>type Cache&lt;&#39;a&gt; = HashMap&lt;String, i32&gt;;<br><br>impl Solution {<br>    pub fn die_simulator(n: i32, roll_max: Vec&lt;i32&gt;) -&gt; i32 {<br>        let mut cache: Cache = HashMap::new();<br><br>        fn helper&lt;&#39;a&gt;(<br>            k: i32,<br>            number: i32,<br>            n: i32,<br>            roll_max: &amp;Vec&lt;i32&gt;,<br>            cache: &amp;mut Cache&lt;&#39;a&gt;,<br>        ) -&gt; i32 {<br>            if n == 0 {<br>                return 1;<br>            }<br>            let key_string = format!(&quot;{} {} {}&quot;, k, number, n);<br>            let ref key = key_string.to_string();<br>            match cache.get::&lt;str&gt;(&amp;key) {<br>                Some(&amp;number) =&gt; return number,<br>                _ =&gt; {}<br>            }<br>            let mut temp: i64 = 0;<br>            for i in 0..6 {<br>                if number != i {<br>                    temp += helper(1, i, n - 1, roll_max, cache) as i64;<br>                } else if k &lt; roll_max[i as usize] {<br>                    temp += helper(k + 1, i, n - 1, roll_max, cache) as i64;<br>                }<br>            }<br>            let result = (temp % (10_i64.pow(9) + 7)) as i32;<br>            cache.insert(key_string, result);<br>            // println!(&quot;temp: {}, result: {}&quot;, temp % (9_i64.pow(10) + 7), result);<br>            result<br>        }<br><br>        helper(0, 0, n, &amp;roll_max, &amp;mut cache)<br>    }<br>}</pre><h3><a href="https://leetcode.com/contest/weekly-contest-160/problems/tiling-a-rectangle-with-the-fewest-squares/">1240. Tiling a Rectangle with the Fewest Squares</a></h3><p>Keyword: <strong>DP</strong></p><p>It’s an interesting DP problem, as it only cares about 1&lt;=n,m&lt;=13 cases. For larger ranges it would become very complicated, please check this <a href="http://int-e.eu/~bf3/squares/">link</a> for more info.</p><p>Solution in Rust:</p><pre>use std::cmp::min;<br><br>struct Solution {}<br><br>impl Solution {<br>    pub fn tiling_rectangle(n: i32, m: i32) -&gt; i32 {<br>        let mut record = vec![vec![0; n as usize + 1]; m as usize + 1];<br>        record[0][0] = 1;<br><br>        //special case<br>        if (n == 11 &amp;&amp; m == 13) || (n == 13 &amp;&amp; m == 11) {<br>            return 6;<br>        }<br><br>        for i in 0..m as usize + 1 {<br>            for j in 0..n as usize + 1 {<br>                if i == 0 || j == 0 {<br>                    record[i][j] = 0;<br>                    continue;<br>                }<br>                if i == j {<br>                    record[i][j] = 1;<br>                    continue;<br>                }<br>                let mut temp = 13*13;<br>                for k in 1..=min(i, j) {<br>                    temp = min(temp,<br>                               min(1 + record[i-k][j] + record[k][j-k], 1 + record[i][j-k] + record[i-k][k])<br>                    );<br>                }<br>                record[i][j] = temp;<br>            }<br>        }<br>//        println!(&quot;{:?}&quot;, record);<br>        *record.last().unwrap().last().unwrap()<br>    }<br>}<br><br>#[cfg(test)]<br>mod tests {<br>    use super::*;<br><br>    #[test]<br>    fn test() {<br>        assert_eq!(Solution::tiling_rectangle(2, 3), 3);<br>        assert_eq!(Solution::tiling_rectangle(5, 8), 5);<br>        assert_eq!(Solution::tiling_rectangle(11, 13), 6);<br>    }<br>}</pre><p><em>Originally published at </em><a href="https://www.usegitflow.com/posts/leetcode-contest-rust/"><em>https://www.usegitflow.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbdb8f59e0e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Insomnia for GraphQL requests]]></title>
            <link>https://markselby9.medium.com/how-to-insomnia-for-graphql-requests-b270e16876a1?source=rss-79f79d2d5991------2</link>
            <guid isPermaLink="false">https://medium.com/p/b270e16876a1</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[insomnia]]></category>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[Mark Feng]]></dc:creator>
            <pubDate>Sat, 17 Aug 2019 10:25:57 GMT</pubDate>
            <atom:updated>2019-08-17T10:43:17.638Z</atom:updated>
            <content:encoded><![CDATA[<h4>Complete video tutorial is online! Please check the playlist <a href="https://www.youtube.com/playlist?list=PL13mreFCu1Josp4PCNb1WlOiaRY6p73D1">here</a>. Total time would be in 8 minutes.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_-hS9cTvZifKodeThLnLNw.jpeg" /></figure><ol><li>Explore Github GraphQL API: <a href="https://youtu.be/fX7mxRCDgJI">https://youtu.be/fX7mxRCDgJI</a></li><li>Download Insomnia client: <a href="https://youtu.be/Y2a68Zacv84">https://youtu.be/Y2a68Zacv84</a></li><li>Authenticate request: <a href="https://www.youtube.com/watch?v=QZCw5dcu5Yg">https://www.youtube.com/watch?v=QZCw5dcu5Yg</a></li><li>Useful features for editing: <a href="https://www.youtube.com/watch?v=FkbTV_Q1a9Q">https://www.youtube.com/watch?v=FkbTV_Q1a9Q</a></li><li>How to share my workspace?: <a href="https://www.youtube.com/watch?v=86KkpFAYOkA">https://www.youtube.com/watch?v=86KkpFAYOkA</a></li></ol><h3>Use cases when we work with a GraphQL endpoint</h3><ul><li>Send my first request to a new GraphQL endpoint</li><li>Introspection query to fetch the schema</li><li>Manage environment-related variables like the authentication token</li><li>Manage a bunch of queries</li><li>Save/Share requests with others</li></ul><h3>How to use Insomnia to manage my requests?</h3><p>Please check the <a href="https://www.youtube.com/playlist?list=PL13mreFCu1Josp4PCNb1WlOiaRY6p73D1">complete youtube videos</a> for a demo!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x2rl5QGLyD9cpb6GNG3LnQ.png" /><figcaption><a href="https://www.youtube.com/playlist?list=PL13mreFCu1Josp4PCNb1WlOiaRY6p73D1">https://www.youtube.com/playlist?list=PL13mreFCu1Josp4PCNb1WlOiaRY6p73D1</a></figcaption></figure><p>Here we’re going to communicate with Github’s <a href="https://developer.github.com/v4/">public GraphQL API</a>. Basic steps would be:</p><ol><li>Automatic fetch GraphQL Schema from the endpoint.</li><li>Authenticating the requests through a <a href="https://developer.github.com/v4/guides/forming-calls/#authenticating-with-graphql">personal access token</a>, set the token as an environment variable.</li><li>Construct your query with the auto-complete feature enabled. Use <a href="https://graphql.org/learn/queries/#variables">variables</a> when needed.</li><li>Send and check your response, work on fixing errors.</li><li>Export your current workspace and send it to your teammates. (Or use ‘Share’ feature which requires a Insomnia Plus subscription. 💰)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*B3Uk3TIDvnqWLkL8BedL1Q.jpeg" /><figcaption>If you’re in Singapore, welcome to join our meetup! <a href="https://www.meetup.com/GraphQL-SG/">https://www.meetup.com/GraphQL-SG/</a></figcaption></figure><h4>References</h4><ul><li><a href="https://support.insomnia.rest/article/61-graphql">Insomnia Official document for GraphQL Queries</a></li><li><a href="https://developer.github.com/v4/public_schema/">Github public schema</a></li></ul><p><em>Originally published at </em><a href="https://www.usegitflow.com/posts/insomnia-graphql-requests/"><em>https://www.usegitflow.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b270e16876a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A guideline for effectively building a responsive & blazing fast website in a weekend, using…]]></title>
            <link>https://medium.com/techtrument/a-guideline-for-effectively-building-a-responsive-blazing-fast-website-in-a-weekend-using-2eaa55d41a60?source=rss-79f79d2d5991------2</link>
            <guid isPermaLink="false">https://medium.com/p/2eaa55d41a60</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[boilerplate]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[build-blogs]]></category>
            <category><![CDATA[gatsbyjs]]></category>
            <dc:creator><![CDATA[Mark Feng]]></dc:creator>
            <pubDate>Wed, 01 May 2019 07:38:36 GMT</pubDate>
            <atom:updated>2019-05-01T07:39:53.342Z</atom:updated>
            <content:encoded><![CDATA[<h3>A guideline for effectively building a responsive &amp; blazing fast website in a weekend, using GatsbyJS</h3><p><em>Follow the right guideline with the right tools to save your effort, and deliver the impressive, blazing fast website effectively! For React.js engineers.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*YiGyMbcx0wp0GvBI.jpg" /><figcaption><em>Always use the right tool to do your job!</em></figcaption></figure><p>Nowadays there are many excellent React.js programmers but not all of them can quickly deliver a responsive, blazingly fast portfolio website in a weekend without using a proper toolkit.</p><p>It can be quite common that we want to quickly build a portfolio to showcase our awesome products, but we wouldn’t want to spend too much time on coding every detail of the entire website. What we need are just the right tools to do the job and avoid repeat work. Suppose you are a software engineer who is already familiar with React.js, now this article is exactly what you want to guide your work!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UXp-RVd6vMekal1k.png" /><figcaption><em>I tried </em>GatsbyJS<em> through the official tutorial, and then built my simple blog in a weekend, and this is the speed score I got. You can do better.</em></figcaption></figure><h3>What we want to build</h3><p>Let’s say we want to build a portfolio website to present some nice blog articles, or to showcase a list of side projects. We expect it to have the following features.</p><ul><li>mainly it presents a list of items, could be article or projects,</li><li>the website contains several static pages, we want to optimize the performance, the website needs to be responsive and sometimes mobile-first,</li><li>need to be able to optimize for search engines, or SEO,</li><li>can have a direct embedding section to a social network like Twitter,</li><li>it allows visitors to leave some comments, but we don’t want to maintain a user authentication flow.</li></ul><p>Most importantly, suppose that we only have one engineer who can write great React.js, but we don’t want to spend too much effort on building the website. That’s when the great GatsbyJS can come in handy! We can literally build the website as easy as building a Lego house.</p><h3>The complete framework/tools/libraries to use</h3><ul><li><a href="https://www.gatsbyjs.org/">GatsbyJS</a>, after you’ve become familiar with React, of course.</li><li>Github to host your code.</li><li>Host service like <a href="https://pages.github.com/">Github Pages</a> or <a href="https://www.netlify.com/">Netlify</a>. If you don’t have your own server, you need a service to host the website. Both platforms are free for deploying with a sub-domain!</li><li>A Gatsby starter project as a quick boilerplate for your own purpose. Usually, I would recommend these few boilerplates, but you can view the whole list <a href="https://www.gatsbyjs.org/starters?v=2">here</a>:</li><li>1. for ecommerce: <a href="https://www.gatsbyjs.org/starters/parmsang/gatsby-starter-ecommerce/">https://www.gatsbyjs.org/starters/parmsang/gatsby-starter-ecommerce/</a></li><li>2. for blogging: <a href="https://www.gatsbyjs.org/starters/gatsbyjs/gatsby-starter-blog/">https://www.gatsbyjs.org/starters/gatsbyjs/gatsby-starter-blog/</a> or <a href="https://www.gatsbyjs.org/starters/alxshelepenok/gatsby-starter-lumen/">https://www.gatsbyjs.org/starters/alxshelepenok/gatsby-starter-lumen/</a></li><li>3. for showcase: <a href="https://www.gatsbyjs.org/starters/contentful-userland/gatsby-contentful-starter/">https://www.gatsbyjs.org/starters/contentful-userland/gatsby-contentful-starter/</a></li><li>4. if you want to customize as most as you can, just use the advanced starter template: <a href="https://www.gatsbyjs.org/starters/Vagr9K/gatsby-advanced-starter/">https://www.gatsbyjs.org/starters/Vagr9K/gatsby-advanced-starter/</a></li><li>A UI framework to save your time from basic styling and responsive layout, I would recommend <a href="https://bulma.io/">Bulma</a> to do the job, with several <a href="https://dansup.github.io/bulma-templates/">templates</a></li></ul><p>And for the GatsbyJS project, we need many Gatsby plugins to enrich the feature list. But it’s really handy as most <a href="https://www.gatsbyjs.org/plugins/">plugins</a> can be very simple to use, when they just require some minor config changes. Most of the plugins can be found (and already configured) in the starter templates, I’ll give a list here for you to check if you missed anything you need.</p><ul><li>gatsby-plugin-offline, to enable drop-in support for making a Gatsby site work offline and more resistant to unstable network connections, using service worker.</li><li>gatsby-plugin-react-helmet, provides drop-in support for server rendering data added with React Helmet.</li><li>gatsby-plugin-sitemap, create a sitemap for your Gatsby site.</li><li>gatsby-remark-images, processes images in markdown so they can be used in the production build.</li><li>gatsby-transformer-remark, parses Markdown files into contents.</li><li>gatsby-plugin-google-analyticsm, easily add Google Analytics to your Gatsby site.</li><li>gatsby-remark-prismjs, adds syntax highlighting to code blocks in markdown files using PrismJS.</li><li>gatsby-plugin-feed, create an RSS feed (or multiple feeds) for your Gatsby site.</li><li>several <a href="https://www.gatsbyjs.org/plugins/?=data%20source">data source plugins</a>, many ways to provide data to your website who can function as a simple read-only DB.</li></ul><p>Because GatsbyJS would generate static websites from React project, we can also use popular React components here to enhance the functionalities. For example:</p><ul><li>react-twitter-embed, to embed Twitter timeline/share button in your page</li><li>disqus-react, to embed Disqus comments module in your webpage</li><li>any popular 3rd party UI libraries, but please keep bundle size in mind</li></ul><h3>Guideline</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DuBLb4VIkk1tdKeF.jpg" /><figcaption><em>What does a guideline mean? It is a streamline to indicate a course of actions, if you are equipped all the tools and skills, but don’t know how to use them effectively.</em></figcaption></figure><h4>Prerequisites</h4><ol><li>Familiar with React.js programming, if not <a href="https://insights.stackoverflow.com/survey/2018">it’s really time to learn Reactjs</a> now!</li><li>You have taken an hour to read over GatsbyJS official <a href="https://www.gatsbyjs.org/tutorial/">tutorial</a>. Trust me, you only need an hour to know what does the concepts of GatsbyJS mean, it’s a good official tutorial.</li></ol><p>Now you should know about the concepts like Gatsby starters, plugins, GraphQL query, page slugs, and how to use <a href="https://www.gatsbyjs.org/docs/gatsby-cli/">Gatsby CLI</a>.</p><h4>Let the rock begins!</h4><p>In this section, we’ll walk through a guideline of how to build a reliable website in high efficiency. So grab a coffee and let’s begin!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H-hpM47rpBc1Iohv.png" /><figcaption>Steps in short</figcaption></figure><p>I list it as the first step because it’s always important to keep in mind what you want to showcase, and what does the meta-data combined of. To be more specific, if you want to build a blog system, the <strong>data</strong> you need is possibly combined of {title, subtitle, description, slug, content, author, datetime, tags, category}. And for a product showcase site, you may need {product name, category, sale price, original price, description, where it&#39;s produced, where it&#39;s imported, product license, etc.}. I think it&#39;s fair to say that you need to design the data structure before design the website. And then you&#39;ll find many ways to provide data to your GatsbyJS project, using plugins listed <a href="https://www.gatsbyjs.org/plugins/?=data%20source">here</a>. Please notice that because the &#39;public&#39; files you build is static, so it can&#39;t act like a PHP page which refreshes every time showing different data when the supporting database updates. Here you can only get the new website for the data change after building the static files again. As a hint, you can use <a href="https://www.gatsbyjs.org/packages/gatsby-transformer-remark/?=markdown">gatsby-transformer-remark</a> to build a blog from several markdown files, or use <a href="https://www.gatsbyjs.org/packages/gatsby-source-mongodb/?=mongodb">gatsby-source-mongodb</a> to pull data into Gatsby from MongoDB collections. Never restrict your thoughts, why not use <a href="https://www.usegitflow.com/posts/a-guideline-to-effectively-build-a-responsive-blazing-fast-website/gatsby-source-google-sheets">Google sheets</a> to provide data? Actually, that can satisfy most portfolio sites, as what you eventually want to do is to present a list of data in a website. Isn&#39;t it?</p><p>Generally speaking, consider how to design the UI components that could be <strong>repeatedly</strong> used on your website. For example for blogs, the reused components could be:</p><ul><li>each blog page component, presenting the article details</li><li>blog item component for the blog list, containing minimal details like title, description, creation date, etc, and link to the article.</li><li>a card component to present best blogs in your index page, also containing some information and a link</li></ul><p>Thanks to React, you can easily implement and test the components in a separate Component class, even styling inside the class using inline styles or <a href="https://blog.bitsrc.io/5-ways-to-style-react-components-in-2019-30f1ccc2b5b">some better approach</a>. Please take a look at the <a href="https://reactjs.org/docs/thinking-in-react.html">Thinking in React</a> article if you&#39;re not very clear about what I mean, and remember to <strong>reuse components</strong>.</p><p>I’ve already listed some starter libraries of my recommendation in the last section, you can also check this <a href="https://www.gatsbyjs.org/starters/?v=2">link</a> for complete choices. A hint: if you’re familiar with how GatsbyJS works, take the most basic template and do your cool stuff inside. Otherwise, please take the template as much feature-rich as possible to save your effort. Ideally, for a simple website, most layout/routing/data source configuration work has been done in the starter library of your choice.</p><p>After having a clear idea about how the reused components should be presented, we can then focus on how the skeleton layout should be arranged, and put the components properly. We may expect to have some pages for a different router, for example for blogs we expect at list two different pages, a blog list page and an article detail page. An example is when using <a href="https://github.com/gatsbyjs/gatsby-starter-blog">official blog starter template</a>, you need to implement your design at least in these three files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/0*cCVYno4s2MC46OJL.png" /><figcaption>least modifications in a starter template</figcaption></figure><p>Usually, a navigation bar/menu is the first step, then another page container for each page is sufficient for small websites. This is when <a href="https://bulma.io/">Bulma</a> framework can be very handy (of course <a href="https://getbootstrap.com/">Bootstrap</a> can also do the job if you’re already familiar with it). Just import the bulma.css style in your main style file (I would recommend using <a href="http://lesscss.org/">less</a>/scss preprocessor CSS language), and take the &#39;out-of-the-box&#39; components as you need. Another helpful website you can make use of is the <a href="https://dansup.github.io/bulma-templates/">Bulma templates</a> site, which contains several useful layout templates for many different kinds of websites. Of course, you can&#39;t directly copy &amp; paste all the time, but it can really save you some effort.</p><p>Another thing about layout I’d like to introduce is the <a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/">CSS flexbox</a> layout. As responsive design is becoming more and more useful nowadays, flexbox can be a very efficient and easy-to-understand way to layout your things. It’s also very easy in flexbox to align and centering things. CSS flexbox is already supported in all major desktop/mobile browsers.</p><p>OK, with some hard work we should now have some nice pages in hand. Next step is to bring it together as a working website. We’re expecting to run the website locally through gatsby develop in Gatsby CLI.</p><p>If you’re following a boilerplate to start your work, mostly you won’t need to worry about routing for pages as they are already there. If you need to implement some custom pages, Gatsby core automatically turns React components in src/pages into a new router to serve the new file. You can check <a href="https://www.gatsbyjs.org/docs/routing/">routing</a> docs for more information.</p><p>Because we have only limited time, so I skipped an important element for common websites: forms. It can be a very common use case that a website needs the visitor to submit some information, but mostly using forms would require a user login step so that we can know which user submitted this information, and that can cost some effort. I’ll talk more about it in the next section, but if you don’t want to spend much effort on forms, just use <a href="https://www.google.com/forms/about/">Google forms</a>, possibly in a iframe. I&#39;m not advertising Google product, but you really don&#39;t need to spend much effort when we already have a reliable way to &#39;implement&#39; forms for our usage.</p><p>The same thing works for social network and comments system, by relying on 3rd party libraries. We can easily use React embedding components to embed social network, like <a href="https://www.npmjs.com/package/react-twitter-embed">twitter-embed</a> to embed Twitter timeline in your page, or use <a href="https://github.com/disqus/disqus-react">disqus-react</a> to embed Disqus for comments. Of course, it would introduce some issues like introducing 3rd party dependencies and ‘not saving data in our own server’, but personally I think it’s sufficient for many use cases. I’ll also talk more about it in the next section.</p><p>SEO is another built-in feature for GatsbyJS projects, as it can help you add required metadata for SEO on each static page, and it’s server-side rendered so all your information is available to search engines or crawlers. Basically, you only need to add required information in config file to make SEO work. Please check this <a href="https://www.gatsbyjs.org/docs/seo/">doc</a> and this <a href="https://www.gatsbyjs.org/packages/gatsby-plugin-react-helmet/?=SEO">plugin</a> for details.</p><p>If you have your own server, simply build your Gatsby project and serve the public/ folder using Nginx or whatever, and that&#39;s it!</p><p>Otherwise, all possible deploying and hosting choices are listed <a href="https://www.gatsbyjs.org/docs/deploying-and-hosting/">here</a>. I would recommend Github Pages and Netlify, especially <a href="https://www.netlify.com/">Netlify</a> which I used in two projects already and doing well. Netlify can have free CI integration with Github private repos, which allows build and deploy automatically from master code changes.</p><p>Both Github Pages and Netlify platform are free and widely used &amp; recommended, here’s a simple <a href="https://www.slant.co/versus/13313/16947/~github-pages_vs_netlify">comparison</a> between these two platforms.</p><h3>Because I just have a weekend…</h3><p>Congratulations about how much you already achieved through the guidelines! Only in a weekend, you have successfully built a website with blazing fast performance and responsive design, which performs well in all platforms. Your audience would be impressed.</p><p>If given more time and effort, absolutely we can do more! Here are some aspects that I think you can continually work on.</p><ol><li>User authentication. Sometimes you need to create a site with gated content and access control, Gatsby has a <a href="https://www.gatsbyjs.org/docs/authentication-tutorial/">document</a> about client-only routes which can control which pages user can access after logging in. Personally I would recommend using 3rd party OAuth authentication which could save lots of effort, another approach is using some server-side control like Netlify’s <a href="https://www.netlify.com/docs/identity/">identity</a> feature.</li><li>Localization, or i18n. It can be easily done by using any React i18n components, but pay attention that i18n is always related to routers. You can use a <a href="https://github.com/angeloocana/gatsby-plugin-i18n">gatsby plugin</a> to do the job.</li><li>Forms. Previously I mentioned that you can use Google Forms to act the form role, that could be not feasible sometimes. If you host a server-side code to deal with forms, you can send requests from front end form components to your server, as any React project does. Netlify also has a built-in <a href="https://www.netlify.com/docs/form-handling/">form handling</a> to help you host server-side code without actually running a server.</li><li>Styling. In the last section, we can build the system with a basic skeleton containing some layout and components in a short time, but the complexity may be not enough. You can check <a href="https://www.gatsbyjs.org/showcase/">showcase</a> and see how other complex website works with GatsbyJS. From my point of view, the complexity is the same, we just need to spend more effort on better layout styling and design more components, that’s all. Nothing special.</li></ol><p>Thanks for reading! If you have any questions or suggestion, please leave a note or <a href="https://twitter.com/markfeng_sg">twitter</a> me anytime.</p><p><em>Originally published at </em><a href="https://www.usegitflow.com/posts/a-guideline-to-effectively-build-a-responsive-blazing-fast-website/"><em>https://www.usegitflow.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2eaa55d41a60" width="1" height="1" alt=""><hr><p><a href="https://medium.com/techtrument/a-guideline-for-effectively-building-a-responsive-blazing-fast-website-in-a-weekend-using-2eaa55d41a60">A guideline for effectively building a responsive &amp; blazing fast website in a weekend, using…</a> was originally published in <a href="https://medium.com/techtrument">Hackmamba</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mark Notarize: A simple notarization DApp based on truffle framework]]></title>
            <link>https://markselby9.medium.com/mark-notarize-a-simple-notarization-dapp-based-on-truffle-framework-553b9db32f5f?source=rss-79f79d2d5991------2</link>
            <guid isPermaLink="false">https://medium.com/p/553b9db32f5f</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[Mark Feng]]></dc:creator>
            <pubDate>Sun, 06 May 2018 10:07:42 GMT</pubDate>
            <atom:updated>2018-05-06T10:23:41.238Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3hyWN8UhcrL7P0Opbu7IQg.jpeg" /><figcaption>image from <a href="https://magazine.seats2meet.com/more-about-blockchain/">Seats2meet Magazine</a></figcaption></figure><p>Hi,</p><p>This is a introduction to my very recent project <strong>‘Mark Notarize’</strong>, which is a very simple notarization DApp based on Truffle (<a href="http://truffleframework.com/">http://truffleframework.com/</a>) framework.</p><p><strong>It’s open sourced with github link: </strong><a href="https://github.com/markselby9/mark-notarize"><strong>https://github.com/markselby9/mark-notarize</strong></a><strong>, and you can visit it directly through: </strong><a href="http://matri.tech/"><strong>http://matri.tech/</strong></a><strong>.</strong></p><p>You can check a demo gif below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ySdfAfA2mkkyCVq0R81isA.gif" /><figcaption>demo for release v0.1</figcaption></figure><p>With Mark-Notarize, you can create a document with content for notarization, and it contains two blockchain addresses. Only account with the contained address can sign the document. <strong>After both sides have signed the document, it would be considered as ‘finished’, and can never be changed again</strong>. All documents are preserved on the blockchain network, for now I’m using Rinkeby test network.</p><p>It’s open sourced, and you can visit it directly through: <a href="http://matri.tech/">http://matri.tech/</a>. However there are some pre-requirements to visit the website:</p><ul><li>Modern browser with Metamask installed. link: <a href="https://metamask.io/">https://metamask.io/</a></li><li>After switching to Rinkeby network, you’ll need an account with some ether balance in it. Two websites which can give you some ether: <a href="http://rinkeby-faucet.com/">http://rinkeby-faucet.com/</a>, <a href="https://faucet.rinkeby.io/">https://faucet.rinkeby.io/</a>.</li></ul><p>Mark Notarize is in a very early stage of development and will be updated later. Please check roadmap/plan: <a href="https://github.com/markselby9/mark-notarize/projects/1?add_cards_query=is%3Aopen">https://github.com/markselby9/mark-notarize/projects/1?add_cards_query=is%3Aopen</a>. Again, it’s completely open source, please feel free to contribute/give issues if you have any interest. Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=553b9db32f5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Neural network in your browser, for Front-end engineers]]></title>
            <link>https://markselby9.medium.com/neural-network-in-your-browser-3e6fc91709ca?source=rss-79f79d2d5991------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e6fc91709ca</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Mark Feng]]></dc:creator>
            <pubDate>Fri, 18 Aug 2017 03:50:20 GMT</pubDate>
            <atom:updated>2017-08-18T05:10:59.852Z</atom:updated>
            <content:encoded><![CDATA[<h4>A simple recommendation system using synaptic.js, training in the browsers</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*dzZBXQgxhnX7FKRRnOUtiA.png" /><figcaption>Machine learning in JS? Why not!</figcaption></figure><h4>Project overview</h4><p>We’re going to build an artificial neural network based, simple recommendation system web application. The application contains two pages, with first page showing books, and the second page showing movies. The user can select the books he or she is interested in in the first page, and when he clicks the next page button, we would actually predict what movies he would likely be interested in in the background. After the user finished choosing the movies he like, we would give the user a result showing what he chose and what we predicted about his choice. Some screenshots are shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*spfhPuuXxRcz5zHM0wp5xw.png" /><figcaption>Select the books you’re interested in the first page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4kInq-46H5Oa10Dc-AYnMQ.png" /><figcaption>Select the movies you’re interested in the second page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9sI_kZFIfMZq4bP3U1APLg.png" /><figcaption>Compare the selections with predicted results</figcaption></figure><p>We’re using Vue.js and ElementUI ( a Vue.js UI framework) to build the application, and synaptic library to build the neural network.</p><p><strong>What’s the advantages?</strong></p><p>The advantages of our project can be concluded as:</p><ul><li>We moved the model training work to front-end instead of back-end, which reduced the server’s pressure and apportioned some computational power to many clients. That should be feasible thanks to the many neural network related Javascript library provided by npm community.</li><li>We protected the user’s privacy. No user’s data has actually been transferred to server, they kept their data anonymous to server, when the server has updated it’s training model.</li></ul><h4>Simple introduction to Neural Network</h4><p>First of all, the neural network we used here is a most fundamental ANN, and we also decided to use only the user’s selection to be input and output set. The images used in this section come from a nice introduction blog about neural network: <a href="https://ujjwalkarn.me/2016/08/09/quick-intro-neural-networks/">https://ujjwalkarn.me/2016/08/09/quick-intro-neural-networks/</a>.</p><p>The concepts involved in the project includes: Artificial Neural Network, neurons, layers and training (back-propagation).You can skip this part if you’re already familiar with these concepts. An Artificial Neural Network (ANN) is a computational model that is inspired by the way human’s brain work. It’s made up by neurons, which is a basic unit of neural network. Neurons receives inputs from other source, each input has a weight, which is assigned according to each input’s importance. And the neuron apply an activation function to the weighted sum of all inputs, then gives an output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a0HFkFBTKaiq7MxxXYCqrw.png" /><figcaption>Neuron</figcaption></figure><p>A layer is composed by several neurons, which looks like the image below. A neural network may or may not contain several hidden layers, each pair of neighboring layers have connections between them, which usually means the weight mentioned before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*d4iXh7gbVcuAd06TfpJ8sA.png" /><figcaption>Layers</figcaption></figure><p>But how can we design the network by correctly measuring these weights? We need to train it to let the neural network work properly. Suppose we have a table of data, which contains 1000 pair of inputs and corresponding outputs. We firstly gives all the weights by a random number between 0 and 1, and then iterate over all the data pairs. In each pair of input and output, we activate the neural network to give a calculated result, and compare it to the actual output. Then we would use back-propagation algorithm to retrain the network and adjust the weights. The weight updates of back-propagation can be done via stochastic gradient descent, which is a method to get optimal values for the weights.</p><p>In this article I only give a very brief introduction. For better reference, please check these links:</p><ul><li><a href="https://ujjwalkarn.me/2016/08/09/quick-intro-neural-networks/">https://ujjwalkarn.me/2016/08/09/quick-intro-neural-networks/</a></li><li><a href="https://en.wikipedia.org/wiki/Artificial_neural_network">https://en.wikipedia.org/wiki/Artificial_neural_network</a></li><li><a href="https://github.com/cazala/synaptic/wiki/Neural-Networks-101">https://github.com/cazala/synaptic/wiki/Neural-Networks-101</a></li></ul><h4>Neural Network implementation in browser</h4><p>Recently there have been some related works about implementing NN in browsers, like:</p><ul><li>Deeplearnjs, <a href="https://github.com/PAIR-code/deeplearnjs">https://github.com/PAIR-code/deeplearnjs</a></li><li>ConvnetJS, <a href="http://cs.stanford.edu/people/karpathy/convnetjs/">http://cs.stanford.edu/people/karpathy/convnetjs/</a></li><li>synaptic.js, <a href="http://caza.la/synaptic/">http://caza.la/synaptic/</a></li></ul><p>We use synaptic.js here as it’s an architecture-free neural network library for both node.js and the browser, the documents can be checked through wiki in the github repository: <a href="https://github.com/cazala/synaptic/wiki/Architect">https://github.com/cazala/synaptic/wiki/Architect</a>. We plan to move all the neural network training and activation part in the browser, and the server (simple node.js server by express) only maintains a JSON file, which contains the network parameters. synaptic.js has a handy API to parse the neural network to JSON and parse JSON to a NN instance.</p><p>The application is built up by Vue.js and ElementUI. In the created lifecycle of the main app component, the application would fetch the model’s JSON file from server, and build a neural network instance based on the JSON file. Then it presents 20 cards containing movie information, and let the user select the items he/she is interested in. After the user finished selection and click next step, the network instance would call activate function, and give a predicted value about the books this user would possibly want (among the 20 options of books). Meanwhile, the application presents another 20 cards containing book information, and also let the user select. After click the submit button, the app would present the predicted book list and the actual book list to the user, and in the background use the new training data to back-propagate and retrain the model. After retraining, the new NN would be parsed as a JSON object and sent back to server.</p><p>Now let’s talk about the code. The server is a very simple express server with node’s file IO API.</p><pre>app.post(&#39;/getNetwork&#39;, (req, res) =&gt; {<br>    <strong>if </strong>(req.body) {<br>        console.log(req.body);<br>        readJSONFromFile((network) =&gt; { // read local JSON file<br>            res.send({<br>                code: 200,<br>                network,<br>            });<br>        }, (err) =&gt; {<br>            console.log(err.toString());<br>        });<br>    }<br>});<br><br>app.post(&#39;/setNetwork&#39;, (req, res) =&gt; {<br>    <strong>if </strong>(req.body &amp;&amp; req.body.networkJSON) {<br>        console.log(req.body);<br>        <strong>const </strong>{ networkJSON } = req.body;<br>        saveJSONToFile(networkJSON, (err) =&gt; { // write to local JSON file<br>            <strong>if </strong>(err) {<br>                res.send({<br>                    code: 500,<br>                    err<br>                });<br>            } <strong>else </strong>{<br>                res.send({<br>                    code: 200,<br>                });<br>            }<br>        });<br>    } <strong>else </strong>{<br>        res.send({<br>            code: 406,<br>        })<br>    }<br>});<br><br>app.listen(3000, () =&gt; {<br>    console.log(&#39;server started&#39;);<br>});</pre><p>And in the client, we would not dive into the DOM detail here in the article, we will just focus on the script part of the particular app.vue file.</p><pre>created() {<br>            // fetch the train model from server<br>            <strong>this</strong>.content_data = <strong>this</strong>.shuffle(book_data);<br>            <strong>this</strong>.loading = <strong>true</strong>;<br>            axios.post(&#39;http://localhost:3000/getNetwork&#39;)<br>                .then((response) =&gt; {<br>                    console.log(response);<br>                    <strong>this</strong>.loading = <strong>false</strong>;<br>                    <strong>const </strong>networkJSON = response.data.network;<br>                    <strong>if </strong>(networkJSON &amp;&amp; Object.keys(networkJSON).length &gt; 0) {<br>                        <strong>this</strong>.$message(&#39;Received neural network from server.&#39;);<br>                        localNetworkInstance = Network.fromJSON(networkJSON);<br>                    } <strong>else </strong>{<br>                        <strong>this</strong>.$message(&#39;Created a new network instance.&#39;);<br>                        // create a new network instance<br>                        <strong>const </strong>inputLayer = <strong>new </strong>Layer(20);<br>                        <strong>const </strong>hiddenLayer = <strong>new </strong>Layer(20);<br>                        <strong>const </strong>outputLayer = <strong>new </strong>Layer(20);<br><br>                        inputLayer.project(hiddenLayer);<br>                        hiddenLayer.project(outputLayer);<br><br>                        localNetworkInstance = <strong>new </strong>Network({<br>                            input: inputLayer,<br>                            hidden: [hiddenLayer],<br>                            output: outputLayer<br>                        });<br>                    }<br>                })<br>                .catch(<strong>function </strong>(error) {<br>                    <strong>this</strong>.loading = <strong>false</strong>;<br>                    console.log(error);<br>                });<br>        },</pre><p>Above is the created lifecycle hook in our application. It tries to fetch a JSON object from ‘getNetwork’ API, if it’s an available JSON configuration for network, it would create a local network instance through synaptic’s fromJSON method. Otherwise, it would create a new network instance and saves into ‘localNetworkInstance’ variable.</p><p>After the user clicks the ‘next page’ button from the first page, we call the activation function in the ‘onClick’ function, and save it as a predicted result in the Vue component’s data. Then after the user selects his/her interested films, a retrain function is called.</p><pre>reTrainByThisUserData() {<br>    // retrain the model by this user&#39;s data<br>    <strong>if </strong>(localNetworkInstance) {<br>        localNetworkInstance.propagate(learningRate, <strong>this</strong>.trainingSet.output);   // propagate the network<br><br>        <strong>this</strong>.$message(&#39;Neural Network retrained!&#39;);<br><br>        <strong>const </strong>successFunc = () =&gt; {<br>            console.log(&#39;success&#39;);<br>            <strong>this</strong>.$message(&#39;Successfully sent the new Neural Network!&#39;);<br>        };<br>        <strong>const </strong>errorFunc = (error) =&gt; {<br>            console.log(&#39;error&#39;, error);<br>            <strong>this</strong>.$message(error);<br>        };<br><br>        <strong>this</strong>.loading = <strong>true</strong>;<br>        axios.post(&#39;http://localhost:3000/setNetwork&#39;, {<br>            networkJSON: localNetworkInstance.toJSON()<br>        })<br>            .then((response) =&gt; {<br>                <strong>this</strong>.loading = <strong>false</strong>;<br>                <strong>if </strong>(response.data &amp;&amp; response.data.code === 200) {<br>                    successFunc();<br>                } <strong>else </strong>{<br>                    errorFunc(response.data);<br>                }<br>            })<br>            .catch(<strong>function </strong>(error) {<br>                errorFunc(error)<br>            });<br>    } <strong>else </strong>{<br>        <strong>this</strong>.loading = <strong>false</strong>;<br>        console.log(&#39;network is undefined!&#39;);<br>    }<br>}</pre><p>The retrain process is a back-propagation process, by the current user’s selection as a pair input and output data. The user’s selection about movies would become the data for back-propagation. After back-propagation, the neural network’s weight would be adjusted, and the new data of neural network would be transferred to server and saved. Ideally, the new network should be stronger :).</p><h4>You can do more …</h4><p>As our reader may have already considered, we can do far more things than a simple recommendation system, using this strategy. Some possible roadmap for improving this project contains:</p><ul><li>More factors from the browser can be taken into account as input set, like time spent on each cards, user’s click event and scroll event, etc. These factors are accessible for front-end’s perspective.</li><li>The neural network can have more complicated architecture, but meanwhile it can’t be trained overfitted.</li><li>Build size should be taken into consideration for front-end project. Currently the build file size is around 1Mb, which is acceptable on PC but maybe too large for mobile sites. Optimizations should be taken if you want to use the project’s approach on mobile.</li></ul><p>For the complete code of this project, please check the reference: <a href="https://github.com/markselby9/ml-in-browser/tree/feature/Recommendation_system_in_browser_demo">https://github.com/markselby9/ml-in-browser/tree/feature/Recommendation_system_in_browser_demo</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e6fc91709ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vuez — A very simple but powerful option for state management in Vue.js projects]]></title>
            <link>https://markselby9.medium.com/vuez-a-very-simple-but-powerful-option-for-state-management-in-vue-js-projects-2b3f5cc0e48f?source=rss-79f79d2d5991------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b3f5cc0e48f</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Mark Feng]]></dc:creator>
            <pubDate>Mon, 08 May 2017 05:59:03 GMT</pubDate>
            <atom:updated>2017-05-08T06:01:32.394Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi,</p><h4>Here in medium, I want to introduce a new state management library for Vue.js projects named <a href="https://github.com/markselby9/vuez">Vuez</a>. You can check the github repo at: <a href="https://github.com/markselby9/vuez">https://github.com/markselby9/vuez</a>.</h4><p>In short, Vuez is a centralized monitoring ‘store’ which is accessible for all your Vue components after installing Vuez. From each component, you can access the store through this.$store.</p><p>The store concept in Vuez is very simple, imagine an excel table with three columns: ‘name’, ‘object’, ‘actions’. Whenever you are interested in monitoring an object or an event, you would like to start a new column in the table with a new name, with an object you plan to monitor. Then put everything you want to do when the object changed, as functions in the ‘actions’ column. Whenever you want to care about the ‘name’, you use store.observe(this_name) to observe it, if the object column&#39;s value has changed, all actions related to the name would be triggered.</p><p>It has only two set of APIs:</p><ol><li>Observe/unobserve</li></ol><p>store.observe(name, observing_object), takes two parameters: name is a string for the observer, and observing_object is an object to observe. If a name is firstly created as an observer’s name (firstly used in observe function), the object would be recorded. Then everytime whenever the observe function is called with the name, all actions with the name would be triggered if and only if the observing_object is changed.</p><p>store.unobserve(name) would cancel every action and observers related to the name.</p><p>2. Action</p><p>store.action(name, action_function), takes two parameters: name is a string for the observer, and action_function is the function to act when the object is changed during an &#39;observe&#39;. The action_function here can have a parameter representing the current object value of the observing object.</p><p>With these simple APIs, Vuez can deal with many troublesome event handling such as data communication, monitoring data change, etc.</p><p>Let’s check a very simple example.</p><pre>// Make sure to call Vue.use(Vuez) first before usage</pre><pre>const store = new Vuez.Store();<br>let changingObject = {<br>    number: 1<br>};<br>store.observe(&#39;changing&#39;, changingObject);<br>store.action(&#39;changing&#39;, (obj) =&gt; {<br>    console.log(obj.number);<br>});<br>observeObject.number = 2;<br>store.observe(&#39;changing&#39;, changingObject);  // trigger the action and console would show &#39;2&#39;</pre><p>For somehow more detailed examples to use Vuez in your Vue.js projects, please check these links:</p><ul><li><a href="https://github.com/markselby9/vuez/tree/develop/examples/todolist">Todo List</a></li><li><a href="https://github.com/markselby9/vue2-vuez-weather">Weather Application</a> A weather application using Vuez and Vue2.x.</li></ul><h4>Currently Vuez is compatible with both Vue1.x and 2.x. As a newborn project, Vuez is currently under rapid development, and has a lot of space to improve. So please kindly give some suggestions, issues when you faced in usage, and PR if you’re interested. The more the better! :)</h4><p>Thanks again for your time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b3f5cc0e48f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>