<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: superoverflow</title>
    <description>The latest articles on DEV Community by superoverflow (@superoverflow).</description>
    <link>https://dev.to/superoverflow</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F389202%2F3d5854a1-8390-46e2-a011-44351ef7fe74.jpeg</url>
      <title>DEV Community: superoverflow</title>
      <link>https://dev.to/superoverflow</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/superoverflow"/>
    <language>en</language>
    <item>
      <title>Using Binance APIs</title>
      <dc:creator>superoverflow</dc:creator>
      <pubDate>Mon, 12 Jun 2023 20:10:55 +0000</pubDate>
      <link>https://dev.to/superoverflow/using-binance-apis-4kd3</link>
      <guid>https://dev.to/superoverflow/using-binance-apis-4kd3</guid>
      <description>&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;As someone who worked with data for entire of my career, I always love to learn how to build a useful live data dashboard. One of the problems for build a live data dashboard comes with live data. Most live data are behind a hefty price wall and not really accessible to most people. However, Binance has a wonderful &lt;a href="https://binance-docs.github.io/apidocs/spot/en/#websocket-market-streams"&gt;public Websocket API&lt;/a&gt; and it is really useful for anyone to learn!&lt;/p&gt;

&lt;p&gt;In this blog, I am going to share my experience in learning websocket. This is the link to the &lt;a href="https://crypto-investment-journal.vercel.app/"&gt;final product&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Websocket API
&lt;/h2&gt;

&lt;p&gt;The websocket API we are going to use is the &lt;a href="https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-mini-ticker-stream"&gt;miniticker&lt;/a&gt;, which we can receive the latest closing price. According to the document, this is the payload&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  {
    "e": "24hrMiniTicker",  // Event type
    "E": 123456789,         // Event time
    "s": "BNBBTC",          // Symbol
    "c": "0.0025",          // Close price
    "o": "0.0010",          // Open price
    "h": "0.0025",          // High price
    "l": "0.0010",          // Low price
    "v": "10000",           // Total traded base asset volume
    "q": "18"               // Total traded quote asset volume
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In order to receive the miniTicker socket stream, we would need to &lt;a href="https://binance-docs.github.io/apidocs/spot/en/#live-subscribing-unsubscribing-to-streams"&gt;subscribe &lt;/a&gt; to it. What it means is that, we need to send below json to websocket url, say if we want to subscribe to BTCUSDT and ETHUSDT&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "method": "SUBSCRIBE",
    "params":
    [
        "btcusdt@miniTicker",
        "ethusdt@miniTicker"
    ],
    "id": 1
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, the market data websocket url is &lt;code&gt;wss://data-stream.binance.vision&lt;/code&gt;. Now, we are good to go 😎&lt;/p&gt;

&lt;h2&gt;
  
  
  Trying the websocket API
&lt;/h2&gt;

&lt;p&gt;Most morden web browser support websocket, so we just need to open the developer console to try&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ws = new WebSocket('wss://data-stream.binance.vision/ws');
ws.onmessage = function (e) { console.log(e.data) };
ws.send('{"method":"SUBSCRIBE","params":["btcusdt@miniTicker"],"id":0}');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we should see log messages like below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"e":"24hrMiniTicker","E":1686600526157,"s":"BTCUSDT","c":"25813.21000000","o":"26116.47000000","h":"26206.88000000","l":"25602.11000000","v":"32722.94617000","q":"846855564.49409930"}
...
{"e":"24hrMiniTicker","E":1686600527217,"s":"BTCUSDT","c":"25813.20000000","o":"26114.91000000","h":"26206.88000000","l":"25602.11000000","v":"32711.86119000","q":"846566058.39423260"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;WIP&lt;br&gt;
&lt;a href="https://codesandbox.io/s/binance-websocket-l2dglq?file=/src/ContextProvider.tsx"&gt;https://codesandbox.io/s/binance-websocket-l2dglq?file=/src/ContextProvider.tsx&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cryptocurrency</category>
      <category>websocket</category>
    </item>
    <item>
      <title>Something for interviews</title>
      <dc:creator>superoverflow</dc:creator>
      <pubDate>Mon, 01 May 2023 17:46:18 +0000</pubDate>
      <link>https://dev.to/superoverflow/something-for-interviews-4bgj</link>
      <guid>https://dev.to/superoverflow/something-for-interviews-4bgj</guid>
      <description>&lt;p&gt;There are some important phrases thats good to have a refresher just before you head to an interview room to show that you are not just a code monkey 🐵. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SOLID&lt;/strong&gt; is 5 principles to follow when you ask where you should put your code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;S&lt;/strong&gt;ingle responsibility&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;O&lt;/strong&gt;pen-closed principle&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;L&lt;/strong&gt;iskov subsitution principle&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;I&lt;/strong&gt;nterface Segregation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;D&lt;/strong&gt;ependency Injection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;ACID&lt;/strong&gt; is database characteristic for ensuring transactions correctness&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A&lt;/strong&gt;tomicity&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;C&lt;/strong&gt;onsistency&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;I&lt;/strong&gt;solation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;D&lt;/strong&gt;urability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Database isolation has 4 levels. Make sure you know what is dirty read, non-repeatable read and phantom read&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read Uncommitted&lt;/li&gt;
&lt;li&gt;Read committed&lt;/li&gt;
&lt;li&gt;Repeatable Read&lt;/li&gt;
&lt;li&gt;Serialisable&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>interview</category>
    </item>
    <item>
      <title>Make a slide open envelope</title>
      <dc:creator>superoverflow</dc:creator>
      <pubDate>Fri, 23 Dec 2022 18:25:26 +0000</pubDate>
      <link>https://dev.to/superoverflow/make-a-slide-open-envelope-oem</link>
      <guid>https://dev.to/superoverflow/make-a-slide-open-envelope-oem</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;Everyone loves receiving a letter from a friend. But with technology advances, does anyone miss receiving one?&lt;/p&gt;

&lt;p&gt;I thought of making a wedding invitation recently. And I wanted to make the receipients felt like opening a letter!&lt;/p&gt;

&lt;p&gt;To do that, I have learnt:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to create an envelope just by css&lt;/li&gt;
&lt;li&gt;How to animate the envelope openning with &lt;a href="https://www.framer.com/motion/" rel="noopener noreferrer"&gt;framer motion&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The end result for me looks like this and I am pretty happy with it :) &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ik8q3bl2iovyfmaf2h4.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ik8q3bl2iovyfmaf2h4.gif" alt="Image description" width="220" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Making an envelope with css
&lt;/h2&gt;

