teleren/devto huggingface dataset:
Logging Request Bodies For Golang REST APIs
Tags: go, http, restapi, serverless
Published: 2019-03-16 14:43:50

---
title: Logging Request Bodies For Golang REST APIs
published: true
description: Logging HTTP request bodies
tags: Golang, HTTP, REST API, Serverless
---

Go does not support JSON natively, so our first step should be to learn how to decode the JSON format.
Thankfully Go comes with the "json" package which makes decoding easy and convenient to do.

## A Basic Example

This simplified example comes from the [Go docs](https://golang.org/pkg/encoding/json/#Decoder):

```Go
const jsonStream = `{"Name": "Ed", "Text": "Knock knock."}`

type Message struct {
    Name, Text string
}
var m Message

dec := json.NewDecoder(strings.NewReader(jsonStream))
err := dec.Decode(&m)
if err != nil && err != io.EOF {
    // handle that error
}

fmt.Println(m.Name, m.Text)

```
After handing our JSON stream over to a Reader, we're using the `json.NewDecoder()` and `dec.Decode(&m)` to "translate" and read our data into the previously defined `Message` format. 

## The Request Body

When handling an HTTP request, we are doing something very similar already which helps us skip a step here.
I'll also show you a nifty tool, we'll be using for our logging output!

```Go
func (h *handlerShared) doSomething(w http.ResponseWriter, r *http.Request) {
    // we still need a type definition for the receiving struct! 

    type Request struct {
        CompanyName string
    }
    // create a pointer to said struct
    req := &Request{}

    // create Decoder to "translate" our data
    // you probably spotted the step we can skip already!
    // if you haven't: the request body already comes in a Reader,
    // we don't have to hand it to one!
    decoder := json.NewDecoder(r.Body)

    err := decoder.Decode(&req)
    if err != io.EOF {
        // handle the error 
    }
    
    // At this point, we can a) access the data we read into our Request
    // struct: 
    fmt.Println(req.CompanyName)

    // As well as log it using the logrus logger I've included on my handlers                    
    h.log.WithFields(logrus.Fields{
        "host":     r.URL.Host,
        "path":     r.URL.Path,
        "header":   r.Header,
        // as you can see, there is a lot the logger can do for us
        // however "body": r.Body will not work, and always log an empty string!
        "body":     req
        // this is why we'll log our crated struct instead.
    })
    // send a response!
}

```

This is a very easy example, but should give you a good idea how to implement logging for your endpoints.

I've seen a few examples that go an extra step and read the body into an input buffer, to then cast it to a string. That is not necessary.

If you know of an easier way to achieve this or have any other feedback please let me know. I'll update this article and am always eager to learn!
I'm writing a bash course
Tags: bash
Published: 2019-03-16 14:38:29

---
title: I'm writing a bash course
published: true
description: Writing a live bash course, come join me!
tags: 
  - bash
---

I love bash. For me it is the most powerful language I have ever used. But unfortunately it has a very difficult syntax and concepts which confuse the hell out of me time and time again.

This course started as a way for me to have a reference to all the things I keep forgetting or need to refresh syntax-wise before I use them in a script or automation. I was getting a lot of positive feedback from friends and coworkers about my ability to use bash scripts as automations or to perform difficult (manual) tasks, and that they found it difficult to start writing scripts themselves.

That's when I decided that this course shouldn't be just a catch-all or notepad for my thoughts but something more structured which offers a simple way and examples of how to do things in bash or use certain patterns.

I'm currently writing this course on Notion and it live updates, I'll try to do my best to update it regularly. If you want you can see what I'm doing here and comment on it!

https://www.notion.so/thibmaek/Bash-shell-scripting-bef80e00b7994a9bb1228f97594430a8
Dear [Applicant]
Tags: interview, rejection, template, career
Published: 2019-03-16 12:59:13

---
title: Dear [Applicant]
published: true
description: Interview rejection letter template
tags: #interviews #rejection #template #career
---
This is an interview rejection letter template to be used as needed by companies. I’ve included a few passages from various rejection letters of my own.


_Dear [Applicant’s First Name],_

_Thank you for completing the interview for the [position name] job with us. After careful evaluation in collaboration with the hiring team, we regret to inform you that we won’t be moving forward with your application, at this time._

_As you can imagine, there is a lot of competition for the role and we can only take forward the people we think would be most suitable. While we are convinced that you are perfectly skilled for this position and you appear to have enough academic qualifications, we still somehow feel that you are not the right candidate. You seem like someone who would get in an unpleasant argument with someone from the management team at some point in the future. Surely you understand that we would prefer to avoid these type of situations, it serves no one any good._

_We’re also grateful that you took the time and complete our 4+ hours assignment so skilfully that we even got some ideas from it. We would like to encourage you to re-apply for this role in the future, should you still be interested, however please bear in mind that your chances of success will still be limited._

_New opportunities arise every day to help us make real what matters. Please don’t let this stop you from applying for a different role, at different company._

_We wish you the best of luck with your career, wherever it may take you._

_Yours truly,_
_The Company_
What is it like to work at a startup? 
Tags: startup, developer, career, softwareengineers
Published: 2019-03-16 10:38:23

---
title: What is it like to work at a startup? 
published: true
description: 
tags: startup, developer, career, software engineers
---

Ahoy mates!

– Every day is a roller coaster ride.

– You are not a valued employee. You are a pirate or a jedi instead.

– You work with a great bunch of motivated, talented and coolest geeks who are not shy to use F*** word a bit too frequently.

– Action may speak louder than words but code definitely speaks louder than any action!

– You are always updated about the coolest technical stuff happening all around the globe; thanks to the crazy folks all around you!

– You are not just a developer. You are a scrum-master, a deploy-king, a tester, a code-reviewer, a recruiter, an interviewer and sometimes you even get to pitch for your company! (If you are lucky enough..)

– You may feel intimidated and nervous at times!

– You learn the meaning of ownership and accountability.

– You continuously learn a lot of things simultaneously. Sometimes in a hardest way possible!

– Your mind suddenly gets tweaked to engage itself in provoking new thoughtsand ideas.

– You are free to choose and explore new technologies. Start-ups don’t believe in legacy tech!

– Your ideas  and grievances are heard effectively and immediately.

– You are expected to work hard and trained to work smart.

– You might get addicted to caffeine and beer in long run. 😀
Strategy Design Pattern [Behavioral]
Tags: concepts, designpattern, designpatterns, programming
Published: 2019-03-21 19:28:58

---
title: Strategy Design Pattern [Behavioral]
published: true
tags: concepts,Design Pattern,Design Patterns,programming
canonical_url: https://itscoderslife.wordpress.com/2019/03/16/strategy-design-pattern-behavioral/
---

The strategy pattern allows us to change the behavior of a type by switching algorithms.

The pattern works by defining a common interface for a family of algorithms. Each algorithm gets encapsulated in its own strategy type. The client only depends on the interface, so it can vary the algorithm by simply switching the concrete strategy object. There is a context, which delegates the client request to its strategy. The strategy is a protocol; it defines a common interface for all concrete algorithms. The concrete strategy types implement a specific algorithm. Clients instantiate the context with a concretestrategy object. The algorithm can then be updated by applying a different strategy instance to the context.

1. Identify a behavior that the client would prefer to access.
2. Specify the signature for that algorithm in an interface.
3. Bury the alternative implementation details in derived classes.
4. Clients of the algorithm couple themselves to the interface.

> The strategy pattern is about decoupling the algorithm implementation details from the type that uses it. This allows changing the object’s behavior at runtime by switching algorithms.

Example:

Modes of transport to travel to one place to another would be a trivial example but suits aptly IMHO. I can choose my own car or a public transport – bus or cab or I can choose flight. I can choose any of these whenever I want to commute.

Logger system with options like logging to Console or logging to file or logging in memory. User can choose the strategy at the time of usage.

So the strategy should be used if you need to implement algorithms that need to be used interchangeably. The algorithm is decoupled from the type that uses it. The context only sees the protocol, which allows clients to easily switch between the various implementations. Another benefit of the strategy pattern is that it lets us add new algorithms without modifying the class that uses them.

The strategy pattern is so straightforward that there are no pitfalls I could mention.
What is a variable
Tags: beginners, tutorial, learning, devtips
Published: 2019-05-31 09:03:29

---
title: What is a variable
published: true
tags: beginners, tutorial, learning, devtips
canonical_url: https://www.codetips.co.uk/beginner/what-is-a-variable/
---

> A variable is a container for information.

 ![What is a variable](https://images.unsplash.com/photo-1493946740644-2d8a1f1a6aff?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjExNzczfQ)

Imagine everyone in your family **wasn't** identified by a name, but a series of letters and numbers.

Your brother is no longer called **James**, he's now called **cfixe18918zt9o7g4nxl**. That would be a real pain trying to remember every time you wanted to "reference" him.

One day you decide to write your brother a letter. You don't want to keep having to write his name ( **cfixe18918zt9o7g4nxl** ), and you want to send the same letter to your mum ( **uqo2v892exahunofrii0** ), dad ( **0wj3hcy8userefzdiko7** ) and partner ( **4vxucjom1lakup3to71i** ).

You could make the letter generic, without any names, but you want your family to feel special and think you've written each letter specifically for them.

So instead, you make a computer program to output your letter for you, with the correct name.

<!--kg-card-begin: code-->
```
name = cfixe18918zt9o7g4nxl

Dear $name

.... body of text goes here that has a reference to the persons name 10 times ....
```
<!--kg-card-end: code-->

When you're done writing your letter, you can ask your program to generate it. Every time it sees `$name` it will replace it with the name you've assigned at the top (in the above example `Dear $name` becomes `Dear cfixe18918zt9o7g4nxl`) and prints it - completely personalised to each family member.

What if you were sending this letter to 20 family members? If you didn't use this variable technique, you'd have to keep 20 copies of the letter; personalised to each person. Then, after writing all of the letters, all exactly the same other than their name, you realise there are 10 spelling mistakes.

With the variable technique - you fix it in one place, and then generate each letter again by changing the name in your program.

Without the variable technique - you have to fix it in all 20 copies of the letter, manually, making sure you do every single one exactly the same so you don't make more spelling or grammatical errors.

Now imagine if you were writing it to your whole extended family - 120 people, and you found 30 mistakes. You'd wish you'd used a variable!
copy and paste , with or against
Tags: help, discuss
Published: 2019-03-16 08:45:51

---
title: copy and paste , with or against 
published: true
description: 
tags: help, discuss
---
So i think most of developers don't write code from scratch any more , actually they edit it.
each time i start a new project i find myself taking codes from different resources and bind them together to come up with the final result,i consider this as a short cut , it saves me a lot of time and energy ,  especially if one of the tasks is not that hard  and  does not require a huge effort . so do you think this a code habit or i should change it ?
What kind of articles do you like the most?
Tags: discuss, javascript, react, rust
Published: 2019-03-16 07:29:16

---
title: What kind of articles do you like the most?
published: true
description: Let's start a discussion about what kind of articles you all enjoy the most
tags: discuss, javascript, react, rust
---

# TL;DR

Do you prefer casual or super technical articles?

# Let me know

I started a few weeks ago to write in this network and I already feel at home.

I usually like to write about JavaScript, React, Redux and, soon, even Rust.

I would like to be able to write something that you all can enjoy without being bored or confused.

Write in the comments what you think about and leave a 🦄!
Around the Web – 20190315
Tags: blog
Published: 2019-04-10 13:44:12

---
title: Around the Web – 20190315
published: true
tags: Blog
canonical_url: https://wipdeveloper.com/around-the-web-20190315/
cover_image: https://wipdeveloper.com/wp-content/uploads/2017/07/WIPDeveloper.com-logo-black-with-white-background.png
series: Around the Web
---

And now for somethings to read (or watch) over the weekend, if you have some spare time that is.

## [209: Multi-paradigm](https://www.gooddaysirpodcast.com/podcast/2019/3/13/209-multi-paradigm)

**Good Day, Sir! Show – Salesforce Podcast**  – / John De Santiago – Mar 13, 5:32 PM – In this episode, we discuss sleep apnea, tips and resources for developers getting started, sqlite, gacks, and issues with email relaying.

## [THE EXTRACURRICULAR](http://theextracurricular.org/)

The Extracurricular is a learning event for Salesforce developers and architects interested in advanced and interesting uses of Salesforce and other technologies. It is a community-built mini-event hosted inside TrailheaDX at Moscone West.

## [Getting Started with Lightning Web Components](https://www.mattgoldspink.co.uk/getting-started-with-lightning-web-components/)

**Matt Goldspink**  – View all posts by Matt Goldspink – Jan 13, 7:43 AM – Salesforce have just announced one of the most exciting changes to the platform and to web development in general: See the official announcement on Salesforce here:…

## [Web Standards Meet User-Land: Using CSS-in-JS to Style Custom Elements](https://css-tricks.com/web-standards-meet-user-land-using-css-in-js-to-style-custom-elements/)

**CSS-Tricks**  – Mar 15, 8:22 AM – Create your own website with Wix.com The popularity of CSS-in-JS has mostly come from the React community, and indeed many CSS-in-JS libraries are React-specific. However, Emotion, the most popular library in terms of npm downloads, is framework…

## [Editable SVG Icon Systems](https://vuejs.org/v2/cookbook/editable-svg-icons.html)

**Vue.js**  – There are many ways to create an SVG Icon System, but one method that takes advantage of Vue’s capabilities is to create editable inline icons as components. Some of the advantages of this way of working is: They are easy to edit on the fly They…

## [Woody Hearn – Comics](http://gucomics.com/20190315)

**GU Comics by**  – Tomorrow (3/16/19) marks the 20 year anniversary of EverQuests official launch. And, the folks at DayBreak asked if I would do a comic to commemorate the event to which I said of course. I may not play EQ or MMOs anymore, but EverQuest is the heart…

## Till Next Week

Want to share something? Let me know by leaving a comment below or emailing [brett@wipdeveloper.com](mailto:brett@wipdeveloper.com)  or following and tell me on [Twitter/BrettMN](https://twitter.com/BrettMN).

Don’t forget to sign up for **[The Weekly Stand-Up!](https://wipdeveloper.com/newsletter/)** to receive free the [WIPDeveloper.com](https://wipdeveloper.com/) weekly newsletter every Sunday!

The post [Around the Web – 20190315](https://wipdeveloper.com/around-the-web-20190315/) appeared first on [WIPDeveloper.com](https://wipdeveloper.com).
Explain NoSQL Databases Like I'm Five
Tags: explainlikeimfive, nosql
Published: 2019-03-16 03:35:39

---
title: Explain NoSQL Databases Like I'm Five
published: true
tags: explainlikeimfive, NoSQL
---
Hello dev!

I'm having a hard time trying to understand NoSQL Databases. Can someone tell me what advantages and disadvantages has when compared to Relational databases? When would you choose for example MongoDB instead of SQLServer? Is it worth studying them for my career?
The Building an Indie Business Podcast- About the Podcast
Tags: podcast
Published: 2019-03-16 03:18:42

---
title: The Building an Indie Business Podcast- About the Podcast
published: true
description: 
tags: podcast
---

https://overcast.fm/+RG5grVfr8

[Episode Page](https://baib-podcast.com)
[Revenue Research](https://revenueresearch.co/)
How Do You Understand a Complex Code Base?
Tags: discuss, career, developer
Published: 2019-03-16 02:13:38

---
title: How Do You Understand a Complex Code Base?
published: true
description: 
tags: discuss, career, developer
---


You're new to a project and you're working with a complex code base. What are some things that you do to get comfortable with each component and really gain a clear understanding of how things work, as well as why that specific tech is being used? Here's the kicker, you have to figure it out on your own without asking the other devs questions.
I am a lawyer who became a iOS developer, Ask Me Anything!
Tags: ama, ios, developer, career
Published: 2019-03-16 00:55:24

---
title: I am a lawyer who became a iOS developer, Ask Me Anything!
published: true
tags: ama, ios, developer, career
series: ama
---

Hello! My name is Karen and I am lawyer/developer, currently working at Shopify. One of my friends encourage me to create this AMA, because she thought that maybe I can give a good advice to people that are changing careers or are thinking in doing that in the future. 

More info?

As a dev, I am very interested in clean code, architecture patterns and improving the user experience.

As a lawyer, I am very interested in analyzing legislation with a gender perspective, employment law, human rights and constitutional law.

:)
Compare Password in Angular with RxwebValidator
Tags: angular, rxweb
Published: 2019-03-16 00:29:37

---
title: Compare Password in Angular with RxwebValidator
published: true
description: 
tags: angular, rxweb
---
Here, we discuss the approach of how to compare the password with the RxwebValidators. 


# Why RxwebValidator?
Comparing the password is possible with the standard approach as well. Because angular provides a feature to manage the cross-field validation. But I see some design issue with the standard approach of Angular. If I refer to the [angular doc on cross-field validation](https://angular.io/guide/form-validation#cross-field-validation). The Angular doc suggests that the custom validator I have to put on FormGroup level for comparing two fields or some other actions. This approach is less appropriate for large/complex forms. Because that custom validator makes a call every FormControl value changes, blur, etc events. 

Let's see the below screenshot, The custom validator is calling non-validation field as well, The code I have copied from Angular Doc.

<img src="https://thepracticaldev.s3.amazonaws.com/i/6j99xge0pmhotijlls8d.gif" />


As per the above screenshot, I am entering the value in the 'power' FormControl and this FormControl isn't have relation with validation in the Form. But still, the custom validator is calling while entering the value in this FormControl.

Now, we talk about RxwebValidator to overcome this problem. 

First of all, we have to install the package [**@rxweb/reactive-form-validators**](https://www.npmjs.com/package/@rxweb/reactive-form-validators)
> npm install @rxweb/reactive-form-validators

Once it's installed, we have to register the 'RxReactiveFormsModule' in the root module. 


```js
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule,ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';

import {  RxReactiveFormsModule } from "@rxweb/reactive-form-validators"
@NgModule({
  imports:      [ BrowserModule, FormsModule,ReactiveFormsModule,RxReactiveFormsModule ],
  declarations: [ AppComponent],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

```
Now let's create two FormControls inside the FormGroup and use the compare validator of RxwebValidator. The two FormControls are 'password' and 'confirmPassword'. 

The functional requirement is if I change the value any one of the FormControl, the validation should fire.

We apply the compare validator on 'confirmPassword' FormControl. 

```js
this.userForm = this.formBuilder.group({
  'password': '',
  'confirmPassword':['',RxwebValidators.compare({fieldName:'password'})]
  });
```
As we have provided the fieldName of 'password' FormControl in the compare validator to compare the value with the 'password' FormControl.

See the action below:



You can refer to the [*stackblitz example of compare password*](https://stackblitz.com/edit/rxwebvalidator-compare-password?file=src/app/app.component.ts).

All done!.


If you have any question/suggestion, Please share your comments below.
How improve diversity at your company ?
Tags: discuss, diversity
Published: 2019-03-15 22:41:28

---
title: How improve diversity at your company ?
published: true
description: 
tags: #discuss #diversity
---

What are some of the things that companies or an individual can do to make it more attractive for underrepresented groups to join them ? or what would some things you'd like to see done better ?

I don't really see any good resources on this or even have information about it at all. Any insights would be great. Thanks!
The JavaScript Developer's Reading List
Tags: javascript, react, beginners, showdev
Published: 2019-03-15 22:22:44

---
title: The JavaScript Developer's Reading List
published: true
description: A list of hand-picked books and articles for JavaScript developers
tags: javascript, react, beginners, showdev
cover_image: https://res.cloudinary.com/twhiteblog/image/upload/v1552688071/cover_books_whzcfb.svg
---

I made a little repo of books and articles for JavaScript devs to read that either I've read or have been recommended to me by other devs.

{% github twhite96/js-dev-reads  %}


If you have a suggestion, [submit an issue](https://github.com/twhite96/js-dev-reads/issues) or [pull request](https://github.com/twhite96/js-dev-reads/pulls).

Feel free to add your favorites but please keep it to JavaScript and maybe, once I get a feel for who wants what, I'll add other web tech like CSS and HTML. Also, make sure you've either read the book or it came highly recommended to you. I tried to avoid *really bad books and articles* from making it on this list so please keep that in mind.

Let me know what you think! 📚📝