teleren/devto huggingface dataset:
Lessons from opensource: How to check if your program has internet connectivity in Nodejs?
Tags: webdev, javascript, node, nextjs
Published: 2024-02-29 21:26:52

These lessons are picked from [next.js/create-next-app](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) open source code. In this article, you will learn how you could check if your program has access to internet in Nodejs.


![https://github.com/vercel/next.js/blob/canary/packages/create-next-app/helpers/is-online.ts#L18](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6mvvjr3u2yxqxbdv7g8.png)

There could be numerous reasons as to why you want to check if you program has internet connectivity. One usecase in [next.js/create-next-app](https://github.com/vercel/next.js/blob/canary/packages/create-next-app/create-app.ts#L214) is that the program checks it's online to install a npm command.


![Install](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q2p57bnmcvbg0lb2od20.png)

```
export async function getOnline(): Promise<boolean> {
  try {
    await dns.lookup('registry.yarnpkg.com')
    // If DNS lookup succeeds, we are online
    return true
  } catch {
    // The DNS lookup failed, but we are still fine as long as a proxy has been set
    const proxy = getProxy()
    if (!proxy) {
      return false
    }

    const { hostname } = url.parse(proxy)
    if (!hostname) {
      // Invalid proxy URL
      return false
    }

    try {
      await dns.lookup(hostname)
      // If DNS lookup succeeds for the proxy server, we are online
      return true
    } catch {
      // The DNS lookup for the proxy server also failed, so we are offline
      return false
    }
  }
}
```

[Subscribe to my newsletter](https://medium.com/@ramu.narasinga_61050/subscribe) to get more lessons from opensource.

## DNS package?

At the top of [is-online.ts](https://github.com/vercel/next.js/blob/canary/packages/create-next-app/helpers/is-online.ts#L2) file, you will find below snippet:

```
import dns from 'dns/promises'
```

> he node:dns module enables name resolution. For example, use it to look up IP addresses of host names.

> Although named for the [Domain Name System (DNS)](https://en.wikipedia.org/wiki/Domain_Name_System), it does not always use the DNS protocol for lookups. [dns.lookup()](https://nodejs.org/api/dns.html#dnslookuphostname-options-callback) uses the operating system facilities to perform name resolution. It may not need to perform any network communication. To perform name resolution the way other applications on the same system do, use dns.lookup(). - [Source](https://nodejs.org/api/dns.html#dns)

## Conclusion:
A simple DNS lookup is used to detect if you are online when you run your NodeJs program. Now you know how to check if you got internet connectivity before you do some operations programatically and throw some error if you are offline.

If you are looking to improve/learn frontend, checkout my website: https://tthroo.com/ where I teach project based tutorials.
Making a simple trivia Game
Tags: react, javascript, showdev, webdev
Published: 2024-02-29 21:17:31

## TLDR
I created a trivia game over the past couple of weeks. It's inspired by the Waveform podcast that comes out weekly on Fridays. 

**_Play:_** https://www.wvfrmtrivia.xyz/

![homepage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a0wqxvaedypdpu2e2397.png)

**_Source Code 🌟_** 
{% github arndom/wvfrm-trivia %}

### The Idea

I watch the Waveform podcast the MKBHD team hosts on Fridays after work. It's a great way to catch up on tech plus their personalities also make it more enjoyable. They have this entertaining trivia segment that ranges across tech, science and randomness.

Sometime last year a fan built a dashboard with stats for the segment and it was so nice to see that I got inspired to make a game out of it(there's also been a lack of hackathons 🤷‍♂️).

![Intro GIF](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mjhnykf7zl6k02bhd7nm.gif)

### How I built it

I used these to build the app
- NextJS
- MUI 
- Firebase (Firestore and Cloud Functions)
- Vercel

I got the question bank from the source of the [dashboard](https://wvfrmtrivia.com/) created by Howie Adderly. After which I wrote a script to upload to firestore...it's pretty weird that firestore still doesn't support JSON imports directly. After which it was a matter of building out the UI and functionalities of the app.

I was able to build some of these features with the others on the way:
- Gameplay
- Anonymous users with a point system
- Leaderboard (Currently limited)
- Social sharing (TBD)
- Push Notifications (TBD)
- Community Questions via FireCMS (TBD)


I hope you enjoyed the [game](https://wvfrmtrivia.xyz/) 

PS: I recently joined Twitter and made a post about this, some love there would be nice 🥹

{% twitter https://twitter.com/arndomG/status/1762959126567555576?theme=dark %}
Polygon’s Performance Indicates Market Anomaly 📈
Published: 2024-02-29 21:10:48


📈 While all this is happening, MATIC’s price was trading at $1.04, with a rise of less than 1%. On the other hand, there was also an increase in MATIC’s 24-hour trading volume and overall volume.

💼 MATIC’s total volume increased by 0.4%, rising above $10 billion. The 24-hour volume saw an 86% increase, exceeding $1 billion.

📉 Currently trading at $1.05, MATIC’s stagnant structure compared to the broader market trend seems to have created an inverse correlation. This inconsistency is also reflected in the Weighted Sentiment Indicator, which shows a negative trend among investors, indicating a noticeable decline in market sentiment towards the token.

🚩 Captain Faibik, a name frequently mentioned in recent cryptocurrency analysis, commented in a recent analysis that MATIC is very close to breaking out of an ascending triangle formation. A potential breakout in price, coupled with a positive outlook in market dynamics, could lead to MATIC reaching the eagerly anticipated $2 level in the coming weeks.

🛑 However, there are challenges on the way to the $2 mark. Resistance levels seen on the charts are considered a significant barrier for the token. Data provided by Hyblock Capital suggests that liquidations could be high at the $1.08 level, which is seen as a significant resistance. Such liquidation zones could bring about a correction in price and hinder MATIC’s progress.

📊 Looking at MATIC’s daily chart, a volatile structure is evident, as shown by the Bollinger Bands. However, the appearance of the MACD indicates a strong buying market, paving the way for investor optimism.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dl74io37v7kt0lt2raoa.png)
Ethereum’s Price Surge: Will It Hit $4,000? 🚀
Published: 2024-02-29 21:11:32

Ethereum's recent surge to near $3,500 and the ongoing debate about its potential to reach $4,000 has certainly captured the attention of investors. 📈 With its market cap exceeding $418 billion and a significant increase in trading volume, Ethereum's momentum is notable.

The fact that Ethereum has already surpassed predictions of reaching $3,000 suggests that the $4,000 milestone could indeed be within reach. 🎯 Analysts and institutions like Standard Chartered have also weighed in on the possibility of Ethereum hitting this target.

Ethereum's current price is only 28% below its all-time high, indicating a strong potential for further gains. 🚀 Additionally, the crypto market's sentiment, as reflected in the fear and greed index, is leaning heavily towards extreme greed, which historically correlates with significant price increases.

Bitcoin's recent surge to $64,000 and its influence on the broader altcoin market, including Ethereum, further support the bullish outlook. 🌐 As Bitcoin approaches its all-time high, Ethereum seems to be following suit, suggesting continued positive momentum for ETH.

Overall, the combination of market dynamics, investor sentiment, and Bitcoin's trajectory indicates promising prospects for Ethereum's price movement towards the $4,000 mark. 🌟

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p5tpachu4zvz8w3er2fx.png)
XRP Price Surge: Can It Reach $1 Again? 🚀
Published: 2024-02-29 21:11:08

🚀 XRP has been one of the most engaging assets in the cryptocurrency world, with the Ripple-SEC case potentially shaping its future.
📈Bitcoin's recent surge past $64,000, alongside the overall uptrend in the market, sets an optimistic tone for XRP's potential return to $1.
📊 According to a well-known analyst, XRP's recent movement above $0.60 indicates a potential path towards $1, supported by technical indicators like the Ichimoku clouds and the Bullish hammer.
📈 XRP's recent price action shows promising signs, with a 5% increase in the last 24 hours and notable gains over the past week and month.
🚀With increasing trading volume and market cap, XRP's journey to $1 could be propelled further by positive developments in the Ripple-SEC case and continued bullish sentiment in the market.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kd9m3fgvbz2c0a3c2syn.png)
Bitcoin Reaches New Heights with a Surge to $64,000 🚩
Published: 2024-02-29 21:10:28

📈 The largest cryptocurrency Bitcoin (BTC) surged past the $61,000 mark, briefly touching $64,000, a level not seen in over two years. This extraordinary price rise marked a period of impressive gains as Bitcoin‘s total market value exceeded $1.2 trillion last month.

⚠️ Matrixport’s co-founder Daniel Yan warned of a potential 15% correction, advising investors to prepare for a pullback to the range of $52,000 to $53,000 by the end of April. He highlighted macroeconomic events such as the Fed interest rate meeting and GDP figures as potential triggers for this correction.

📉 The Crypto Fear and Greed Index, currently at 80, signals “extreme greed,” reminiscent of the sentiment seen two years ago when Bitcoin reached a peak around $69,000. This cautionary signal urges investors to exercise caution amidst the market excitement.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w0tnlhwmoo45tzfqdamw.png)
Cardano Enthusiasts Rally for ADA Support in Brave Browser 📈
Published: 2024-02-29 21:10:02


🚀 The crypto community is buzzing with excitement as Cardano enthusiasts unite in the Brave Browser to advocate for ADA support. This movement was sparked by a passionate post expressing disappointment over the absence of Cardano support in Brave's features, particularly its wallet.

👨‍💼 Cardano founder Charles Hoskinson stepped in, rallying supporters to back this initiative. His call garnered significant interest, with 51,400 views, highlighting widespread attention. However, the number of votes on the petition for Cardano integration on Brave's community website was relatively low, signaling a potential gap between interest and action within the ADA community.

🌐 Despite the disparity in viewing and voting rates, this initiative reflects the proactive approach of stakeholders in the Cardano ecosystem. With Hoskinson's support and the collective efforts of ADA enthusiasts, integrating Cardano into Brave's web browser could enhance accessibility and usability for users worldwide.

💡 This initiative underscores the importance of collaboration and integration among projects in the crypto space. Addressing user demands sensitively is crucial, and initiatives like these are vital for Cardano's long-term success and widespread adoption.

💰 At the time of writing, Cardano (ADA) is trading at $0.68, showing an approximate 35% increase over the past week.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ptza0gdeh0mbyqxvnyp7.png)
Uniswap ($UNI) Price Hits Two-Year High and Signals Further Growth 📊
Published: 2024-02-29 21:09:43


📈 The cryptocurrency market is surging, led by Bitcoin, with many altcoins hitting record highs. Uniswap (UNI) reached a two-year peak of $12.85 on February 24 before experiencing a slight decline.

📊 Weekly UNI Chart Analysis:
UNI has been rising within a long-term horizontal support area since October 2023. It broke out from a declining resistance trend line after 480 days. Recently, it broke out from a horizontal resistance area and reached a high of $12.86 before a slight pullback. The Weekly Relative Strength Index (RSI) supports the rise, indicating upward momentum.

📉 Daily UNI Chart Analysis:
The daily timeframe also shows an upward trend, with the most likely wave count suggesting UNI's movement will continue. UNI is potentially in the third wave of a five-wave upward movement, with the current correction likely leading to another upward move towards the next resistance level of $16.10.

⚠️ Despite the positive forecast, failure to break out from $12.10 could trigger a drop to the nearest support at $7.80, representing a roughly 30% decrease.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8dppgawgbt914m864i1m.png)
Dogecoin Soars with a 20% Surge in Value 📊
Published: 2024-02-29 21:09:10

🚀 Dogecoin, the largest meme coin by market value, surged over 20% today, while BTC found buyers at $60,700. However, altcoins haven't seen desired gains except for a few like SOL, SHIB, and DOGE, which gained over 15%.

💰 In the last 24 hours, Dogecoin's value surged by 30%, with its market cap reaching $18.6 billion. Interest in Dogecoin futures increased by 50%, with open interest hitting a record level of $1.09 billion. However, a market sentiment relaxation is expected.

📈 Other meme coins like BONK and Shiba Inu also became active today, reflecting rapid rises typical during such periods.

🔮 Market commentators like Kaleo and Rekt Capital express optimism about Dogecoin's future, predicting further price rises. Rekt Capital suggests a potential increase of over 300%, with a monthly close above the macro downtrend signaling a new uptrend for DOGE.

⚠️ However, caution is warranted as Dogecoin is currently in the "overbought" zone according to CryptoQuant analysis, suggesting profit-taking may follow.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3qo1hx3q0fhvvlvfwhis.png)
POLKADOT PRICE PREDICTION 2024-2033: A BULLISH PATTERN? 🚀
Published: 2024-02-29 21:08:48

📈 Polkadot's price predictions for the upcoming years show a resilient performance in the crypto market:

🔮 2024: Minimum: $9.63, Average: $9.97, Maximum: $11.38
🚀 2025: Minimum: $14.23, Average: $14.63, Maximum: $16.77
📊 2026: Minimum: $20.07, Average: $20.65, Maximum: $24.62
💰 2027: Minimum: $27.76, Average: $28.59, Maximum: $34.24
🔥 2028: Minimum: $41.33, Average: $42.76, Maximum: $48.55
🌱 2029: Minimum: $61.02, Average: $62.73, Maximum: $72.29
💡 2030: Minimum: $91.34, Average: $93.85, Maximum: $105.80
📈 2031: Minimum: $134.35, Average: $139.04, Maximum: $158.26
🚀 2032: Minimum: $188.75, Average: $194.32, Maximum: $234.99
💰 2033: Minimum: $303.66, Average: $312.26, Maximum: $364.06

These predictions indicate a stable upward trend for Polkadot, with continued market confidence and potential for growth.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ecugtp4ocn4hnesyyf2.png)
Aptos Price Forecast: Is $20 Price Target Imminent Amid zkME Partnership Boost?
Published: 2024-02-29 21:08:17


📈 Aptos, a prominent Layer 1 Proof-of-Stake (PoS) blockchain, has shown a significant bullish trend, reflecting a wider positive movement in the cryptocurrency market.

💰 Currently priced at $11.61, Aptos has surged over 16%, signaling a shift towards a more bullish stance for the altcoin.

🚀 In the past 24 hours, Aptos surged past the $11 resistance mark, following a bullish trend in the aftermarket, aligned with the overall market movement.

📊 Over the last week, Aptos saw its value soar by more than 26%, positioning it as one of the leading performers in the altcoin market.

💼 Aptos boasts a market capitalization of around $4.2 billion, making it the 25th largest cryptocurrency by market cap.

📈 The trading volume for Aptos spiked by 185% in the last 24 hours, reaching $624 million, indicating growing trader interest.

🔐 Aptos' ecosystem's decentralized finance (DeFi) protocols have experienced a significant surge in total value locked (TVL), doubling since the start of the year to surpass $255 million.

🤝 Notable partnerships with zkME and Ondo Finance aim to enhance security and integrate real-world assets within the Aptos blockchain, fueling user engagement and adoption.

📈 Technical analysis suggests a bullish outlook for Aptos, with potential targets of $15 and even $20 in the near future, supported by bullish indicators like the RSI and MACD. Initial support is projected around $10, with a significant safety net at $9.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vbt3xs1qi07tl8jy60bq.png)
How Stellar Lumens (XLM) Is Set to Surpass $1.03: A 2024 Prediction 📈
Published: 2024-02-29 21:07:56

🚀 Stellar Lumens (XLM) has an ambitious roadmap and strategic partnerships that pave the way for surpassing the $1.03 mark by 2025.

📈 Experts predict XLM to average $1.166586 amid advancements, showcasing highly positive market sentiment.

💪 With a minimum trading price of $0.2877, XLM demonstrates strong stability and growth prospects for 2024.

🌟 Stellar Lumens emerges as a beacon of potential in the competitive digital currency landscape, forecasted to achieve remarkable milestones in 2024.

💼 Stellar's robust ecosystem, innovative technology, and strategic partnerships position it for success, potentially exceeding $1.03 in the near future.

💡 As Stellar evolves, its role in facilitating cross-border transactions and enhancing financial inclusivity is expected to catalyze its growth, potentially averaging $1.166586 by 2025.

🔮 XLM's resilience and strategic positioning hint at a bright future, making it a pivotal year for Stellar and its stakeholders.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/94zye106xzbpqntfz8uu.png)
Understanding Cache Memory in Linux
Tags: linux, redhat, memory, devops
Published: 2024-02-29 21:02:02


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pwwsoedog4zjy5129yn4.jpg)

