teleren/devto huggingface dataset:
Express-jwt and Keycloak: how I didn't use Keycloak's official library
Tags: node, springboot, jwt, keycloak
Published: 2020-10-30 18:56:41

# Problem

We have many microservices that run on multiple deployments. I wanted to add security by using Keycloak with the help of JWT. 

# Solution

One of the earliest solution was to use [Keycloak Js Adapter](https://github.com/keycloak/keycloak-nodejs-connect). Yet, Keycloak JS adapter requires following:

```js
var keycloakConfig = {
    clientId: 'nodejs-microservice',
    bearerOnly: true,
    serverUrl: 'http://localhost:8080/auth',
    realm: 'Demo-Realm',
    credentials: {
        secret: '62c99f7c-da55-48fb-ae4e-a27f132546b7'
    }
};
```
which seems cumbersome way of doing this.

---

I thought there must be more simple way, I just wanted to **validate requests**. 

That's why I liked [Spring Boot approach](https://www.appsdeveloperblog.com/oauth2-resource-server-and-keycloak/) which is:
- include package
```xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
```
- add one line config
```yaml
spring.security.oauth2.resourceserver.jwt.issuer-uri = http://localhost:8080/auth/realms/appsdeveloperblog
```
At start, it fetches makes request to `issuer-uri` which has response like this

```json
{
  "realm": "appsdeveloperblog",
  "public_key": "...",
  "token-service": "http://localhost:8080/auth/appsdeveloperblog/master/protocol/openid-connect",
  "account-service": "http://localhost:8080/realms/appsdeveloperblog/account",
  "tokens-not-before": 0
}
```
and stores `public_key` which is used to **validate JWT tokens**. It doesn't make request each time to verify JWT.
As result, any request is validated and working out of box.


---

So I wanted to replicate this on NodeJS.

I started with [express-jwt](https://github.com/auth0/express-jwt) and simple example was like this

```js
var jwt = require('express-jwt');

app.get('/protected',
  jwt({ secret: 'shhhhhhared-secret', algorithms: ['HS256'] }),
  function(req, res) {
    if (!req.user.admin) return res.sendStatus(401);
    res.sendStatus(200);
  });

//Or with public key, shortened

var publicKey = fs.readFileSync('/path/to/public.pub');
jwt({ secret: publicKey, algorithms: ['RS256'] });

```

However it was problem for us to provide public key because 
- we have multiple deployments
- each deployment has its own Keycloak. 

We couldn't maintain this so I decided to implement like in Spring Boot.

With the help `sync-request` package:

```js
const res = request('GET', 'http://localhost:8080/auth/realms/appsdeveloperblog');
const response = JSON.parse(res.getBody().toString());
const publicKey = `-----BEGIN PUBLIC KEY-----\r\n${response.public_key}\r\n-----END PUBLIC KEY-----`;

app.use(jwt({ secret: publicKey, algorithms: ['RS256'] }));
```
I achieved on-start fetch of public key without cumbersome settings on NodeJS.
Thank You 🙏
Tags: communityrocks, conference, thankyou
Published: 2020-10-30 17:53:38



In the current situation we don’t deem ourselves able to create a JSKongress as fun, as welcoming and an amazing experience that we always want to offer to YOU. Therefore we take a break. (If you had a ticket for the 2020 edition, you have received a refund note – please  [get in touch if you didn’t](mailto:hello@js-kongress.com).)  
  
  
First of all we want to THANK YOU: A lot of thanks for the  **great time we had together!** Thanks to  **everyone**  involved, friends, guests, speakers, partners and volunteers. Thank you for joining us, each one of you has contributed to creating a wonderful experience. Any less would have been a missing piece of the puzzle. 🧩  
  
  
Thank you for the  **priceless** moments in breaks and in between talks. For the  **worthwhile**  chats and drinks on the parties. 🍻 For the table soccer games – won and lost. ⚽ For looking beyond our noses – in technical problems and every day questions. Thanks for letting us be  **ourselves**. Thanks for our  **shared years of  [JSKongress](https://js-kongress.com/memories/)  and  [DeepTrack](https://github.com/JSKongress/JS-Kongress-Munich-Deep-Track)**, for all the sessions included and all the sessions planned, all your preparation and time and  **heart**  invested. For every single session in sign language 🤟 and the corresponding applause in gestures. 👋 For the groovy music in between and in the evening. 🎸 For every drink, that we  **cheered**  with. Thank you for every cat and unicorn. 🐱 🦄  
  
  
Today is not the end of time, we will return some time and are already looking forward to meeting you again ❤️  
  
Your JSKongress Team  
  
Béla, Jowe, Kerstin, Natalie, Marco E, Marco S and Robin … as well as Axel, Cornelia and Julia
PLEASE DONT IGNORE
Tags: javascript, googlechrome, errors
Published: 2020-10-30 18:39:53

PLEASE KINDLY HELP ME OUT HERE , MY BROWSER...GOOGLE CHROME DOESNT RENDER MY JAVASCRIPT. ALL MY PROJECTS DONT RENDER ON IT BUT IT DOES WHEN TESTED ON CODEPEN.IO
PLS DO I NEED TO INSTALL SOMETHING TO ENABLE IT OR WHAT IS STOP PING OR INHIBITING IT.

HELP WITH SOLUTIONS
Roller Coaster!  On the Canvas with ZIM
Tags: rollercoaster, zim, zimjs, amazing
Published: 2020-10-30 18:36:40

Roller Coasters are a little tricky to code but ZIM has some treats to make it possible.  First... ZIM does have physics but we are not going to use physics for this example.  Instead we animate along a path.  Here is the example on CodePen https://codepen.io/zimjs/pen/yLJKKwJ.

Animating on a path is easy in ZIM - we have Blob and Squiggle paths so here we use a Squiggle.  The general animation looks like this:

```javascript
const path = new Squiggle().center();
new Circle().addTo().animate({
  props:{path},
  time:3,
  loop:true,
  rewind:true
});
```

You can drag along a path too and all sorts of things!  Check out some examples at https://zimjs.com/nio - this was the mini-site for ZIM NIO (9) where we introduced a bunch of exciting path features.

A special thing we are doing in the animate is making the speed change depending on the height of the car.  This makes the car slowdown higher up and speed up lower on the screen giving it a realistic effect!  There are cool other effects like this you can do with ZIM animate and the EXTRA features (see the ZIM NIO examples).

```javascript
  // adjust the speed from .1 to 4 
  // proportionally between y height of 270 to 450
  props:{path:path, speed:[.1,4,270,450]},
```

In the Coaster example, we use a second fatter Squiggle just above the track.  We then mask this with the circle so we can only see it through the circle.  This makes it appear like a car is traveling along the path.

```javascript
fatSquiggle.setMask(circle);
```

We have made the path longer than the stage (viewable area).  So we use the follow method of the Frame to move the scene to follow the car!

```javascript
Frame.follow(car);
```

It is so fun working with ZIM!  Everybody who does loves it... come on and join us.

---

If you have not checked out the Canvas recently - you simply must!  Here is the [ZIM&nbsp;Dev&nbsp;Site](https://dev.zimjs.com) and some [In-depth&nbsp;Guides](https://drabstract.medium.com/) by Dr&nbsp;Abstract including [Your Guide to Coding Creativity on the Canvas](https://drabstract.medium.com/your-guide-to-coding-creativity-on-the-canvas-ada0996298f6).
Auswahl Webhosting und Domain-Provider - WepE Teil 3
Tags: wordpress, domain, hosting, websiteerstellen
Published: 2020-11-02 11:33:59

---
title: Auswahl Webhosting und Domain-Provider - WepE Teil 3
published: true
date: 2020-10-30 18:09:25 UTC
tags: Wordpress,domain,hosting,websiteerstellen
canonical_url: https://j0e.org/webhosting-und-domain/
---

![Auswahl Webhosting und Domain](https://j0e.org/wp-content/uploads/2020/10/webhosting-domain.png)

 Die Wahl des richtigen Webhosting und des Domain-Providers wird dir viel Kummer und Arbeit ersparen. …

[Auswahl Webhosting und Domain-Provider - WepE Teil 3 »](https://j0e.org/webhosting-und-domain/)
Using existing regression model for statistics
Tags: python, help, statistics, machinelearning
Published: 2020-10-30 17:24:32

Looking for some direction on this situation.

Previously, I have created OLS models using [statsmodels](https://www.statsmodels.org/stable/index.html). This works great and is easy to use when creating a new model from scratch.

Now, we have a new requirement to allow users to submit an existing equation (from a pre-existing model), to allow for comparison between the user submitted regression model and the statsmodels generated model. This comparison would ideally be able  to be done looking at each models resulting [ANOVA table](https://sphweb.bumc.bu.edu/otlt/MPH-Modules/BS/BS704_HypothesisTesting-ANOVA/BS704_HypothesisTesting-Anova3.html#:~:text=The%20ANOVA%20table%20breaks%20down,Source%20of%20Variation).

I have looked at using r-style formula to set the existing equation, like so.
```python
eq = 'y ~ 2.3(x) + 0.86(y) + 0.85(z) - 1786'
```
This causes some issues with how statsmodels implemented the equation parsing, which uses patsy.

Basically I'm looking for a way to set a regression formula, and pass in data to generate stats about the model.

Possible solutions don't have to be in python.

Thanks in advance!
Can Insomnia Be Cured?
Tags: discuss
Published: 2020-10-30 17:20:40

Insomnia is my old friend. I like to work at night as there is no disturbance and I can concentrate well due to that. So I used to read, learn, and complete assignments at night from the 10th standard(year 2011) and I continued. It eventually became a habit and now I have trouble falling asleep. It many times helps though and many times I want to get rid of it.

I have read a few remedies, haven't tried anything yet but I am curious **Has anyone been cured of insomnia?** If yes, please share **How** in the comment!

Thank you
Ask Octopus - How do I ignore messages written to stderr?
Tags: octopus, tutorial, devops
Published: 2020-10-30 17:16:51

---
title: Ask Octopus - How do I ignore messages written to stderr?
published: true
description: A tool that you're using in your deployments is writing informational logs to stderr, but you don't want the messages to show up as errors. What do you do? Find out in this Ask Octopus!
tags: octopus,tutorial,devops
series: Ask Octopus
---

A tool that you're using in your deployments is writing informational logs to stderr, but you don't want the messages to show up as errors. What do you do? Find out in this Ask Octopus!

{% youtube chBGBfNd8X0 %}

Do you have a question about how to use Octopus? Email advice@octopus.com and someone from our team will get you an answer. You might even see it in a future episode.

Join our community slack at https://octopus.com/slack
Being a programmer... is pain
Tags: video, career, advice, watercooler
Published: 2020-10-30 17:02:54

---
title: Being a programmer... is pain
published: true
description: The reality is that when you're trying to expand your skills, there will be times when you hit a wall. Trying to do something and being bad at it is painful, and it's human to withdraw from pain.
tags: video, career, advice, watercooler
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/kqr3q9u7n02oceddme6h.jpg
---
I set up my camera and streaming rig yesterday to film some easy Javascript coding. I ended up making incredibly loud static for reasons I couldn't figure out.

{% youtube 5Qhfl0TWZi4 %}

The reality is that when you're trying to expand your skills, there will be times when you hit a wall. Trying to do something and being bad at it is painful, and it's human to withdraw from pain.

As a developer you face this pain more often than you would in other jobs, and in the video above I talk about why that is and what to do about it.
What was your win this week?
Tags: discuss, weeklyretro, hacktoberfest
Published: 2020-10-30 17:01:58

---
title: What was your win this week?
published: true
description: Got to all your meetings on time? Started a new project? Completed Hacktoberfest? 
tags: discuss, weeklyretro, hacktoberfest
cover_image: https://cl.ly/188e843c2985/download/Image%202019-02-15%20at%202.36.37%20PM.png
---

Cheers to the weekend!


**Looking back on your week — what was something you're proud of?**

All wins count — big or small 🎉

Examples of 'wins' include:

- Completing [Hacktoberfest](https://dev.to/devteam/hacktoberfest-2020-completion-thread-de82)!
- Starting a new project
- Fixing a tricky bug
- Prioritizing rest and exercise...or whatever else that may spark joy 😄


**Happy Friday!**

![Halloween Dance](https://media.giphy.com/media/7702jh3NsloOseiDUk/giphy.gif)
The CSS Series - Part 1: An Intro to CSS
Tags: codenewbie, css, beginners
Published: 2020-10-30 17:01:14

*This is Part 1 in a multi-part CSS educational series developed for the #vetswhocode non-profit coding boot camp. And if you are a veteran, apply for this free coding boot camp [HERE](https://vetswhocode.io/apply).*

*Follow @nbhankes and [@vetswhocode](https://twitter.com/VetsWhoCode) to get notified when then next part of this educational series is released.*

*Expect the following parts in this series to serve as valuable reference material for your development career.*

### **Some of the topics to look forward to are:**
- Connecting the CSS style sheet to the index.html file
- Box Model
- Selectors
- Specificity
- CSS Units
- Flexbox
- Grid Layout
- Mobile First Design
- CSS Variables
- & more

</br>

### Donate to #vetswhocode life-changing mission [HERE](https://vetswhocode.io/donate). 🙏

## Introduction
This part will give a high level overview of CSS. This will help bring context to the purpose and potential of CSS in modern web development. By the end of this page, you will understand the concept and basic syntax of CSS.

## Prerequisites
A basic understanding of HTML

## Defining CSS
Cascading Style Sheets (CSS) is a language web developers use to describe how HTML and XML elements appear on the screen. Simply put, CSS allows developers to add style (color, form, contrast, shape, movement, responsiveness, etc.) to HTML layouts. CSS is not a programming language, but rather a style sheet language. Functionally, it works by selecting an HTML element and assigning the selected element CSS properties.

## Introducing CSS Syntax
CSS syntax follows a simple three-part naming convention. The "selector" selects an html element. The "property" is a pre-defined CSS property. The "property value" is a value assign to the "property."

```css
selector {
  property: property value;
}
```
The above example is only for teaching purposes so that you can understand the CSS naming conventions. The example below is similar to what you will write in the real world:

```css
div {
 background-color: red;
 width: 50%;
}
```

The above code block shows an example of basic CSS syntax where all elements from a linked HTML document are assigned a background color of red and a width equal to 50% of the viewport width.

The selector, in this case "div," is followed by curly braces. The CSS properties (background-color and width) assigned to this selector are placed within the brackets and supplied with CSS properties values (red and 50%). Property and property value pairs are always separated by semi colons.

## Conclusion
You just learned about the definition and purpose of CSS and gained exposure to its most basic syntax.
Escape the Loop 2020: Returned 0;
Tags: hacktoberfest, ucschf2020
Published: 2020-10-30 16:50:26


The hackathon “Escape the Loop” conducted by Mozilla Club of UCSC was a remarkable success witnessing a huge participation of young undergraduates amidst this pandemic. It opened up the door to bring out the hidden talents of the young enthusiastic undergraduates. The hackathon commenced on the 22nd of October 2020 with an awareness session and came to end on the 29th of October 2020.

This year's participation of the UCSC undergraduates was monumental. They presented many innovative applications blended with retro/cyberpunk themes, which impressed our judge board too. There were personal assistant applications, volunteering, donation platforms, recycle and reuse promoting applications, virtual learning environments integrated with machine learning, entertainment applications and so much more. 

And these projects can be accessed via the following link.
<a href="https://hacktoberfest.ucscmozilla.com/">https://hacktoberfest.ucscmozilla.com/</a>

-------------------------------------------------------

# The Winners of Escape the Loop 2020

The judging panel was at a hard place selecting the winners, but finally, with much difficulty, they determined the winners and runners-up as stated below. But after all, Escape the Loop is not about places on a podium. It’s all about collaboration and having fun. According to the feedback of our participants, we surely know that they had fun, and learned new things too.

Here are the Winners of Escape the Loop 2020 🎉  *Drum roll please*

## Escape the Loop Champions 🏅 : Bits N’ Bytes
{%link https://dev.to/ranahp/cyboshool-5hko %}
## 1<sup>st</sup> Runners Up 🏅 : Escaped
{%link https://dev.to/nandulaperera/start-here-npi %}
## 2<sup>nd</sup> Runners Up 🏅 : Amba_GMs
{%link https://dev.to/maleesha98/ambagms-hacktoberfest-436l %}

Hence, that concludes this year’s Hackathon. We would like to extend our heartiest congratulations to the winning teams, and all the participants for bringing out their brilliant minds into action, and we also offer our sincere gratitude to the UCSC lecturers, Dr. Thilina Hallolluwa, Dr. Manjusri Wickramasinghe and Mr. Pasindu Marasinghe for undertaking the hardest part of them all, the judging. 

We hope that everyone has gained a great knowledge as well as experiences in managing group projects, time management and in other technological aspects also. 
Let’s meet again in Hacktoberfest 2021, hopefully, face-to-face!

Signing out,
Escape The Loop 2020 Crew.
Laravel middleware: My notes
Tags: laravel
Published: 2020-10-30 16:25:55

## > Create Middleware

**Middleware provides a convenient mechanism for filtering HTTP requests entering your application. For example, Laravel includes a middleware that verifies the user of your application is authenticated. If the user is not authenticated, the middleware will redirect the user to the login screen. However, if the user is authenticated, the middleware will allow the request to proceed further into the application.**

To create a new middleware, use the make:middleware Artisan command:

 >  **php artisan make:middleware NameOfMiddlwere**

After we create a new middleware, we can put our condition inside its method: 

For example, a user wants to access his profile, so we need to check if he is login or not, for that we use middleware.

we create a method check if $_SESSION['is_login'] = true;

```
namespace App\Http\Middleware;

use Closure;

class CheckLogin
{
   
    public function handle($request, Closure $next)
    {
        if (isset($_SESSION['is_login']) {
             if ($_SESSION['is_login'] == false) {
               return redirect('/');
             }
        }

        return $next($request);
    }
}
```

As we see, we get the request and check if the user login or not, if he not we redirect him into the home page, otherwise, we allow him to access his profile. (we use a callback function 'closure' )

## > Assigning Middleware To Routes

> if we want to assign middleware to a specific route, First we should assign the middleware a key in our app/Http/Kernel.php file.

then we can use our middleware like this:

```
Route::get('admin/profile', function () {
    //
})->middleware('theKey');
```

## > Middleware Parameters

Let's imagine that before we allow any user to access a specific route, we need to check if he's an Admin first. 

```
public function handle($request, Closure $next, $type)
    {
        if (isset($_SESSION['user_type'])) {
         
            if ($_SESSION['user_type'] == $type) {
               //Redirect...
            }
        }

        return $next($request);
}
```

And we can put the parameter like this...

```
Route::get('admin/profile', function () {
    //
})->middleware('theKey:Admin');
```
Nullish Coalescing (??) in Javascript
Tags: javascript
Published: 2020-10-30 12:21:06

### Basics

Before we start, let's get the basic concepts out of the way.

There are 6 falsy values in JavaScript which are `undefined`, `null`, `NaN`, `0`, `""` , `false`.

These above values will be taken as a `false` value in a condition. [learn more](https://www.sitepoint.com/javascript-truthy-falsy/)


### Introduction
We generally use logical OR (`||`) operator to return the right operand if the left operand is falsy.

The syntax goes as `leftExpression || rightExpression`

If the `leftExpression` is truthy, it will be returned.

If the `leftExpression` is falsy, `rightExpression` will be returned.

For example:

```javascript
let falsyValue = 0;
let truthyValue = 1;

console.log(falsyValue || 'printed'); //output: 'printed'
console.log(truthyValue || 'nope'); //output: 1
```

This can lead to unexpected issues if you consider `0` or `""`(empty string) as valid values.

This is where Nullish Coalescing (`??`) operator helps us. It was introduced in ES2020.


### Nullish Coalescing (??)
Nullish Coalescing (`??`) operator is used to return the right expression if left expression is nullish.

> A nullish value is a value that is either `null` or `undefined`.

Here are some examples of expressions:-

```javascript
// comments represent the value returned

0 ?? 'expressionB' // 0
0 || 'expressionB' // expressionB

'' ?? 'expressionB' // ''
'' || 'expressionB' // expressionB

null ?? 'expressionB' // expressionB
null || 'expressionB' // expressionB

undefined ?? 'expressionB' // expressionB
undefined || 'expressionB' // expressionB

let object = {}; // same for [] as well
object ?? 'expressionB' // {}
object || 'expressionB' // {} 
```

### Short-Circuiting

Similar to AND (`&&`) and OR (`||`) operators, Nullish Coalescing (`??`) is also short-circuited meaning it will not execute the right operand if the left operand is neither `null` nor `undefined`.

### Chaining

Chaining `??` with `&&` or `||` operator will throw a `SyntaxError`

```javascript
 null || undefined ?? 'OK'; // Uncaught SyntaxError: Unexpected token '??'
```

This can we avoided by using parentheses to explicitly specify the operator precedences

```javascript
(null || undefined) ?? 'OK'; // "OK"
```

#### References

[JavaScript Nullish Coalescing Operator](https://www.javascripttutorial.net/es-next/javascript-nullish-coalescing-operator)
Linux TZ environment variable not being set and the impact to Caché
Tags: cache, database, suse, linux
Published: 2020-10-30 16:13:35

During recent large scale benchmarking activities, we were seeing excessive %sys CPU time that negatively impacted scaling of the application.

**Problem**

We have found that a lot of the time was spent in the _localtime()_ system call due to the TZ environment variable not being set.  A simple test routine was created to confirm the observation, and the elapse time differences and CPU resources needed with TZ set versus TZ not set were astonishing.  It was discovered that the inherit use of _stat()_ system calls to /etc/local_time from _localtime()_ are very expensive when TZ is not set.

**Recommendation**

InterSystems highly recommends confirming in any Linux installation whether x86 or Linux on Power that the TZ environment variable is set appropriately for optimal performance.  For more details see: "man tzset".

The current Caché 2016.1 Field Test contains optimizations in regards to date and time functions, and initial testing indicates a profound improvement.  Below are sample outputs from testing the new internal function calls in a loop with Linux on Power in both cases with TZ \*not\* being set:

Before Caché 2016.1 FT:

<pre width="100%"><code>real	0m22.60s</code>
<code>user	0m1.64s</code>
<code>sys	0m20.89s</code></pre>

With Caché 2016.1 FT:

<pre width="100%">real	0m0.40s
user	0m0.37s
sys	0m0.00s</pre>

Please post comments with any experiences you may have had with your application regarding TZ environment variable and also the impact of Caché  2016.1 Field Test has with or without TZ being set.