<?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 Ayushman Gupta on Medium]]></title>
        <description><![CDATA[Stories by Ayushman Gupta on Medium]]></description>
        <link>https://medium.com/@duoro?source=rss-40c78042157f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XVf6ZvQYv0Kkop4PJuRJRA.jpeg</url>
            <title>Stories by Ayushman Gupta on Medium</title>
            <link>https://medium.com/@duoro?source=rss-40c78042157f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 04:23:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@duoro/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[Why I Built a Database Client]]></title>
            <link>https://duoro.medium.com/why-i-built-a-database-client-16e08e2e9c9a?source=rss-40c78042157f------2</link>
            <guid isPermaLink="false">https://medium.com/p/16e08e2e9c9a</guid>
            <category><![CDATA[seqora]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Ayushman Gupta]]></dc:creator>
            <pubDate>Wed, 21 Oct 2026 00:00:10 GMT</pubDate>
            <atom:updated>2026-10-23T06:09:19.347Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ph6-HlcJ9m65uBIJ0_BI2g.jpeg" /></figure><p>For the past few months I’ve been building Seqora, a desktop database client, almost entirely with AI, and I want to write down how that went while it’s still fresh. This is the first devlog. It covers why I started, what the thing is, and how it is built.</p><h3>The itch</h3><p>Every time I opened DBeaver I got a little more annoyed. It takes ages to load. The shortcuts I reached for were never there, and the ones that existed I could never remember. pgAdmin is the same story. Both of them work. Neither looks like it was made in the last ten years.</p><p>I was doing more and more backend work, which meant going through one of these every day. So I looked at the modern ones. TablePlus is nice, and it looks like it was made this decade. Then you hit the free tier, which lets you open two tabs and two windows at a time. I understand wanting to be paid, I want to be paid too, but a database client that stops you looking at your own database is a strange thing to sell.</p><p>I didn’t set out to build a product. One weekend I built a prototype that did one thing: connect to a database and let me move around it fast. No edits, no completion, no design to speak of. Just a tree, a grid, and Ctrl+P to jump to any table by name. It was ugly and I used it every day, which told me something.</p><p>That prototype grew into Seqora. The first commit in the real repo is from 28 July. For the first month it was evenings and weekends. For the last month or so it has been the main thing I do. I didn’t track the hours. It felt like a lot.</p><h3>What Seqora is today</h3><p>Seqora is a desktop database client for PostgreSQL, MySQL, MariaDB and SQLite, with more to come. Mac and Windows today, Linux soon. Version 0.4.2 as I write this, 750 commits in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pIon-Bq_NlfHzMxwwC_89g.jpeg" /></figure><p>The short version of what it does:</p><ul><li>A SQL editor with completion, snippets and history.</li><li>A data grid where edits are staged, so you read the change before it runs.</li><li>An ER diagram of the live schema.</li><li>A schema design mode. You draw the change, read the SQL it will produce, and apply it. Before applying, it rehearses the change inside a transaction and rolls it back, so you find out about the failing constraint before your table does.</li><li>Object pages for the things that are usually just names in a sidebar: indexes, sequences, functions, views, partitions, triggers, grants, row security.</li><li>A visual EXPLAIN that draws the plan as row flow and index access, so you can see where the planner guessed 612 rows and found 206,880.</li><li>Close to 40 keyboard shortcuts, for everything I could think of. Ctrl+P opens a palette that takes you to any table, query or connection.</li></ul><p>Every connection opens read-only until you unlock it. Production connections are marked in colour. There is no account and nothing goes to a server of mine. Credentials live in an encrypted local store keyed from the system keychain.</p><p>The core is free, with no tab limit and no query limit. Schema design, the object pages and visual EXPLAIN are Pro, at $99 a year, or $49 a year if you subscribe before the end of 2026.</p><h3>The four questions</h3><p>The first thing I wrote down wasn’t a feature list. It was four questions I wanted answered at a glance, without clicking anything:</p><ol><li>Which connection is this action going to hit?</li><li>Will it change data?</li><li>What just ran, and did it fail?</li><li>How does this object relate to that one?</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*IRcQlXsLkTvOGboGYSsojw.jpeg" /></figure><p>Every tool I had used answered those questions somewhere. None of them answered them where I was looking. The connection name was in a dropdown I had scrolled past. Whether a query would write was something I worked out by reading it. The last error was in a log panel I had closed.</p><p>Those four questions became the spec. The spec is still in the repo, and most of the app is a consequence of taking it seriously. The colour on production connections is question one. The lock on every new connection is question two. The staged edits are question two again. The ER diagram and the object pages are question four.</p><p>I also wrote down a rule for myself, which I’ve mostly kept: before copying how an existing tool does something, ask whether it does it that way because it’s right, or because someone decided it years ago and nobody has looked since.</p><h3>Why Svelte</h3><p>I started frontend with Vue 2 and liked it. The way it worked made sense to me, and I could hold the whole model in my head. Then I moved to React, like most people did. I liked bits and pieces of it. Over time the bits I liked got smaller and the code around them got uglier, and I spent more of my day managing React than building things.</p><p>A few years ago I watched a talk by Rich Harris, the person who made Svelte, and it was the first time in a while that a framework felt simple on purpose rather than simple until you looked closely. Svelte 5 with runes is what Seqora is written in. It’s also where my most embarrassing bug lives, which I’ll get to.</p><p>The formal decision record in the repo lists React, Vue, Solid and a Rust-only UI as the options I rejected. The honest reason is shorter than the record. I knew I’d be reading and reviewing a lot of code written by AI, so I wanted it to be code I enjoy reading. For me that’s Svelte.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mEOFJbMU3e6X4dor6wA32w.png" /></figure><p>The stack is Tauri 2, Svelte 5 and Rust. The UI runs in a webview. Everything that touches a database, a file, the keychain or an SSH tunnel runs in Rust. A database client holds people’s credentials, opens tunnels into their servers and runs their queries. I wanted that part in Rust.</p><ul><li>Each engine uses its own native driver: tokio-postgres, mysql_async and rusqlite. There is no abstraction layer pretending four databases are one. They aren&#39;t, and every abstraction I looked at hid exactly the differences I cared about.</li><li>The Postgres parser is pg_query, which wraps the parser Postgres itself uses. Seqora reads your SQL the way the server will, which is how it knows a query will write before it runs.</li><li>The app’s own local store is SQLite with SQLCipher, so saved connections and metadata are encrypted at rest.</li><li>CodeMirror 6 for the editor. I wasn’t going to write an editor.</li><li>SSH tunnels through russh, the OS keychain through keyring, and a built-in terminal through portable-pty, because sometimes you need psql and switching windows is the thing I was trying to stop doing.</li></ul><p>Some choices I’m glad about:</p><p>Twelve weeks in, the repo has about 400,000 lines of Svelte, TypeScript and Rust across 1,200 files. If that number makes you suspicious, good. It makes me suspicious too, and it’s the subject of the next section.</p><h3>99.9 per cent</h3><p>I wrote almost none of the code by hand. Something like 99.9 per cent of the lines were typed by a model. The number is the least interesting part of the story.</p><p>Here is what I actually did instead of typing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_scf8WqjwDqv2-FIXUZWWw.png" /></figure><p>I started the project on Codex, with GPT 5.6, Sol and Luna. Luna was cheap and I liked that, but it needed a lot of hand holding, and hand holding is still work. About a month ago I moved to Claude Code and stayed. For anything genuinely hard I plan with Fable first, as a conversation about what the thing should be and what could go wrong, and then hand the plan to Opus to build. For small things I skip the planning and just ask.</p><p>I still use Codex for one job: pretending to be a user. Astra and Sol 6.1 drive the app with computer use, click through it the way someone new would, take screenshots and tell me where the app deviates from what I described. I also use Astra for images and UI assets. I describe what an asset should look like, Codex opens Affinity and draws it, and the result is better than I expected and still not as good as I want. I’m looking for a better way to do that part.</p><p>The thing I didn’t expect to love is choosing. When I’m not sure how a panel should work, I ask for two or three working prototypes, run them, and pick. Before, a prototype cost an afternoon, so I built one and defended it. Now it costs minutes, and I’ve become a much harsher judge of my own first idea.</p><p>What I review, honestly: every line of the Rust. It’s the core, it holds credentials and runs queries against databases that aren’t mine. The Svelte I skim. I run it, I use it, I click on everything, and I read the diff when something feels off. I’m not going to claim a discipline I don’t have.</p><p>My job on this project is architect and product owner. I decide what it is, how it should feel, what is in and what is out, and then I make sure I can explain exactly what I want in technical terms. The day I can no longer explain what I want is the day the tools stop being useful. That is the part I guard.</p><h3>What I mean by slop</h3><p>People are shipping AI-built software left and right, and some of it is fine. The word slop gets thrown at all of it, and I don’t think that’s what the word is for.</p><p>Slop, to me, is the absence of obsession. It’s software where nobody went into each crack to see what could be smoother. You can get 80 per cent of a product’s features in a weekend now. That part is true and it’s not going back. The 80 per cent is also the part everyone can copy, so it is the part that is worth the least.</p><p>The other 20 per cent is small, human things. Ctrl+P opening the palette with the cursor already in the search box. The grid scrolling back to the top when you switch tables, because that&#39;s where you expect to be. A warning when you type a string into an integer column, before the database tells you off. The ER inspector not being confusing. None of that comes out of the first prompt. Each one is several rounds of back and forth with the tool, and the tool doesn&#39;t care either way. You have to.</p><p>Katie Dill, who runs design at Stripe, <a href="https://www.youtube.com/watch?v=GLvFTMtw4Jk">said something close to this </a>on Lenny’s Podcast, better than I can: the craft lives in the details that no spec asks for.</p><p>So when I say Seqora was built with AI, I mean the typing. When I say it was handcrafted, I mean those small things.</p><h3>Three bugs that cost me the most</h3><p>The short versions.</p><p><strong>The grid that took five seconds.</strong> The most embarrassing version of Seqora was the one where a query with 10,000 rows made the whole window stutter. I had put the result rows into Svelte’s deep reactive state, which wraps every object in a proxy, including the thousands that nothing was ever going to react to. About 4.7 seconds of the lag was that. The store and the IPC bridge, which I blamed first, were 370 milliseconds. The fix was moving the rows out of reactive state altogether.</p><p><strong>The editor that lost its CSS.</strong> In packaged builds, and only in packaged builds, the SQL editor lost all of its styling. Dev builds were fine, which is the worst kind of fine. The cause was a Content Security Policy nonce that Tauri adds in production, which quietly disables the inline styles CodeMirror depends on.</p><p>All of this is planned for this year, before the founder price ends on 31 December. A lot more will come after that. The more I use Seqora every day, the more things I find that need adding, and they get added. The same goes for you: if you have feedback or want a feature, let me know.</p><h3>What is next</h3><p>All of this is planned for this year, before the founder price ends on 31 December. A lot more will come after that. The more I use Seqora every day, the more things I find that need adding, and they get added. The same goes for you: if you have feedback or want a feature, let me know.</p><p><strong>The point release that broke CI.</strong> Rust 1.99 changed how bindgen finds libclang, which broke the pg_query build on macOS and Linux while Windows carried on passing. The toolchain is now pinned to 1.98.1. The shortest of the three, because the lesson is one line: pin your toolchain.</p><ul><li><strong>Linux.</strong> It’s the most asked-for thing and the sign-up for it is on the site.</li><li><strong>MCP.</strong> Seqora will expose your connections to whatever model you already use, with your own key. There will be no AI built into the app itself, and no model of mine in the loop. You bring the model, Seqora brings the database, and you can still read everything before it runs.</li><li><strong>A dashboard per connection.</strong> One screen that answers “what is going on in this database right now”: size, activity, the slow queries, the tables that grew.</li><li><strong>More pictures.</strong> The visual EXPLAIN and the ER diagram are the two features people react to most, so there will be more of the schema and the statistics drawn rather than listed.</li></ul><h3>Try it</h3><p>The Free version is at <a href="https://seqora.dev/?utm_source=medium&amp;utm_medium=article&amp;utm_campaign=medium-launch">seqora.dev</a>. No account, no tab limit, Mac and Windows.</p><p>It started as a weekend prototype I couldn’t stop using. Try it on your own database and see if it does the same for you. If something annoys you, tell me.</p><p><em>Originally published at </em><a href="https://www.ayushman.dev/blog/devlog/seqora_devlog_0/"><em>https://www.ayushman.dev</em></a><em> on October 21, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16e08e2e9c9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Vue Developer’s Guide to Redux]]></title>
            <link>https://medium.com/bitsrc/a-vue-developers-guide-to-redux-4a0de9217bfd?source=rss-40c78042157f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a0de9217bfd</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[redux-toolkit]]></category>
            <dc:creator><![CDATA[Ayushman Gupta]]></dc:creator>
            <pubDate>Sun, 06 Mar 2022 06:55:13 GMT</pubDate>
            <atom:updated>2023-06-14T05:09:45.320Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7b-4Gt64YjbMmFl3uq0drA.png" /></figure><p>If you have worked in the front-end scene for a while, you must have come across myriad state management tools. Some of these tools are simple and try to solve only a specific problem in an elegant manner while others have some complexity that in turn benefits scaling the app.</p><p>Under this spectrum, you will find Vuex somewhere in the middle and Redux on the far right. Since the majority of my projects were based on Vue, I used Vuex a lot and it was about time to move out of my comfort zone and tip my toes in the waters of Redux.</p><p>First of all, let’s understand what state actually means in a Front-end world. We can say, a reactive state is basically a variable that once changed will re-render a specific part of the UI.</p><p>In a typical vanilla JavaScript, it becomes an increasingly challenging job to handle a state change. Although it is possible to do so using JavaScript proxies, which is a topic in itself and you can explore more about it here.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy">Proxy - JavaScript | MDN</a></p><p>As the complexities of the app grow, reactive states with only JavaScript proxies become cumbersome to manage. Most JavaScript frameworks like React, Vue and Angular try to solve this reactive state problem.</p><blockquote><em>💡</em> To tackle the complexities of a growing codebase, consider adopting a component-driven approach to developing your applications. And you can do that using open-source tools such as <a href="https://bit.cloud/"><strong>Bit</strong></a>. With Bit you can extract reusable components out of your codebase and use across multiple projects. <a href="https://bit.dev/blog/unlock-the-power-of-vuejs-with-bit-lgah52ts/"><strong>Learn more here</strong></a>.</blockquote><h4>Get started:</h4><p><a href="https://blog.bitsrc.io/getting-started-with-a-new-vue-js-project-in-2023-7ea97498ab6a">Getting Started with a New Vue.js Project in 2023</a></p><h3>Vuex</h3><p>In the Vue ecosystem, the most popular state management library is Vuex. Still, there are many great alternatives such as Pinia, xState etc but we will only talk about Vuex as this is the most popular one and is suggested by Vue.</p><p>Vuex is based on something known as the Flux state management tool. It was a tool that was developed by Facebook to handle state in their front-end projects. If you’d like to learn more about Flux you can find it here.</p><p><a href="https://facebook.github.io/flux/docs/in-depth-overview">In-Depth Overview | Flux</a></p><p>Vuex tries to implement methodologies set up by flux and give us an abstracted tool that lets us perform state management without worrying much about the intricacies.</p><p>In Vuex you have a global state. But you can’t access/mutate state directly. You need to follow some procedures. If you want to change some state you need to dispatch actions. An action is an async function where we either fetch data from an API or perform calculations. At the end of that action, after we get the values we can commit the changes using mutation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/0*3EAHR9KST-4eRFFW.png" /></figure><p>A mutation is an impure function that receives the state as well as the argument passed by the action. Now mutation can alter the state with some new value.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/942de0cc41eab2a153b78c81a23226a7/href">https://medium.com/media/942de0cc41eab2a153b78c81a23226a7/href</a></iframe><p>After committing the changes we need to access the new value from the state. For that, we can fetch it directly but the convention is to use getters that are pure computed functions that get the state in the argument and return a particular part of it.</p><p>Whenever the value changes, we will get the updated value via this getter. Since these getters are computed they are optimized, so they are only executed when the variables used inside that function change.</p><h3>Redux</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W9NGfN1iP05oCx8o" /></figure><p>Redux also use the agnostic integration of the Flux system which enable us to use it with Vue, vanilla JS or any JavaScript library. In redux, again we have some initial state defined in the store.</p><p>Now the question is how will we mutate this state? For that we have actions. These actions are very different from Vuex’s actions.</p><p>In Vuex we defined business logic here, but redux actions are only simple objects that have two properties — type and payload that tells the reducer how to change the state.</p><p>Now this dispatched action will trigger some reducer that in turn will change the state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52494acf06e1e07e071323cc3fe73e66/href">https://medium.com/media/52494acf06e1e07e071323cc3fe73e66/href</a></iframe><p>Reducers are functions that receive the action object. Now inside this reducer, we will have to check the type to perform an update.</p><p>One thing to note here, the store object is immutable and you can’t change it directly. So how we will update the store? To update the state we need to return a completely new store object with the updated value.</p><p>We can use Immer, a package that allows us to mutate the object in the store. But technically it makes sure that we return a new object in the end.</p><h3>Making our life easier with Redux Toolkit</h3><p>Using redux is great, but we have to make some additional configs to make sure that we use it correctly.</p><p>Another alternative is to use Redux Toolkit, it is an opinionated way of using redux and takes care of some initial configs.</p><p>In the redux toolkit, we can create slices. These slices are basically modularized ways to access/update the state. In the end, all data in the store is stored in an object.</p><p>But we can create slices in this object to have separation of concerns.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18f00818bfdbb210114a4b1917e90214/href">https://medium.com/media/18f00818bfdbb210114a4b1917e90214/href</a></iframe><p>A slice takes some arguments, it takes name to namespace slices, initial state, reducers and “extraReducers”. Reducers are synchronous functions that update the store. We don’t need to cover “extraReducers” but they simply allow createSlice to respond to other action types besides the types it has generated.</p><p>As I have stated before, redux is synchronous, for anything asynchronous we have to a middleware thunk which enables us to create async functions. In a normal redux project we had to config it manually but the redux toolkit has thunk out of the box.</p><p>We can define a function that returns a function that gets a dispatch argument. With this, we can perform any async task and in the end call dispatch to store it synchronously.</p><p>Now we can register these slices using the “<strong>configureStore” </strong>function provided by the Redux Toolkit. We pass the imported slices and give them a name.</p><p>So counterSlice reducers and state will be namespaces under counter. In the end, we need to export the store and use it in the Provider HOC component at the root level only then our components can access these states.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/307e1f2ee026ed8d598acc7f5a374586/href">https://medium.com/media/307e1f2ee026ed8d598acc7f5a374586/href</a></iframe><p>React-redux package gives us useSelector hook which we can use to get the state and useDispatch hook to call the reducers and action creators to change the state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f26d4ef17c99c542a5149b74bd146136/href">https://medium.com/media/f26d4ef17c99c542a5149b74bd146136/href</a></iframe><h3>Conclusion</h3><p><em>“If the only tool you have is a hammer, you tend to see every problem as a nail.” </em>— Abraham Maslow</p><p>This is a quote by Abraham Maslow which refers to a concept commonly known as the ‘Law of Instrument’ or Maslow’s Hammer. It refers to an over-reliance on a familiar or favourite tool. Redux/Vuex can be very useful state management tools at times, but over-reliance can result in approaching problems in ways that are not always helpful or even destructive. So it always helps to have a basic understanding of a number of these tools and carefully contemplate the requirements before integrating one into your project. See you next time.</p><h3>Build composable web applications</h3><p>Don’t build web monoliths. Use <a href="https://bit.dev/">Bit</a> to create and compose decoupled software components — in your favorite frameworks like React or Node. Build scalable and modular applications with a powerful and enjoyable dev experience.</p><p>Bring your team to <a href="https://bit.cloud/">Bit Cloud</a> to host and collaborate on components together, and speed up, scale, and standardize development as a team. Try <strong>composable frontends</strong> with a <strong>Design System</strong> or <strong>Micro Frontends</strong>, or explore the <strong>composable backend</strong> with <strong>serverside components</strong>. <a href="https://bit.dev/"><strong>Give it a try →</strong></a></p><figure><img alt="https://cdn-images-1.medium.com/max/800/1*ctBUj-lpq4PZpMcEF-qB7w.gif" src="https://cdn-images-1.medium.com/proxy/1*ctBUj-lpq4PZpMcEF-qB7w.gif" /></figure><h4>Learn More</h4><ul><li><a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">How We Build Micro Frontends</a></li><li><a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">How we Build a Component Design System</a></li><li><a href="https://blog.bitsrc.io/the-composable-enterprise-a-guide-609443ae1282">The Composable Enterprise: A Guide</a></li><li><a href="https://blog.bitsrc.io/7-tools-for-faster-frontend-development-in-2022-43b6f663c607">7 Tools for Faster Frontend Development in 2022</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a0de9217bfd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bitsrc/a-vue-developers-guide-to-redux-4a0de9217bfd">A Vue Developer’s Guide to Redux</a> was originally published in <a href="https://medium.com/bitsrc">Bits and Pieces</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Visualizing Bubble Sort]]></title>
            <link>https://duoro.medium.com/visualizing-bubble-sort-c5ee6173c986?source=rss-40c78042157f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5ee6173c986</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[bubble-sort]]></category>
            <category><![CDATA[p5js]]></category>
            <category><![CDATA[visualization]]></category>
            <dc:creator><![CDATA[Ayushman Gupta]]></dc:creator>
            <pubDate>Fri, 09 Apr 2021 08:02:54 GMT</pubDate>
            <atom:updated>2021-04-10T00:58:11.941Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*taMQobXdSUzKepYse28b0w.png" /></figure><p>I’m pretty sure that you’ve heard about the bubble sort algorithm before. It is probably the simplest and weakest sorting algorithm. Honestly, I had never found algorithms interesting, but I was fortunate enough to stumble upon <a href="https://bost.ocks.org/mike/algorithms/">this article</a> by Mike Bostock. In this article, he explained how different algorithms can be visualized. He stated the point that you don’t need a data set to visualize it. You can use the elegance of maths and logic to create stunning visuals.</p><p>I searched through the internet and I found wonderful visual arts created by using simple algorithms. So I decided to unpack my paintbrush as start visualizing different algorithms.</p><p>Since I’ve never tried visualizing algorithms before, I wanted to start with something simple yet graceful and the only algorithm that I could remember from my college days was the bubble sort algorithm.</p><h3>Bubble Sort Algorithm</h3><p>There are numerous articles out there that can explain this algorithm better than I. But I’ll try to give a brief overview, so you don’t have to take the extra pain of clicking on the new tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q8HQg-53CO6T1x41aQNFUg.png" /></figure><p>So this is how bubble sort works. You take the first element compare it with the immediately adjacent one and switch them it meets your sorting criteria.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DHDtvscczS9UjacBbAJe_A.png" /></figure><p>Move to the next element and again compare it to the immediate next element. Repeat this process till you reach the end of your element. By this time you should have the largest or smallest element (based on your criteria) on the right-most side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WDKuSrYcUUz3249wMWZAOg.png" /></figure><p>The next time you loop through your elements you don’t need to consider the last element. This means we will be looping through the elements one less time than the previous one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S1-cDiN2yDKXLA-knsltYw.png" /></figure><p>Now that the boring part is covered, we can visualize data. By data, I mean the random values that I’ll generate.</p><h4>Sorting random heights</h4><p>I’m using P5.js here to visualize this algorithm. It’s a very powerful and yet simple JavaScript library to handle 2D and 3D processing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nl1TglkkygdLyNHPY8upGg.png" /></figure><p>Let’s take a look at the code. Here the two functions at global scope — setup and draw are provided by P5.js. The setup function runs only a single time at the start of the execution. As the name applies, this function can be used to set up the initial state of our processing. The draw function is called on every frame. So here we actually draw on the canvas.</p><p>We have three global variables — array, i and sortedArr. The array is where I’m storing the elements to filter them later on. i is the counter which tracks the loop progress and finally sortedArr an optional variable that I’m using to change the colour of sorted elements.</p><p><strong>setup() — </strong>The first line inside the setup function is createCanvas() which takes two arguments — width and height of the canvas. On the next line —</p><pre>array = new Array(width).fill().map(() =&gt; floor(random() * height));</pre><p>I’m creating a new array with elements number equals to the width of the user’s browser and filling them with random values from the range of 0 to the height of the browser.</p><p><strong>draw() — </strong>Inside the draw functions, after setting the background colour and I’m having an if check which will run the bubble sort algorithm.</p><pre>if (i &gt; 0) {<br> for (let j = 0; j &lt; i; j++) {<br>  if (array[j] &gt; array[j + 1]) {<br>  const temp = array[j];<br>  array[j] = array[j + 1];<br>  array[j + 1] = temp;<br>  }<br> }<br> sortedArr[i] = true;<br> i--;<br>}</pre><p>Here an if condition is required to make sure it stops the sorting after all the elements are sorted and not continue with each subsequent draw method. Inside the loop, I’m checking the two adjacent elements and switching them based on the sorting criteria [bubble sort].</p><pre>for (let i in array) {<br>    stroke(42, 178, 138);<br>    line(i, height, i, height - array[i]);<br>}</pre><pre>if (sortedArr[i]) {<br>      stroke(24, 98, 76);<br>      line(i, height, i, height - array[i]);<br>    }<br> }</pre><p>In this final piece of code, I’m drawing the lines, based on the height of the element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nGNffMmq1VhgWffOI3qZtg.gif" /></figure><h4>Sorting random grayscale</h4><p>Instead of sorting height’s on lines, let’s sort grayscale. A grayscale value is 2⁸ bits. Meaning it can hold value from 0 to 255. 0 being the absolute black and 255 being absolute white.</p><pre>array = new Array(width).fill().map(() =&gt; floor(random() * 255));</pre><p>Here I’m generating random value from 0–255.</p><pre>for (let i in array) {<br>   fill(array[i]);<br>   rect(i, 0, 2, height);<br>}</pre><p>This time I’m creating rectangles of width 2 pixels and height of the user’s browser. Filling them with randomly generated grayscale value in my array.</p><p>I couldn’t upload the GIF for grayscale sorting. <a href="https://ayushman-git.github.io/bubble-sort-visualization/pages/grayscale.html">Click here for a preview.</a></p><h4>Sorting random circles radii</h4><p>If we are sorting circles based on their radius and drawing them from a single point of origin, then it’s useless to sort them because you will just change the circle’s position and since all circles’ centre is the same, it won’t change the visual appearance. So here I changing the colour of sorted circles. It came out pretty good visually in the end, even though it doesn’t make much sense sorting them like this.</p><pre>array = new Array(noOfCircles)<br>    .fill()<br>    .map(() =&gt; floor(random(1, height - 50)));</pre><p>This time I’m filling the random values from a range between 1 to height — 50 to make sure the circles are not overflowed from the browser’s view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ViS_pMAdh8EjsKvFH83PEg.gif" /></figure><h3>Conclusion</h3><p>Visualizing algorithms is quite fun and I’ll be visualizing some advanced algorithms in the future. You can use P5.js or unity for visualizing these algorithms. If you find these sort of things fun, read the article that I mentioned in the starting. I suggest you check this <a href="https://www.youtube.com/user/Cercopithecan">youtube channel</a> (I don’t know anything about this guy besides that he creates wonderful simulations in unity) as well. You can also visit the <a href="https://github.com/ayushman-git/bubble-sort-visualization">GitHub repo</a> for the complete code. See you next time with some other visualization.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5ee6173c986" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Proto — a project manager made with Next.js]]></title>
            <link>https://javascript.plainenglish.io/proto-a-project-manager-made-with-next-js-da2d82eeee37?source=rss-40c78042157f------2</link>
            <guid isPermaLink="false">https://medium.com/p/da2d82eeee37</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[project-management]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Ayushman Gupta]]></dc:creator>
            <pubDate>Mon, 29 Mar 2021 13:35:26 GMT</pubDate>
            <atom:updated>2021-03-29T17:33:30.663Z</atom:updated>
            <content:encoded><![CDATA[<h3>Proto — a project manager made with Next.js</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ojHyC9I-5O3nWDZcInUNrA.png" /></figure><p>For several years, I’ve been on the hunt to find the perfect tool to manage my projects. I’ve used Trello to track my tasks, notion for writing notes, and Milanote for organizing my ideas. These wonderful tools get the job done for the most part and keep you productive.</p><p>When working on a personal project, I’ll create notes and store references in notion, then I’ll use Trello to track my tasks. I’ve been using this workflow since the launch of notion back in 2018. But the approach of moving from tool-to-tool adds an extra layer of unnecessary work. I wanted a single tool to handle these needs. You could implement Trello&#39;s kanban board, but I still don’t prefer Notion to track my tasks.</p><p>Recently I fell in love with Milanote. It’s a pretty neat tool that lets you jot down ideas and transpile them into boards and nodes of images, to-dos, columns, and a lot more. But it’s not all paradise here, Milanote doesn’t provide a generous quota for images, links, and files that are uploaded on their free tier. If you want to use it for multiple projects and needs you’ll have to buy a paid subscription. If you are someone like me who likes to build a lot of projects, you will love Milanote and I recommend you give it a spin. There’s also tools that are solemnly built to manage projects, like — Plutio, ClickUp, etc. These tools work wonders if you are working on a professional project with a team. But for a small personal project, they are overkill.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*PsQ3hrSExhehuk6nlF7JvQ.gif" /></figure><p>The idea to manage personal projects with pieces that are genuinely needed gave birth to <strong>Proto. </strong>I created Proto to manage my small personal projects. You can take a look <a href="https://proto-lilac.vercel.app/">here</a> or click <a href="https://github.com/ayushman-git/project-manager">here </a>for the GitHub repo.</p><h3>Foundation</h3><p>The plan for <strong>Proto</strong> is quite simple. Create a tool that lets you track your project in harmony and don’t add an extra layer between your idea and execution. For managing a personal project you basically requires three things — idea, stories and references. With Proto, I try to include these three elements. Proto has shortcuts (links that are necessary for the project like — firebase console, azure, netlify, etc), which I may need frequently. A scrum board where I could track my tasks and a list of websites for reference.</p><p>Up until now, I’ve mostly used Vue.Js to create my front-end projects. But for Proto, I wanted to shake things up. Recently I was exploring NextJs &amp; Gatsby and found them very appealing. So I went through their documentation to get a basic idea of how they work. Finally, I decided to use <strong>NextJs</strong> for Proto. Besides NextJs, I’m using <strong>firebase authentication</strong> for user authentication, <strong>firebase firestore</strong> to store user’s data, <strong>SASS</strong> for styling, <strong>js-cookie</strong> &amp; <strong>nookies </strong>to handle cookies, and, finally, <strong>react-spring</strong> to sprinkle style in proto.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FqI10HxIDI72tgrXYH1WBg.png" /></figure><h3>Design and Layout</h3><p>There are only three pages in <strong>Proto</strong>. First is a landing page, which is a bare minimum page and let user login/signup using their Google or GitHub account. I haven’t put much time into styling the landing page yet. It’s down on the road. The next main two pages are the Home and Project page.</p><h4>Home Page</h4><p>This is the page user is displayed after the user has logged-in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*tBkkorpDDiN5M1SeGuxiKg.jpeg" /></figure><p>Let’s go from top to bottom here. On the topmost side, there’s our navbar. It has a logo and on the right user’s profile. Below the navbar, there’s a module that displays the details of the main project. The idea was to have the main module that will display the details of the project, the user is currently working on. Based on visual hierarchy this module will be the dominant one, then there are small modules that contains inactive projects or future projects.</p><p>The main module which displays active project have tasks ordered based on the type showing on the right, some stats in the middle and on left there are shortcuts and description below project’s name. I considered these as essential information which the user may need.</p><p>Below the main module, multiple mini-modules contain information about the projects which the user is not currently working on. Inside these modules, I’m showing only the project’s name and deadline.</p><p>Based on this skeleton I created my Figma design.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBdl9InDXFRhMNrayet9Ew.png" /></figure><h4>Project Page</h4><p>Whenever a user clicks on any project, he/she will be redirected to the project page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*6r2eyf_AlwN8FADR7mxSOQ.jpeg" /></figure><p>The project page is the bread and butter of <strong>Proto</strong>. Navbar stays the same with one exception of a back button on the left side. Below the navbar, the main module remains the same as the main module from the home page. I’ve added a button that lets the user mark this project as an active project, and a circle through which the user can change the theme.</p><p>Then there’s a scrum board. The main idea of the scrum board is to convert the whole project into stories. An example of the story can be ‘<em>User can add projects</em>’. Now this story will have multiple tasks which can be tracked.</p><p>So inside the scrum board, there are four columns — <strong>stories, idle, doing and done</strong>. The last three will be used to track the task’s progress. User can click on a story to create a task inside that story. The task can be then moved between different status.</p><p>I was thinking of adding a section on this page that will deal with the references. So the user can add websites for reference here. I wasn’t able to implement it yet but I’ll be adding it soon.</p><p>In the end, two buttons will mark the project as completed or delete the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CcrNi2ehxTS8ZXbt9eAdBw.png" /><figcaption>This is the Figma design I came up with for the project page.</figcaption></figure><h3>Implementing Authentication</h3><p>For authentication, I’m using firebase auth. Firebase auth is quite easy to setup. But setting up authentication for NextJs is a little different because of how NextJs works. NextJs is built with Node.Js, which allows it to perform server-side rendering or static site generation. So it’s a server as well as a client. This idea was a little difficult for me to wrap my head around.</p><p>Anyways, it means that you need to initialize firebase-SDK as well as firebase client. Let’s look at the three files that deal with authentication.</p><h4>firebaseClient.js</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OAyf0Sm04Ae7VW3wtaAWfQ.png" /></figure><p>This file is where I’m initializing the firebase client. We need a config object which can be extracted from the firebase console. In this file, we are exporting a function which first checks whether there’s an existing app in the firebase, if yes then it does nothing, otherwise it uses the initializeApp function to initialize the firebase client. Here we are not required to hide the config for the client-side. The FIREBASE_CONFIG object’s visibility to the user doesn’t change anything.</p><h4>firebaseAdmin.js</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ukg03Y1eZun5u9N_uyBHJQ.png" /></figure><p>In this file, I’m exporting the verifyIdToken function. This function takes a token as an argument, then it initializes the firebase-SDK so that we can use server-side functions. In the end, it performs verification of the Token to validate the user.</p><p>We will be executing the verifyIdToken function on the server-side before sending the pages to the user.</p><h4>auth.js</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Nd0LzVdcxSLmthXyOavkQ.png" /></figure><p>In auth.js, inside the useEffect hook which will execute its callback function on being mounted. I’m executing the onIdTokenChanged function that is executed every time the token changes. So every time user log-ins or signs-out. The onIdTokenChanged function pass argument in its callback function the user’s information. So if a user is logged in, it will contain information regarding the user and if the user hasn’t logged in, it will be null.</p><p>So if there’s no user, it will delete the cookie which stores token and user’s information and also changes the state of user to null. But if there’s a user, it will set the state of user variable with the user’s information and also set cookies regarding the same.</p><p>This function exports two things — one is a context provider with the value user, and the other is the userAuth hook which consumes that context.</p><h4>Login via Providers</h4><p>I’m letting user login/signup using their Google and GitHub account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LnJyulrhKryaHwR8aJ6HJA.png" /></figure><p>To achieve that I’m creating providers using firebase auth functions. Then I’m passing that provider as an argument in the signInWithPopup function.</p><h3>Project structure</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*4QHGew9V1-O7iPbRMkPpnA.png" /></figure><p>I tried to follow the DRY principle while organizing the proto structure. <strong>assets </strong>folder contains the theme.js file which exports the theme details. <strong>auth </strong>folder has three files — auth.js, firebaseAdmin.js and firebaseClient.js, which are required for authentication. Then there is a <strong>components </strong>folder that contains every component used in proto. The <strong>HOCs </strong>and <strong>hooks </strong>are used to differentiate logic from the components. The <strong>pages </strong>folder is responsible for routing and determining which page to display. The <strong>sass </strong>folder contains global styling for the project.</p><h4>Protected pages</h4><p>Let’s look at the home page. The home page is protected, so the only user who has signed in can access it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tfdZXPmAuRYLdQ_URTK33A.png" /></figure><p>Next.js provides a getServerSideProps function. It will pre-render this page on each request using the data returned by getServerSideProps. So inside this function, we can check whether the user has access to this page or not. Here I’m accessing the cookie that I stored when the user first logs in. Then I’m using the verifyIdToken function exported from firebaseAdmin.js<strong> </strong>to check the validity of the token. If it is legit, it will forward the user’s information as a prop to our client. But if there’s an error it will redirect it to the landing page (‘/’).</p><p>On the client-side, I’m fetching user’s projects from firestore and displaying them to the user.</p><h3>Styling &amp; Animation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*JkVHWp7vkPSh_me3aufZ-g.gif" /></figure><p>For basic styling, I’m using SASS. SASS is a CSS preprocessor, meaning it has everything CSS has and more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*9_C4iTPaEZ4Ytau-4c9fmw.png" /></figure><p>Currently, I’ve four sass files. The first one deals with fonts — like changing font-size, font-family etc. The _globals.scss deals with things that are needed globally — like changing default input, textarea styling etc. The _vars.scss have variables, that may be needed in multiple places.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ouijdb2hBpKyKZ7LYzaMYw.png" /></figure><p>Finally the main.scss file which includes every other scss files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PW0mFkfIn-yWki5Pku6ncg.png" /></figure><p>For individual components, I’m using scss modules, which comes out of the box for us to use. Let’s look at one of our components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cHidu0wQ6qwl41s4ilkNpw.png" /></figure><p>Here, I’m importing styles from the <strong>EmptyScreen </strong>scss module. Then applying it as a className using syntax {styles.&lt;class name&gt;} . This will create a random name for the class which makes it accessible only to the component it is imported in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*rG-X7n5-zS3E2pOC68cFBQ.png" /></figure><h4>React-spring</h4><p>Let’s make proto good to look at. For adding transitions and animations, I’m using <strong>React-spring</strong>. It&#39;s an animation library that operates a little different from typical animation libraries. Most of the animation libraries transitions from point A to B with some curves on a fixed duration. Changing the curve determines the flow of the animation. But you don’t have to worry about duration or curve in react-spring. You only need to modify the values, it will calculate the duration and curve based on real physics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*UaiztkX2asBvPv-K6oau_A.gif" /></figure><p>You can also change the feel by changing the config, and modify mass, tension, friction and so on. For more information go through their <a href="https://www.react-spring.io/">documentation</a>.</p><p>Let’s take a look at the <strong>SecondaryCard </strong>component to figure out how react-spring works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3QSuH9L4tlEQwM08kDjK9Q.png" /></figure><p>We are importing useSpring and animated from react-spring. After that, we are creating a constant onMountTransition which is using the useSpring function. Inside the useSpring function, we are passing an object to determine which properties to transition. Inside that object, we define the initial values of properties by adding a key with an object containing the initial values. Outside that object, we can determine the end values.</p><p>Then we need to convert the HTML element we want to animate to a special react-spring element using the animated prefix. So in the above code, I’m converting &lt;div&gt; with &lt;animated.div&gt; and then passing the onMountTransition constant in the style attribute.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tUxElE2llWN0EibWvk4Z9A.gif" /><figcaption>Changing scale and opacity</figcaption></figure><h4>HOC to add a hover effect</h4><p>We can encapsulate the whole animation in a HOC and add that animation to its children. So we don&#39;t have to create the same animation over and over again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lAjiwJUMJqLO0WYAiKYwbw.png" /></figure><p>In this HOC we are encapsulating the children component with another div. This div is the special spring div because we have added the animated prefix.</p><p>Unlike last time we are destructuring the useSpring function with two values — element is the animation itself, and setElement function to modify the element’s animation, just like useState hook. Inside the useSpring function, I’m passing the object like last time to set initial and end values of animated properties. But this time we are adding onMouseEnter and onMouseLeave events on the animated div with a function hoverHandler. This function is changing the values of the element with setElement function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/297/1*i3qNluL75v4hDOBh-o6m3A.gif" /></figure><p>So every time user hovers the card, the element’s Y position will be changed to -3px, thus making it move upward.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_VAU542miLVXXOvtiLFL9Q.gif" /><figcaption>You can also make something cool like this using react-spring.</figcaption></figure><h3>Deployment</h3><p>I deployed proto on vercel. The whole process of deployment was pretty straightforward. Go to vercel.com &gt; login &gt; create a new project &gt; link GitHub &gt; attach the repo &gt; finally add the environment variables in the settings.</p><p>Vercel also provides multiple URLs, one would be your main URL and others could be used for testing the new commits before permitting them to the main URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*wGnBz9_2mU_BljHQd_rJ3Q.gif" /></figure><h3>Conclusion</h3><p>Proto was my attempt to create the perfect project manager. It’s a little ambitious project and far from being a finished product that could be used by consumers. I only implemented 20% of what I initially envisioned. But this 20% made me learn a lot of things which I never knew. This project made me step out of my comfort zone and try things that I normally try to stay away from.</p><p>I mostly used Vue.js before so I’m still pretty new to React scene. But I’m finding new things each day about react. This project helped me a lot to transition myself from my vue mindset to react.</p><p>This project is also not a one-time effort, I’ll be coming back to it to improve this project, add new features and implement new techniques that I’ll learn on the way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da2d82eeee37" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/proto-a-project-manager-made-with-next-js-da2d82eeee37">Proto — a project manager made with Next.js</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Chrome extension with Vue.js and Node.js]]></title>
            <link>https://javascript.plainenglish.io/creating-a-chrome-extension-with-vue-js-and-node-13ddafcf0d84?source=rss-40c78042157f------2</link>
            <guid isPermaLink="false">https://medium.com/p/13ddafcf0d84</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Ayushman Gupta]]></dc:creator>
            <pubDate>Wed, 24 Mar 2021 06:36:56 GMT</pubDate>
            <atom:updated>2021-03-25T14:52:49.249Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cU5qrgkS3_dDo1gYlm02yw.png" /></figure><p>Penumbra is a new tab replacement for chrome in the form of an extension. It overrides the existing new tab to give some very minimal add-ons or features.</p><p>The main problem that I have with default new tab is that it is little too simple. It limits users to only eight shortcuts and it uses favicons of those websites for the preview. The favicons are usually very small (16×16px) and when they are used anywhere other than the tab they look blurry. This pet peeve forced me to create my own Chrome extension with subtle traits that I like.</p><p>There’s plethora of new tab replacements out there. But they either try to have prolific features that it becomes nuisance to use or so little that I start wondering what’s the point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*lpW-wLZrQ_K3XqcytkV1Cg.gif" /></figure><h3>Project Structure</h3><p>Now let’s talk about how this extension works. <strong>Penumbra</strong>, like most of the web apps have two parts— frontend and backend. The front end is where user can interact with extension and the back-end which sends high quality icons of the website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*dXPMzch8mwkabc4rXiJa2g.png" /></figure><p>On the client, I’m using VueJs to create UI. VueJs is a JavaScript framework used to create reactive and modular UIs for the web.</p><p>The UI of penumbra is quite minimal and similar to the default one with few exemptions. It lets you add websites (more than 8), it displays weather and a random quote on each request. You can also change background color if you wish.</p><p>On the back-end side, I’m using Node with express to create API endpoints and a logo-scraping NPM package to fetch the icons of the websites. Node is a JavaScript runtime that lets you execute JavaScript on your system instead executing inside browser. ExpressJs lets you easily create API endpoints. You can also create API endpoints with vanilla Node but its HTTP module is little ugly to use. Using express can save a lot of time.</p><h3>Back-End</h3><p>The back-end for penumbra is quite simple. I’m creating an API endpoint where user can send the URL of the website he/she wants to add. Then there’s a NPM package <a href="https://www.npmjs.com/package/logo-scrape"><strong>logo-scrape</strong></a> which scrapes the icons of that website and returns an array of objects containing address of the images. There’s also a JSON file that I created containing image addresses of some popular websites. Then I’m merging both arrays — one from JSON file and the other fetched using logo-scrape package and sending it back to the client.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eeu-J9wrt7FCtWwscjDqcw.png" /></figure><p>After importing necessary packages I’m creating a port constant which stores the value of port available in the system or 3000 if there’s none. When hosting most of the time the host provider system have a port for our app stored in the PORT environment variable, and we can use that port to connect to internet.</p><p>Then I’m creating a new instance of express and storing it in app constant. Just after that there’s three app.use() functions. These functions allow us to run some function after receiving each request and before sending each response. These functions which run after every request are known as middlewares. So there’s three middleware functions that are executing after every request. The first one is cors(). It is a NPM package that deals with the CORS policies. It basically allows cross domain information interchange with REST. For more information regarding CORS you can visit <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS">MDN docs</a>. The second and third middlewares deals with the parsing body of a REST request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*E7ba_VDoaxvuStG0mloEug.png" /></figure><p>app.get() takes two arguments, first is the path and the second is a callback function that will execute on every GET request hit on the provided path.</p><p>In our case the first argument is a “/” which means the root domain. So if this site is hosted on www.example.com then the callback function that we provided as a second argument will run every time user visits this page.</p><p>Our callback function takes two parameters — req and res. The first parameter is an object which contains all the information regarding that particular request. So header details, body if it&#39;s a post request and a lot more. The second parameter is also an object which contains methods dealing with sending response to the user. Here we are using res.send() method and inside it, we are sending an HTML element.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S6e9LgQsBSOtvB7Jy-iJ-g.png" /></figure><p>app.post() is where our main objective of fetching image is executed. Like app.get() method it takes two arguments, one path and other a callback function. In this case path is “/url”, so it will yield into www.example.com/url. The callback function will execute on every post request made on this path. Inside our callback function there’s an async IIFE (Immediately Invoked Function Expression). IIFE is just a fancy name for a function that is immediately invoked/executed. You just put the whole function declaration inside parenthesis followed by another set of parenthesis. Inside our async function we are storing url sent from client. Then we are using LogoScrape.getLogos() function and passing the URL, after that we get an array of objects containing image address which we are stored inside logos.</p><p>There’s an if block which adds the image address from JSON file (hdLogo) on first index of the logos array. In the end we are sending the logos array containing the image’s address from most relevant to the least relevant. For sending the array back to user we are using res.send() method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8CohmSLpCNt12DI0u2H1NA.png" /></figure><p>app.listen() is the last method we are using. This function is pretty self-explanatory. Here we are listening to the port and executing a callback function. This function basically starts our server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qDxe6SLQUDAAffQkzI_gzQ.png" /></figure><h3>Front-end</h3><p>The client-side UI is pretty straightforward. We have a weather notification on top left. In the middle there’s a random quote, below that there’s your website shortcuts. On the bottom right there’s a lock button which locks/unlocks all settings like prompting use website delete while hovering on cards, changing temperature unit from Celsius to Fahrenheit and vice-verse and also changing background color. There’s also a container at the bottom which appears when you hover near it and it contains several themes you can pick from.</p><p>Let’s diversify each UI feature into separate component.</p><h4>Components</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*uYyakVjHA-eYq1IlsH55Ig.png" /></figure><p><strong>Weather</strong> — Inside our main App.vue we have a weather component. I’m using an IP address API here to get the location of the user. I could’ve used JavaScript built in Geolocation web API to get the user’s location which could’ve been more precise and faster, but that would open a prompt where user have to give the permission to use Geolocation. This would add another layer of user interaction. So I opted to get user address with IP address API and use that location to get the weather data from weather API. This is little slower as we are using two APIs back to back, but the good thing is that user don’t have to do anything. Weather will be displayed without user have to click anywhere.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2S3VjfC8XYgzS34h9CnMMg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EK-BQXJ-3GYmlHMFivWPKg.png" /></figure><p>In this component, we have a prop <strong>type </strong>which determines whether user will be able to change temperature unit. Then we have two variables in this local state. <strong>weatherData </strong>and <strong>showMetric</strong>, weatherData will be used to store weather data and showMetric will determine the type of unit.</p><p>We are not using any database to store the user’s preference, instead we are using <strong>localStorage</strong>. So inside created hook, we are checking whether there’s user preference is stored in localStorage, if there’s something use that if not then use metric unit.</p><p>Then when our component is mounted, we are executing <strong>fetchWeather </strong>function. This function first gets user’s location from IP address API, then I’m using that data to fetch the weather which I’m storing in weatherData variable.</p><p>We also have a <strong>changeMetric </strong>function which will be executed every time user clicks on the weather component. It changes the showMetric variable and store the new one in localStorage.</p><p><strong>Information — </strong>This is another simple component which displays a new quote on each request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C8F_VUFX99UHrD9804nVSw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2KOjWrXBB21PrxMY7mOYCw.png" /></figure><p>Here we have three variables in local state — <strong>qod, author</strong> and <strong>showAuthor</strong>. qod is where I’m storing the random quote, author stores the author name and showAuthor is a Boolean which determines whether to show the author or not.</p><p>Inside mounted hook we are fetching the random quote with a constraint of maximum length being 80.</p><p><strong>WebsiteModule — </strong>This component is responsible for displaying the websites to the user and let user delete, change icon, refresh etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6jyH-4OGNB2BJRkjke44FQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eIuCyenRHZawsISL1TxiMQ.png" /></figure><p>This component receives <strong>websiteObj </strong>as a prop which includes website name and array of icons which user can switch through. If the prop of lock is true it will prevent any changes, otherwise it will emit events of deletion, changing icons etc. Then these events are handled in <strong>App.vue.</strong></p><p>There’s few other components like BackgroundColor, Lock etc. There’s also a component <strong>InputModal </strong>where I create the POST request to the get the HD icons from the back-end that we created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PVJyBoBWidqhbsKByfQqog.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cfnoe-rez2RhXxYNeqRANQ.png" /></figure><p>The <strong>fetchIconsFromAPI </strong>creates a post request which contains URL user has entered (after being validated). Then I’m emitting an event when new icons have been received.</p><p>Then inside App.vue, I’m catching that emit and executing a function <strong>addMoreIcons </strong>with icons received from post request as argument. During execution, it stores the new icons inside the <strong>initialWebsites </strong>array. This array contains objects of websites user has added and stores them in localStorage if any change is made inside it.</p><h3>Publishing on Chrome web store</h3><p>For publishing it on chrome’s web store, first we need to make some changes in our new tab. Currently, it is only a website not an extension. To make is an extension we would need a <strong>manifest.json </strong>file inside the root directory of the build.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*p1EknCz16p2UrdGSIyFHJw.png" /></figure><p>First we need to build our vue app, for that we need to run <strong><em>npm run build. </em></strong>It will build our app and give us a dist folder.</p><p>Inside this dist folder we will create our manifest file. This manifest file will tell chrome about our extension.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mM-khVIQSrKphX-r_lSB8g.png" /></figure><p>Here we will give our extension name, version, description etc. Two important things for our extension is <strong>chrome_url_overrides</strong> and <strong>icons. </strong>The chrome_url_overrides is an object which overrides the existing URLs, in our case it&#39;s the new tab and it should point to our main index file.</p><p>The icons also is an object, here we declare the icons of our extension of different sizes.</p><p>Different types of extension requires different parameters inside manifest. You can look at official <a href="https://developer.chrome.com/docs/extensions/mv3/manifest/">documentation here</a>.</p><p>Now for hosting you will have to go to <a href="https://chrome.google.com/webstore/devconsole/">Chrome developer console</a> and pay a one-time fee of $5. Once done, click on add item and attach the zip file of the dist folder here. Then you’ll need to submit some details about your extension and publish. It takes some time for review, after some time your extension will be deployed for others to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*bXhxHXyEOEBe6KWlART5rA.gif" /></figure><h3>Conclusion</h3><p>Penumbra was a little side-project that I created to have a new tab that works for me. The whole experience of building this new tab was pretty straightforward, I didn’t try to do anything extreme. But it doesn’t mean that I didn’t learn anything new. I figured out how to create an API endpoint and what problems arise while creating one. On the front-end I tried to keep the whole structure DRY and simple. Finally, learned how chrome extensions really work and harness chrome features using manifest. I’ll be building some more complex extensions in the future. You can try this extension yourself from <a href="https://chrome.google.com/webstore/detail/penumbra-newtab-minified/gfcknafpdhcijijjbkekflmpfagdcdgd?utm_source=chrome-ntp-icon">here</a> or go through codes in <a href="https://github.com/ayushman-git/newtab">GitHub repo</a>.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13ddafcf0d84" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/creating-a-chrome-extension-with-vue-js-and-node-13ddafcf0d84">Creating a Chrome extension with Vue.js and Node.js</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Discord Bot with discord.js]]></title>
            <link>https://javascript.plainenglish.io/creating-a-discord-bot-with-discord-js-2f9f7a1a9d80?source=rss-40c78042157f------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f9f7a1a9d80</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[discord]]></category>
            <dc:creator><![CDATA[Ayushman Gupta]]></dc:creator>
            <pubDate>Wed, 25 Nov 2020 13:15:15 GMT</pubDate>
            <atom:updated>2021-05-13T09:15:07.771Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rvh7SsihchvuR0Y77itWVw.jpeg" /></figure><p>Let’s start by talking about <strong>astronomia.</strong> Astronomia is a discord bot that can provide news, give information about celestial objects, suggest random movies, and a lot more. You can go to <a href="https://ayushman-git.github.io/astronomia-site/">this site</a> to explore all its commands.</p><p>The astronomia project was perhaps the most exciting project that I worked on. It’s because of two reasons — first, I got something to build that includes astronomy and astronomy always gets me hyped up; the other reason being I get to use so many technologies in a single project. I used several APIs to get data and if there was no API, I scrapped data with <strong>puppeteer</strong>. I also used <strong>Firestore </strong>for some cool stuff and finally the <strong>discord.js </strong>npm module to interact with Discord. I’ll talk about all those technologies and how they helped me to build astronomia.</p><h3>What is discord.js?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sC1_F3ZD4dVXWPrzPSovrg.png" /></figure><p>Before diving into discord.js, let me briefly explain <strong>Discord</strong>. Discord is basically slack, but marketed towards gamers, though it can be used by anyone who wants to hang out with their friends online. Users can chat with each other in text channels or join voice channels to talk with other members.</p><p>With that out of the way, let’s talk about <a href="https://discord.js.org/#/"><strong>discord.js</strong></a>. Discord.js is an npm package that interacts with discord API. It is based on Event-Driven Architecture, so if any user on the discord sends a message, that message can be caught in the discord.js API. It is not limited to messages, we can catch almost every activity like — user joining server, reactions to messages, text channel creation and much more. It is also possible to make a bot do anything that a server’s owner is capable of (except server deletion) given the bot has proper permissions.</p><h3>How does the Discord bot work?</h3><p>Let’s take a minute to understand how a discord bot works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xxIJOSJbuUcUtSxzCvtYCw.jpeg" /></figure><p>So the user enters a message in the discord client, then that message is sent to our server via discord API, where our bot is hosted. The server then executes some codes based on the command sent by the user.</p><p>Here, we will take the example of the <strong>.hi </strong>command of our bot. Whenever user types <strong>.hi </strong>is discord, an event is emitted by the discord API which we catch with —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4421e635955dcefaac83668ff21f06b/href">https://medium.com/media/d4421e635955dcefaac83668ff21f06b/href</a></iframe><p>The first challenge is to determine whether the message sent was a regular message or a command meant for <strong>astronomia bot</strong>.<strong> </strong>So I wrote a condition which ignores anything that doesn’t start with a <strong>“.”, </strong>which is a prefix that I picked.</p><p>After detecting its a command meant for the bot, I’m breaking down the message into command name and argument. The first letter after <strong>“.”</strong> is considered as a command and everything after that is converted into an array which will be used as arguments for commands.</p><p>After detecting its a command meant for the bot, I’m breaking down the message into command name and argument. The first letter after <strong>“.”</strong> is considered as a command and everything after that is converted into an array which will be used as arguments for commands.</p><p>So when the user enters <strong>.hi,</strong> at the server-side, the bot is randomly selecting a greeting word from an array that I created and it gets sent back to the user via discord API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*G5QJIy4ADLZMPnajD8LFwg.gif" /></figure><p>If we look at the whole concept, it’s not that complicated. I’m identifying commands sent by the user and executing a specific function which returns the processed message back. But what happens when astronomia doesn’t have data that the user is requesting for? It gets a little complicated when we have to fetch data to send it back to the user.</p><h3>Getting data</h3><p>In the previous section, we explored a simple <strong>.hi </strong>command, which honestly is not that interesting. In this section, we will talk about two more commands — <strong>.explore </strong>and <strong>.wallpaper.</strong> These commands are a little bit more intriguing to understand.</p><p>The <strong>.explore </strong>command takes an argument. So a proper syntax would look something like this — <strong>.explore titan</strong> and it will return this as a response.</p><figure><img alt=".e is a shorthand for .explore" src="https://cdn-images-1.medium.com/max/958/1*1uE5hlKQdN2WzF2MMQv6Ig.gif" /><figcaption>Here .e is a shorthand for .explore</figcaption></figure><p>So what’s going on here? Actually a few things. Let’s break it down. As soon as the user sends this command, the bot is making a <strong>GET </strong>request to <a href="https://api.le-systeme-solaire.net/en/">The Solar System OpenData</a> API, which is an API containing data about celestial objects in our solar system. After identifying the explore command, astronomia is sending a request to that API which responds back with the JSON data about Titan moon. This JSON data looks something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ddbd8ff51465f99f53ad05e82fc7942/href">https://medium.com/media/4ddbd8ff51465f99f53ad05e82fc7942/href</a></iframe><p>It contains a lot of cool stuff, but there are two things missing — an image of titan and a brief description. To add these two, I manually collected images and descriptions from the internet for well-known celestial objects which included all eight planets, the sun and few popular moons, and stored them in a JSON file.</p><p>So whenever a user hits <strong>.explore titan </strong>command, the bot is fetching data from API as well as taking data locally from the JSON file and returning the proper message with all sorts of data.</p><p>Until now, we have only used APIs to fetch data, but what are we supposed to do when there’s no API or there’s some restrictions in using API. That was the case when I was implementing the wallpaper feature.</p><p><a href="https://wallpaperscraft.com/catalog/space">Wallpaperscaft</a> have some great astronomy wallpapers, but they had limited requests for API calls and some CORS restrictions. So I installed puppeteer, which is a npm package for scrapping data with chrome and scrapped all the wallpaper’s URL related to astronomy.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51b0ddfe8420065f914db4949c0c7f26/href">https://medium.com/media/51b0ddfe8420065f914db4949c0c7f26/href</a></iframe><p>This small script made it possible to collect 1200+ wallpaper URLs. Let’s break the above code to have a better understanding.</p><p>I’m importing <strong>fs </strong>modules as I’ll be storing the fetched URLs in a file. The second module is <strong>puppeteer</strong> which I’m using inside an async function. Puppeteer features must be used inside an async function because it takes some time to complete tasks like — opening chrome, opening tab etc.</p><p>Then I’m using loop to traverse through each page. On line 11 and 12, I’m launching chrome and creating a new tab. After that, I’m going to the URL provided.</p><p>From line 20 to 26, <strong>evaluate() </strong>function is returning the URLs of wallpapers on that page and storing it in <strong>const result</strong>. Then I’m making some adjustments to the URL to lead to the correct path. Finally I’m storing these URLs in wallpaperUrl.js file using <strong>fs.writeFile()</strong>. Now I can use these 1200+ wallpapers and send it to users.</p><h3>Auto Functions</h3><p>Every command that I explained till now executes a piece of code after user enters a certain commands. But for something like news updates, a function should be executed periodically. Let’s explore these auto functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Aixf4bct7EmvUQPtpBEl0g.jpeg" /></figure><p>With <strong>setInterval()</strong> functions, I’m passing a callback function. That callback function makes a request to the <a href="http://hubblesite.org/api/documentation">hubble site API</a> every hour, after getting the response I’m checking whether the JSON received is the same as JSON stored in the firestore DB. If it’s the same then the function will return and do nothing else. But if there’s a difference between the JSON received and the JSON in firestore, it will process that data and sends it back to the Discord. Finally the JSON stored in firestore will be replaced with the JSON that was fetched with axios. This whole process repeats every 60 minutes and that’s how users get the latest news.</p><h3>Conclusion</h3><p>It’s only the beginning, I’ve plans to scale up this bot and add lots of new commands and features. If you have some ideas, please share them with me.</p><p>This idea was started as another week-long project. But I kept coming back to it to add new features or to improve upon existing ones. This project helped me to explore unexplored territories and helped me to face real-world problems like — what should we do when there’s no API for a service, how to host Node.js apps, and a lot more. This project also has its challenges, for example, it took me a full day to figure out how to scrape data for quotes from Goodreads.</p><p>You can visit this <a href="https://ayushman-git.github.io/astronomia-site/"><strong>site</strong></a><strong> </strong>to explore more about the bot or you can <a href="https://github.com/ayushman-git/astronomia-bot">contribute </a>to this project. If you love astronomy you will love this bot. I’ll end this article with one of my favorite quotes.</p><blockquote>“”The cosmos is all that is or ever was or ever will be. Our feeblest contemplations of the Cosmos stir us — there is a tingling in the spine, a catch in the voice, a faint sensation, as if a distant memory, or falling from a height. We know we are approaching the greatest of mysteries.” — Carl Sagan</blockquote><p><em>More content at </em><a href="http://plainenglish.io/"><em>plainenglish.io</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f9f7a1a9d80" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/creating-a-discord-bot-with-discord-js-2f9f7a1a9d80">Creating a Discord Bot with discord.js</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a Portfolio Website with Vue.js]]></title>
            <link>https://javascript.plainenglish.io/building-a-portfolio-website-with-vuejs-20d908973fe7?source=rss-40c78042157f------2</link>
            <guid isPermaLink="false">https://medium.com/p/20d908973fe7</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ayushman Gupta]]></dc:creator>
            <pubDate>Fri, 20 Nov 2020 11:59:00 GMT</pubDate>
            <atom:updated>2021-04-13T12:37:28.377Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*A_Pdvofzw4jGyh50BvzK2A.jpeg" /></figure><p>Building<strong> </strong>a portfolio website from scratch is a great method to learn web development. It helps developers show their creativity and improve their problem-solving capability. These were the two keystones that I wanted to improve upon. I picked Vue.js a few months back and wanted to explore further into this framework.</p><p><a href="https://ayushman.me/"><em>For a live preview, click here.</em></a></p><h4>What is Vue.js?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*MStmxLf35FfrH6Lpp2PEpg.png" /></figure><p>The three main front-end frameworks that are currently dominating the market are React, Angular and Vue.js, with React being the most popular and Vue.js being the easiest. These frameworks help in building user interfaces and single-page applications. The reason why I picked Vue.js over other frameworks is because of its easy-to-go-through documentation and its clean syntax.</p><h4>Research and Searching for Ideas</h4><p>From the start, I was aware of the possibility of creating UI too artistic that threw user experience out of the window. I had seen websites whose aesthetics made my jaw drop but I never understood where I was supposed to click or what was the flow. So, I read few articles about portfolio websites and typography and created bullet points for myself to follow.</p><ul><li>Have a proper Call To Action (CTA).</li><li>Don’t make the user feel lost.</li><li>Make the user click less.</li></ul><p>I wanted my design to follow these points.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vAm0GYAW-pP5XOoYTniYlg.png" /></figure><p>I did what I always do before designing any UI. I went to <a href="https://dribbble.com/">Dribble </a>and <a href="https://www.behance.net/">Behance </a>for inspiration and searched for portfolio websites. There were so many designs, but the one I liked the most was by <a href="https://www.behance.net/gallery/97854185/Alex-Sanmartino-Personal-Branding?tracking_source=search_projects_recommended%7Calex%20sanmartino">Alex Sanmartino.</a></p><h4>Wireframing &amp; Designing</h4><p>I drew rough sketches for each section. In my design, a single section takes a minimum of 100% viewport height (vh) and viewport width (vw). These are CSS units. Basically, it means each section will cover everything from the top left to the bottom right of the visible browser’s view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6_jAKhRBGFtzJhbLbJ4gPQ.png" /><figcaption>Home Section</figcaption></figure><p>For the Home section, I kept the design minimal. There’s my name, image, and a big CTA button. On the top right, there’s a hamburger menu for easy navigation and on the top left, there’s my logo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kEGPq-Bpog1nBLJIJhfalQ.png" /><figcaption>About Me Section</figcaption></figure><p>In the second section, I gave a brief description of myself. Below the description, there are a few logos of the technologies that I’m good at. It also helps give the viewer a quick overview of my skills.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tsrkPrMPuPhLGRxFCa8mgA.png" /><figcaption>Work Section</figcaption></figure><p>Each box contains details about a single project. These boxes contain a title, a tag to describe the type of project, preview buttons on the top right, a description, cover image, and a ‘read more’ button. I also gave a filter option at the top for users to quickly list similar types of projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0BQSVQtln1XZdoXuJmJRnw.png" /><figcaption>Find Me Section</figcaption></figure><p>In the last section, there’s a grid of different platforms where viewers can go and explore more about me.</p><h4>Putting the pieces together</h4><p>After finalizing the design of the portfolio, the next step was to look into the programming aspect of it. I won’t go into much technical detail, but I’ll try to give an overview of the logic and project structure.</p><p>Let’s start by diving a little deeper into Vue.js.</p><p>The way Vue.js works is by injecting itself into a div inside an HTML file and everything inside that div is rendered by the Vue.js engine.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/46a1c000e241d5751aa8c693094ac16f/href">https://medium.com/media/46a1c000e241d5751aa8c693094ac16f/href</a></iframe><p>In the above code snippet, the HTML file is mostly empty except for a div with the id of “app”.</p><p>In Vue.js, we have components that are reusable Vue instances. These components are the building blocks of a website.</p><p>Let&#39;s take the example of Medium’s sidebar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*vQUWcdPMBb9FKFy3XfaIhg.png" /></figure><p>Here we have two different blocks: one is the “<strong>Latest From Following”</strong> which has icons with names and notifications; the other is “<strong>Topics You Follow”</strong> which only has the names of the topics that I follow.</p><p>If we want to recreate this in Vue.js, we will have two components, one for each section. The first component will get values such as name, image, and notification number as props (props are values that the parent component sends to its child component) and then we will use those values to render a single profile. The second component can be for “<strong>Topics You Follow”</strong> which takes in the name and returns a single tag. Then we can reuse the same components with different values and it will give us a list of profiles and a list of tags.</p><p>You can create a Vue.js project with <strong><em>vue create &lt;project-name&gt;</em></strong>. It creates most of the boilerplate files. But I added few tweaks to the structure of the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*L4tdsqmGr5_S2nhi4P6kFw.png" /><figcaption>Project structure</figcaption></figure><p>This is how I organized my project. The assets folder has icons, images, patterns, and data for my work projects. This <strong>projectData.js </strong>file is exporting an array of objects where I’m storing details for every project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1b4f44518b4953ca4aa82097fd4cae7/href">https://medium.com/media/d1b4f44518b4953ca4aa82097fd4cae7/href</a></iframe><p>In my components folder, I have components that I’m using throughout my project. I’ll go through each component later.</p><p>In my section folder, I am dealing with individual parts of the page. For eg. <strong>Home.vue</strong> is responsible for the first section. So if we divide the whole structure of my project into tree, it would look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y7sJHm4wRy6_xlHA_KyIlw.png" /><figcaption>Tree of components</figcaption></figure><h4>Components</h4><p><strong>Home.vue &gt; Hero.vue</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKPkfHI3Fd7ocLruljVwog.png" /></figure><p>It’s a flexbox containing two elements. One is a div that contains text on the left side and an image on the right. I’m using <strong>vw </strong>unit for measurement, so that if the width of the browser is less, so will be the size of text and image. I also applied flex-wrap, so that the text and image divs wrap into rows after a certain point.</p><p><strong>App.vue &gt; Menu.vue</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*KC4AqShhp24QwvtmkagGcQ.png" /></figure><p>The menu bar gives a quick look at each section of the page. It&#39;s a navbar with an unordered list. It takes 40vw of the page on desktop and 100% width on mobile devices.</p><p><strong>Me.vue &gt; Description.vue</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_lOOFf4D7jD9k6b4UwcVuA.png" /></figure><p>It&#39;s a simple component, with heading, text, and list elements. Here as well, I used responsive units so their size changes based on the user’s screen resolution.</p><p><strong>Work.vue &gt; FilterTags.vue</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*094I3UbdG2n4oWWmwFbCdQ.png" /></figure><p>This component is simply a div with text in it.</p><p><strong>Work.vue &gt; ProjectModule.vue</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NO3AdZJ1_XjS2A-vjlqIiA.png" /></figure><p>This is the most complex module of this project. But it’s not that complex in general view. When I was reviewing the project structure, I talked about <strong>projectData.js</strong> in the assets folder, which is a collection of my project’s details. I’m importing those details here, and sending them to the <strong>ProjectModule.vue </strong>component as props.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/678b8832f5e2e19f14d39b066484f61f/href">https://medium.com/media/678b8832f5e2e19f14d39b066484f61f/href</a></iframe><p><strong>FindMe.vue &gt; FindMeIcons.vue</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ObKZYaYQFZTxMQL9PY1NQ.png" /></figure><p>In the <strong>FindMe.vue </strong>section, I have two divs in a flexbox. The right div is a grid with the <strong>FindMeIcons </strong>component. This component is also taking props from <strong>FindMe.vue</strong> to render the final view.</p><h4>Conclusion</h4><p>This was a week-long project and I learned a lot. I have always struggled with messy code and organization, but this project helped me organize my project structure and my logic in a scientific manner.</p><p>Now I also have a better understanding of Vue.js. I extensively used its built-in <strong>&lt;transition&gt; </strong>with GSAP library using hooks to get smooth transitions and animations.</p><p>In the end, it was quite a learning adventure that gave me the opportunity to learn lots of new things that I was not aware of earlier. I’ll continue this adventure with new projects.</p><p><em>More content at </em><a href="http://plainenglish.io/"><em>plainenglish.io</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20d908973fe7" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/building-a-portfolio-website-with-vuejs-20d908973fe7">How to Build a Portfolio Website with Vue.js</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mitio — weather simplified]]></title>
            <link>https://duoro.medium.com/mitio-weather-simplified-ae8bce8626db?source=rss-40c78042157f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae8bce8626db</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[students]]></category>
            <category><![CDATA[weather]]></category>
            <dc:creator><![CDATA[Ayushman Gupta]]></dc:creator>
            <pubDate>Tue, 08 Sep 2020 12:32:18 GMT</pubDate>
            <atom:updated>2020-11-18T08:20:06.345Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mitio — weather simplified</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t-E-Xp4K3uv0lk_EsTt15Q.png" /></figure><h3>What is Mitio?</h3><p><strong>Mitio </strong>is a weather app that I created to have a better understanding of the web development process and what it takes to build a web app. I wanted to create a simple-looking weather app without using any third-party libraries (except for animation). I tried to keep the design simple and practical where user can have access to the weather information without much hassle. You can go here for live <a href="https://weathertestapp.netlify.app/">preview</a>. <strong>It only works on desktop, not on mobile devices.</strong></p><p>To give a basic idea of the functionality of the website, I used the geolocation API to fetch the user’s location and then <a href="https://www.weatherbit.io/api">weatherbit API</a> to receive necessary weather data. It was then processed into meaningful information and then rendered in the browser. Below I’ve a detailed explanation of the important part.</p><h3>Setting up the UI</h3><p>After dribbling through dribbble, I came up with something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ziiH3zlUDEiKd0oTkeIYMw.jpeg" /><figcaption>Rough sketch of the app</figcaption></figure><p>My idea was to display information in grids, so it would be easier for the user to go through them easily. I also gave grid cells different dimensions based on the hierarchy of the information. So if the information is something that I think is important to the user then I gave that cell a bigger dimension with higher depth.</p><p>To convert my design into code, the obvious choice for me was to use CSS grids. I declared <em>&lt;body&gt;</em> as a grid container because I wanted to show the whole page in single view without any scroll.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*O63nRqR5Aj8e9w6u-g9Y3w.png" /><figcaption>I divided the whole body into 8 columns and 4 rows, each occupying one fraction of the page.</figcaption></figure><p>This is the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*br2M9mjBzVirFCCOxPd3xw.png" /><figcaption>8x4 grid</figcaption></figure><h3>Functioning</h3><p>Let’s divide this section into three parts — Getting data, Modifying Data and Rendering data.</p><p><strong>Getting Data </strong>— The first step was to get the data. Here by data I mean user’s location and the weather data fetched by keeping user’s location into mind. In programming to access data from a service we use an <strong>API </strong>(Application Programming Interface). So if we want to access data from Youtube website, we would use Youtube API which acts as a mediator of the information.</p><p>In our case to get user’s location I used Geolocation API. Geolocation is one of the many Web APIs browsers provide. In this project I learned something interesting that I want to share. JavaScript is a simple programming language that runs in browser in isolation without having access to internet. It access internet and <em>DOM</em> through Web APIs, which are browser features. So whenever we access <em>DOM</em> using <em>document.getElementById</em> or something else of that sort, we are actually reaching <em>DOM</em> using <em>DOM API. DOM</em> is not a part of JavaScript environment. To read more about Web API, <a href="https://developer.mozilla.org/en-US/docs/Web/Reference/API">click here</a>.</p><p>Geolocation API provides information regarding user’s device location which includes latitude, longitude, acceleration etc. You can find more about Geolocation API <a href="https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API">here</a>.</p><p>We can prompt for user’s location with the following code. If user gives the permission then value will be stored in long and let variables, if not then we can try IP address API to fetch location. But I didn’t use the IP address API in my case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*pCwpxqBU-dhOmw61Wd8kDw.png" /><figcaption>Asking user for geolocation permission</figcaption></figure><p>The second data we need is the weather data. I used weatherbit API and in weatherbit API, it had two endpoints — one for current weather and the other having weather forecast for next 16 days. Endpoints are actually URL which can be used to access data in JSON format. I needed to fetch two different API endpoints. I used fetch method to access these data and then used destructuring to store those data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*HiZB8Qk2jIVPyndlu80AuQ.png" /><figcaption>Storing data from weatherbit API locally</figcaption></figure><p><strong>Modifying Data </strong>— The weatherbit API gives temperature information in Celsius. So I used a simple function that converts Celsius into Fahrenheit when user clicks on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*_u6vE6XoQNbeH4rtDefcLA.png" /><figcaption>Function to change measurement unit</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*X1ojp-uYC2i2ITH1zgdr6g.gif" /><figcaption>Clicking on temperature will change to the alternative measurement unit</figcaption></figure><p>The main challenge that I faced while modifying data was to convert UTC time into the time user is in, in 12 hour time format. The weatherbit API always gives UTC time. So I needed to add or subtract the timezone offset from the UTC time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*EBf1M7n-73KZEUttivtjfQ.png" /><figcaption>Function to change time from UTC to current Timezone</figcaption></figure><p>Here, the idea was to convert the UTC string which comes as a string “00:10” into two separate integers. One being 00 and the other being 10. Then I calculated the Timezone offset using in-built date function. The interesting thing that I found was that for positive timezone, like +5:30. It always gave me a negative number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*XbyrpVodfWm4aDhYdhUx6w.png" /><figcaption>I had to multiply it by -1 to correct the sign, and also to divide it by 60 to get timezone in hours.</figcaption></figure><p><strong>Rendering data</strong> — For rendering data to the DOM, I simply used textContent to display the values. dayOneDate.textContent = dayOne;</p><p>For animation I used Lottie animation library. If you want to know more about Lottie go <a href="https://lottiefiles.com/what-is-lottie">here</a>. I will try to explain the animations briefly because there’s not much going on here. First I imported the lottie js files in my index.html. Then I’m using if…else conditions to show the right weather animation for the right condition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*6fg-MRB01SUCxDEOEhbK_Q.png" /><figcaption>Invoking a loadAnimation function and passing an object containing the details of the animation.</figcaption></figure><p>Here’s an example. The currentIconId and currentPod are weatherbit data that tells the current weather(rain, snow etc) and whether its day or night respectively. On that basis I’m deciding which animation to show.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*2GNHh8fjejVBmxUjhRkt9Q.gif" /><figcaption>lottie animation</figcaption></figure><h3>Background Animations</h3><p>There are four types of background animations which depends on the weather — cloudy, snow, rainy and night.</p><p>Among them I want to explain here the night animation, the reason being, one it looks great and unlike other animations I came up with the whole idea. The idea was to create several html divs, each having different size and positioning and also different animations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*j3zoOz87We2TVgSPUQSA6w.png" /></figure><p>In this makeStars function, I’m creating 200 <em>&lt;div&gt;</em> elements, each having a size which can be from 1 to 3 pixels using random Math function. Then I’m populating these <em>&lt;div&gt;</em> in the parent div which occupies the whole screen. I’m assigning them different CSS IDs and a main CSS class. On line 903 &amp; 904, I’m shifting their position from top and left randomly based on user screen’s width and height.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*aOq314jpT70d6YlBAit1hA.png" /><figcaption>Giving each star a universal styling.</figcaption></figure><p>The code below is the SCSS snippet which provides randomness (sort of) to the stars. SCSS or SASS is a CSS pre-processor which gives you ability to add logic to your CSS. In other words you can use CSS as a programming language instead of using cascading programming style. Also SCSS or SASS are basically the same things, the only difference is of syntax. SASS uses indent to define scope like in python, on the other hand SCSS uses our friending curly braces {}. To learn more about SASS, click <a href="https://sass-lang.com/guide">here</a>.</p><p>So here, the idea was to divide the 200 star divs into three categories each having different keyframe animations. In the code snippet, I’m again looping through 200 times (no of divs) and assigning two variables — randomId and randomFl. The value of randomId can anything from 1 to 3. randomId variable determines which animation will be given to the star. There’s also three keyframes each having different motions which are attached to the stars div on the basis of randomId.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cSwAyVMIbXrq6PAJYLQOKA.png" /></figure><p>The first three values in animation property are the keyframe name, time of the animation and the delay.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*vnWTWxegLRjRMC2eu5Gvyw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*YYdJZ7u5dyybKuFp4Zth0g.png" /></figure><p>In my case I am adding two animations to each star div, one is the universal stars class and the other can be one of the three animation keyframes. While assigning them for the time of the animation I am giving a random number which can be anywhere between 16 to 55 seconds for move-1 animation, on top of that I’m also adding an animation delay which can be anywhere between 0 to 9000 ms. These random time values gives an illusion that movement of stars are random. But as you can see all the motions are fixed, I’m just changing the speed of animation and its delay. I’m also adding a flicker animation based on the same logic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*pY7V56JkgSL9H3szrDIDQA.png" /></figure><h3>Conclusion</h3><blockquote>Education without application is just entertainment. — Tim Sanders</blockquote><p>Though I had some understanding of the web development in bits and pieces before, but I never understood how these technologies worked together in conjunction with each other. This project helped me to put those pieces together and made me understand the big picture. It made me realize the elegance of web development. Web development has many parts — browser, javascript, DOM, APIs, server and the list goes on. But when you put these things together, it makes sense why these things exists.</p><p>I love creating things and I’m pretty sure that I’ll continue to work on new projects with these new tools that I have learned. 😄</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae8bce8626db" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>