&lt;p&gt;Before making an animated envelopes, it is important we can make a static one and understand how it works. Here is an example,&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/divine-cherry-thssmz"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Point to note:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The envelope is essentially a zero width/height div with transparent top border&lt;/li&gt;
&lt;li&gt;To make the lip half open, we will just need to use &lt;code&gt;transform: rotateX(45deg)&lt;/code&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Making css animation with framer motion
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Framer motion is an easy way to animate the evelope lid open&lt;/li&gt;
&lt;li&gt;see below example
&lt;iframe src="https://codesandbox.io/embed/jolly-aj-lf3uc6"&gt;
&lt;/iframe&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Repo and Demo
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;With above serving the basics and some hard work, you will be able to make a scroll controlled envelope. Enjoy!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/superoverflow/rsvp-gsheet" rel="noopener noreferrer"&gt;Repo&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/superoverflow/rsvp-gsheet#:~:text=Live%20Demo-,Demo,-GSheet" rel="noopener noreferrer"&gt;Demo&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.google.com/spreadsheets/d/1kspesLqIszPAM45-Y7d4M10TPKWyBPoGj2xubVYlPsE" rel="noopener noreferrer"&gt;GSheet capturing response&lt;/a&gt;&lt;/p&gt;

</description>
      <category>welcome</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Learning Rust Offline</title>
      <dc:creator>superoverflow</dc:creator>
      <pubDate>Sat, 20 Nov 2021 12:55:24 +0000</pubDate>
      <link>https://dev.to/superoverflow/learning-rust-on-a-plane-4p69</link>
      <guid>https://dev.to/superoverflow/learning-rust-on-a-plane-4p69</guid>
      <description>&lt;p&gt;I would be on a 13 hour flight and I look for some good offline resources to learn &lt;code&gt;rust&lt;/code&gt;:&lt;/p&gt;

&lt;h4&gt;
  
  
  The Rust Programming Language
&lt;/h4&gt;

&lt;p&gt;This is THE first book to rust. If you already have &lt;code&gt;rustup&lt;/code&gt; installed on your laptop, you can read the book from your browser offline pretty easily&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rustup doc --book
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Rust by example
&lt;/h4&gt;

