teleren/devto huggingface dataset:
A search engine - Part 4: Concurrency and safety
Tags: go, algorithms, datastructures, computerscience
Published: 2020-12-08 16:37:21



Since our index can now be accessed from several goroutines,
data races can occur, when we do not eliminate them using some additional logic. We have to synchronize the access to our data structures. We can utilize the `sync` package for this, which is already a built in Go library.

## Go's Mutex

The `Mutex` type from the `sync` package will allow us to place a lock on a shared resource using mutual exclusion. The first call to `Mutex.Lock()` will set the mutex to locked and if some other goroutine calls the same method again, it will block (and therefore wait) until the resource gets a call to `Mutex.Unlock()`. We'll use this simple synchronization helper to eliminate possible parallel access to the same data structure.

We extend the GlSearch struct type by the mutex and initialize it in the `New()` method.

```go
type GlSearch struct {
	config Config
	cache  []string
    index  map[string][]int
    // the syncronization helper
	mu     *sync.Mutex
}

// New creates a new GlSearch instance
func New(c Config) *GlSearch {

	glsearch := GlSearch{
		config: c,
		cache:  []string{},
		index:  map[string][]int{},
		mu:     &sync.Mutex{},
	}

	return &glsearch
}
```

Using a deferred call, we can very easily make sure that the mutex gets unlocked after our method returns. We have to simply add these two lines to every `func` which reads or writes on our resources.

```go
// Add appends the provided string to the cache and updates the index accordingly
func (g *GlSearch) Add(s string) {
	g.mu.Lock()
    defer g.mu.Unlock()
    
    // ...
}


// Find queries the index and returns the results from the cache
func (g *GlSearch) Find(s string) SearchResult {
	g.mu.Lock()
    defer g.mu.Unlock()
    
    // ...
}
```

## The Flush() method

This method will reset our cache and index, while keeping the configuration the same.

Here we just initialize a new slice and map and let the old ones be garbage collected.
```go
// Flush resets the index and cache
func (g *GlSearch) Flush() {
	g.mu.Lock()
	defer g.mu.Unlock()

	g.cache = []string{}
	g.index = map[string][]int{}

}
```

So we're done for this episode, we ensured that our data can't be accessed in paralell. In the next one we'll talk about more generic access to the index and cache.

Stay tuned.
Instagram bot implemented in python 3.7 using selenium web driver
Tags: python, bot, github
Published: 2020-12-08 16:31:12

I implemented a simple Instagram bot that,
1. Find users who don't follow you back.
2. Bulk liker to get attention and more followers.
3. Find users that follow you, but you don't follow back(fans)