❓This question has gained quite an infamous reputation and can be frequently found in technical forums and Stack Overflow posts. Upon inspecting the output of the free -m command, many users start to panic and wonder if they have enough available RAM in their system. It often raises concerns like Does Linux eat all my RAM?

`$ free -m
total used free shared buff/cache available
Mem: 7741 661 6591 23 488 6825
Swap: 2047 0 2047`

🤔 The reason behind this panic is a common misunderstanding of how Linux manages memory. Linux employs an efficient memory management strategy involving utilizing available RAM to maximize system performance. As a result, a significant portion of RAM may be used even when the system is not under heavy load.

💡 In reality, Linux actively uses RAM for various purposes like caching frequently accessed data, buffering I/O operations, and optimizing system performance. This proactive memory management approach allows faster data access and improved system responsiveness.

🔄 When an application requires more memory, Linux can quickly release cached or buffered data to accommodate the application's needs. This dynamic allocation and deallocation of memory ensure optimal utilization without compromising system stability or performance.
Therefore, it is essential to understand that Linux's memory management is designed to use available resources efficiently. So, even if the free -m output shows a significant portion of used memory, it doesn't necessarily indicate a problem or a lack of available RAM.

👀 Instead of panicking about memory usage, monitoring the overall system performance, including CPU utilization, disk I/O, and application responsiveness, is recommended. By holistically evaluating the system's behavior, you can 
determine if any actual performance issues need attention.

