teleren/devto huggingface dataset:
Importance of writing a clean code and how to make code readable
Tags: cleancode, readability, maintainablecode
Published: 2021-05-06 22:55:43

Today, I needed to add a new feature to  an old project I have worked on about three months ago. When i opened it,  I could not tell which part of the code does what. It took me three hours to add a minor feature which I would have added in half an hour had the code been clean and tidy. 


When it comes to writing a clean maintainable code even experienced programmers struggle. As programmers, most of the time, we work in teams weather small or big. Writing clean and readable code is  important not only to us but also to people who may read our code. Below are the three top reasons why it is important to write a clean code.

####Importance of writing clean code 

1- It makes our work easy to maintain.
2- It makes our code easy to understand. 
3- It saves time in the long run. If you write a clean code, you know which part of you code does what so it is easy to add new features. 

##### How to write a clean code 

###### 1 Add meaningful and descriptive comments 
Comments are very important when writing a code. They provide information about what you code does. They need to be clear and descriptive.
 
###### 2 Add proper indentation and formatting 
Indentation and formatting makes code look organised and pleasing to look at.Tools such as the vs code document formatter and  the vs code extension prettier prettify code. There is also an extension called bracket pair colorizer in vs-code that colourises matching brackets and make code look colourful and pretty.

###### 3 Avoid creating longer and complex functions 
It might feel that you are saving time by writing one big function instead of breaking it down into smaller functions, but in the long run it is not the case. If you have a function that does a complex task, maintaining it will be a nightmare and time consuming. I found this out the hard way.

######4 Declare global variable at the beginning of your code
Having global variables at the top makes it easy to navigate and find variables later when you code becomes longer and complex.

###### 5 Get rid of unused code
Having pieces of code that do not do anything laying around with you other code is not a good practice. When you come back later to have a look or to maintain your code it will be confusing. As soon as you are done working with your code, review one more time to see if you have unnecessary and unused pieces of code.

Writing clean, readable and maintainable code takes practice. You do not just master it overnight. If you follow the good practices of writing clean code and try to implement them on every piece of work that you do, they will became second nature. 
Write a code that is easy to read and maintain, your future self and people who might collaborate with you will thank you.
More Securely Access an HTTP Request Trigger
Tags: development, flow, powerautomate, triggers
Published: 2022-06-15 17:23:58

---
title: More Securely Access an HTTP Request Trigger
published: true
date: 2021-05-06 22:08:00 UTC
tags: Development,flow,PowerAutomate,triggers
canonical_url: https://barretblake.dev/2021/05/more-securely-access-an-http-request-trigger/?utm_source=rss&utm_medium=rss&utm_campaign=more-securely-access-an-http-request-trigger
---

In a previous post, we learned how to trigger a Power Automate flow by calling an HTTP endpoint. The best part of this trigger is that it allows you to trigger your flow from anywhere on the internet, be it an application or right in your browser. The trouble is, there isn't security for that endpoint 'out of the box'. Anyone who knows the endpoint's URI can call it. So how do you secure that endpoint so that only someone who is authorized to call the endpoint can get it to run?

The post [More Securely Access an HTTP Request Trigger](https://barretblake.dev/2021/05/more-securely-access-an-http-request-trigger/) first appeared on [Barret Codes](https://barretblake.dev).
Just published the 5th Issue of my Newsletter
Tags: news
Published: 2021-05-06 22:42:27

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/49io6hjpat8oki8wd6ju.png)
Click to read [here](https://anotherbug.substack.com/p/-your-
ci-service-free-tier-generous)
That boot camp might be lying to you
Published: 2021-05-06 22:22:42

## Have you noticed that ALL of the boot camps get the "Best Boot Camp" award - in some shape or form?

Had you noticed that they almost all get 5/5 scores? Can they really ALL be _the best_. Well, if you didn't notice _that_ - then you definitely didn't notice all of the really sneaky stuff.

{% youtube luxIa3Qs2lA %}

Before you fall into the high-pressure sales trap, take a second look. Just because they are lying to _you_ doesn't mean you have to lie to yourself.

---

Also - if anyone needs some fake awards, _we have Photoshop_.
Avoid. Magic. Numbers
Tags: javascript, computerscience
Published: 2021-05-06 22:18:21