&lt;p&gt;While the first book gives you lots of background and theory, this book gives you some more examples for some common tasks that can get you started. The github page gives you instruction to use &lt;code&gt;mdbook&lt;/code&gt;, which allows you to read the book offline.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/rust-lang/rust-by-example"&gt;rust-by-example&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Rust Cookbook
&lt;/h4&gt;

&lt;p&gt;I found this book really practical. It has some example, say to connect to a database, manipulating datetime, which are very common things you need to deal with at work. Again, blessed by &lt;code&gt;mdbook&lt;/code&gt;, you can read it offline too!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/rust-lang-nursery/rust-cookbook"&gt;rust cookbook &lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Async Rust
&lt;/h4&gt;

&lt;p&gt;Another common task you will come across a lot at work is parallelism. The textbook way to handle it is threading. but for small/simple task (eg downloading files from web), async may be a better choice since it consume less resources. This book gives a good walk through of this feature in rust. Of course, it can be read offline with &lt;code&gt;mdbook&lt;/code&gt; !&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/rust-lang/async-book"&gt;Rust Async&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So thats it! If you are also preparing for your flight ✈️, I wish you a safe journey!&lt;/p&gt;

</description>
      <category>rust</category>
      <category>beginners</category>
    </item>
    <item>
      <title>building a cryto pnl dashboard lightweight-chart (part 1)</title>
      <dc:creator>superoverflow</dc:creator>
      <pubDate>Sun, 11 Jul 2021 22:22:13 +0000</pubDate>
      <link>https://dev.to/superoverflow/building-a-cryto-pnl-dashboard-lightweight-chart-part-1-4n7e</link>
      <guid>https://dev.to/superoverflow/building-a-cryto-pnl-dashboard-lightweight-chart-part-1-4n7e</guid>
      <description>&lt;p&gt;I used Binance to trade some crypto. While they offer a competitive fees and wide range of products, I found understand it P&amp;amp;L a bit difficult. Usually I use TradingView to visualize my positions, therefore I am thinking if it is possible to build an app to show my crypto P&amp;amp;L 🤑 and that begin my journey&lt;/p&gt;

&lt;p&gt;I haven't decided everything yet, but I want to use NextJs for building this project. The project scaffoldings is nice and the deployment pipeline is surprising wonderful! For chart library, I want to try the one offered by TradingView - &lt;a href="https://github.com/tradingview/lightweight-charts"&gt;lightweight-chart&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The example of lightweight-chart is not a common React style I learnt. After a bit of studying, we can achieve the same with &lt;code&gt;useRef&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createChart&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lightweight-charts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useRef&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;time&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2019-04-11&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;80.01&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;time&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2019-04-12&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;96.63&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="c1"&gt;//... skipped ...&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;time&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2019-04-20&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;74.43&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Chart&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chartRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chart&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createChart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;chartRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lineSeries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;chart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addLineSeries&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;lineSeries&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;chartRef&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Chart&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My understanding is that:&lt;br&gt;
1) first a &lt;code&gt;div&lt;/code&gt; is created in the React Page, the &lt;code&gt;chartRef&lt;/code&gt; is bind.&lt;br&gt;
2) the &lt;code&gt;useEffect&lt;/code&gt; hook kicks in after the page is loaded&lt;br&gt;
3) the &lt;code&gt;createChart&lt;/code&gt; can render into the &lt;code&gt;div&lt;/code&gt; that was bind&lt;/p&gt;

&lt;p&gt;The full example will be liked this:&lt;br&gt;
&lt;iframe src="https://codesandbox.io/embed/suspicious-https-o1f3h"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;which is still having one error to resolve:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SyntaxError: Cannot use import statement outside a module
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This error basically means that the &lt;code&gt;lightweight-chart&lt;/code&gt; is a frontend library but we are using it in a SSR (server side rendering) context, which is how NextJs work. Fortunately, it is pretty easy to resolve it. You will just need to dynamics import it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Chart&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;dynamics&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../components/charts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;ssr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/adoring-darkness-21v5v"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There are some Babel plugin config difference with codesandbox, but the code works on my VSCode. The working version of code can be found &lt;a href="https://github.com/superoverflow/crypto-dashboard/tree/part_01"&gt;here&lt;/a&gt; and demo can be found &lt;a href="https://crypto-dashboard-ocz5clkq5-superoverflow.vercel.app/"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>nextjs</category>
      <category>lightweightchart</category>
    </item>
    <item>
      <title>Visualising data</title>
      <dc:creator>superoverflow</dc:creator>
      <pubDate>Sat, 29 May 2021 20:49:25 +0000</pubDate>
      <link>https://dev.to/superoverflow/visualising-data-52je</link>
      <guid>https://dev.to/superoverflow/visualising-data-52je</guid>
      <description>&lt;p&gt;As a backend engineer, I always wanted to build graphs to show some data interactively. I look up a few libraries but they are not quite easy to use as a relatively new React dev. So I ask my si-fu &lt;a class="mentioned-user" href="https://dev.to/_denb"&gt;@_denb&lt;/a&gt;
 again, he recommended me to look at &lt;a href="https://airbnb.io/visx/docs/xychart"&gt;visx/xychar&lt;/a&gt;. And yea, it was surprising neat!&lt;/p&gt;

