teleren/devto huggingface dataset:
Golang DNS Resolving
Tags: dns, go, tips, todayilearned
Published: 2020-04-23 10:56:04

---
title: Golang DNS Resolving
published: true
date: 2020-04-23 10:04:33 UTC
tags: dns,golang,tips,til
canonical_url: https://revs.runtime-revolution.com/golang-dns-resolving-a56ed59981fe
---

![](https://cdn-images-1.medium.com/max/1024/1*9NA3QJOTTXQeCQRp1IAFqQ.jpeg)

Lately, I have been writing Golang (more commonly known as just Go, which is what I’ll be using from here on out) at work, and so far I have been enjoying it a lot! This is a small TIL (_Today I Learned_) about making Go correctly communicate with services in the local machine like, for instance, Redis, Postgres, or Kafka.

In my particular situation, the project I am working on is running on my machine, however, some of the needed services (Redis, Kafka) are running inside a Docker container. For instance, Redis is accessible via the hostname redis, and likewise for Kafka. Initially, I thought that simply adding the following entries to my etc/hosts files would be enough for the name resolution to work properly:

```
127.0.0.1 redis kafka
```

However, the code was still throwing errors because it could not connect to redis or Kafka. Turns out that Go has [two ways to perform address name resolution, depending on the operating system it is running on](https://golang.org/pkg/net/#hdr-Name_Resolution). On OS X (which is my case), Golang uses a different name resolution library called cgo, which is a bit different than the default name resolver. You can see which name resolver your Go program is using by setting the flag GODEBUG with the value netdns=2. Here’s a sample output for my program:

```
GODEBUG=netdns=1 go run main.go
> go package net: hostLookupOrder(redis) = cgo
...
```

**On OSX, applications are not allowed to make direct DNS requests**. So, let’s try running the program with the pure Go name resolver:

```
GODEBUG=netdns=go+2 go run main.go
> go package net: GODEBUG setting forcing use of Go’s resolver go 
> package net: hostLookupOrder(redis) = files,dns
```

(The + sign is used to tell Go to force a specific name resolver and to show debugging information).

And it works! Since the pure Go name resolver is used, Go accesses local files in the machine to perform name resolutions such as [/etc/resolv.conf](https://github.com/golang/go/blob/d32ec38f1cfe69ed2a553272f6c8f425c59577f2/src/net/conf.go#L100) and [/etc/hosts](https://github.com/golang/go/blob/7bb33179cadf072403b2f1d8f8210c5ae414d135/src/net/dnsclient_unix.go#L526)

_Nowadays I work at_ [_Runtime Revolution_](http://www.runtime-revolution.com/) _as a full-stack software developer. Working here has been, and continues to be, a great learning experience. I’ve matured professionally as a developer, as well as a human being._

* * *
How To Add Speech Functionality To Your App
Tags: vue, javascript
Published: 2020-04-23 10:02:21

In this article, I will show you how to add speech functionality to your applications. 

I recently made a simple <a href="https://timothyokooboh.github.io/dictionary/#/"> dictionary app </a> with vue.js using the owlbot-js API. so I needed users to listen to the correct pronunciation of the words. I used the technique am about to show you and it took less than a minute to add speech functionality to my dictionary app. 

*P.S: On my android phone, I sometimes experience some delay before the voice note begins. But on my laptop, there is never a delay.* 

#So let's begin! 
I'm gonna embed a code pen.
{% codepen https://codepen.io/timopharm/pen/NWGdgao %}


First, we initialize the built-in speech synthesis API

*const speech = window.speechSynthesis;*

Then, we access the DOM to select the text we want to get spoken.

*const text = document.querySelector("#text"). innerHTML;*


The speech synthesis API has a constructor called SpeechSynthesisUtterance. This constructor receives one argument which is the text we want to get spoken. In our code, this argument is the same as the *text* variable we declared.

*const utterance = new SpeechSynthesisUtterance(text)*

So, we created a variable called *utterance* and assigned it the *SpeechUtterance* constructor

function sayTheWords(){
  speech.speak(utterance);
  }

Finally, when our button is clicked, we call the built-in *speak* method on the speech synthesis API. The built-in *speak* method receives one argument, which is the *utterance* variable we declared.

#So that's how you can add speech functionality to your app.

You can think of several use cases where this functionality may be useful in your app. For instance, apart from displaying flash messages when a user creates, edits, or deletes a post, you could also send a voice message. 

To learn more about the speech synthesis API, you can check out this <a href="https://www.youtube.com/watch?v=ZORXxxP49G8&t=184s"> video by Brad Traversy</a>

He went further to explain how you could select the particular voice, pitch, and even the rate at which the voice note is spoken.

#Thanks for reading.
f is not the same as x => f(x)
Tags: functional, javascript, learning
Published: 2020-04-23 09:50:37

---
title: f is not the same as x => f(x)
published: true
description: Eta abstractions are useful
tags: #functional, #javascript, #learning
---

`f` is not the same as `x => f(x)` when it comes to evaluation in a strictly evaluated language like Javascript. The latter renders a function slightly more lazy:

```javascript
const mapFold = f => acc => ix => {
  for (let [i, x] of ix)
    acc = f(acc) (x);

  return acc;
};

const arrSnoc = xs => x =>
  (xs.push(x), xs);

const mapToArr =
  mapFold(arrSnoc) ([]);

const mapToArr_ = ix =>
//                ^^
  mapFold(arrSnoc) ([]) (ix);
//                      ^^^^

const foo = new Map([[0, "foo"], [1, "bar"], [2, "baz"]]);

mapToArr(foo);
mapToArr_(foo);

mapToArr(foo); // ["foo", "bar", "baz", "foo", "bar", "baz"]
mapToArr_(foo); // ["foo", "bar", "baz"]
```
`mapToArr` gets a fesh array as accumulator each time it is called and hence keeps the side effect caused by `arrSnoc` local. Adding redundant lambda abstractions to a derived function is called eta abstraction and the opposite operation eta reduction.

[Read more on lazy evaluation](https://github.com/kongware/scriptum/blob/master/ch-5.md).
How can object-oriented metric affects to the complexity
Tags: complexitymetric, solved
Published: 2020-04-23 09:45:11

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/lvcpxn2onlxfoyygyu0l.gif)
We were recently allocated group assignments by our university.

Based on the knowledge gathered from Cyclomatic Complexity (CC) and the Weighted Composite Complexity(WCC) metrics, we have to write a report proposing a new object-oriented(OO) complexity metric. 

The new metric should consist of **four** complexity factors. Out of the four factors, **at least two of the factors must be OO specific factors** (polymorphism, encapsulation, abstraction, association, aggregation, composition, method chaining, etc). However, we are **not allowed to consider inheritance as an OO specific factor.** 

As in the WCC metric, the newly proposed metric should be able to measure the complexity of each program statement based on all the four factors. In other words, using the newly proposed metric, it should be possible to measure the complexity of a program line by line. In addition, we are required to consider about the practicality of implementing a complexity measuring tool based on the proposed metric. That one should be able to easily develop a complexity measuring tool based on the proposed metric.

We must include following,

1)Explanation of how each factor considered in the new metric affects to the complexity of a program.

2)Explanation of how the new metric captures the complexity introduced by each factor. 

3)Explanation of how the new equation was constructed.

4)Calculation of complexity of **four** different executable java programs using the newly proposed OO metric.

In addition, an explanation of how complexity of each program was calculated should also be included.

[Click here to see the answer](https://drive.google.com/file/d/1on54mToGt17Y7qK9lg1bre0OCFG69Ppa/view?usp=sharing)
Why my async functions are not behaving correctly? The important differences between Javascript for() vs forEach() vs map()
Tags: javascript, notes
Published: 2020-04-23 09:36:49

When iterating through an array, when should we use `for`, `forEach`, or `map`?

Here's a quick summary of each.

## for()

- Performance: Built-in function. Faster than the other iteration methods due to less overhead (e.g. no callbacks to initialize). Use it for large arrays.

- Short-circuiting: can use the `break` statement to stop the iteration.

- Beware of ES6 syntax--e.g. `for (const key in object)` for iterating objects, or `for (const element of array)` for iterating arrays--essentially this syntax turns the for() loop into a forEach loop--meaning, no short-circuiting available anymore. (Note: one is `in` and the other uses `of`)

## forEach()

- Takes a callback function: `arr.forEach(callback)`

- It has 3 params: value, index, and the original array. See example:
```javascript
> [1, 2].forEach((value, index, arr) => console.log(value, index, arr))
1 0 [ 1, 2 ]
2 1 [ 1, 2 ]
undefined
```
The `undefined` is the returned value of the `forEach()` call.

- `forEach` ALWAYS iterate through the entire array. Not good for large arrays.

- It does NOT wait for asynchronous tasks to complete.

## map()

- Returns an array of the return values of the callback function. Everything else behaves the same as a `forEach()` call.

- The keys of a `map()` is ordered, it follows the order of insertion for objects. (While `Object.keys()` does not guarantee the order.)

- It does NOT wait for asynchronous tasks to complete. (Worth repeating).

- Because it returns an array, you can use `map()` with asynchronous calls like this: `await Promise.all(array.map(...))`
Set up online accounts on Elementary OS
Tags: linux, opensource, elementaryos, tips
Published: 2020-04-23 09:29:53

**You know you need this.**

One of the things which I have been missing quite a lot while using elementaryOS is that it doesn't support syncing with online accounts like Google or Microsoft. I say this because I quite often have use for my Google Calendar and Drive and being able to view them using the default applications on the desktop is quite nice.

I like how Gnome allows us to sync in with such online accounts and seamlessly integrates the Google Calendar with the Gnome Calendar and Drive with the File Manger respectively.

**So what is the solution?**

If anyone is in the same boat as me, and wishes to enable setting up those accounts on Elementary OS, here are the steps which can be used to enable online accounts.

**Step 1:**

First, we have to install the Gnome Control Center using the following command.

```bash
sudo apt-get install gnome-control-center
```
**Step 2:**

Then, with the following command we can enable the Gnome online accounts
in the control center.

```bash
sudo apt-get install gnome-online-accounts
```
**Step 3:**

Now, to open the Gnome Control Center to configure the account type the following command in the terminal.

```bash
Exec=env XDG_CURRENT_DESKTOP=GNOME gnome-control-center --overview
```
Configure your account in the Gnome Control Center and you are all set.

**Enjoy!**

![](https://dev-to-uploads.s3.amazonaws.com/i/ezjn31kpw6jtujui0kk4.gif)<figcaption>Gif via Giphy</figcaption>
Agile and Scrum: Our Favorite Duo
Tags: agile, scrum
Published: 2020-04-23 09:27:32

---
title: Agile and Scrum: Our Favorite Duo
published: true
description: In this article, you can read about similarities and differences between Agile and Scrum.
tags: agile, scrum
---

In our previous articles we wrote about [Agile](https://kolosek.com/agile-philosophy-youll-love/) and [Scrum](https://kolosek.com/scrum-agile-put-into-practice/), separately, and now **we decided to mix them and bring together**. If you want to know more, be sure to read those blog posts, and now, let's get to the the benefits of both of these productivity raisers.
## Agile and Scrum
These two grew up in the same cocoon. Precisely, **Agile is Scrum's older and wiser relative**, similar to Rick and Morty.
As you probably learned by now, Agile is a philosophy, a concept that explains how a team should do a project, on a theoretical level. **Agile describes principles, while Scrum is all about implementing principles** by following the rules. Agile is a philosophy and Scrum a methodology.

![Agile and Scrum_4](https://storage.googleapis.com/kolosekblog/2017/11/paul-bence-395888-7.jpg)

## Agile and Scrum - the similarities
The similarities are:
* using an iterative approach of making a project,
* adapting to change,
* making improvements,
* delivering the product on time.
## Using Scrum
Scrum is not for everybody. I mean, it is, but you don't need it all the time. Here are some cases in which Scrum can help:
* when you are about to do a large project,
* when there is no deadline for an app to be delivered to the client,
* when team members want more autonomy.

![Agile and Scrum_12](https://storage.googleapis.com/kolosekblog/2017/11/lee-campbell-86958-5.jpg)

Not to sound rude, but Scrum is **amazing for clients that change their minds quickly** and are not sure what exactly they want because development team can easily adapt to that change.
## Using Agile
Every time you think you need a project management concept, think of Agile. No matter for which method you decide to go with, **Agile, as a philosophy, is the way to go.** 
## In the end...
... Agile and Scrum are inseparable. **They go like hamburger and french fries.** Not from McDonald's. From some fancy restaurant that sells hamburgers. Delicious!

![Agile and Scrum-11](https://storage.googleapis.com/kolosekblog/2017/11/edward-franklin-72304-11.jpg)

If you want to know more about Agile, also check out [our post on Agile and Lean](https://kolosek.com/lean-agile-enemies-or-friends/).

Hope you learned something new today.


*Originally published at [Kolosek blog](kolosek.com/agile-and-scrum/).*
For those who learn COBOL
Tags: legacy, cobol
Published: 2020-04-23 08:36:24

For those who learn COBOL in response to the needs of the Covidic Era, there's a pile of programming tasks over on [RosettaCode](http://rosettacode.org/wiki/Rosetta_Code) that have [COBOL examples](http://rosettacode.org/wiki/Category:COBOL) and [a tonne that need one](http://rosettacode.org/wiki/Reports:Tasks_not_implemented_in_COBOL).
Changing Classes
Tags: javascript, beginners
Published: 2020-04-23 08:34:23

---
title: Changing Classes
published: true
description:Check, Add, Remove, Class 
tags: javascript, beginners
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/a6q1y4f5ni58lk9pvn5c.jpg
---

#Add Class
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/k57bajv0c8k0q2ixe7f6.png)
When we use the **querySelector()** method and after we have to use **classList** property it is easy to make the mistake of adding **"."**
We may add multiple classes in the same time but we don't need to do this.
To be sure that we have added properly the class we may check in our elements inside our inspector if the class is present.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/j4kq46thezd2w5kzjv1e.png)
#Remove Class
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/m7tv93mi2ma2d7dyx31g.png)
If we have to remove a class from an element, we simply replace **add** with **remove**. In this case we may also remove multiple elements at the same time but we still don't need to perform this.
#Checking
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/g5nqzm3uekcgc746wes5.png)
Sometimes we need to check if a class is present and, if It is, we perform same tasks.
#Toggling
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/oo5o5mym4r0ro8dluqya.png)
Often we have to toggle a class. We may remove or add a class with **if/else** statements but with **toggle** method is more simple and coincise. Like in the example above toggle checks automatically if a class exists and if it exists, remove it else add is.
Super simple and usefull.
[More about classList here: MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/classList)
Sharing single mongoDB connection object in Express Application
Tags: express, mongodb, database, node
Published: 2020-04-23 08:15:13

An appilcation may have multiple APIs. Now it is required to share single database object through out all APIs with out creating multiple collections.
First let us see the incorrect implementation
	Ex:
		app.get(‘/path1’,(req,res,next)=>{
	MongoClient.connect(…………………….)
});
		app.get(‘/path2’,(req,res,next)=>{
	MongoClient.connect(…………………….)
})
Here two  request handlers are creating their own connection whenever they execute.Multiple collection can effect the scaling of database.

Sharing the connection
----------------------
There are a bunch of approaches that we can follow, and we'll discuss one that seems to be a really interesting one. We'll base our application on the fact that the API should not be available if the database is not available that powers it. This makes sense - there's no point in providing any endpoints if the database is down and we can't effectively display data.
To achieve this, we need to re-think our logic around connecting to the database a little bit - first, we should attempt to make the connection, and if that is successful, we can fire up the API server as well.


var MongoClient= require(“mongodb”).MongoClient;

MongoClient.connect(dbUrl,{useUnifiedTopology:true},(err,client)=>{
    if(err){console.log("err in db con",err)}
    else{
        var dbo=client.db("b26db");
        var usercollection=dbo.collection("usercollection");
        var admincollection=dbo.collection("admincollection");
        console.log("connected to db");
        console.log(app.locals)
	
	//assign the values to “locals” property of express object “app” 
        app.locals.usercollection=usercollection;
        app.locals.admincollection=admincollection;

        const port=3000;
app.listen(port,()=>{ console.log(`server listening on port ${port}`)});
    }
});


app.locals  object
------------------
The app.locals object has properties that are local variables within the application. Once set, the value of app.locals properties persist throughout the life of the application.
In the request handlers of api, we can access the data from “app.locals” property using “request” object.
	someRouter.get( ‘/path’,(req , res , next )=>(
let usercollection=req.app.locals.usercollection;
	…………………………………………
	………………………………………..
)};
Monitor Sangoma Vega VOIP Gateway with Nagios
Tags: sangomavega, nagiosmonitoring, opensource
Published: 2020-04-23 08:08:40

Today the topic is about how we can monitor the Sangoma Vega VOIP Gateway with Nagios Core Monitoring tools. Around 6 months back I got a project to Build a Monitoring system for the entire IT infra. So I started with Nagios Core 4.3, and it was going fine. Then I stuck in with Sangoma Vega 400G VOIP Gateway. Our Telephony server is connected with this Vega device and I want to monitor the Interface status, call status & No of active calls.

I started searching the same in Google and Forums, but no Luck. Finally, I got the solution and configured the same. Here I mentioned all the steps I did to configure the same. Maybe this article will help you to set up Nagios monitoring for Sangoma Vega Device.

Therefore I use the below setup for Monitor Sangoma Vega with Nagios Core 

I use CentOS Linux 7.6

Nagios Configuration Directory:  /usr/local/Nagios/etc/objects

First of all, you have to configure the Vega device so follow the below steps

<a href="https://www.seoexpertstuff.com/monitor-sangoma-vega-nagios-core/">Read More</a>...
COBOL - not dead; not dying; not even idle (#4)
Tags: legacy, cobol
Published: 2020-04-23 08:01:36

If you haven't discovered [TECHURLS](https://techurls.com/?msg4c), now's a good time.

Hunting for things COBOL (as one does when one can't think of anything else to write about), I found the following via TechUrls:

 * [Brush up your COBOL: Why is a 60 year old language suddenly in demand?](https://stackoverflow.blog/2020/04/20/brush-up-your-cobol-why-is-a-60-year-old-language-suddenly-in-demand/?cb=1)
 * ['COBOL Cowboys' Aim To Rescue Sluggish State Unemployment Systems](https://www.npr.org/2020/04/22/841682627/cobol-cowboys-aim-to-rescue-sluggish-state-unemployment-systems) (National Public Radio report)
 * [Can't File for Unemployment? Don't Blame Cobol](https://www.wired.com/story/cant-file-unemployment-dont-blame-cobol/)
 * [Mainframes Are Having a Moment](https://spectrum.ieee.org/tech-talk/computing/software/mainframes-programming-language-cobol-news-coronavirus) 
 * [Cloudflare Workers Now Support COBOL](https://blog.cloudflare.com/cloudflare-workers-now-support-cobol/)
What is the reason for appdata installs?
Tags: install, windows, tools, apps
Published: 2020-04-23 07:54:27

Hello everyone.

This is a Windows specific question here, but hopefully someone has an answer.

Over the last few years there are more and more application that are installed in appdata/roaming, and I was wondering where that come from?!
It annoys me not to have the control over there install locations, but it bugs me even more that its hard to find all those folders when I'm looking for them.

Is there a reason that this is common sense nowadays and did I missed some technical reason for this? Or is it just laziness of some devs / companies?

If you're a dev of this kind of apps / tools / programs please give the user the chance to change the location before installing. 
Or is it just me that gets annoyed by this?

Have a nice day everyone and stay safe!
Looking for some backend node help here
Tags: help, authentication, mongodb, node
Published: 2020-04-23 07:45:56

So i am working on this application (side project) and i am mainly a frontend developer. And now i am really stuck on getting the authentication in place.

I have written user registration and simple email + password login, but now getting the authentication and sessions in place is just something i keep getting stuck on. 

I am running a MEVN (Mongo, Express, VueJS 2, Node) stack so i tried some of the options (auth0, express-connect, json webtokens), but i just can't find a combination that works and that i feel is secure.

So if someone wants to offer a hand / help with implementation or just knows the right up to date tutorial.


(or if you are a backend focused person and are very into music / a musician, i am looking for partners as well).
Why I am unable to retrieve the composer caching folder dir on aws codebuild?
Tags: help, aws, php, codebuild
Published: 2020-04-23 07:45:31

Arg why the build seems not to retrieve the cached content?

I attempt to cache the composer's caching folder to an s3 folder so I can speed up my builds. But even though it stores the cached content into the s3 it seems the build is unable to retrieve it.

So do you know why?
 
{% stackoverflow 61381793 %}
open source projects for beginners ! 
Published: 2020-04-23 07:32:40

I am software engineering student, I've been learning java since one year ago and i builded some small projects ( desktop using swing  and web using spring )  and I really like that language and i want to level up my skills in, I believe that the best way is the open source but i don't know how to do that .I don't know too much about the process how beginners like me can find projects to contribute in ?
I will be very thankful guys if you can give me any advice or more beautiful suggest for me some projects .