teleren/devto huggingface dataset:
Memoization Simplified
Tags: javascript, react, reactnative
Published: 2023-04-01 15:22:26

---
title: Memoization Simplified
published: true
description: Frequent FE Interview Question explained in simple language with example
tags: javascript, react, reactnative
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2023-04-01 13:29 +0000
---

One of the common interview question asked during interview is memoization. 

Before starting on technical details, lets understand general definition - 

Memoization is a programming technique that speeds up the execution of functions by **caching the results of previous function calls and returning the cached result when the same inputs occur again**. 
This can be useful for functions that take a long time to compute and are called repeatedly with the same inputs. By caching the results of previous function calls, memoization avoids redundant computations and improves the overall performance of the function. 

In simple words, memoization is a process where we cache the result of a function against function's input arguments and use cached value when same input arguments are used. 

Implementation : 
You can create generic function which coverts a normal function into memoized function.

Consider the following example - Assume you have a expensive function which multiply 2 big integers
```
const multiply = (a, b) => {
	return a * b;
}
```
There is no point in calling this function again and again with same arguments. You can just create a memoized version of same function which will save you execution time and computational space.

In order to achieve this, we need to use High Order Functions. Find more information on HOF [here](https://dev.to/rv90904/high-order-function-explained-20b1)

```
const memoizedFunction = (func) => {
        let cache = {}
        return (...args) => {
            var stringifiedArgs = args.toString();
            if (cache[stringifiedArgs]) {
                return cache[stringifiedArgs]
            }

            var result = func(...args)
            cache[stringifiedArgs] = result;
            return result;
        }
}
```

Here `memoizedFunction` accepts function as argument and return a new funtion. It also maintain history of all the function call and its value inside `cache` which is then used to determine if it need to call the function or return value from cache. 

```
const memoizedMultiply = memoizedFunction(multiply)


memoizedMultiply(314, 340) // calculated
memoizedMultiply(10, 340) // calculated
memoizedMultiply(314, 340) // cached

```

Voila! You have successfully memoized a function. 

If you're interested in learning more about React, React Native and JS, check out my Linkedin profile [here](https://www.linkedin.com/in/rameshvishnoi/). And feel free to share it with anyone who might find it helpful!

Happy coding!
Ways To Collaborate More Effectively In a Coding Team
Tags: webdev, beginners, programming, career
Published: 2024-06-20 05:14:57

A sign of an inexperienced dev, is that they make huge changes to the codebase at once.

Meaning, your Pull Requests are too big to make sense of.

They are too big for any meaningful comments or remediation.

And not checking in your code more often, you can introduce problems that are harder to diagnose because of all the changes to the codebase that you introduced.

A Pull Request should really have just one cohesive feature that you are working on, not multiple. And of course, if a feature is big, then perhaps it should be broken up into multiple logical parts.

So, commit often and make sure to test each commit. If you have sketched or planned out your feature first, like I just mentioned, you probably have ended up with a checklist of steps to get your feature working.

And every time you check off a step or task, test it and commit it.

And once a feature is a whole, it is fully working and tested, then push your code up and create the PR.

Here is a good example that I came across.

"I commit every time I finish a unit of work, but don't push my code to the server until the feature is fully complete. I'll try to elaborate with an example:

Say my job is to develop a login system for some website. I would write my class for a 'user' then commit. Then I'd create the html form to accept the username and password, and then commit. Then I would add the appropriate validation(make sure password is long enough, make sure email is valid) and then commit.

This could be three commits in one day or spread over multiple days, it depends on how long each unit of work takes.

Once everything is done, I would then push up my branch, create a Pull Request to be reviewed and then merged into master by somebody who approves that.

If it is a personal project, I would just merge my development branch(es) into master and push to origin.

I would never ever ever push code that would cause a crash, or break the build for a project. Especially if you are collaborating with others.

So, if you are in the middle of writing a class, but haven't finished typing out a function, don't commit until everything is done, and you can successfully build."

So, if you planned out your work and have some sort of checklist, you would commit at each checkmark. The main thing here is that don't write a bunch of code and then push them up all at one time.

Happy Coding!
Karl

P.S. [The Art of Job Interviews](https://karlgusta.gumroad.com/l/pizbkr) Course is live! Go and check it out!
In Excel, Judge Whether A Word Has Duplicate Letters
Tags: beginners, programming, tutorial, productivity
Published: 2024-06-20 05:14:12

**Problem dscription & analysis**:

In the following column, each cell contains a word and certain words have duplicate letters:

![original table](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qvoqt38h4hsppgq2yq55.png)

If a word has duplicate letters, display NOGOOD in the right cell; if it hasn’t, display GOOD in the cell:

![desired table](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6rwskgq4uoonrdsc8phq.png)

**Solution**:

Use **SPL XLL** to enter the following formula and drag it down:

```
=spl("=d=?.split(),if(d.icount()==d.count(),$[GOOD],$[NOGOOD])",A1)

```

![result table with code entered](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o8b368ojdbfvcl02zqyj.png)
**Explanation**:

split()function splits a string according to unique letters. icount() function counts unique letters in a word. count() function calculates the number of unique letters in all the words.
Inheritance in OOP
Tags: devchallenge, cschallenge, computerscience, beginners
Published: 2024-06-20 05:08:38

*This is a submission for [DEV Computer Science Challenge v24.06.12: One Byte Explainer](https://dev.to/challenges/cs).*

## Explainer
Inheritance is an important paradigm in OOP. It refers to the concept that methods and properties defined by a parent class are available on all of its subclasses, e.g. an Animal class with the method **bark** will have this method available on other classes which extend it.
<!-- Explain a computer science concept in 256 characters or less. -->

<!-- Please share any additional context you think the judges should take into consideration as it relates to your One Byte Explainer. -->

<!-- Team Submissions: Please pick one member to publish the submission and credit teammates by listing their DEV usernames directly in the body of the post. -->

<!-- Don't forget to add a cover image to your post (if you want). -->

<!-- Thanks for participating! -->
Running an Android App in React-Native CLI
Tags: reactnative, androiddev, javascript, react
Published: 2024-06-20 05:03:04

This guide will walk you through the steps to run an Android app using React Native CLI. By following these steps, you can ensure your development environment is properly set up and your application runs smoothly on your connected device.

**Steps**

**Step 1: Check Connected Devices**

1. Connect Your Device:
   - Use a USB cable to connect your PC/Mac to your testing mobile 
  phone.
   - Make sure USB debugging is enabled on your mobile phone.

2. Check Connected Devices:
   - Open a terminal on your PC/Mac.
   - Run the following command to check the list of connected devices:

```
adb devices

```
   - This command will show a list of devices attached. If your device appears in the list, it is correctly connected.

**Step 2: Clean Previous Builds**

   - Run the following command to clean the previous cache and builds. This helps prevent unwanted bugs:

```
./gradlew clean

```

**Step 3: Run the React Native App**
  - Go back to the root directory of your project:
  - Run the React Native App:

```
npx react-native run-android

```
  - Optional: Reset Metro Bundler Cache:
 

```
npx react-native start --reset-cache

```

**Step 4: Generate the Debug APK**

 Build the Debug APK:
 By running the previous commands, React Native will create an APK file named debug.apk for testing purposes.
The Creepy Crawlies of Code: Why Bugs Are Gross (Even in the Digital World)
Tags: webdev, programming, productivity, javascript
Published: 2024-06-20 05:00:00

We all know the feeling – you're excitedly tapping away on your phone, ready to conquer that new level in your favorite game, when suddenly... everything freezes. An error message pops up, a cryptic code you don't understand. You sigh, muttering, "There goes another bug."  

But beyond the technical frustration, there's a deeper reason bugs in software evoke feelings of disgust.  Let's explore why these digital glitches trigger our aversion.

**The Eww Factor:**

The word "bug" itself is rooted in the physical world. It conjures images of tiny, unwelcome creatures – beetles scuttling across the floor, cockroaches emerging from the shadows.  These real-life bugs are often associated with dirt, disease, and a general sense of uncleanliness.  This negative association spills over into the digital realm. A program riddled with bugs feels, well, buggy – like something unclean and malfunctioning.

**The Unpredictability Factor:**

Real-life bugs are unpredictable. You never know where they might crawl or what damage they might cause.  Similarly, software bugs can wreak havoc in unexpected ways.  A game might crash at a crucial moment, an important document might be corrupted, or a website might display nonsensical gibberish. This unpredictability fuels our sense of unease – we can't control the bug, and we don't know what kind of chaos it might unleash.

**The Disruption Factor:**

Bugs interrupt our digital flow.  Just like a sudden spiderweb on your face disrupts your walk through the park, a software bug disrupts your digital experience. You're on a roll, focused on a task, and then – **bam!** – the bug throws you off track. This disruption can lead to feelings of frustration and even powerlessness. 

**The Ick Factor:**

Let's face it, some bugs (both digital and physical) leave a trail of… well, ick.  Corrupted data can manifest as garbled text, distorted images, or nonsensical audio – a digital mess that's visually unpleasant and unsettling. It's like finding a spiderweb not just on your face, but smeared all over your phone screen. Double ick.

**Beyond the Grossness: The Importance of Bug Squashing**

Despite the ick factor, software bugs are a fact of life.  The good news is that developers are the ultimate bug exterminators. They use their skills to hunt down, understand, and eliminate these digital nuisances. The next time you encounter a bug, take a moment to appreciate the tireless work of developers who keep our digital world running smoothly (and hopefully, gross-free).

**So, while the "grossness" of bugs might be a bit tongue-in-cheek, it highlights the importance of keeping our software clean and functional.  After all, no one wants a digital world crawling with creepy crawlies!**
Creating a storage account and configuring basic settings for security and networking in Azure
Tags: webdev, programming, beginners, devops
Published: 2024-06-20 04:50:01

In the Azure portal, navigate to Resource groups and click create. Name your resource group, and then select a region.

![storagerg](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4u2ecp2yt7i7e77hl6m8.png)

To validate the resource group press review + create. To deploy the resource group press create.

![review and create for storagerg](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h9o144u3dmteohg69w97.png)

Now to create and deploy a storage account you search and click on Storage accounts and click create. Just as before, select your Resource group, and give a Storage account name. Set the Performance to Standard. Select Review + Create, and finally click Create.

![storage account creation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0spix35sqoi5vgj5d6e3.png)

Once the storage account is deployed press go to resource. The next steps are to configure simple settings in the storage account. Since the data in this storage account doesn’t require high availability or durability, a lowest cost storage solution is desired. In the created storage account, in the Data management section, select Redundancy. Select Locally-redundant storage in the Redundancy drop-down and click save. 

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

The storage account should only accept requests from secure connections. In the Settings section, select Configuration. Click Enabled on the Secure transfer required. Since the developers would like the storage account to use at least TLS version 1.2, in the Settings section, select Configuration and make sure the Minimal TLS version is set to Version 1.2. Until the storage is needed again, you can disable requests to the storage account. In the Settings section, select Configuration. Click to disabled on Allow storage account key access. Save changes. 

![version 1.2 and disabling configuration](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/51a5c81xtxdr8vkl3424.png)

To ensure that the storage account allows public access from all networks navigate to the Security + networking section, and select Networking. Enable Public network access from all networks. Save changes.

![enable public network access](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2waaxtwkrj2nt91ozae5.png)
Renaming Bugs as "UnWritten Test Cases"
Tags: bugsarenewtestcases, notabug, xp
Published: 2024-06-20 04:48:53


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

**The Code Crusaders Story**
There was a team of superheroes called the "Code Crusaders". Their job was to protect the digital world from bad things like glitches and bugs.

One day, they got a call that a virus was causing trouble in Pixelville. The team went to fix it but discovered a very complex bug. They tried and tried but couldn't get rid of the bug.

Then their wise teacher said, "The bug isn't a bug in the code. It's a test you haven't written yet."

This made the team think in a new way. 
Instead of seeing the mistake as a failure, they saw it as an opportunity to improve their testing.

They carefully researched the bug to understand how it works. Then they wrote new tests to catch such a bug next time. With new tests, they were finally able to beat the bug!

The people of Pixelville celebrated their heroes. Since then, the Code Crusaders have seen every bug as an opportunity to improve testing.

**True Lesson (Simply)**
Although the story is a hoax, it teaches an important true lesson about mistakes.

The reality is Bugs doesn't exists in real life, it's just some test cases they didn't wrote.

Instead of fixing the bug, you should write a new test for such a problem. That way it won't happen again.

Handling errors in this way changes your thinking. Not only will you react to mistakes, but you will be better able to prevent them.
It also helps teams work together better. 

Instead of blaming, you investigate the error and improve your testing as a team.

This test-focused mindset keeps your skills sharp as technology changes. Testing must also adapt to changing user needs.

Seeing bugs as "missing tests" changes the way you develop software. This leads to higher quality code and a better user experience.

Meanwhille we can connect over 
https://www.linkedin.com/in/ashish-codejourney/
https://x.com/codejourney_
Ultimate Guide to Effective Project Progress Communication with Top Management
Tags: webdev, leadership, teamlead, projectmanager
Published: 2024-06-20 04:37:33

Effective communication of project progress to top management is pivotal for the success of any project. Beyond sharing updates, it involves presenting information in a way that is strategic, insightful, and aligned with organizational goals. This guide outlines advanced strategies and tips for project managers to convey progress to top management in a manner that is both influential and educational.

1. Understanding the Executive Perspective
2. Crafting Clear and Impactful Reports
3. Tailoring Communication Methods
4. Highlighting Achievements and Addressing Issues
5. Demonstrating Value
6. Fostering Transparency and Trust
7. Advanced Tools and Techniques for Reporting
8. A Real-Life Example

Get the full scoop! [Read more here](https://futuristicgeeks.com/ultimate-guide-to-effective-project-progress-communication-with-top-management/). 

Visit our [website](https://futuristicgeeks.com) for more informative insights!
Setting up NVIDIA stuff on Pop!_OS
Tags: ubuntu, nvidia, linux
Published: 2024-06-20 04:03:41

I had a lot of trouble with Ubuntu+NVIDIA which I solved by just installing PopOS. On Ubuntu I was getting small 'hiccups' all the time (my machine was freezing for a few seconds) and sometimes crashed under heavy video usage.

Technically PopOS is just Ubuntu under the hood, so it shouldn't be better when compared to a well-configured Ubuntu. Maybe it's me sucking setting up the driver myself. Maybe the NVIDIA-specific ISO has some secret sauce not easily achievable. Probably both.

Before we start, here is the machine I'm using:

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

Fresh from the installation I already had NVIDIA settings installed and showing my card temperature, what a relief:

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

The PowerMizer setting was a little stubborn. I want to always be on "Prefer Maximum Performance", but it ended up losing my settings once I rebooted. I fixed by adding those two commands to run at startup:

```
nvidia-settings -a '[gpu:0]/GPUPowerMizerMode=1'
system76-power profile performace
```

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

Next, let's proceed and get `nvtop` for verifying the GPU usage and `glxgears` to run something on it:

```
sudo apt install nvtop mesa-utils
```

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

Let's put CUDA on this thing and test it out with PyTorch:

```
$ sudo apt install nvidia-cuda-toolkit
$ python3 -m venv venv
$ . venv/bin/activate
$ pip install torch
$ python3
>>> import torch
>>> torch.cuda.get_device_name(0)
'NVIDIA GeForce RTX 2060'
```
สัญญาณเตือน ที่ธุรกิจต้องจ้างบริษัทรับทําเว็บไซต์มาช่วยแก้วิกฤต
Published: 2024-06-20 04:00:01

1. เว็บร้างไร้คนเข้าเยี่ยมชม
ประเดิมกันที่ข้อแรกที่ดูเหมือนจะเป็นสัญญาณเตือนที่ชัดที่สุด ทำเว็บไซต์มาแต่คนเข้าเยี่ยมชมเว็บไซต์ไม่เป็นไปตามเป้า และเริ่มน้อย ๆ ลงเรื่อย จนท้ายที่สุดกลายเป็นเว็บร้างที่ถูกลืม สืบค้นก็หาไม่เจอ จำเป็นอย่างยิ่งที่ต้องให้ผู้เชี่ยวชาญระดับมืออาชีพเข้ามาช่วยกู้ชีพ ปรับปรุง แก้ไข และพัฒนาเว็บไซต์แบบด่วน ๆ
2. เว็บรกไม่น่าชม
ขนาดคุณเองที่เป็นเจ้าของเว็บไซต์ยังสัมผัสได้ถึงความรก ไม่เป็นระเบียบ ข้อมูลกระจัดกระจายไม่น่าชม ซึ่งลูกค้าผู้ที่เข้าใช้งานเว็บไซต์ก็คงรู้สึกไม่แตกต่างจากคุณเท่าไหร่ ซึ่งจำเป็นอย่างยิ่งที่ต้องให้บริษัทรับทําเว็บไซต์เข้ามาช่วยออกแบและปรับโครงสร้างเว็บไซต์เสียใหม่
3. ค่าโฆษณาบนแพลตฟอร์มต่าง ๆ เริ่มสูงขึ้น
เมื่อมีผู้สนใจทำธุรกิจออนไลน์มากขึ้น จึงไม่แปลกที่ค่าใช้จ่ายต่าง ๆ จะเพิ่มขึ้นตามปริมาณความต้องการ โดยเฉพาะค่า Ads หรือค่าโฆษณาที่จำเป็นอย่างยิ่งในการทำการตลาดออนไลน์ หากคุณยังฝากธุรกิจไว้กับแพลตฟอร์มอื่น ๆ ก็จำเป็นต้องเสียค่า Ads ตามเงื่อนไขของแพลตฟอร์มนั้น ๆ แต่หากคุณมีเว็บไซต์ที่มีคุณภาพเป็นของตัวเอง ก็ไม่จำเป็นต้องจ่ายค่าโฆษณาที่สูงขึ้นตาม Demand แถมยังทำงานและลงโฆษณาเองได้อย่างอิสระ ไม่มีกฎเกณฑ์เงื่อนไขใด ๆ มาตีกรอบให้หงุดหงิดใจ
4. ต้องการเพิ่มประสิทธิภาพของ SEO

http://xn--c3cugjc8cxav6e2a9j2bxb0e.com
A simple task, a senior's mind
Tags: programming, designsystem, api, softwareengineering
Published: 2023-07-24 12:24:03

As all software developers, especially seniors, I was faced today with the task of making a simple, brain dead, design decision that I should be able to make in my sleep, but with every passing minute I came up with new designs and solutions to reach the same result so after spending 15 minutes thinking about it I got confused and the seemingly simple task became an important design choice.

> For every problem, there is a solution that is simple, neat, and wrong. - H. L. Mencken

Let me walk you through what happened.
 
I was tasked with developing a solution to block some phone numbers (based on country codes) from receiving SMS from our APIs. The requirements are clear:

1. have a configurable list of country codes
2. validate the phone number against them
3. throw a nice exception telling the user to use email instead of phone!

Starting off I began wondering where to store this list of country codes, the first option that came to my mind was: <u>Store it in a configuration file</u>. Easily editable and accessible, but then I remembered that we are hosted on AWS and are using IaC which means that to change the configuration file I'll need to push my infrastructure.  
**Back to my brain lab** I thought about <u>storing this list in a new DB table</u>, simple, easy, straight forward, a table that contains a list of blocked countries with their codes, but worth it? 

I gave it an extra minute…. 
Why not create a DB table with a list of all countries and add a flag to it specifying if the country is supported or not? 

OR, another minute passes...
Why not create an application settings table (basically a configuration file stored in a DB table where each record is a key value pair) having an entry containing a list of these blocked countries…..

A simple task now needs a decision making chart of Pros and Cons


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

Even the most experienced amongst us will face this issue, a simple question a multitude of right answers! That's the job!

> With great power comes great responsibility
Volunteer Backend Developer
Tags: backend, backenddevelopment, node, nextjs
Published: 2024-06-20 03:48:24

Join **Generals** as a volunteer Backend Developer and help build a platform that fosters unity in the body of Christ!

**Responsibilities:
**- Design and develop the server-side logic and database integration
- Create RESTful APIs and ensure data security and scalability
- Collaborate with our team to integrate frontend and backend functionality
- Troubleshoot and optimize backend performance
- Be a believer of the gospel

**As an unpaid volunteering opportunity, you'll gain:**
- Experience working on a project with a meaningful mission
- Opportunity to develop your skills and build your portfolio
- Collaborative and supportive team environment
- Reference letter and recommendation upon completion of project
- The joy of serving and making a positive impact in the community!


If you're interested in this opportunity, please reach out to us at rejoiceoedokpayi@gmail.com.

Let me know if you need any further assistance!