Magic numbers, you see them everyday and probably have used a fair amount of them once in a while. What are magic numbers, and magic booleans?.

Well, I'll try to define both of them at once, a magic number (or boolean)is an argument to a function, you don't know how it works, or what it will do and how it will affect the function, you just know that it's there, and you don't play with it in fear something breaking. 

So, what would you usually do to discover what a magic number/boolean will do?. Well, you might go visit the docs of the tool that you're using, or read the source code trying to figure out what this black magic does and why it exists in your codebase.

Let's illustrate this with an example,

```javascript
  check(e) {
    if (e.keyCode === 13) {
      this.attemptSendMessage(e);
    }
  }
```
What does this do?. Well, obviously this is an event listener, as it receives `e` as an argument, it listens for a specific key-code `13` and when matched it calls `attemptSendMessage`. We're not concerned with the `attemptSendMessage` method. But, let's examine the number. What does the number refer to? which is the key that this accepts?.

A few possible solutions that might come to mind, you mind find yourself doing this 

```javascript

  check(e) {
    console.log(e.code) // logs the key that was pressed
    if (e.keyCode === 13) {
      this.attemptSendMessage(e);
    }
  }
```

Or, you might google and find a question on stackoverflow. These, all are possible solutions that will eventually solve this issue of your understanding of this magic number. However, a better way to write this is storing the magic number inside a variable that explains what this number is really is.

If you tried any of the solutions above you'll find out that the number 13 is the key-code of `enter` key on the keyboard.

Now, with this knowledge let's store the number inside a variable and see what changes, shall we?.

```javascript
  check(e) {
    const keycodeOfEnter = 13;
    if (e.keyCode === keycodeOfEnter) {
      this.attemptSendMessage(e);
    }
  }
```

Can you spot the difference?, Well we stored the number inside a constant and used the constant instead of the number. Now, any developer(or yourself) when they look at this code, they will now instantly what this magic number is, it saves you a couple of minutes of googling and searching.

You should also be aware that `keyCode` has been deprecated and replaced with `code`. Then you can replace it with 

```javascript
check(e) {
    if (e.key == "Enter") {
      this.attemptSendMessage(e);
    }
  }
```

Always, try to store magic numbers inside variables. Magic numbers can be vague and evil, because you have no idea what they are for and what they represent.

In a future post, I'll be illustrating the case for magic booleans. Until then, have a great day. And, thank you for reading this.

Related Links 

[Keyboard Events](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode)
Things I learnt doing a small fuzzy search UI element
Tags: fsharp, postgres, svelte
Published: 2021-05-06 21:49:26

