teleren/devto huggingface dataset:
Refactoring for readability
Tags: readability, refactoring
Published: 2022-10-19 16:58:48

---
title: Refactoring for readability
published: true
date: 2022-08-28 00:00:00 UTC
tags: readability,refactoring
canonical_url: https://jhall.io/archive/2022/08/28/refactoring-for-readability/
---

I’ve been doing a lot of refactoring lately. This is pretty common when I join a new project, especially one with a lot of technical debt.

At this stage, a large portion of my refactoring is _purely_ readability related.

“Isn’t all refactoring readability-related?” one might ask.

Perhaps in a sense. Code structure is largely about readability.

But what I mean is that a lot of my refactoring is just trivial things, like renaming variables.

While pairing on Friday, we came across a function called `CheckUser`. What does that mean? We didn’t know. So we started reading that function for comprehension, when we found that it called another function called `CheckLimited`. Uhh. Here we go again.

(**Pro tip: _Never_ use the name [`Check` in your functions](https://jhall.io/archive/2021/09/29/save-check-for-chess/)**)

After reading through that function, we found that it was returning `true` if the relevant user had a flag called `AccessLimited` enabled, or if the user’s parent account had the same flag. So we renamed that function to `HasAccessLimited`. We also added a bit of [GoDoc](https://tip.golang.org/doc/comment) so that future readers of the code would hopefully never face the same confusion we did.

We then did the same exercise for `CheckUser`, and found it was only being legitimately used in one place, for a very specific use-case, so we renamed the function to `UserCanCreateCards`, and added some more GoDoc.

The refactoring itself, to codify what we had learned, took about five minutes. But reading the code for comprehension took over an hour. Fortunately, that’s an hour nobody should ever have to spend again.

* * *
_If you enjoyed this message, [subscribe](https://jhall.io/daily) to <u>The Daily Commit</u> to get future messages to your inbox._
Chrome插件开发 - Repeating notifications
Published: 2023-08-13 02:17:11

---
title: Chrome插件开发 - Repeating notifications
published: true
date: 2022-08-28 00:00:00 UTC
tags: 
canonical_url: https://manon.icu/blog/translate/build-chrome-extensions/repeating-notifications
---

基在前一篇文章介绍了[Adding browser notification](https://manon.icu/blog/translate/build-chrome-extenstions/adding-browser-notification)，这篇将学习如何创建重复的通知。

## 创建重复通知

为了实现重复通知，我们必须利用[alarm api](https://developer.chrome.com/docs/extensions/reference/alarms/)。这允许我们创建可以在指定时间发起通知。

首先更新`manifest.json`，以便获取使用`alarm`权限

```json
{
  "permissions": ["alarm", "notifications"]
}
```

定时发起通知需要后台运行的服务，在 v3 manifest，可以注册一个后台服务

```json
{
  "background": {
    "service_worker": "background.js"
  }
}
```

然后修改`App.jsx`

```jsx
export function App() {
  const createNotification = () => {
    chrome.alarms.create({
      periodInMinutes: 1
    })
    window.close()
  }

  const stopNotification = () => {
    chrome.alarms.clearAll()
    window.close()
  }
  return (
    <div className="flex flex-col items-center justify-center w-screen h-auto bg-indigo-400 p-4">
      <button
        className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 text-2xl px-4 rounded"
        onClick={createNotification}
      >
        Motivate me 🎉
      </button>
      <br />
      <button
        className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 text-2xl px-4 rounded"
        onClick={stopNotification}
      >
        Stop motivating me 😅
      </button>
    </div>
  )
}
```

修改`background.js`

```js
chrome.alarms.onAlarm.addListener(() => {
  chrome.notifications.create({
    type: 'basic',
    iconUrl: 'icons/icon-48.png',
    title: 'Hi there 👋',
    message: 'Just a reminder that you rock!',
    buttons: [{title: 'I know ☺️'}],
    priority: 0
  })
})
```

## Source Code

[【Source Code】](https://github.com/rebelchris/popup-extension/tree/weather)
Select unique elements from an Array using: lastIndexOf() & indexOf()
Tags: javascript, array, tutorial, uniqueelement
Published: 2022-08-27 23:25:00

Hello guys! So, today I am going to show you how to use the following built-in array methods ([lastIndexOf()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf) & [indexOf()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)) to select unique elements from an array.

## indexOf()
The indexOf() method of the array returns the first index or position at which a given element can be found in the array. It returns **_-1_** if the element is not found.
Eg: 

```
const numberArray = [1,2,3,4];
const index = numberArray.indexOf(3);
console.log(index) => 2

const noIndex = numberArray.indexOf(9);
console.log(noIndex) => -1
```

## lastIndexOf()
The lastIndexOf() method of the array returns the last index or position at which an element can be found in an array. The array is searched backwards.
Eg: 

```
const numberArray = [1,2,3,4,5,7,3,6,9];
const lastIndex = numberArray.lastIndexOf(3);
console.log(lastIndex ) => 6

const noLastIndex = numberArray.lastIndexOf(90);
console.log(noLastIndex ) => -1
```

---
Now, let's go into the business of the day.
**NOTE**: _The purpose of this tutorial is not to make an array of repeated values a unique array, rather it is to pick elements that appear only once in a repeated array._

## **Example**
Given an array of repeated values:

`const repeatedVals =  [5, 7, 3, 9, 4, 9, 8, 3, 2, 7, 2];`
We are going to output a new array of unique values.

```
function uniqueValues(arr) {
  const uniqueVals = [];

  return uniqueVals
}
```
Explanation: we created a function, inside the function, we created an empty array to hold the unique values and then return that new array. Next, we are going to write our for-loop and some conditions.

```
// [5, 7, 3, 9, 4, 9, 8, 3, 2, 7, 2];

function uniqueValues(arr) {
  const uniqueVals = [];
  const lenOfArr = arr.length;

  for (let i = 0; i < lenOfArr; i++){
    const val = arr[i];
    if (arr.lastIndexOf(val) === arr.indexOf(val)) {
      uniqueVals.push(val)
    }
  }
  return uniqueVals
}
uniqueValues(repeatedVals)
```

## Output-
`[5, 4, 8]`

**Explanation:**
The `if` conditional simply checks if the returned indices of both methods are equal. In the case where they are not equal, it simply means that the current value has a duplicate in the array.

Thank you for checking out this post. In case of any errors or suggestions, kindly notify me.
Tips for aspiring web developers.
Tags: webdev, programming, beginners, career
Published: 2022-08-27 22:21:41

Hi there, I'm sure some of the aspiring webs developers here have been searching thoroughly for websites to learn web development for free, so I added a web development page to my website where developers can stay updated on what's going on in the tech space. My website will guide you through your web development journey if you are patient enough and also make you job ready. I also share tips on sites that you can apply for jobs and get hired. Not only is my service limited to that, I teach people how to make their resume worth considering by hiring managers. With all these checked, that is 70% of your journey, the remaining part is being consistent which is up to you. I also own a virtual university on Telegram and Discord. Though it's a paid group, only people who subscribe to my blog and are active on it I.E (comment on my latest posts and share them) are added for free. Subscribe to the blog now and send a Twitter message with the link on the blog to be added to my uni. You don't want to miss this🚩❗ 🔰🔰
https://thenewslab.news.blog
Hackintosh☠️
Published: 2022-08-27 23:11:59

#include<stdio.h>
void main()
{
printf("Today was a wonderfull day cos i spent more than 11hrs to triple boot Hackintosh,Ubuntu and windows 10.finally i made it possible but mac os is feeling to slow so i thought to delete hackintosh and continue using dual boot.litreally i worked till 4:30 in the morning.now 4:40 AM i'm writing this article right after the work.anyway it was fun installing hacintosh.i got so many errors and i rectified it one by one");
}

Thank you❤️.
Ah yes...React and it's Redux minions
Tags: javascript, programming, react, redux
Published: 2022-08-27 22:44:01

## Somewhat Familiar
I am nowhere near a pro when it comes to using ReactJS but I can definitely build you a simple project with relative ease. On the other hand, Redux was a library I only read about as if it were some agent lore. Thankfully there was a good amount of information to guide me through it all...

## So I Thought
I watched some videos, read some post and answers from StackOverflow. I felt in good hands, with good knowledge. The more I followed a long with a tutorial (while I adjusted a few things to better suit my liking), the more I understood that Redux isn't so complex. I then had to createStore. Unfortuantely, we don't  createStore anymore around these parts, we configureStore from reduxtoolkit. Now, I had no issue adjusting for updated methods, but up until that point, I was using previous versions to build. I think I can safely assume that many of us newcomers have been down this road before. You find the perfect mix of guides to help you build an app you want to stand out from the rest. This was nothing new, but I was already hours in to my CSS styling, and hours in to my component structuring. This was not good news.

## So I thought...again
After feeling defeated, and after a few glasses of scotch, I decided that I could not adjust my current build. I would have to start a new build, but I promised myself I would only look at the positive. The positive was that my back-end was built and deployed on Heroku (IYKYK). At this point, it's all about the front-end and adjusting for new methods. I knew I could do this, even with this being my first go-around with Redux. 

## Toolkits are easy to find after all
Throughout YouTube and Google searches, there is quite a lot of information on the Toolkit that is now used with Redux. I found it all quite useful, especially after struggling with certain concepts my first go around with the previous version. I still couldn't understand a few points some videos were making. This is where a wild idea came to me: Visit the resource pages on Redux's official site. As they say, some common sense isn’t so common. In my defense, my brain was mush after my first failed attempt. One piece of advice after this endeavor, go to the source files/resources first. As great as Google is...documentation is there for a reason. 

## Finally!
Through a week of struggles, I completed my store (which I'll link below). Although not perfect, I am proud of my work. I am proud that I truly understand 80% of my code, while somewhat understanding 20% of it. My education does not stop here, but it certainly is a nice point to look back and smile. It's about the small wins after all. It's about the small steps forward. It's about the building of knowledge after the stumbles along the way.

Site: https://legendary-palmier-cc51ed.netlify.app/
Day 140: Hello Postgres!
Published: 2022-08-27 22:06:22

Hi!
So today I got a little bit better and managed to work on the project and I shifted from Jasmine to jest and supertest I realized I was having a bad experience with Jasmine so I decided to get it out and Jest was easy to use and set up. the next task was about setting up a database which I had to use PostgreSQL so I had to learn about it. I have already worked with Postgres but everything was fast then so I didn't get a chance to learned it deeply so I got started to the basics again. Today also I completed the course one into the Google user experience design certification so It was a big win as well

Tomorrow I have nothing planned since it's a resting day and I'm sick anyway :) so I will see what to do but still I can't make any promises. 

signing off...
The 9 Key Questions for Google's Helpful Content Update
Tags: beginners, seo
Published: 2022-08-27 22:39:00

Google's new AI powered [Helpful Content Update](https://developers.google.com/search/blog/2022/08/helpful-content-update) is rolling out right now.

SEO experts are predicting it could be quite a big update.

Planning a quick content audit is something you might want to consider.

Here are the 9 questions Google recommend you ask in relation to your content.

1. Is the content primarily to attract people from search engines, rather than made for humans?
2. Are you producing lots of content on different topics in hopes that some of it might perform well in search results?
3. Are you using extensive automation to produce content on many topics?
4. Are you mainly summarizing what others have to say without adding much value?
5. Are you writing about things simply because they seem trending and not because you'd write about them otherwise for your existing audience?
6. Does your content leave readers feeling like they need to search again to get better information from other sources?
7. Are you writing to a particular word count because you've heard or read that Google has a preferred word count? (No, we don't).
8. Did you decide to enter some niche topic area without any real expertise, but instead mainly because you thought you'd get search traffic?
9. Does your content promise to answer a question that actually has no answer, such as suggesting there's a release date for a product, movie, or TV show when one isn't confirmed?

If you run an ecommerce site we have put together a [guide to the Helpful Content Update](https://www.searchcandy.uk/ecommerce/helpful-content-ecommerce/) that you can read here.
How to get the memory address of a variable in Go or Golang?
Tags: go
Published: 2022-08-27 22:36:35

---
  title: How to get the memory address of a variable in Go or Golang?
  published: true
  tags: Go
  date: Sun Aug 28 2022 04:06:35 GMT+0530 (India Standard Time)
  canonical_url: https://melvingeorge.me/blog/get-memory-address-of-variable-go-golang
  cover_image: https://melvingeorge.me/_next/static/images/main-069cc6e2e03dff38e8b1bf6159dd411c.jpg
  ---
  [Originally posted here!](https://melvingeorge.me/blog/get-memory-address-of-variable-go-golang)
  
To get the memory address of a variable in Go or Golang, you can use the `&` symbol (ampersand) followed by the name of the variable you wish to get the memory address of.

### TL;DR

```go
package main

import "fmt"

func main(){

    // a simple variable
    role := "Admin"

    // get the memory address of
    // the `role` variable
    // using the `&` symbol before
    // the `role` variable
    roleMemAddr := &role

    // log to the console
    fmt.Println(roleMemAddr) // 0xc000098050 <- this was the memory address in my system, yours may be different
}
```

For example, let's say we have a variable called `role` having a `string` type value of `Admin` like this,

```go
package main

func main(){
    // a simple variable
    role := "Admin"
}
```

Now to get the memory address of the `role` variable you can use the `&` symbol followed by the variable name `role` without any whitespace.

It can be done like this,

```go
package main

func main(){
    // a simple variable
    role := "Admin"

    // get the memory address of
    // the `role` variable
    // using the `&` symbol before
    // the `role` variable
    roleMemAddr := &role
}
```

Finally, let's print the `roleMemAddr` value to the console like this,

```go
package main

import "fmt"

func main(){
    // a simple variable
    role := "Admin"

    // get the memory address of
    // the `role` variable
    // using the `&` symbol before
    // the `role` variable
    roleMemAddr := &role

    // log to the console
    fmt.Println(roleMemAddr) // 0xc000098050 <- this was the memory address in my system, yours may be different
}
```

We have successfully got the memory address of a variable in Go. Yay 🥳!

See the above code live in [The Go Playground](https://go.dev/play/p/s9tIRUIYRbp).

That's all 😃.

### Feel free to share if you found this useful 😃.

---
7 different ways of Looping in JavaScript with example.
Tags: javascript, programming, jsloop, webdev
Published: 2022-08-27 22:34:00

In this blog, you will learn about the 7 different ways of Looping in JavaScript with the help of examples.

For example, if you want to show a message 100 times, then you can use a loop. It's just a simple example; you can achieve much more with loops.


![7 different ways of Looping in JavaScript with example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u6uaqbhby42jw67cy1vx.png)
---
### List of Loops in JavaScript
There are 7 kinds of loops you will find in JavaScript. I've listed them in an order that will help you to get a clear view of their working process and usage. This article will also help you to differentiate between all these 7 loops like where, when, or how you should use them. So let’s start.

1. `while`
2. `do-while`
3. `for`
4. `forEach()`
5. `map()`
6. `for…in`
7. `for…of`

---

> ## **1. while loop**

`while loop` is one of the most basic kinds of loops available in JS. If JavaScript is not the only programming language you know, you must have heard about this one already.

The while statement generates a loop that gets executed over a particular block of the statement (code) as long as the condition is true. Every time before executing the block of code the condition gets checked. 

### while loop Syntax

> while (condition) {
>   Block of code
> }

### while loop Example

```
let i=5;
while (i<10){
 console.log("I is less than 10");
 i++;
}
```

### Output

```
I is less than 10
I is less than 10
I is less than 10
I is less than 10
I is less than 10
```
In the above example, the condition is getting checked if the value of i is less than 10 or not. If the condition is true, the block of code gets executed and before iterating next time the value of i is getting increases by 1 as we’ve added a statement `i++`. 

---

> ## **2. do-while Loop**

`do-while` loop is slightly different from while as it includes one extra feature. In case of `do-while` loop, the block of code gets executed at least once and if further the condition satisfies the code block will be executed accordingly. 

### do-while Loop Syntax

> do {
>     Block of code
>  }
> while (condition);

### Example

```
let i=5;
do{
    console.log("The value of i is " + i);
    i++;
}
while(i>5 && i<10);
```

### Output

```
The value of i is 5
The value of i is 6
The value of i is 7
The value of i is 8
The value of i is 9
```

As you can see the condition is- *the value of `i` is greater than 7 but less than 10; but in output the value of `i=7` has been printed. Because this looping technique first `do` execute the code irrespective of the condition and then compares the condition from 2nd round of execution. For all the true condition from the 2nd looping round the code block will be executed. 

## _Continue Writing......_
Update - 3
Tags: redishackathon
Published: 2022-08-27 21:53:00

Finished most of the UI
Contributor: @Shrithan
### Sign up page
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/33mj9ck1azdwxlnfwmdw.png)


### Sign in page 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3je9gy4cubc77ajtzdlx.png)


### Dashboard

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ag3bm2u8h6ek8volk8tx.png)
What's on my Raspberry-Pi
Tags: raspberrypi, docker, selfhost, opensource
Published: 2022-08-27 21:23:12

Raspberry PI is slowly crawling its way up to top of things you should own as a Software Developer. All because of its low-power-consumption, configurable, open-source and the biggest one of all, you can own a server toooooo. I get it, its not like what is being offered by big players like _Azure, AWS, GCLOUD_, come on guys saying that you own a server would be a great ice-breaker when you are in a party, talking to your non-techie friend's or you can brag about it on your first-date (Dating advice 101). 

<img width="100%" style="width:100%" src="https://media.giphy.com/media/d3mlE7uhX8KFgEmY/giphy.gif">

Jokes apart, it has become part of my daily-developer-cycle. So here are some the services I run in my Raspberry-PI along with docker.

1. [Docker](https://www.docker.com/) 
2. [Pi-hole](https://pi-hole.net/) -- A simple Network Wide Ad-Blocker.
3. MySQL Server
4. ElasticSearch and Kibana.
5. [Portainer](https://www.portainer.io/) - to manage the docker.
6. [Firefly](https://www.firefly-iii.org/) - to manage finances.
An Introduction to the useEffect Hook
Tags: react, webdev, beginners, programming
Published: 2022-08-27 21:10:17

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

## What are React Hooks?

   In React, there are **hooks** which essentially give function components permission to "hook" into React's features such as state and other methods. There are three general rules when it comes to hooks that should be kept in mind when working with them. 

## React Hooks Rules: 

1. Hooks can only be called inside React function components
2. Hooks can only be called at the top level of the function component
3. Hooks cannot be conditional

## Side Effects

   A function is considered to have a **side effect** if it is called and the function causes change outside of the function itself. Examples of common side effects are making requests, fetching data from a database, incorporating a timer, directly updating the DOM, etc.

## The useEffect Hook

   The **useEffect hook** available in React allows us to perform some of these side effects mentioned earlier in the function components. To use this hook, it needs to be imported, first. 

```
import React, { useEffect } from "react";
```

  Inside the function component that we want to perform the side effect, we can call the useEffect hook and pass in a callback function which will act like the desired side effect. 

```
function App() {
 //side effect function
  useEffect(
     () => {
       console.log("Hello, I am second");
     }
  );
  console.log("Hi, I am first");
  return (
    <div> 
       <button>Click me</button>
       <input type="text" placeholder="Type here..." />
    </div>
  )
}

```

  When we run the code above, the messages will appear in this order: 
    1. Hi, I am first
    2. Hello, I am second
 
  By passing a console message in the useEffect hook, we are telling the function component to do something after it renders which is console logging the message we want. We can do other things in the hook such as fetching data, creating a timer, or updating the DOM. 

## useEffect Dependencies

   Because the useEffect hook runs on every render meaning it may perform the side effect many times, we need to control this using a dependency. To control the amount of renders, we can incorporate a second parameter, a **dependency array**, in the useEffect hook. 

## No Dependency 

```
useEffect(() => {
   //Runs on every render
});
```

## Empty Array

```
useEffect(() => {
   //Runs only on the first render
}, []);
```

## Props/State Value

```
useEffect(() => {
   //Runs on the first render 
   //And when dependency value changes 
}, [prop, state]);
```

Now, that you have the introductory knowledge needed to put the useEffect hook to use, go ahead and try it out! Good luck!