&lt;p&gt;Step 1: display a simple line chart&lt;br&gt;
&lt;a href="https://codesandbox.io/s/visx-xychart-00-qp99f"&gt;https://codesandbox.io/s/visx-xychart-00-qp99f&lt;/a&gt;&lt;br&gt;
&lt;iframe src="https://codesandbox.io/embed/visx-xychart-00-qp99f"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The main thing to display the data is just this piece of code. Simple enough!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      &amp;lt;XYChart height={300} 
        xScale={{ type: 'band' }} 
        yScale={{ type: 'linear' }}&amp;gt;
          &amp;lt;Axis orientation="bottom" /&amp;gt;
          &amp;lt;Axis orientation="left" /&amp;gt;
          &amp;lt;LineSeries data={data} dataKey="line" {...accessors} /&amp;gt;
      &amp;lt;/XYChart&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step Final: custom y axis, adding glyph and toolstips, etc&lt;br&gt;
&lt;iframe src="https://codesandbox.io/embed/xychart-final-example-8zj10"&gt;
&lt;/iframe&gt;
&lt;br&gt;
In the final code, I tried to represent a team match position. Since position 1 means the team is a top, I will need to reverse the y-axis. And to make it the graph interactive, I added some icons on the data points and tools tip&lt;/p&gt;

&lt;p&gt;visx has other lower level libraries, but I found xychart is really battery included and simple to use :D&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Making a Dropdown</title>
      <dc:creator>superoverflow</dc:creator>
      <pubDate>Sun, 21 Feb 2021 00:29:04 +0000</pubDate>
      <link>https://dev.to/superoverflow/making-a-dropdown-1li0</link>
      <guid>https://dev.to/superoverflow/making-a-dropdown-1li0</guid>
      <description>&lt;p&gt;I was trying to make a dropdown button with React. It turns out to be more tricky than I first thought 🤯.&lt;/p&gt;

&lt;p&gt;After discussing with my &lt;em&gt;React Si-Fu&lt;/em&gt; &lt;a class="comment-mentioned-user" href="https://dev.to/_denb"&gt;@_denb&lt;/a&gt;
, I finally managed to make a prototype. Below are the libraries I need to use.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;downshift&lt;/code&gt;: a base library for making a dropdown. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;react-useportal&lt;/code&gt;: a library to move the dropdown items to the end of body&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;react-popper&lt;/code&gt;: a library to fix the position of the dropdown items&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Step 1: make a dropdown menu
&lt;/h5&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/quizzical-currying-g71gd?initialpath=/src/dropdown.js"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is already a dropdown-ish component. However, you will notice when the dropdown list opens, it pushes the content below it down. This is not ideal.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Step 2: adding in Portal
&lt;/h5&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/upbeat-thunder-pywhl?initialpath=/src/dropdown.js"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;now, if the dropdown list open, it is appended at the end. This is still not what we want&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Step 3: adding in Popper
&lt;/h5&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/goofy-pasteur-lcf4p?initialpath=/src/dropdown.js"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;finally, the dropdown list open, it is rendered below the dropdown button on top of the text. This is what we want. However, the dropdown items still doesn't align with the dropdown button (It will if you resize the window). I think this is because the component reference is set up before rendering and thus confused Popper for the sizing&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Step 4: fixing alignment issue after resizing window
&lt;/h5&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/beautiful-night-3n37g?initialpath=/src/dropdown.js"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now, I tried to use &lt;code&gt;useState&lt;/code&gt; instead of &lt;code&gt;useRef&lt;/code&gt;. It seems to solve the initial alignment issue&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  What's next?
&lt;/h5&gt;

&lt;p&gt;I hope to add a transition components wrapper next to make it look even better✌🏻&lt;/p&gt;

</description>
      <category>react</category>
    </item>
  </channel>
</rss>