🛠️ If you're still feeling uncertain, there's a simple way to determine the memory available for your system. Look at the "available" column in the free -m output. This column provides an accurate representation of the memory that is currently available for use.

`$ free -m
total used free shared buff/cache available
Mem: 7741 661 6591 23 488 6825
Swap: 2047 0 2047`

Remember, Linux's memory management is optimized to maximize your system's resources, and seemingly high memory usage is normal.
📸 Pic Reference:
www.linuxatemyram.com

📚 If you're interested in more DevOps interview questions, please check out my new book "Cracking the DevOps Interview."
Cracking the DevOps Interview
https://pratimuniyal.gumroad.com/l/cracking-the-devops-interview
Kotlin can do it all??
Tags: kotlin, kmp, fullstack, datascience
Published: 2024-02-29 20:51:03

![Kotlin can be used in various use cases you cannot believe](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/89xiv7miulm8u15gkfjt.jpg)

Hello Everyone, you all know that I like to share my opinion that Kotlin is a better programming language that everyone should try. And it is actually very useful for general purpose programming, Android development, backend and cross platform development etc.

But many improvements are going on to make Kotlin even more better. So let's talk about it here:
- [Kotlin will be having a new compiler called **K2**](https://blog.jetbrains.com/kotlin/2023/02/k2-kotlin-2-0/), that will improve overall performance and will have many improvements and it will be stable in Kotlin 2.0 .
- Kotlin is targeting web assembly through it's new **[Kotlin/WASM compiler](https://kotlinlang.org/docs/wasm-overview.html)** that is alpha state right now, that will help better interoperability with JS and web APIs as well as WASI APIs. See the [Introductory Video](https://youtu.be/oIbX7nrSTPQ?si=fNETj_itKORoA_cy).
- **[Kotlin Multi-Platform(KMP) is stable](https://www.jetbrains.com/kotlin-multiplatform/)** and many Android frameworks and libraries are migrating or already have migrated to KMP.
- Kotlin has a cross platform UI framework called **[Compose Multiplatform](https://jb.gg/compose)**, which is already stable for Android(via Jetpack Compose) and Desktop, but Alpha support for iOS(as it's support has recently been announced) and Experimental support for Web as it will use Kotlin/WASM compiler instead of Kotlin/JS. Yet the Compose Multiplatform has a wonderful DSL for writing Declarative UIs. See how to [Build an iOS and Android app using 100% Kotlin with Compose Multiplatform](https://youtu.be/5_W5YKPShZ4?si=FtSbDhgoQ4BVg-76).
- **[Kotlin Interactive Notebook available in IntelliJ IDEA ultimate](https://blog.jetbrains.com/kotlin/2023/07/introducing-kotlin-notebook/)**, and Kotlin first frameworks and libraries such as KotlinDL, Kandy, KMath, Kotlin DataFrame, MultiK, Krangl, lets-plot, kravis etc, and Kotlin bindings for Apache spark, and interoperability with Java to use its frameworks, makes it a better language for [data science and machine learning](https://kotlinlang.org/docs/data-science-overview.html). See [Introductory Video](https://youtu.be/2PLYlDJPelQ?si=HfYiP3jInHli6ACa), [Tutorial 1](https://youtu.be/m4Cqz2_P9rI?si=6hp2XrpQ-r5l9RvC), [Tutorial 2](https://www.youtube.com/live/_RYV7ZvMKpE?si=GV2leopOAaw3z24U).

That's all I wanted to say. I hope you like this post. Please give your reactions to it. And if you have any suggestions please let me know. 

See you all in my next post. 
And happy Kotlin to you 😊.