I added search functionality to [Opus Classical](https://opusclassical.net). It was quite simple, but I learnt a few things.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpqkivfjrmkrw9td9rav.gif)

## Adding CORS to [Saturn](https://saturnframework.org) is pretty straightforward

```fsharp
let configureCors (builder: CorsPolicyBuilder) =
    builder
        .AllowAnyOrigin()
        .AllowAnyMethod()
        .AllowAnyHeader()
    |> ignore

let app =
    application {
        // ...
        use_cors "All" configureCors
        // ...
    }
```

## [Svelte](https://svelte.dev) is fantastic for this kind of thing

Choose a node, attach a Svelte component to it. Have reactivity, nice clean syntax and TypeScript.

5kb of compressed JS bundle is pretty comparable to what I would have had with Vanilla JS and hardly possible with Vue/React/Angular.

## Postgres [trigram](https://www.postgresql.org/docs/13/pgtrgm.html) is godly

Do an index:

```sql
CREATE INDEX idx
   ON composers USING gin(last_name gin_trgm_ops);
```

Make super fast fuzzy search selects:

```sql
select id, last_name, similarity(last_name, 'beth') as score
from composers
where last_name % 'beth'
order by score desc
limit 5
```
Birds Attack
Published: 2021-05-06 21:40:18

<p>See the making of here : <a href="https://codepen.io/emilienleroy/pen/LYWEPoJ" target="_blank">https://codepen.io/emilienleroy/pen/LYWEPoJ</a>
Made with all my love on Twitch.tv ! &lt;3</p>

{% codepen https://codepen.io/emilienleroy/pen/bGqNbyd %}


<p>Follow me :p
<br>
<a href="https://twitch.tv/emilienjc" target="_blank">https://twitch.tv/emilienjc</a>
<br>
<a href="https://github.com/EmilienLeroy" target="_blank">https://github.com/EmilienLeroy</a>
<br>
<a href="https://codepen.io/emilienleroy/" target="_blank">https://codepen.io/emilienleroy/</a>
<br>
<a href="https://twitter.com/LeroyEmilien" target="_blank">https://twitter.com/LeroyEmilien</a></p>
<br>
Day 361 : Woman
Tags: hiphop, code, coding, lifelongdev
Published: 2021-05-06 21:34:05

_liner notes_:
- Professional : Another chill day. Just worked on doing screen recordings for the tutorial video template. A few things have changed, so I figured might as well update the recordings. Had a couple of meetings. Pretty good day.

- Personal : Last night I fixed the issues I was having with the Service Worker in my side project. I just added an array with all the files that were being called from the wrong location and when the Service Worker tried to call them, I just redirected the request to the correct location. Also refactored some code in my Web Component so that the attributes were now hyphenated and that fixed them from disappearing when navigate between pages. Got everything pushed and published and verified it works on multiple devices. Also worked how I wanted to layout some text on the side project. Watched an episode of "Yasuke" and went to sleep.

![View into a valley in Tham Sa Koen, Thailand with large rock formations sticking up from the fields covered in a fog.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/atwlksfzivp4aype9fn5.jpg)

Going to add some text and layout to the side project. Once that's done, just need to work out the Notification system and then it should be good to post. Looking to start doing the streams in June, hopefully. I want to go through some tracks for the radio show this week. Little Simz just dropped a video for a dope track called "Woman" featuring Cleo Sol. Will definitely give that a spin. Then end the night watching "Yasuke". That last episode was wild! There's only a few more episodes in Season 1 so I'm interested in how they finish it.

Have a great night!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube zHGf6tmnLYE %}
Let's write a tiny JSON parser in Kotlin! Part 2: The Parser
Tags: kotlin, json, tutorial
Published: 2021-05-06 21:01:19

So now we have an understanding of JSON and the components that make it up, but we have to create something that will read it - this will be our parser.

Our parser will step through our JSON file character by character to read it, so it'll need to:
 - remember our JSON
 - remember where in the JSON it's currently looking
 - know if it's at the end
 - read the current character
 - step to the next character

So let's do it!
First, we'll create a class which will take in our JSON as a `CharSequence` (we could use a `String`, too - the functionality is the same, but this lets you do something weird like throw a `StringBuilder` in there), and will remember where it's currently reading:

```kotlin
class Parser(private val input: CharSequence) {
    var cursor: Int = 0
}
```

Now let's give it the ability to read and step through the input.

```kotlin
class Parser(private val input: CharSequence) {
    var cursor: Int = 0

    private fun step(): Char {
        return input[cursor++]
    }

    private fun peek(): Char {
        return input[cursor]
    }

    private fun skip() {
        cursor++
    }
}
```

`peek()` will read the current character, `skip()`, will move the cursor forwards by one, and `step()` and read and then move on.

However, trying to read past the end will throw an exception, so let's add a method to check if we're at the end:

```kotlin
    private fun hasNext(): Boolean {
        return cursor < input.length
    }
```

This is everything we'll need for moving along our JSON text. Next, let's add some functions to actually read it:

```kotlin
fun read(predicate: (Char) -> Boolean): String {
    val result = StringBuilder()
    while (predicate(peek())) {
        result.append(step())
    }
    return result.toString()
}

fun read(pattern: CharSequence): String {
    val result = StringBuilder()
    var patternCursor = 0
    while (peek() == pattern[patternCursor++]) {
        result.append(skip())
    }
    return result.toString()
}
```
These two functions are vital to how the parser will do its job:

They read the JSON one character at a time, and store what they've read in a buffer, until the character they read reaches a certain condition. For the first function, that condition is given via a predicate, and in the second, the condition is that the buffer's contents match a given string. Once the condition is met, the buffer's contents are returned.

These five methods, simple as they seem, are extremely powerful, and all we need as a foundation for our parser!
Destructure Optional Params in Typescript
Tags: dev, frontend, typescript
Published: 2021-05-06 20:52:08

Sometimes you have a function with an optional Object argument that you want to destructure in the function. Like so:

```ts
interface SomeObject {
  option1: boolean;
  stuff: boolean;
}

function foo(param?: SomeObject) {
  const { stuff } = param;
}
```

However you'll get an error because `param` could be undefined and TS doesn't like you trying to destructure something that's undefined. There are a couple ways around this...

Define a fallback in the initializer and don't use the ? optional identifier:

```ts
function foo(param: SomeObject = {}) {
  const { stuff } = param;
}
```

Use nullish coalescence:

```ts
function foo(param?: SomeObject) {
  const { stuff } = param ?? {};
}
```

Or just call the propery on the parameter directly with optional chaining:

```ts
function foo(param?: SomeObject) {
  anotherFunction(param?.stuff);
}
```

All of these work and will handle `param` being undefined.
How to increase income from the restaurant business?
Published: 2021-05-06 20:35:30

The best way to get more revenue from your cafe or restaurant is to convert your business to an online + add delivery and new dishes to the menu. 

Thanks to the service https://yammy.best/ you can completely transfer your business online in a few hours, as well as come up with a unique design for the site. It seems to me that this is the perfect solution. And what do you think?
Introducing Auth0 Organizations
Tags: security
Published: 2021-05-06 20:09:08

What if you could spend a LOT less time enabling and managing access to teams?

We're very excited to announce a new way to enable businesses and teams to access your applications: **Auth0 Organizations!**

Auth0 is a software-as-a-service product. Like many SaaS platforms, Auth0 can be used by individuals, but more often than not, it is used by teams. When building SaaS, or any B2B application, developers need a way to represent and manage those teams.

Often, SaaS products will have dashboards that allow each of their customers’ administrators to manage their organizations:

- Manage membership and access levels of their team members
- Invite new members with predefined roles
- Connect their identity provider for single sign-on
- Define authentication factors and security policies

We’re forced to build this all from scratch each time we create an application, which cuts into the time we have to build the app itself. We’ve struggled with this at Auth0 when building our applications, like [our Dashboard](https://manage.auth0.com/), and when we speak with engineers and architects that work at our customers’ companies, we’ve heard similar stories.

These problems are common enough to deserve a purpose-built solution, and that is why we built Organizations.

### How Does it Work?

[Read more...](https://auth0.com/blog/introducing-auth0-organizations/?utm_source=content_synd&utm_medium=sc&utm_campaign=auth0_org)
Top 5 DEV Comments of the Past Week
Tags: bestofdev
Published: 2021-05-06 19:55:01

---
title: Top 5 DEV Comments of the Past Week
published: true
description: 
tags: bestofdev
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nvjh80kv1nr41sw6wxke.png
---

_This is a weekly roundup of awesome DEV comments that you may have missed.  You are welcome and encouraged to boost posts and comments yourself using the **[#bestofdev](/t/bestofdev)** tag._


Having a lot of [unfinished projects](https://dev.to/madza/how-many-unfinished-projects-do-you-have-56fg) floating around can seem daunting, but this is a great outlook and work ethic to have, @zedvas!
{% devcomment 1e2mp %}

[Being a developer is not an easy path](https://dev.to/tyaga001/7-uncomfortable-truths-about-being-a-developer-1gec), and imposter syndrome gets the better of us sometimes. @hseritt has an awesome mindset - thanks for the boost!
{% devcomment 1e4gd %}

These are some [really great wins](https://dev.to/devteam/what-was-your-win-this-week-29e4), @devlorenz0 ! And following [DevNews](https://dev.to/devnews) is 100% a win  😃
{% devcomment 1e37c %}


It's [Bug Smash](https://dev.to/devteam/join-us-for-the-first-dev-community-bug-smash-3plm) time! Good job on the find, @thomasbnt 😂! Have fun fixing the bugs [we've outlined in our repo](https://github.com/forem/forem/labels/Bug%20Smash) for Bug Smash, everyone! 
{% devcomment 1e65k %}


This post on [journeying into coding in Nigeria](https://dev.to/resourcefulmind/a-beginner-s-journey-into-software-development-in-nigeria-86b) is a fantastic, necessary read for any developer. Thanks for helping create a great community with this comment, @dammyreginal.
{% devcomment 1e2ia %}

See you next week for more great comments ✌
VSCODE shortcuts for speedy editing
Tags: vscode, codenewbie
Published: 2021-05-06 19:14:46

### #1 Move line Up/Down

By using  **alt + Up Arrow / Down arrow**  we can easily move the lines up or down.

### #2 Copy line Up/Down

By using  **shift + alt + Up Arrow / Down arrow**  we can copy current line up or down.

### #3 Jump to matching brackets

By using `Ctrl + shift + \` we can easily jump to matching brackets with less time when we got huge code.

### #4 Indent line

By using  **Ctrl + ] or [**  we can easily indent line in appropriate location, this helps us from pressing tab.

### #5 Fold or unfold code

By using **Ctrl + shift + [ or ]** we can fold or unfold selected code or selected region.

### #6 Toggle line comment

By using **Ctrl+/** we can comment or uncomment the whole line, this makes easy to test or while rewriting code.

### #7 Toggle block comment

By using **Shift + alt +a** we can toggle block comment (/* */). we can how imp comments are and we can't write block comment every time this makes it easy to write comment

######Hope atleast one shortcut helps you out for speedy workflow
See the errors your users are experiencing. From your IDE. Live.
Tags: vscode, showdev, productivity
Published: 2021-05-06 18:47:41

If you have built a library, command line tool, or API, Bugout helps you understand:
1. Who your users are
2. How they are using your software
3. What errors they experience

Once you [set up an integration](https://bugout.dev/app/public/d550eb09-7c85-4fdc-b687-9f04b730f6e1/entries/07b21356-2e3f-4fa9-bd77-764fe903a640?sidebar=true) and [instrument your code](https://github.com/bugout-dev/humbug), you can access your user reports at https://bugout.dev. This gives you a live view of what your users are experiencing:

![Live view of user reports](https://s3.amazonaws.com/static.simiotics.com/bugout-dev-docs/humbug-journal.png)

This week, we released the latest version of the [Bugout VSCode extension](https://marketplace.visualstudio.com/items?itemName=bugout.Bugout).

Now you can see the latest issues your users have had from VSCode. Just hover over an exception to see how many users were affected by it:

![Hover over an exception to see how many users were affected by it](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o3oz8m6ngdl3p6oam301.png)

You can even click through to see their stack traces:

![See your users' stack traces right in VSCode](https://s3.amazonaws.com/static.simiotics.com/bugout-dev-docs/bugout-vscode-exception-traceback.png)

This is just a taste of things to come. If you use VSCode and would like to try this out, Bugout supports Python, Go, and Javascript.

[Sign up and get started!](https://bugout.dev/register)
Ruby Galaxy - Beyond Ruby3 w/ Yukihiro "Matz" Matsumoto
Tags: ruby, matz, watercooler, devrel
Published: 2021-05-06 18:44:22

## 🎂 Version 0.1 Launched on Jan 28th, 2021 
### The First Ruby Galaxy


Ruby Galaxy is a virtual meetup hosted on [Twitch](https://www.twitch.tv/therubygalaxy) on the last Thursday of every month. It allows Ruby developers of all skillsets to share their experience with the language. First-time speakers are encouraged!

The goal of Ruby Galaxy is to create an inclusive and intentional space for Ruby enthusiasts to share their experiences from all around the world 👽🌌

Below is the keynote video for the first Ruby Galaxy that aired on January 28th, 2021. We were so excited to have Yukihiro "Matz" Matsumoto, the creator of Ruby, join us.

{% youtube buhig8jr-Mo %}

> Beyond Ruby3 is presented by the creator of Ruby, Yukihiro Matsumoto. This talk focuses on how Ruby3 makes progress without breaking the past. In Matz's words, Beyond Ruby3 ultimately explains Ruby's whole purpose - "to create a better world."

Interested in speaking at our next event? Check out our CFP on our website at [rubygalaxy.io](https://www.rubygalaxy.io).

For all things Ruby follow us on [Twitter](https://twitter.com/therubygalaxy) and [Twitch](https://www.twitch.tv/therubygalaxy).