teleren/devto huggingface dataset:
Learning Golang (some rough notes) - S02E01 - My First Kafka Go Producer
Tags: go, learning, apachekafka, kafka
Published: 2020-07-13 13:42:29

---
title: Learning Golang (some rough notes) - S02E01 - My First Kafka Go Producer
published: true
date: 2020-07-09 00:00:00 UTC
series: Learning Go with Kafka
tags: go, learning, apachekafka, Kafka
canonical_url: https://rmoff.net/2020/07/08/learning-golang-some-rough-notes-s02e01-my-first-kafka-go-producer/
---

 ![My First Kafka Go Producer](https://rmoff.net/images/2020/07/myfirstkafkaproducer.png)

To install the Confluent Go client you need to run

```
go get gopkg.in/confluentinc/confluent-kafka-go.v1/kafka
```

With that done, we can run our first Kafka Go code! Make sure you’ve got a local Kafka broker running first, and then give this a spin:

```
package main

import (
	"gopkg.in/confluentinc/confluent-kafka-go.v1/kafka"
)

func main() {

	// --
	// The topic is passed as a pointer to the Producer, so we can't
	// use a hard-coded literal. And a variable is a nicer way to do
	// it anyway ;-)
	topic := "test_topic"

	// --
	// Create Producer instance
	// https://docs.confluent.io/current/clients/confluent-kafka-go/index.html#NewProducer
	//
	// Variable p holds the new Producer instance. There's a bunch of config that we _could_
	// specify here but the only essential one is the bootstrap server.
	//
	// Note that we ignore any error that might happen, by passing _ as the second variable
	// on the left-hand side. This is, obviously, a terrible idea.

	p, _ := kafka.NewProducer(&kafka.ConfigMap{
		"bootstrap.servers": "localhost:9092"})

	// --
	// Send a message using Produce()
	// https://docs.confluent.io/current/clients/confluent-kafka-go/index.html#Producer.Produce
	//
	// Only essential values are specified here - the topic, partition, and value
	//
	// There is NO handling of errors, timeouts, etc - we just fire & forget this message.
	// Did it work? ¯\_(ツ)_/¯
	p.Produce(&kafka.Message{
		TopicPartition: kafka.TopicPartition{Topic: &topic,
			Partition: 0},
		Value: []byte("Hello world")}, nil)

	// --
	// Close the producer
	p.Close()
}
```

When you run this, you get a message written to a Kafka topic!

 ![kafkacat01](https://rmoff.net/images/2020/07/kafkacat01.gif)

## Don’t try this at home!

Well, try it at home. But don’t take it anywhere near _actual code_ that you need to write. As the comments in the code above show, there is **NO** error handling, whatsoever. I’m going to explore that in subsequent posts, but want to start at the very simplest example to start with here.

## IDE FTW

(WTF? [IDE](https://en.wikipedia.org/wiki/Integrated_development_environment) [FTW](https://www.yourdictionary.com/ftw))

The VS Code environment is nice and helpful for writing Go and brings in function definitions etc

 ![vscode02](https://rmoff.net/images/2020/07/vscode02.png)

You can press Ctrl and click on a function or type and it will take you through to the definition, which is often quicker than looking up the API documentation

 ![vscode03](https://rmoff.net/images/2020/07/vscode03.gif)
Automated Upgrades for k3s
Tags: kubernetes, devops, gitops
Published: 2020-08-31 19:12:30

---
title: Automated Upgrades for k3s
published: true
date: 2020-07-08 23:50:17 UTC
tags: ["kubernetes", "devops", "gitops"]
canonical_url: https://www.joshkasuboski.com/posts/k8s-auto-upgrades/
---

My cluster was falling behind the latest k3s version. Time to upgrade.

## Enter the System Upgrade Controller

I basically just did the instructions linked [here](https://rancher.com/docs/k3s/latest/en/upgrades/automated/).

It deploys the system upgrade controller into its own namespace where it won't do anything yet.

You have to give it some plans.

It will read Plans in that same namespace and run the specified image. I used the plan linked above. Instead of tying it to a specific version I set it to the latest channel.

```
# Server plan
apiVersion: upgrade.cattle.io/v1
kind: Plan
metadata:
name: server-plan
namespace: system-upgrade
spec:
concurrency: 1
cordon: true
nodeSelector:
matchExpressions:
- key: node-role.kubernetes.io/master
operator: In
values:
- "true"
serviceAccountName: system-upgrade
upgrade:
image: rancher/k3s-upgrade
channel: https://update.k3s.io/v1-release/channels/stable
---
# Agent plan
apiVersion: upgrade.cattle.io/v1
kind: Plan
metadata:
name: agent-plan
namespace: system-upgrade
spec:
concurrency: 1
cordon: true
nodeSelector:
matchExpressions:
- key: node-role.kubernetes.io/master
operator: DoesNotExist
prepare:
args:
- prepare
- server-plan
image: rancher/k3s-upgrade:v1.17.4-k3s1
serviceAccountName: system-upgrade
upgrade:
image: rancher/k3s-upgrade
channel: https://update.k3s.io/v1-release/channels/stable

```

You'll notice there are actually 2 plans. One applied to the master nodes and the other the worker nodes. This lets you upgrade the master node to the new version before the workers.

The entire process took maybe 5 minutes for my 3 node cluster. I was able to `kubectl get nodes` periodically and watch the progress.
Because there is duplication of users in AWS Cognito
Published: 2020-07-08 23:31:04

Register a user with name, email and cell phone. After that, log in with Facebook. And I register another user with the same email.

I have two users with the same email.

How do I solve that problem?
AWS AMPLIFY AND COGNITO

Image:
https://dev-to-uploads.s3.amazonaws.com/i/r7u3pmm5ztjn9z66g7mm.jpg

#aws #amplify #cognito
Visual Studio Code - my color syntax settings
Tags: vscode, javascript, ide, syntaxhighlighting
Published: 2020-07-08 23:29:41

Here's a screenshot of my syntax color settings:

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


I keep my background as black as possible; unless the sun is shining on the screen, then I'll set it lighter.

I however constantly tweak the syntax font coloring.

### General Notes
Notice function invocations are bright green.
Operators bright yellow.
Function arrow and ternary operators a bold red.
Not show here but object keys are blue.


### JSON Source Code
Place this into your Visual Studio Code (VSC) settings json file (I have it in my Workspace settings, not User settings)

https://gist.github.com/funfunction/8fc8eb93f3f98d7b0f6d690f317a4f75
Asynchronous Observables?
Tags: observables, async, promises
Published: 2020-07-08 23:24:56

**Wrapping an Observable in a Promise**

The pattern...

```typescript
async getSomething() {
   await new Promise((resolve, reject) => {
     let service = this.service
     service.someObservable().subscribe(
      (things) => {         
        // Tell the promise we're done
        resolve(things);
      },
      (error) => {
        console.log({Error:error});
        // Tell the promise there's an error.       
        reject(error);
      }
     );
   });
  }
```

Why would we want to do this? The main reason is to gain more control on the observable. We want to hold up execution until the observable completes. Observables finish in their own time.

**Ensure the Order using a closure**

```typescript
 this.service
   .someEvent
      // Use the async keyword here   
     .subscribe(async (newValue) => {
       // things is the closure of getSomething.
       let things = await this.getSomething();
       this.UpdateRow(newValue);
 });
```

This guarantees that the call to UpdateRow never happens before the return of getSomething. Observables have execution lifecycles of their own.

**Jasmine Expect using async await obserables**

```javascript
describe("Services", () => {
   it("should return the proper url", async () => {
     
      let instance = await getComponent();
      let actual = await new Promise((resolve, reject) => {
         instance.rs.getDashboardInfo().subscribe((result) => {
            resolve(result.reqParams.url === "/Dashboard/Info");
         });
      });
      expect(actual).toBe(true);
   });
});
```

Another example without rejecting the Promise.

```typescript
private async getPeople() {
      await new Promise((resolve, reject) => {
	     // must do this to get addressibility
         let rs = this.rs; 
         rs.getPeople().subscribe(
            (people) => {
               this.people = people;
               this.setTableState();
               resolve(people);
            },
            (error) => {
               console.log("58:Ineligible People Component Error Handler");
               this.es.OpenError(ErrorModel.Create(error));
			   //no reason to reject here because it's being handled
            }
         );
      });
   }
```
**Summary**
Anytime we see a subscription we have to realize that the timing of its completion is in the hands of the V8 engine, we have no control over when it runs. We do however, have control on when the next statements run.


JWP 2020
Getting the API to return something, anything! AC Slayers Part 2
Tags: react, nextjs, typescript, api
Published: 2020-07-08 23:24:00

# Data Fetching

Cool, we are up and running, now what? I will try and pull data from the Riot API.

Looking through the Next.js docs I see they have a section for [data fetching](https://nextjs.org/docs/basic-features/data-fetching). They offer three unique functions that you can use to fetch data for *pre-rendering*.
- `getStaticProps` (Static Generation): Fetch data at **build time**
- `getStaticPaths` (Static Generation): Specify dynamic routes to pre-render based on data
- `getServerSideProps` (Server-side Rendering): Fetch data on **each request**.

Refer to the link above to find out more about the different data fetching methods.

While these are great, after reading when I would need to use them none of them seem to fit my use case, for now.

My home page will have a user input their summoner name and it will route them to a new page with their summoner info. For now, I am just trying to hit the GET request from Riot to see if I can return my Summoner Name.

I created a simple fetch using JS Fetch API and guess what I get hit with. A CORS issue! Not sure what CORS is? [Here is a little info on it](https://javascript.info/fetch-crossorigin#why-is-cors-needed-a-brief-history).

Ahh, so I need to figure out a way to create a proxy to fix this issue. Luckily Next.js has a nice little [example](https://github.com/vercel/next.js/tree/canary/examples/with-custom-reverse-proxy) that I basically copy/pasta'd into my project; I just changed the proxy target, query string, and installed some node packages.

Sweet! I returned my Summoner Name!
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/yfv54dxxm0vys3q7fthn.png)

So most of the code looks like normal stuff but there was something new that I just encountered. A hook called `useSWR` was implemented in the example.

## WTH/F is SWR!? 
This deserves its own blog post but I will put some info here for now. [SWR](https://nextjs.org/docs/basic-features/data-fetching#swr) is a react hook for client-side data fetching built by the devs at [Vercel](https://vercel.com/docs). From Vercel: "The name 'SWR' is derived from `stale-while-revalidate`, an HTTP cache invalidation strategy popularized by HTTP RFC 5861. SWR is a strategy to first return the data from cache (stale), then send the fetch request (revalidate), and finally, come with the up-to-date data."

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

[Offical SWR Page](https://swr.vercel.app/)
[SWR features](https://swr.vercel.app/#features)

Now we know what `useSWR` is and what it does!

### Recap:
- Created a very rough home page
- Fetched data from Riot's API
  - Returned my summoner name
- Created a proxy server for development so I can fetch data from Riot's API

### Next Steps
- Create a rough layout of User Info Page
- Pass the user summoner name input from HomePage to UserInfoPage
- Fetch more data that:
  - Return user info (name, level)
  - Return match history
  - Return Rank
  - Return W/L ratio
  - Return Trati Stats
  - Return Unit Stats
Validate paginated collections has results.
Tags: laravel
Published: 2020-07-08 23:14:40

---
title: Validate paginated collections has results.
published: true
description: Laravel provides an easy helper to validate the data in a paginated collection.
tags: Laravel
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/ujkf5t0r1xsd32a6llo6.png
---

There would be cases where you want to pass a paginated collection to a view, but if the collection is empty maybe you want to return another view.

If you are on a blade file you can handle this by using a "forelse" method but if you want to return different view if the collection is empty?

Laravel provide us a simple method to validate if this collection is empty, but first lets see another approach:

Maybe you were tempt to use the total method to make something like this:

```php
$results = User::paginate();
if($results->total() > 0) {
    return view('users.show', compact('results'));
}
return view('anotherview');
```

an easiest and more readable way to handle this is with the method "hasPages()":

```php
$results = User::paginate();
if($results->hasPages()) {
    return view('users.show', compact('results'));
}
return view('anotherview');
```
Making things transparent in CSS
Tags: css, webdev, design, codenewbie
Published: 2020-07-08 23:09:31

Transparent content is among the most common requests in web design. As part of a beautiful design, we often want to make some content slightly transparent. It is also one of the widespread mistakes among those with less experience in CSS. Quite often, when trying to make background transparent, developers end up with transparent content also. In this post, I am describing how to make the background only transparent and the difference between the two most commonly used CSS properties for that, opacity and background.
 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/yqqzlq4ua6rf3rv06bvc.png)

## Opacity
Opacity is the rule most developers go to when trying to make content transparent. The problem with it is that it doesn’t make just your background transparent; it also makes content inside of it.

{% codepen https://codepen.io/chriss_dev/pen/bGEMRdP %}

Sometimes, this is something you want. There might be an image you want transparent, or it could be part of your hover effect. But if you have text inside, you want it readable. And that can be hard if it is transparent.

## Background RGBA
There are multiple ways you can define the background of the element. You can use the URL of an image, but also, if you want to set the color, there are options like hex code, RGB, RGBA and color name. To have transparency, you can use RGBA, where last, fourth parameter is alpha, amount of transparency. Just like in opacity property, this value is from zero to one, inclusive, where zero means fully transparent and one not transparent at all. What makes this property different from opacity is that content is still not transparent, and only the background has transparency.

{% codepen https://codepen.io/chriss_dev/pen/vYLjZNa %}

## Wrap up
There are many other ways to do this. You could have a separate element in the background having transparency, or maybe using transparent PNG as background. But these are the two most common ways to do it. And two ways that introduce the most significant confusion among new CSS developers. After this post, I hope it is all a bit clearer.

For more, you can follow me on [Twitter](https://twitter.com/hi_iam_chris_), [LinkedIn](https://www.linkedin.com/in/kpajtasev/), or [GitHub](https://github.com/kristijan-pajtasev/).
Technical Interview Questions For A Back-End Job Position
Tags: help, jobhunting, backend
Published: 2020-07-08 23:02:42

---
title: Technical Interview Questions For A Back-End Job Position
published: true
description: Seeking advice on interview preparation 
tags: Help, JobHunting, BackEnd
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/akkp26oiacvjk4yq4udu.jpg
---

What questions one should expect when applying for a back-end job position?
For a developer with 2 years of experience in programming.

Job Description contained Microservices, unit testing, automation, Message Queues, RPC, Caching...etc
EPPR - BASH para revisar DNS/TXT & Caducidad SSL
Tags: linux, bash, eppr, anonymous
Published: 2020-07-08 22:29:50

# eppr-txt-dns-check

### Comando LINUX usando google.com
```
host -t txt google.com
```
### Programa en BASH
```
#!/bin/bash
# BASH Para revisar DNS con TXT
main(){
    echo "Ingresa un dominio (o sub):"
    read vardomain
    host -t txt $vardomain
    # FIN
}
main
```

### GITHUB

```
sudo git clone url
```

### CURL GITHUB+RAW

```
sudo curl -sSL url | sh
```

----------

# eppr-ssl-check
### Comando LINUX usando google.com

```
echo | openssl s_client -servername google.com -connect google.com:443 2>/dev/null | openssl x509 -noout -dates
```

### Programa en BASH

```
#!/bin/bash
# BASH para revisar caducidad en certs. SSL
main(){
    echo "Ingresa un dominio (o sub):"
    read vardomain
    echo | openssl s_client -servername $vardomain -connect $vardomain:443 2>/dev/null | openssl x509 -noout -dates
}
main
```

### GITHUB

```
sudo git clone url
```

### CURL GITHUB+RAW

```
sudo curl -sSL url | sh
```
How to export Excel files in Laravel
Tags: laravel, php, webdev, backend
Published: 2020-07-08 22:17:43

Working on a personal project I saw the need to export data generated by eloquent queries from laravel in Excel format. The dependency that worked quite well for me is the following:

https://docs.laravel-excel.com/3.0/getting-started/installation.html

Additionally I attach two tutorials that I use:

* https://www.youtube.com/watch?v=YOMQudcPYiU
* https://laraveldaily.com/laravel-excel-export-formatting-and-styling-cells/

Best Regards!
Debug A Django Container With VS Code
Tags: django, docker, vscode, debug
Published: 2020-07-08 21:47:56

# I'm not a native speaker 
Well I get tired searching the internet for debugging my colleague's django container, I tried all sort of things:
[Pycharm Doc for docker-compose debugging](https://www.jetbrains.com/help/pycharm/using-docker-compose-as-a-remote-interpreter.html) 
[Pycharm Doc for remote debugging]
(https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html)
[VS Code with ptvsd](https://github.com/Microsoft/ptvsd)
Until I Came into This [article](https://code.visualstudio.com/docs/remote/containers#_attaching-to-running-containers) by microsoft About Developing inside a Container Using  VS Code 
After 10 min reading the article the steps to debug A container:
1. Attach to container
2. Debugging As you usually do in VS Code

# Attach to container

to attach to container it must be running . The problem if we run our container with **python manage.py runserver** this will prevent us from running the debug mode inside the container so we need a hack , the solution here is to keep container running and execute **python manage.py runserver** inside the container.
Now we add this line to Django's Dockerfile :
**entrypoint ["tail","-f","/dev/null"]**
this will keep our container running so we can attach VS Code to it
now type ctrl+shift+P and write **remote-containers:attach to running container** then choose the django container and vscode will install itself inside your container and open it up ...

# Debugging As you usually do in VS Code

Now let's add Django Debugging Configuration to **launch.json** (exist inside .vscode folder)
![alt text](https://i.imgur.com/0zhDoqO.png)
(don't forget  0.0.0.0:8000 to map to the outside world of the container)
of course if you have docker-entrypoint file you can replace "program": "${workspaceFolder}/docker-entrypoint.sh"
and remove args

happy coding :)
Day 170: Travel the Map
Tags: hiphop, code, coding, lifelongdev
Published: 2020-07-08 21:42:23

_liner notes_:
- Professional : Had a few meetings today. Spoke about some really interesting topics. There's a lot going on. Cool to be a part of it and help out however I can. Speaking of helping out, I finished up the application for a co-worker to aide in her live stream shows. Another co-worker expressed some interest in using it as well. I'll be showing her a demo of the app tomorrow. Also finished up making changes to the Web Component I pushed to the repo. Think I got everything, but had a question on how to implement components into other components. Not sure if I need to have them in the package.json of my component or will that be taken care of in the project's overall package.json. I found other components doing different things. I asked the group and I'll see what they say.

- Personal : So I backed this Indiegogo for a new video camera (similar to a DJI Osmo Pocket) last year. It just came in yesterday. I haven't had a chance to play with it yet, but I've been watching some YouTube review videos. They've been mixed. I guess I'll see once I use it. I bought it to shoot some quick videos when I travel the map, but yeah, haven't been traveling much. haha.

![Overhead shot of people in a canoe on a river with palm trees on both sides in Dapa, Philippines](https://dev-to-uploads.s3.amazonaws.com/i/5vs1t1mrkjoex8zjwqic.png)

Going to work on editing last week's radio show and submit it to the station for this week. Maybe go through some tracks for this week's show. Also want to do some more work on my side project. Since I've been working on the application to help co-workers, I've learned A LOT more about our video product. Probably end the night watching some anime.

Have a great night!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube FGTRNsPa-KE %}