Check my [GitHub repo](https://github.com/TharindaDilshan/Instagram-Bot) to see the implementation details. The setup guide is available in the README file.

What are your thoughts on this? Any other functionalities that I should implement?
The End(1) - Start. Plans & Prep. Finals almost here. 
Tags: opensource
Published: 2020-12-08 16:30:58

Hello there bruvs. Welcome back to my last 1 of 3 blog post for a while. This blog post will just mainly be on my plans and strategy I will be doing for the next few days. I was assigned a task by my professor for contributing to open-source projects. Not a simple contribution, but a good one. 

I planned on tackling more than or a minimum of 3 issues for this task. I am still looking for them but I am pretty positive that I will get them as I can see that people around the world posts daily for issues. I am looking for any issues that I find interesting and trying to leave a comment there. If they reply and want me to help, they will assign me and I will be notified that way. I won't be able to share the links to the comments as of now because I do not know if I will be assigned to them or not. So, keep your eyes open for the next blog post because that will be the progress that I will make for this task. 

Not much to talk about else, but semester finals are almost here. Preparing for that for a while now, and honestly, bit scared but I don't know why. Hope all goes well and I will be able to answer questions. The one I am worried about the most is DSA, which stands for Data structures and Algorithms. This course is super fun but I am scared, don't know why. Probably because of my anxiety. Made lots of notes for myself on this course, hope I don't black out lol. As I said this blog post is not a big one. It is on how I will tackle the task. So far as mentioned above, I planned on doing more than or at least 3 issues | PR. I'll be able to give more details on this on the next blog post that I will be uploading as soon as I finish my first or second issue and do a pull request. Till then hope you guys stay healthy and stay safe. COVID in Ontario is increasing rapidly, so please do stay safe and stay home. Thank you for your time!.
Playground for Frontend Developers
Tags: html, javascript
Published: 2020-12-08 16:22:07

Hello, Everyone!

I won't lie to anyone, I am learning and understanding the frontend development from last year and still there is a lot to learn.

But for a start I have done some exercise on the [FrontEnd Mentor](https://www.frontendmentor.io) and love their concept, it really helps me a lot to understand these concepts and to sharpen my skills.

It help me in understanding the small, important stuff and never to forget them.

Thanks for this awesome platform.
Simply Responsive
Tags: flutter
Published: 2020-12-08 15:58:47

Hello guys, so I just published my first open source library for flutter.

This is a mobile-first widget to help us build a responsive app across mobile, tablet, and desktop with ease. Unlike the CSS 12 grid system, The design of simply_responsive is based on 3-columns design of a desktop website. This has an advantage of being simpler to use than the CSS 12 grid system, at the cost of reduced possible flexibilities. I try to make this library as tested as possible.

And, since it's responsive, it'll be no need for you to lock the orientation of your app to portrait only!

## Example

```dart
SimplyResponsiveBody(
  LayoutConfig.build(MediaQuery.of(context).size.width),
  leftChild: ListView(
    children: [
      Text('Home'),
      Text('Profile'),
      Text('Sign Out'),
    ]
  ),
  centerChild: ListView(
    children: [
      Text('Lorem Ipsum'),
      Text('Lorem ipsum dolor sit amet')
    ]
  ),
  rightChild: ListView(
    children: [
      Text('Tap to like')
      Text('Tap to dislike')
    ]
  )
)
```

Just by writing that code, you can make it responsive across screen sizes and orientation.

Basically, the centerChild is the widget which will appears everytime (although not required).

The left column is usually used to display navigational menus. On this early release, the widget will just hide the left column if the screen is not enough (usually in mobile portrait). You should put it in the drawer if that's the case.

The right column is usually used to display additional content (Like Editor Basics on DEV). On this early release, the widget will just hide the right column if the screen is not enough (usually in mobile portrait and tablet if left column is visible). You should put it in the endDrawer if that's the case.

There's also a two-column mode if you pass centerFlex to 0, and set the centerChild to null.

-----

Feel free to ask any question and give any criticism and suggestion! Thank you.

https://pub.dev/packages/simply_responsive
Getting traffic to EKS: Using ALB Ingress Controller with Amazon EKS on Fargate
Tags: aws, fargate, docker, kubernetes
Published: 2020-12-08 15:58:27

---
title: Getting traffic to EKS: Using ALB Ingress Controller with Amazon EKS on Fargate
published: true
description: Using ALB Ingress Controller with Amazon EKS on Fargate
tags: #aws #fargate #docker #kubernetes
cover_image: https://assets.mkdev.me/posts/covers/000/000/012/original/mkdev_article.png
---
What we are going to see today is fascinating. We are going to connect Kubernetes with AWS ALB, by using an Ingress Controller for Application Load Balancer. Ingress objects will automatically hook to ALB and allow us to get traffic to the cluster.

In this video, Pablo Inigo will not only show how EKS and ALB work together, but also explain how to install and use the Ingress Controller from AWS:

{% youtube cRODPz9GXb0 %}

***

*You can always hire our [mentors](https://mkdev.me/en/mentors) and learn directly from them!*
Advent of Code Megathread Comment Tracker!
Tags: showdev, adventofcode, python
Published: 2020-12-08 15:46:55

---
title: Advent of Code Megathread Comment Tracker!
published: true
description: I made a tool that helps me tabulate which languages were used which days and I'm really happy with how it turned out.
tags: showdev, adventofcode, python
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/hxl086hfnoahlkxd9gk1.png
---

I'm having a lot of fun this year with Advent of Code, and it's awesome getting to see all of the community solutions on the [Megathread](https://dev.to/rpalo/advent-of-code-2020-solution-megathread-day-8-handheld-halting-16hp).  One thing I decided to do this year that I hadn't done before but the guy who did it last year decided to do is track how many submissions of each different programming language were submitted for the previous day on each post.

I think it's a really neat idea and it's always exciting when somebody posts a language we haven't seen before like Scratch or Racket or something.

However.

I did not account for the fact that people batch their AoC work, and they'll often submit several days behind the curve.  Which is totally fine and I should have foreseen it, but it means that every day I get to go into the comments and re-count them all manually, even though I've already counted 99% of them before.

You know what that sounds like a good job for?

A computer.  Assisted by me.

So I wrote a tool I cleverly and pithily call the "Advent of Code Language Bot."  It goes through each article in the series, grabs the comments, ignores the ones it has seen before (it's got a history file!), automatically detects languages from code blocks in the markdown if they are present, and if the user submitted a solution via a gist or image or something, it shows me the HTML and asks me to tell it what language they said they used.  It then *remembers my answer forever more!*

If you comment and say you solved it in 3 languages, it even accepts my answer when I tell it you used 3 languages.

It's not a big tool, bit it's exceptionally effective, I was able to give it a little polish, I'm happy with the interface, the configuration strategy, the workflow, and it's already saved me a bunch of time this morning.

If you're doing AoC via the Megathread this year, you can help me out by using language-specific code blocks (triple back-tics followed by the language you used), or, at the very least, writing in your comment what language you used so I don't have to chase through your Gist or specifically open up your image/blog post to see what you used.  But even if I do, I'll only have to do it once now 😊

You can see the repo here:

{% github https://github.com/rpalo/aoc_language_bot %}

P.S. shout out to @rhymes and the team.  The API docs are great and I didn't have any trouble at all getting the data I needed.  I tried to cache judiciously and sprinkle `time.sleep(1)` throughout my API calls to be nice to your servers.  Let me know if I'm causing any problems!
Twitch Recap: Building a Small-Service Delivery App!
Tags: techtalks, wecoded, algorithms, html
Published: 2020-12-08 15:29:39

Last week on Twitch, we did something a little different! As we've grown our channel, we wanted to experiment with doing two shorter streams instead of our regular long session. You can find the links to [part 1](https://www.twitch.tv/videos/829999433) and [part 2](https://www.twitch.tv/videos/829990886) here!

Originally, Jose and I presented a demo of this sample project at the recent virtual WeAreDevelopers conference in Vienna. We had a great time and wanted to break down these components for our Twitch audience.

In general, this project focused on the differences between creating multi-stop routing based on optimal speed vs. based on optimal distance, taking real-time traffic into consideration.

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

In part one, we focused specifically on the principles behind optimal "shortest path" finding, and explained the TSP (Traveling Salesman Problem). 

TSP is familiar to many engineers for its lack of a universal solution - its one mathematical concept which can only be solved by a high-speed check of all possible path options.

When "paths" need to be mapped onto real-life roads, it introduces a whole new set of factors that TSP isn't responsible for - road closures, accidents, winding turns, and daily congestion.

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

In this project specifically, we used the nearest neighbor algorithm to help us marry a need for optimal delivery stops along our route, along with our optimal route calculations. Each route could be calculated with a priority of either the shortest speed or the shortest total distance. These are often not the same!

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

In part two, we used topics from one of our last devisodes to create radial geofences around each delivery waypoint on our route. This would allow us to later use the Notifications API to alert our recipient when their delivery is close to arriving.

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

By using a webhook connecting to MS Teams, we were able to view notifications of when our delivery car arrived in and out of the geofence, or dwelled there for a certain number of seconds.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9t0y3ivsx7eipud6j8og.png)

Be sure to catch our Q&A on Traffic next week, Dec 15th at 12pm PST!
Advent of Code 2020 Solution Megathread - Day 8: Handheld Halting
Tags: adventofcode, challenge
Published: 2020-12-08 15:19:53

---
title: Advent of Code 2020 Solution Megathread - Day 8: Handheld Halting
published: true
description: We're debugging machine code!  Hooray!
tags: adventofcode, challenge
series: Advent of Code 2020
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/j83jgqgywb81tg0xqsoe.png
---

I don't know about you, but I struggled to bend C to my will yesterday.  Had to do it in Python to stay on top, but now that I've done it in Python, I think I could probably make the C code (that I cleverly deleted all trace of) work.  So that's great.  Anyways, today is a new day!

## The Puzzle

I'm so very happy.  This makes up for anything that yesterday did to me.  In [today’s puzzle](https://adventofcode.com/2020/day/8), we're debugging machine code!  I honestly love all of the puzzles like this.  I loved the [Intcode](https://adventofcode.com/2019/day/2) challenges from last year, and I'm hoping there are more of these to come.  We're writing a sort of machine-code interpreter to parse through and evaluate this code to help a kid play his handheld game on the plane!  It's for a good cause!

## The Leaderboards

As always, this is the spot where I’ll plug any leaderboard codes shared from the community.

```
Ryan's Leaderboard: 224198-25048a19
```

If you want to generate your own leaderboard and signal boost it a little bit, send it to me either in a DEV message or in a comment on one of these posts and I'll add it to the list above.

## Yesterday’s Languages

I've got a [dope new automated tool](https://github.com/rpalo/aoc_language_bot) to help me fetch and tabulate the number different language submissions each day!  It helps the tool if you either write what language you used in your comment or (even better) make your code block language specific with syntax highlighting.

Updated 03:08PM 12/12/2020 PST.

| Language   | Count |
|------------|-------|
| Python     |     4 |
| Ruby       |     3 |
| Rust       |     3 |
| JavaScript |     3 |
| C#         |     1 |
| Haskell    |     1 |
| TypeScript |     1 |
| COBOL      |     1 |
| Fsharp     |     1 |

Merry Coding!
Serverless Architectures with Amazon DynamoDB and Amazon Kinesis Streams with AWS Lambda
Tags: aws, dynamodb, kinesisstreams, awslambda
Published: 2020-12-08 15:19:42

[In this tutorial, you will learn the basics of event-driven programming using Amazon DynamoDB, DynamoDB Streams, and AWS Lambda. You will walk through the process of building a real-world application using triggers that combine DynamoDB Streams and Lambda.](https://www.truongbui.com/2020/12/serverless-architectures-dynamodb-kinesis-streams-aws-lambda.html)
How the API community can be more inclusive with Claire Barrett
Tags: devrel, api, community
Published: 2020-12-08 15:06:49

**Theme of the week:**
*Why and how can the API community be more inclusive?*

Inclusivity is key. Allowing more people to join a community and interact with it, network and find and offer help. More diverse communities have more voices heard and can drive progress.

In this episode, we are joined by Claire Barrett, Director at APIfirst consulting and Global leader of the Women In APIs.

We discuss: 
-  What she loves most about her work with Women in APIs and their strategic priorities
-  If and why we need a more diverse API community
-  The challenges for someone joining the API community
-  What we can do to encourage a more diverse audience to join it
-  The importance of balance and diversity within engineering teams and how can team leaders encourage it
-  The evolution of APIs in the future 
-  Opportunities and challenges due to the pandemic

Listen to this episode to see how we can build more inclusive and diverse communities in APIs and tech. 

{% spotify spotify:episode:3RZa62FiRbdikFyZOSDoPK %}

**Let’s talk Data** 
This is the graph we discuss with Claire: [How developer marketing and relations leaders segment their audience](https://www.devrelx.com/trends?lightbox=dataItem-k9mqu4kj1).

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/akaljr7dpi8br25xxz60.jpg)
10 React Example
Tags: javascript, webdev, beginners, css
Published: 2020-12-08 14:52:01

---
title: 10 React Example
published: true
tags: #javascript #webdev #beginners #css
---

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

If You Like This Article then check Out more Examples [gscode.in]

<b>30+ Free React Example for beginners</b>
https://gscode.in/react-example/

<p>1.This started because someone asked me if there was ever a case in a layout for preserveAspectRatio="none" in an SVG. I started with the background, thinking about how the layout could change with this responsive SVG. It's built-in React with React-Motion and CSS working in tandem on both SVG and HTML elements.</p>

{% codepen https://codepen.io/sdras/pen/XdgBOa %}

<p>2.Experimenting with creating a multi-state component with sub-components in ReactJS.</p>

{% codepen https://codepen.io/TylerK/pen/ncJpD %}

<p>3.Accordion  component made with React</p>

{% codepen https://codepen.io/matthewvincent/pen/EKKeyX %}

4.
{% codepen https://codepen.io/marcobiedermann/pen/gfvzx %}

5.
{% codepen https://codepen.io/pizza3/pen/jObRRmE %}

6.
{% codepen https://codepen.io/Lakston/pen/XjAQdP %}

<p>7.Date picker in React, you can select a range of dates.</p>

{% codepen https://codepen.io/RobVermeer/pen/zBgdwg %}

<p>8.A React-based interactive animation of BB-8 from Star Wars. 
<p>Bit of a chance to try out handling animation in React + stress test rendering. Turns out it's fantastic.</p>

<p>Draw circles around him :D </p>

{% codepen https://codepen.io/bullerb/pen/gMpxNZ %}

<p>9.React 16/Store/Context used to create a CSS Box-Shadow sprite animator. I created this to output data for use with Arduino/LED Matrix devices, and then it just became this little thing.</p>

{% codepen https://codepen.io/pjkarlik/pen/MWWNqaq %}

<p>10 A calculator built with React</p>

{% codepen https://codepen.io/mjijackson/pen/xOzyGX %}


<b>30+ Free React Example for beginners</b>
https://gscode.in/react-example/
SonarQube Community edition and PR analysis
Tags: sonarqube, powershell
Published: 2020-12-08 14:51:05

SonarQube is awesome tool and it's Community edition (which is free) fulfills almost everything one could dream for in the world of static code analysis. But, you could not analyze PR's with it by default and have to pay for at least Developer edition. Further you could find my attempt to overcome this limitation (it fulfills MY goals and seems to be worth sharing with broader audience).

When I started working with SonarQube back in version 5 and 6 there was one mode which brought me a lot of interesting discoveries and prevented my colleague developers from submitting bad code - preview. In this mode, SonarQube does not stores data on server, but executes analysis and sends results back - and in conjunction with PR decoration plugin it was very useful. But, time goes by and version 7 removed preview mode from Community edition.

So, I tried to mimic this, using a separate project on SonarQube server and created powershell script, which will retrieve quality gate status from current analysis and create bugs in Jira and attach them to some existing issue (actually, that's the added value of this script, which was my target, opposing to default CI server SonarQube runners, which would just fail your build).

{% gist https://gist.github.com/akuryan/5e2746b60c0e1505af1d34d1f343abc3 %}

Script seems to be heavily commented and speaks by itself. Feel free to adopt it for your own usage pattern, if you will ever need it.

I shall note that Developers edition of SonarQube solves the same problem much better - it have PR analysis and built-in PR decorator, but it costs money, while Community edition brings things in for free.
Project 1, Week 2, Day2
Published: 2020-12-08 14:46:53

To be honest no new changes made today. There are some critical issues which I would like to address though.

* Switching video/audio devices
* Performance: seems to be taking a while to load up. Need to test it on a server to see how it really works
* The chat need to be set up

Will work on it first thing tomorrow to and make that list smaller. :)