teleren/devto huggingface dataset:
How to use useMemo hook in ReactJS
Published: 2022-12-11 00:36:46

In React, **useMemo** is a hook that allows you to optimize the performance of your component by memoizing (saving) the results of a expensive function. This means that if the inputs to the function remain the same, the memoized result will be returned instead of re-computing the result. This can be especially useful when dealing with expensive operations that do not need to be executed on every render, such as complex calculations or expensive DOM manipulations.

To use useMemo, you first need to import it from the react library at the top of your component file:
```import { useMemo } from 'react';```

Next, you can call useMemo in your component and pass it two arguments: the function whose result you want to memoize, and an array of dependencies. The hook will then return the result of calling the function with the current dependencies. Here is an example of how you might use useMemo to memoize the result of a calculation:

```
const MyComponent = (props) => {
  // Define the calculation we want to memoize
  const calculateResult = (num1, num2) => {
    // Do some expensive calculation here
    return num1 + num2;
  }

  // Call useMemo and pass it the calculation function and an array of dependencies
  const memoizedResult = useMemo(() => calculateResult(props.num1, props.num2), [props.num1, props.num2]);

  // Use the memoized result in the component
  return <div>{memoizedResult}</div>;
}
```

In this example, useMemo will call the calculateResult function and save its result when the component is first rendered. On subsequent renders, if the values of props.num1 and props.num2 have not changed, useMemo will return the saved result instead of calling the function again. This can improve the performance of the component by avoiding unnecessary calculations.
Programmers always Overthink
Tags: productivity, programming, career, beginners
Published: 2022-12-11 00:33:51

Overthinking is a common problem among programmers, especially when faced with complex or challenging tasks. It can lead to frustration, stress, and even burnout if left unchecked. Fortunately, there are ways to avoid overthinking and keep your mind focused on the task at hand.

First, it’s important to recognize when you are overthinking. This can be tricky, as it can sometimes be difficult to distinguish between productive and unproductive thoughts. However, there are some common signs to watch out for, such as:

- Obsessing over details or perfectionism
- Constantly second-guessing yourself or your decisions
- Struggling to make progress or move forward with a task
- Feeling overwhelmed or anxious about a project

If you notice any of these signs, it’s time to take action to avoid overthinking. Here are some tips to help:

1. Set clear goals and deadlines. Having a specific goal in mind can help to focus your thoughts and efforts. It’s also important to set realistic deadlines to help you stay on track and avoid getting bogged down in details.
 
2. Break tasks into smaller chunks. Large, complex tasks can be overwhelming, so it’s important to break them down into smaller, manageable pieces. This will make it easier to focus on one task at a time, and it will also help you to see progress as you move forward.
 
3. Take breaks. It’s important to give your mind a break from time to time. Step away from your work, take a walk, or do something else to clear your head. This will help to prevent burnout and keep you refreshed and focused.

4. Talk to someone. Sometimes, overthinking can be a result of feeling isolated or alone. If you’re struggling with a problem, try talking to a colleague or mentor. They may be able to provide a fresh perspective or offer helpful advice.

5. Be kind to yourself. Overthinking can often be a result of self-doubt or negative self-talk. It’s important to be kind to yourself and remember that everyone makes mistakes. Accept your limitations and focus on what you can do to improve.

By following these tips, you can avoid overthinking and keep your mind focused on the task at hand. This will help you to be more productive, reduce stress, and ultimately be more successful in your programming career.

