teleren/devto huggingface dataset:
Concurrent Redis writes and correctness (Take 2)
Tags: redis, distributedsystems
Published: 2021-07-13 10:01:27

---
title: Concurrent Redis writes and correctness (Take 2)
published: true
description: 
tags: redis, distributedsystems
//cover_image: https://direct_url_to_image.jpg
---

Last year I wrote a blog post on [concurrency control and ensuring data consistency](https://dev.to/munawwar/concurrent-redis-writes-and-correctness-3fh3) while caching things to redis from multiple processes.

Recently I revisited the blog post again and I couldn't help wonder *how over-complicated my final solution was*. Custom lua script and stuff!?

Here is my attempt to fix what I started. Going back to the initial requirements:

1. Congestion Control - We need to try our best to call fetchFreshValues() as few times as possible, across all server processes, since it is expensive
(how expensive? e.g. it was a super slow end-point that internally fires 100 of MySQL queries, which if it runs too many times, will slow the database down to a halt).
2. Data Consistency - We need to make sure that all processes returns a consistent value for a key. i.e. let's say our system calls fetchFreshValues() independently & parallelly from two processes, then only one should successfully write to redis whereas the other must fail.

Last blog post I established that redlock (a distributed lock algorithm from folks at redis) is great at congestion control, even though there could be edge cases where two processes manage to get a lock.

However for ensuring data consistency in the case two processes simultaneously gets hold of a lock, I did not have to go with a "versioned" solution. All I needed is redis to not overwrite a key if it already has a value. A simple `SET NX` command would have done the trick.

```
> SET myKey "myValue" EX 60 NX
"OK"
> SET myKey "myValue" EX 60 NX
(nil)
```

When a key expires, and if, two processes manage to get a lock, then only the first write would succeed. Which is what we wanted and is also how the old solution effectively worked. And with the return value, we can detect if a write succeeded or not.

Love the simplicity of this solution over the previous one. That's all for this post. Thanks for reading.

<hr>

This post was reposted from https://www.codepasta.com/distributed-systems/2021/07/13/concurrent-redis-writes-and-correctness-take-2.html. Follow my blog at [codepasta.com](https://codepasta.com) for long-form articles.
40 — Failed lawyer stumbles into tech — Agile from the trenches
Tags: agile, devops, people, process
Published: 2021-07-13 09:59:28

**This post was originally published on Fri, Jun 25, 2021 at [cloudwithchris.com](https://www.cloudwithchris.com/episode/agile-from-the-trenches/).**

In this session Erin and Chris reminisce, talking about how they met and Erin's journey into Technology. Erin talks a little bit about what Agile is, how it works in the real world, and shares some stories and anecdotes she's seen as an Agile Coach in the trenches.

{% youtube Q0b3tOFeJlI %}
You are never finished learning (100 Bytes Of Wisdom: Day 63)
Tags: career, journey, advice
Published: 2021-07-13 09:31:05

---
title: You are never finished learning (100 Bytes Of Wisdom: Day 63)
published: true
description: Bytes of Wisdom is a new project by Sam Jarman that brings together snippets of advice for software engineers
tags: career, journey, advice
//cover_image: https://direct_url_to_image.jpg
---

![You are never finished learning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/25pjfrajj3eimp4lnw3y.png)

The one constant in tech: change. Choosing a career in tech means feeling stupid and behind the 8 ball all the time. You need to be and should be constantly learning. There are millions of us out there making new tools, technologies, figuring out new ways of doing things and mostly teaching those as we go along. As a great engineer, you should be using the power of the internet to learn better ways of doing things, trying new tools, going to events to hear from speakers (not right now obviously, stay safe) and in generally keeping an ear to the ground. 

Other professions just aren't like that, but even in ones that seem stagnant, the most respected professionals are those pushing the boundaries, learning new things and teaching others.

Heads up: As with any terse bit of advice, there will be exceptions of course, and subtleties and nuance that can't possibly be captured in a Byte of Wisdom. This has been what I've experienced, I'd love to hear yours in the comments too!

You can catch up with all the other bytes at http://bytesofwisdom.com/
Creating Angular Pie Charts, Pyramid Charts and Funnel Charts
Tags: angular, charts, webdev, customize
Published: 2021-07-13 09:26:17

Learn how easily you can add and customize the Angular Pie Charts and Doughnut Charts, Pyramid Charts and Funnel Charts of Syncfusion in an Angular application.
To know how to add basic [Angular Charts](https://www.syncfusion.com/angular-ui-components/angular-charts "Angular Charts") to your application, watch this video: 
https://youtu.be/uAubTKfbBy8

The [Angular Pie Charts](https://www.syncfusion.com/angular-ui-components/angular-charts "Angular Pie Charts") and Doughnut Charts are collectively known as Circular Charts and the Angular Pyramid Charts and Funnel Charts are said to be the Triangular Chart types. These Circular and Triangular Chart types of Syncfusion are collectively called as Accumulation chart types. With these Chart types, you can visualize the proportionality of each item in the data set. Apart from visually displaying the cumulative data on the Angular Charts, you can also customize it with the help of built-in features like tooltip, dataLabel, Legend and much more.

Example: http://bit.ly/31pPoPM
Documentation: http://bit.ly/2I9moED

{% youtube ckgEx9oNUXw %}
Go-clean-template: Clean Architecture template for Golang services
Tags: go, opensource, architecture, writing
Published: 2021-07-13 09:23:16

[Go-clean-template](https://evrone.com/go-clean-template) is a Golang template project based on Robert “Uncle Bob” Martin’s Clean Architecture principles, ready for you to clone and use as a starting point for your next Golang app.

Of course, like all architectural foundations, the Clean Architecture is a framework that you have to choose to adhere to throughout the lifecycle of a piece of software, it won’t physically prevent you from writing poor code. Hopefully, though, starting with this template will help you start as you mean to go on!
Top QA and software testing trends in 2021
Tags: testing, testdev, webdev, security
Published: 2021-07-13 09:21:50

Software testing is a rapidly growing market, with constant refinements and new innovations to keep up with ever-changing technology. In 2020, the U.S. software testing market alone reached $13.5 billion, and Technavio predicts that the global market will grow by another $34.49 billion by 2025.

It is vital that enterprises implement and follow modern software testing best practices. [So, we’ve put together this guide to the key software testing trends for 2021.](https://evrone.com/qa-trends)
JS-beginners-projects
Tags: javascript, beginners, webdev, tutorial
Published: 2021-07-13 09:21:49

about the Js beginners projects I want to tell you that I can't continue it here by posting articles, instead I created a repository on GitHub here [Js-beginners-projects](https://github.com/CH4R4F/javascript-beginners-projects)
the repo is a collection of folders of project, every folder has a `index.html` `style.js` `app.js` and a description file `description.md` in case you want to challenge yourself before seeing the source code
>If you have other ideas or projects send them or add a pull request there


I'll add new projects too
hope you are doing fine and good luck.
Best place to put queries in a Django project? Model Managers!
Tags: django
Published: 2021-07-13 09:09:50

A question often arises when Django projects start to grow: "Where to put all the queries?"

When it comes to this question, a good concept to have in mind is **fat models and thin views**. This means that, as much as possible, you should try to keep business logic out of views and closer to your models.

According to [Djagno documentation](https://docs.djangoproject.com/en/dev/topics/db/models/#model-methods), you should:

> Define custom methods on a model to add custom “row-level” functionality to your objects. Whereas Manager methods 
> are intended to do “table-wide” things, model methods should act on a particular model instance. 
> This is a valuable technique for keeping business logic in one place – the model.

Queries on a model can be considered "table-wide" logic, so a good place for them is in the model Manager methods. 

Here is an example to illustrate this point:

Let's say you have a model called Membership in your project. A Membership is connected to a User and an Organization. Now, in one of your views you want to present all the memberships a user has. You could do it like this:

```python
# models.py
class Membership(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    organization = models.ForeignKey(Organization, on_delete=models.CASCADE)

# views.py
def my_memberships(request):
    memberships = Membership.objects.filter(user=request.user)
    return render(request, 'myapp/my_memberships.html', {'memberships': memberships})
```

This is all good and dandy, but what if you want to make another view that needs to retrieve all the user's memberships? Then you would need to copy the memberships query to the new view. You would be duplicating code! 

A better way is to move this query to the Membership model manager:

```python
#models.py
class MembershipManager(models.Manager):
    def get_memberships_for_user(self, user):
        return self.filter(user=user)


class Membership(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    organization = models.ForeignKey(Organization, on_delete=models.CASCADE)

    objects = MembershipManager()

#views.py
def my_memberships(request):
    memberships = Membership.objects.get_memberships_for_user(request.user)
    return render(request, 'myapp/my_memberships.html', {'memberships': memberships})
```

This way, we can reuse the query logic in other places and avoid duplication. Views that use this method will be more readable and self-documenting. Another added benefit is that you can test this query separately without needing to test the entire view.

You can read more about model managers [here](https://docs.djangoproject.com/en/dev/topics/db/managers/).
Learning Route in Laravel
Tags: laravel
Published: 2021-07-13 08:42:59

#**Routes**
Laravel has it’s own route mapping system and it also provides some helpful tools to help us organize our routes. I’ll discuss some proper techniques and how we use them in our app. Here’s is the basic format for our route.

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


Basic example


```
Route::get('/', function()
{
    return 'Hello Laravel~~';
});
```



In our browser, we should see ‘Hello Laravel~~’
Let's add tab to search to our website!
Tags: tutorial, webdev, html
Published: 2021-07-13 08:25:43

You may have used it on a chromium based browser – type out the link of a website, and hit tab to search the site. Works for GitHub, DEV, StackOverflow, Google, Twitter, `npmjs.org`, etc. In this post, I am going to show you how to implement tab to search for your own site.

### 1. Method one: Create a form, and \*hope\* that chromium picks up on it and uses it.

Yes. You can literally create a form (with a few restrictions) and if you are lucky Chromium will recognize it and use it. 

The (main) restrictions:
- The form must generate a `GET`
- The form must result in an `HTTP` url
- The form must not have an onsubmit script(!)
- There must be only one input element with type text.
- No passwords, files or text areas. 
- All other input elements must be in their default state.

OK, not the best way. 

### 2. Method two: Link to an [OSDD](https://developer.mozilla.org/en-US/docs/Web/OpenSearch)

Just create an xml file called `osdd.xml` (or whatever) and put the following code in it:

```xml
<?xml version="1.0"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
    <ShortName>Search My Site</ShortName>
    <Description>Search My Site</Description>
    <Url type="text/html" method="get" template="http://my_site/{searchTerms}"/>
</OpenSearchDescription>
```

And then link to it in your html file like so:

```html
<head>
    <link type="application/opensearchdescription+xml" rel="search" href="url_of_osdd_file"/>
</head>
```

And you are good to go!

You can test mine [here](https://siddharthshyniben.github.io/tab-to-search/). Or if you don't want to, just see the gif below:

![tab-to-search](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4xtettvgyj7faqp61qm7.gif)
 

There's more info on this [here](https://www.chromium.org/tab-to-search). Thanks for reading!
Introducing Gelato’s Limit Order Library: DEX (Limit) Sells
Tags: blockchain, automation, defi, tooling
Published: 2021-07-13 08:23:47

Although commonplace on Centralized Exchanges, [Limit Orders](https://www.sorbet.finance/) have yet to reach wide adoption from Decentralized Exchange platforms. The reason DEX UIs have been lagging behind on implementing this feature is deeply rooted in the limitations of the EVM that make it hard to automate users' trades while also upholding DeFi’s core tenet of being non-custodial.

Gelato now sets out to obliterate this barrier for Decentralized Exchange developers with our brand new <b>[limit-orders-lib](https://www.npmjs.com/package/@gelatonetwork/limit-orders-lib)</b> and <b>[limit-orders-react](https://www.npmjs.com/package/@gelatonetwork/limit-orders-react)</b> npm package releases. <b>These two libraries provide an easy one-stop solution for developers to hook up native Limit Orders to their AMM or other DEX of choice — in as little as 10 minutes!</b> The smart contract components of the limit order system have been audited by Certik. The spectrum of tooling the library provides you with ranges from ready-made React Components for the quickest go-live imaginable, to React Hooks and, on the more customizable end, simple methods for interacting with the underlying Gelato Limit Order infrastructure. The library already works with well-known trading venues on Ethereum, Polygon, and Fantom. Soon BSC and Layer 2s like Arbitrum will also be supported.

If you have any questions or you'd like to build with Gelato, we're here to help! 

--
Read more —> [Gelato Network Medium](https://medium.com/gelato-network/introducing-gelatos-limit-order-library-dex-limit-sells-6d1a38ab7cee)
Let's create a portfolio website using Dev.to as a CMS
Tags: nextjs, webdev, showdev, react
Published: 2021-07-13 08:23:17

I have created multiple portfolio website templates using ChakraUI and React. You can check my previous posts for different portfolio templates. 
My own portfolio [mahmad.me](https://mahmad.me) is built using ChakraUI. 
I am a big fan of ChakraUI but since being introduced to Tailwind at work, I've started to understand the benefits. Now I created a portfolio template with Tailwind using Dev.to as a CMS.  

Github Repo: https://github.com/MA-Ahmad/mahmad.me
Live Demo: https://mahmad-me.vercel.app

## Technologies used
* [Tailwind CSS](https://tailwindcss.com) -  Have been working with CSS for over 4 years and Tailwind just makes my life easier. It is still CSS and you use flex, grid, etc.
* [TypeScript](https://www.typescriptlang.org) - It's how JavaScript should have been by default. The combination of static type checking with intelligent code completion provides a significant boost in developer productivity. Not only can you work faster, but you can also catch a ton of errors before they arise.
* [Next.js](https://nextjs.org) - I don't try to hide the fact that I love Next.js, it's so simple to use and give so many out of the box features.
* [Dev.to API](https://docs.dev.to/api) - to dynamically build the blog.
* [Framer Motion](https://www.framer.com/motion) - to add slick and beautiful animations.

## Things I'll improve
* Add a custom domain name
* Add my resume
* Add Canonical URLs to my blog page

## Preview
![blog](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2g8lsqqgt7gyys8fjrsp.png)
🦊 GitLab Cheatsheet - 7 - Service Desk
Tags: gitlab, tutorial, cheatsheet, devops
Published: 2021-07-13 07:53:59


This cheatsheet speaks about the "Service Desk" offered by GitLab and that I use all the time.

<a href="https://jeanphi-baconnais.gitlab.io/img/cheatsheet/GitLabCheatsheet-7-ServiceDesk.jpg" alt="7 - Service Desk" target="blank">

<img src="https://jeanphi-baconnais.gitlab.io/img/cheatsheet/GitLabCheatsheet-7-ServiceDesk.jpg" alt="7 - Service Desk" />

</a>

I will create others cheatsheet. Tell me if you have comments or suggest about those cheatsheet 😃.
Make Android app with Bubblewrap. How add Admob?
Tags: pwa, webdev, android, discuss
Published: 2021-07-13 07:26:37

I already build my PWA/TWA here hana.rip and already know how to create an Android app with Bubblewrap.

Then I'm wondering, can i put admob to it? How?

Or should I use adsense instead?

Any better idea?
Preventing key-delay in TextArea Element Using Event
Tags: html, event
Published: 2021-07-13 07:16:00

---
title: Preventing key-delay in TextArea Element Using Event
tags: html, event
description: A tutorial showing how to prevent a key delay in a textarea element when using event to listen for change
canonical_url: https://www.kudadam.com/blog/preventing-key-delay-in-textarea
cover_image: https://kudadam.sirv.com/blog/prevent_key_delay_textarea/hero.jpg
---

## The problem...
I was using the onkeypress event to grab the text from the textarea element but I realized that the data collected was one character delayed. I then tried the onkeyup and onkeydown but it was still one character delayed.

Initially, I thought this was a bug with my code but after a careful consideration, I realized my code was fine and the onkeypress event was also working correctly so why the one character delay?

![A gif showing the problem](https://kudadam.sirv.com/blog/prevent_key_delay_textarea/keydelay.gif)

## What was really happening
When ever we want to get the value of an element from an event, what we normally do is to take the `event.target.value`, this code is the code that returns the content in the element. Now when the contents are returned with `event.target.value code`, it returns everything excluding the current event, that means, excluding the current character.

We are going to run an experiment to show what is happening. In the gif below, we add a function to the textarea onkeypress event.

```javascript
const show = e =>{
	console.log(e.target.value);
	console.log(e);
}
```
![A gif debugging the problem](https://kudadam.sirv.com/blog/prevent_key_delay_textarea/debugging.gif)

When the first character is entered, the `event.target.value` is '', this is because, the value is contained in the event object not the `event.target.value`.
This same analogy happens as we continue to type

## Solving the problem...
Now as we are seeing what is the causing the problem, we can see the solution,
to prevent the key delay, we just need to adjust our function to add event.key which contains the current character to `event.target.value` which also contains the 'already' text, so the function will now be like this

```javascript
	const get_value = (e){
		let text = e.target.value + e.key
	}
```
So, that's the solution folks.
Interview Questions For Databases and Information Management
Tags: cs, computerscience, database, informationmanagement
Published: 2021-07-13 06:49:52

A collection of raw facts and figures is called data. Data is collected from different sources. Data may consist of numbers, characters, symbols or pictures, etc.

Define the term data.

A collection of raw facts and figures is called data. Data is collected from different sources. Data may consist of numbers, characters, symbols or pictures, etc.

Define the term information.

The processed data is called information. Information is an organized and processed form of data. It is more meaningful than data and is used for making decisions. Data is used as input for the processing and information is the output of this processing.

What is the difference between data and information?

Data is a set of raw facts and information is processed form of data. Data is input and information is the output of the computer. Data is difficult to reproduce but the information is easier to reproduce. Data is not used in decision-making but the information is used in making decisions.

What is metadata?

Metadata can be defined as data about ‘data. It is used to describe the properties and characteristics of some other data. Metadata describes the size, format, and other characteristics of data. It also includes the rules and constraints about data...

Read More: https://baydari.com/study/databases-and-information-management/databases-and-information-management-short-questions
How To Create Your First Webpage?
Tags: html, webdev, beginners, codenewbie
Published: 2021-07-13 06:28:09

#####Create an index.html file anywhere in your computer. 
#####Open the file in any Text editor like VS Code, Sublime, Atom or even Notepad if you don't have any. 
#####Then type the code given below into it.

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

#####Save your file.
#####Open the file in your favorite browser.

####And Congratulations, you have created your own webpage!
Array.flat() in JavaScript
Tags: tutorial, webdev, javascript
Published: 2021-07-13 06:28:00

Hello Devs,

In this article i will walk you through one of the important methods of Array in JavaScript i.e Array.flat method.


> 
## Table of content
1. [Theory](#theory)
2. [Syntax](#syntax)
3. [Return Value](#return)
4. [Examples](#example)

So without wasting any time lets get into the article


## Theory <a name="theory"></a>
**The flat() method is used to flatten the array of arrays. The process of flatten depends on the depth we want to flattened the array of arrays.**

What this method do is, it takes out the array element from an array of arrays and concat them in the main array.
it will repeat this process till the depth value.


## Syntax <a name="syntax"></a>
```js
Syntax:
flat(depth)
// The depth level specifying how deep a nested array structure should be flattened.
// Defaults to 1.
``` 

## Return Value <a name="return"></a>
```js
return value:
A new array with the sub-array elements concatenated into it.
```


## Examples <a name="example"></a>
**NOTE**: IF YOU WANT TO FLATTEN THE ARRAY UPTO ITS LAST DEPTH THEN PUT `depth` AS `Infinity`
```js
example:
let arr = [1, 2, [3, 4, [5, 6]]];

arr.flat(0) // [1, 2, [3, 4, [5, 6]]];
arr.flat(1) // [1, 2, 3, 4, [5, 6]]
arr.flat(2) // [1, 2, 3, 4, 5, 6]
arr.flat(3) // [1, 2, 3, 4, 5, 6] 
arr.flat( ) // [1, 2, 3, 4, [5, 6]]
// if no depth is provided then it will take the default value i.e 1.
arr.flat(Infinity) //[1, 2, 3, 4, 5, 6]


arr.flat(0).length //3
arr.flat(1).length //5
arr.flat(2).length //6

```

Thank you for reading this far. This is a brief introduction of **Array.flat() method in JavaScript** .
If you find this article useful, like and share this article. Someone could find it useful too. If you find anything technically inaccurate please feel free to comment below.

Hope its a nice and informative read for you.
VISIT https://www.capscode.in/#/blog TO LEARN MORE...
See you in my next Blog article, Take care!!

### IF MY ARTICLE HELPED YOU
<a href="https://www.buymeacoffee.com/capscode" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>


Thanks,
@capscode