[linkedin.com/in/trinmar](https://www.linkedin.com/in/trinmar/)
【XAMPP】How to fix "Error: MySQL shutdown unexpectedly. "
Tags: xampp, mysql
Published: 2022-12-10 23:58:13

This error happens often in my PC and once it happens your MySQL never starts again.
##1.Check the error log.##
Click [logs] of MySQL in XAMPP control panel and select [mysql_error.log] to check the error messages.

##2.Check if the port "3306" is used.##
Click [Netstat] in XAMPP control panel to check "3306" is already used.

##3.Restore data in MySQL.##
If you can not get any hints to solve the problem, try this step.

**1**. Find "mysql">"data" folder in XAMPP and copy and paste it somewhere to back it up.

**2**. Delete files/folders from "mysql">"data" folder.
**ATTENTION**
**KEEP** the folders with names of DB that you created from "data" folder. Delete everything else.

**3**. Find "mysql">"backup" folder to copy everything in it.

**4**. Paste them in "mysql">"data".

**5**. Copy "ibdata1" file in "data" folder you backed up in step1,and paste it in "mysql">"data" folder.

**6**. Start MySQL in XAMPP control panel.

##4.Set user password for MySQL.##
Once the data is restored, your user password for MySQL is reset. You need to set it again.
First, login to MySQL with no password.

```
mysql -u root
```
Then, set the user password.

```
ALTER user 'root'@'localhost' identified by XXXX
```
then, you can log in MySQL with your password.

##Concluion##
Good Luck!!
Introduce Yourself
Tags: opensource, typescript, react, webdev
Published: 2022-12-10 23:22:05

## Meet David.

I am Obodo, David Sopuruchukwu, an Outreachy intern on the project 

> Consolidating and making reusable various react UI components from two user interfaces.


I graduated from the University of Nigeria, Nsukka in 2019 with a bachelors in Mechanical Engineering. After that, I was opportune to work with **Starnet Innovations**, a technology company specializing in software and web development.

My time at Starnet Innovations provided me with enthusiasm and 
fueled my drive for software development. I learnt about opensource and proprietary projects, their benefits and cons.


## My Core Values

> “Creativity doesn’t wait for that perfect moment. It fashions its own perfect moments out of ordinary ones.” —Bruce Garrabrandt

Bruce's quote closely  resonates with my being, I believe that people are born with **creativity** and not developing it is a disservice to humanity.

The first step is thinking out the solution (_creativity_), the next step is enduring the hardships that comes with bringing the creative solution to reality, this is the next best thing I possess, **Determination**. I always believe that it is not enough to possess an Idea, because an Idea that remains in the Idea stage is as good as not having an Idea.

I believe that there are times when we enlist the help of other people to drive our plans for the future. It is paramount that in thinking about the future, I develop the necessary skillset required to lead the people whose help I enlist. I believe that leaders are born out of circumstances but a true leader is one who in the face of adversity, maintains his/her vision and action plan for the future. **Leadership** is key to success


## My Motivation for Outreachy.

Outreachy provides me with the opportunity to learn from very talented mentors. Outreachy projects are opensource and therefore, offers me the flexibility to contribute to projects that impact people's life. Before applying to Outreachy, there are many bias I faced in the world of tech but outreachy encourages persons faced with bias to apply for its internship.

My biggest motivation, was a friend of mine, a previous Outreachy recipient whom I met in a shared program. He told me about Outreachy and encouraged me to apply. In his words, `Outreachy could redefine how I think of software engineering`, and I must confess, It has.
How I use Notion as a Software Developer
Tags: productivity, beginners, notion, 100daysofcode
Published: 2022-12-10 23:20:31

I have spent a lot of time watching a lot of Notion content on Youtube and I even read a bit of the Notion API Documentation to see if there’s any way I can integrate Notion into my existing workflow. Ever since I discovered [Notion](http://notion.so), it has become a productive tool I use almost every day.

Everything in Notion is a block that can be texts, images, videos, links, headings etc. and can be transformed into another type of block or rearranged in any way that may suit your needs.

## Personal Dashboard

I created a personal dashboard to manage myself, my work, my learnings, my library, etc. This is like a homepage that is shown to me whenever I open up Notion.

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

(Trust me, I don’t use Notion in light mode 🙂)

I used to have this dashboard open on an extra monitor so I thought it can be a bit aesthetic by showing a clock and auto-generated quote images. The clock and auto-generated quotes images are widgets created using [indify.co](https://indify.co/).

## Note-taking App

Notion is always my go-to app for note-taking. I find the markdown support extremely useful as a developer to write notes faster. Notion supports syntax colouring for over 60 programming languages making it a good utility for developers.

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

It provides some features that I really find helpful for note-taking. It is cross-platform, can share notes with the public and also invite private collaboration.

## Technical Writing

I manage a Notion database for articles and write my drafts using Notion. Because of my familiarity with markdown and the speed to use any block type on Notion, I am able to focus more on writing while things like formatting, link insertions, etc happen from muscle memory. Notion database is handy for project management. 

This is a screenshot of how I manage my article writing workflow.

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

I am able to use tags to keep track of the article status and ownership and also sort the data based on the deadline, ownership and status of the article. I also had the table configured to remove published items from the table view.

> I am currently researching ways to improve my blogging workflow using Notion API. I am open to recommendations and collaboration, please.
> 

## Wrap Up

That is a quick overall of how I use Notion in my workflow as a developer. I hope you are able to get new ideas from my workflow and able to find new ways to incorporate Notion into your workflow too. 

Kindly share how you use [Notion](http://notion.so) too so we have plenty of inspirations to choose from.

Let’s connect on [Twitter](https://twitter.com/zt4ff), whatcha say?
Uncaught Typeerror: cannot read properties of undefined (reading 'render')
Tags: webdev, react, javascript, codenewbie
Published: 2022-12-10 23:14:59

Encountered a blank screen after running my Server.
Everything had been rendered correctly, but none of the components was visible on the browser.

- Check the render method in the ReactDOM. The likely error is wrong method of importing the ReactDOM

ReactDOM is a default export from the 'react-dom' module

Your code editor might have autocompleted the import by putting curly braces around ReactDOM ie `import {ReactDOM} from 'react-dom'` rather than `import ReactDOM from 'react-dom'`

- Having it in curly braces treats ReactDOM as a named import and not a default one.
Avent of Code - Day 10 - Cathode-Ray Tube
Tags: adventofcode, aoc, programming, ascii
Published: 2022-12-10 23:14:13

[Advent of Code](https://adventofcode.com/) occurs at Dec 01 to 25 where each day, you will need to solve a puzzle. It is Festival and the problem statement is mostly related to Christmas.

## Day 10  - Cathode-Ray Tube
https://adventofcode.com/2022/day/10

### Q1
```python
import sys
from collections import defaultdict

file1 = open(sys.argv[1], "r")
score = 0

def f(c):
        return c in (20, 60, 100, 140, 180, 220)

data = defaultdict(int)

i = 0
while True:
        line = file1.readline()
        if not line:
                break
        i += 1
        a = line.strip().split()
        if a[0] != "noop":
                print(a)
                data[i + 1] += int(a[1])
                i += 1

x = 1
for j in range(i + 1):
        if f(j):
                score += j * x
                print(j, x)
        x += data[j]

print(score)
```

### Q2
```python
import sys
from collections import defaultdict

file1 = open(sys.argv[1], "r")
score = 0

def f(c):
        return c in (20, 60, 100, 140, 180, 220)

row = list("........................................")

data = defaultdict(int)

i = 0
while True:
        line = file1.readline()
        if not line:
                break
        i += 1
        a = line.strip().split()
        if a[0] != "noop":
                data[i + 1] += int(a[1])
                i += 1

x = 1
cur = row[:]
print(i)
for j in range(1, i + 1):
        if j % 40 == 0:
                score += j * x
                print("".join(cur))
                cur = row[:]
        x += data[j]
        if abs((j % 40) - x) <= 1:
                cur[j%40] = '#'

print(score)
```

![5f359d5ca53d15dd4867f3acc10653e.jpg](https://cdn.steemitimages.com/DQmUD7cBwxVzxYm4trjFaqRwHWRPau6nsoMSfS11Lri8QQx/5f359d5ca53d15dd4867f3acc10653e.jpg)


![cebb4ddb98e922d0085610f86c76f26.jpg](https://cdn.steemitimages.com/DQmcS9N2puMUJVCKKt5bGwzA8FVMnnsYb9eW9WTADneJ3eU/cebb4ddb98e922d0085610f86c76f26.jpg)


Getting interesting! Looking at Q1 - Huh? not much useful with only 2 instructions. Q2 - wow! Surprised to see how we make use of only 2 instructions to draw something meaningful using only [ASCII](https://helloacm.com/teaching-kids-programming-introduction-to-ascii/) characters.

I believe,  similar questions have appeared in previous AOC (maybe 2020 or 2021).


<hr/>

### [Steem](https://steemyy.com) to the Moon!
How to parse cpanfile?
Tags: perl, cpanm, cpanfile
Published: 2022-12-10 23:03:05

How to parse cpanfile? <a href="https://metacpan.org/pod/Module::CPANfile">Module::CPANfile</a> makes it possible.

```perl
use Module::CPANfile;
 
my $file = Module::CPANfile->load("cpanfile");
my $prereqs = $file->prereqs; # CPAN::Meta::Prereqs object
 
my @features = $file->features; # CPAN::Meta::Feature objects
my $merged_prereqs = $file->prereqs_with(@identifiers); # CPAN::Meta::Prereqs
 
$file->merge_meta('MYMETA.json');
```
Improvment of Google Searching Result of metaCPAN
Tags: perl, perlsuggestion, google
Published: 2022-12-10 22:48:37

I search <a href="https://www.google.com/search?q=SPVM%3A%3AResource%3A%3ASocketUtil&sxsrf=ALiCzsaW94D_pp5no87985cDWnD5KnkZ3w%3A1670711741556&ei=vQmVY5bKIZL2wAPsq7ToDQ&ved=0ahUKEwjWnIKfjvD7AhUSO3AKHewVDd0Q4dUDCA8&uact=5&oq=SPVM%3A%3AResource%3A%3ASocketUtil&gs_lcp=Cgxnd3Mtd2l6LXNlcnAQA0oECEEYAEoECEYYAFAAWABgqwJoAHAAeACAAXqIAXqSAQMwLjGYAQCgAQHAAQE&sclient=gws-wiz-serp">SPVM::Resource::SocketUtil</a>. The top result is the <a href="https://metacpan.org/dist/SPVM-Resource-SocketUtil">page of the file list</a>.

I often experience this by searching other CPAN modules.

This should be <a href="https://metacpan.org/pod/SPVM::Resource::SocketUtil">the doc page</a>.

This can be fixed by applying SEO to metaCPAN.
Notes about design patterns
Tags: php, designpatterns, beginners, programming
Published: 2022-12-10 22:36:08

Design patterns are practical proven solutions to recurring design problems. They are blueprints not algorithms or code to solve a common software problems.

It's important to note that it won't be so simple to look at a software design problem and automatically know which design pattern to use.

Design patterns are categorized into 3 groups : 
**Creational Patterns :** provide mecanisms for object creation which increase flexibility and reuse of existing code. Example : Factory Pattern, Builder Pattern, Singleton...
**Structural Patterns :** Describe how objects are connected to each other, example : Adapter Pattern, Decorator Pattern, Facade...
**Behavioral Patterns :** how objects distribute work and how they work towards a common goal.

Design patterns help to have a common design vocabulary between developers. Rather than having to explain the details of a design solution you can simplify the discussion by having a suggestive word to describe it.

One of the design principles is to identify the aspects of application that varies and separate them from what stays the same. With this approach we won't have to make changes in different places when a new request is made by the client, that minimize the amount of bugs that can be introduced by the change and it makes the code flexible.

**1. Strategy pattern : **
Define a family of algorithms encapsulates each other and make them interchangeable. Strategy lets the algorithm vary independently from client that use it



![Strategy-pattern-example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fr5vl8yd4zy215lrhli5.png)
Embedded Systems Weekly #130
Tags: embedded
Published: 2022-12-10 22:35:17

Welcome to issue #130! The end of the year is coming and the time to build your plans for the next years is coming. Did you start to think about something new that you want to learn?

**Happy reading!**

## Articles 
[Introduction to Embedded Systems Programming](https://learn.adacore.com/courses/intro-to-embedded-sys-prog/index.html)
I'm happy to share this introduction because it is not one in C or even in Rust but in Ada.

[Predefined Boolean constants (C23)](https://en.cppreference.com/w/c/language/bool_constant)
The future standard of the C language is coming! The header "stdbool.h", introduced in the C99, is removed by the [C23](https://open-std.org/JTC1/SC22/WG14/www/docs/n3054.pdf). A new built-in [bool](https://en.cppreference.com/w/c/language/bool_constant) type is added directly in the language, and so are the predefined constants true and false. With remarkable patience and longevity, we might use them in our embedded projects in 10 years or so.

[A bare metal programming guide](https://github.com/cpq/bare-metal-programming-guide)
It's a beginner guide for developers who want to start their adventure in the bare metal world. It uses the STM32F429, but as the author writes, most of the fundamental parts apply to any other microcontroller.

[How undefined signed overflow enables optimizations in GCC](http://kristerw.blogspot.com/2016/02/how-undefined-signed-overflow-enables.html)
It's an article from 2016, but I have to admit I didn't know that GCC is using some undefined behavior to do optimizations. It's a very interesting technical article.

[NASA Uses RISC-V Vector Spec to Soup Up Space Computers](https://www.eetimes.com/nasa-uses-risc-v-vector-spec-to-soup-up-space-computers/)
Did you know about the RVV spec advantages? If you are like me, and you didn't, this article is a great overview.

[PicoWi: standalone WiFi driver for the Pi Pico](https://iosoft.blog/2022/12/06/picowi/)
In this series of 6 articles, the author writes from scratch a driver for the CYW43439. From the low-level SPI driver to the ARP and ICMP protocols, everything is explained in detail.

## Jobs
[Tietoevry, Embedded Software Engineer – Digital Signal Processor/Processing, Poland, Warsaw (Partially remote)](https://jobs.embedsysweekly.com/job/Kg6R3Jwm/embedded-software-engineer-digital-signal-processor-processing)
We are one of the largest Nordic IT services company. In Poland our specialty is delivering modern IT business solutions, mainly as software development for well-known companies from different sectors like automotive and smart devices.

## Misc
[The sensor which is integrated into the Word Cup ball](https://kinexon.com/blog/fifa-preferred-provider-live-player-and-ball-tracking/)
This week I randomly learned that the World Cup ball embeds a sensor. From the company website: "utilizing both ultra-wideband (UWB) radio frequency and an Inertial Measurement Unit (IMU)"
redirect with parameters
Tags: apache2
Published: 2022-12-10 22:28:47

Hi, i'm trying to setup apache2 to serve a gatsby webapplication.
I need to use a dynamic webpage and I obtain a fast error 404 with an automatic redirect to this page.

I'm trying to configure apache with the following snippet of configurition.

```
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/auto
    RewriteRule (.*) /auto/ [QSA,L]
```
It works, but i need to redirect the parameters, too.
The problem is about the canonical url after the redirect

the input is https://example.com/auto/alfaromeo (alfaromeo is a parameter), the canonical url is
https://example.com/auto/
How can I add the parameter?

how can I solve it?

Thanks a lot
Angelo
Pynecone: Web Apps in Pure Python
Tags: webdev, python, programming, productivity
Published: 2022-12-10 21:56:45

Hello, we just launched the Alpha release of [Pynecone](https://github.com/pynecone-io/pynecone), a way to build full-stack web apps in pure Python. The framework is easy to get started with even without previous web dev experience and is entirely open source / free to use.

If you are a Python dev who values development speed and working within an entirely Python ecosystem, Pynecone is a great option. We made Pynecone for Python devs who want to make web apps, but don’t want the overhead of having to learn or use Javascript. We wanted more flexibility than existing Python frameworks like Streamlit/Dash that don't allow the user to make real, customizable web apps.

You can make anything from a small data science/python project to a full-scale, multi-page web app in Pynecone. We have over 60+ built-in components and support full styling on our all components.


Pynecone is a brand new framework so please star us on GitHub if you want to follow our progress as new updates come. We are actively trying to grow this project no matter your skill level; we welcome contributions! Open up an issue if you find missing features/bugs or contribute to an existing issue.