teleren/devto huggingface dataset:
Clean code and why I'm behind! 
Tags: javascript, programming, codewars
Published: 2018-10-18 05:07:03

---
title: Clean code and why I'm behind! 
published: true
description: RTFM * Practice
tags: #javascript #programming #codewars
---

![image](https://cdn.pixabay.com/photo/2016/11/19/14/00/code-1839406_1280.jpg)

Hello everyone,

This is my first post here, so I'll try & keep it short😃. I've recently started sharpening my javascript axe on [Codewars](https://codewars.com) after several days working on [Watch & Code](watchandcode.com) by [Gordon Zhu](https://twitter.com/gordon_zhu?lang=en), which is amazing first step to get started with JS since I knew nothing, still don't know much, anyway to the point...

There's kata on codewars, an easier one for the experts, but this one is at **6 kyu** and it goes like this:

######Given a list lst and a number N, create a new list that contains each number of lst at most N times without reordering. For example if N = 2, and the input is [1,2,3,1,2,1,2,3], you take [1,2,3,1,2], drop the next [1,2] since this would lead to 1 and 2 being in the result 3 times, and then take 3, which leads to [1,2,3,1,2,3].######

So essentially, you need to remove the **Nth** occurance of a digit without spoiling the indexes.

Easy right? I know **now**! Not last week when I nearly spent 3 days (please don't judge me) breaking my head when I should've just thought about it clearly and **read the filter function documentation clearly**.

Now for the depressingly bad code I wrote, in retrospect I am ashamed!😓

```javascript
function deleteNth(arr, n){
	var final = [];
	var last = [];
	var k = [];
	var f = [];
	var count_inside = 0;

	arr.forEach(function(item, index){
		if(last.indexOf(item)===-1){
			final[index] = arr.map(i=>{
				if(i===item && count_inside<n){
					count_inside +=1;
					return item;
				}
				else{
					return '';
				}
			}
			);
			count_inside = 0;
			last.push(item);
		}
	});

	k = final.filter(function(i){return true;})

	for(var i =0;i<arr.length;i++){
		var sum = '';
		for(var j = 0;j<k.length;j++){
			sum += k[j][i];
		}
		f.push(parseInt(sum));
	}
	return f.filter(function(p){return p>=p});
}
```

I'm essentially trying to do the following:

1. Filter the array with a number, and get the result in an array with that number and all other indexes as empty or ''.
2. Do this other numbers without repeating the number from step 1.
3. Compress the resulting arrays into a single one and BOOM SERVE!

While still proud submitting it...knowing fully well that someone might have done it in a single **LINE**! And yeah after submission...I see this:

```javascript
function deleteNth(arr,x) {
  var result = [];
  return arr.filter(function(n) {
    result[n] = (result[n]||0) + 1;
    return result[n] <= x;
  });
}
```

That's all it took! 

#####Just count the times a number appeared and if it appeared more than N times, don't put it in the returned array.#####

And I missed that! I understand it will take me somewhile to think that clearly.
But I just wanted to put this out and maybe it might help you think in a different way today :).


Thank you Codewars!
Microsoft Flow – Manually Triggering a Flow
Tags: development, flow, powerautomate, triggers
Published: 2022-06-15 17:25:48

---
title: Microsoft Flow – Manually Triggering a Flow
published: true
date: 2019-01-03 14:50:00 UTC
tags: Development,flow,PowerAutomate,triggers
canonical_url: https://barretblake.dev/2019/01/microsoft-flow-manually-triggering-a-flow/?utm_source=rss&utm_medium=rss&utm_campaign=microsoft-flow-manually-triggering-a-flow
---

My previous articles on Flow have all had external Triggers of some kind: a blog post, a tweet, a timer and so forth. There are times when you want to have a Flow that you can trigger on demand. One solution to that is to use a Flow button.

The post [Microsoft Flow – Manually Triggering a Flow](https://barretblake.dev/2019/01/microsoft-flow-manually-triggering-a-flow/) first appeared on [Barret Codes](https://barretblake.dev).
Haskell, what's the point?
Tags: functionnal, helpwanted
Published: 2019-01-03 14:44:27

---
title: Haskell, what's the point?
published: true
description: Learning Haskell but what for?
tags: functionnal, helpwanted
---


![Haskell Logo](https://thepracticaldev.s3.amazonaws.com/i/tqxznexz7xpmhxto2s1m.png)
Last year, I tried to learn Haskell. 
And it was really tough. 
Sure, I've been coding for nearly 15 years and seen my fair share of languages. But this one... yes, it's tough. 
To be totally honest, learning Haskell was a really good (but painful) experience. 
My first attempt was a failure because there's a lot of barbaric concepts in this language (monads, monoids, functors, etc). And I started to learn all these straight away.

![What did I expect?](https://thepracticaldev.s3.amazonaws.com/i/lmcksg5gitgn19vo3swg.gif)

Guess what?
You don't need them to get started.

So, as a good resolution for 2019, I came back to the basics and went head-on with some katas on codewars. And everything looks better. Sure, my solutions aren't optimal (and some of the recommended solutions are really hard to decipher). 
But I think it's a good way to learn the basics and get slowly to the hard parts. Like [Haskell Fast & Hard](https://www.schoolofhaskell.com/school/starting-with-haskell/haskell-fast-hard). 
Soon, I will open again [Happy Learn Haskell](http://www.happylearnhaskelltutorial.com/) and [Learn You a Haskell For Great Good](http://learnyouahaskell.com/starting-out). 
But right now, [Try Haskell](https://www.tryhaskell.org/) has everything I need. 

By the way, there remains one great mystery : [what's the point of all this](https://www.youtube.com/watch?v=iSmkqocn0oQ)?
I know there are some examples of people using [Haskell for industrial purposes](https://wiki.haskell.org/Haskell_in_industry) (Facebook and its anti-spam tools, etc). 

But why? How?
Can someone please help me on this? 
Most likely, my next step will be to browse some github repos but there has to be a better way.

Can anyone help me on that?
Do you have a favorite Udemy course?
Tags: career, discuss
Published: 2019-01-03 14:04:56

I've never paid $199 for a Udemy course, but I have bought quite a few when they are being priced at $10 each. My favorite course was [this Angular course](https://www.udemy.com/the-complete-guide-to-angular-2/) by Maximilian Schwarzmüller that I purchased a few years ago. He's a great instructor, and the course continues to receive updates.

Tell me about the courses you've taken, no matter the subject!
NextJS and its genius ideas
Tags: javascript, nextjs, react
Published: 2019-01-03 13:55:41

---
title: NextJS and its genius ideas
published: true
description: 
tags: javascript, nextjs, reactjs
---

Everyone loves ReactJS.

JS frameworks blow the world out there with each new framework each week.
But when we talk about a server-side-rendering framework, there're still limited choices.

I've played around with VueJS, FusionJS and NextJS and some other "smaller" SSR frameworks, my pick is NextJS, here's why.

1. File-based routing.

Aha, i don't need to code anything to make my React application routable ! Even more, it's not only client-side routing, it's server-side routing , too.
I call it old-but-genius idea about how routing should be done.

The benefit here is, you'll get route-based code splitting for FREE !

2. getInitialProps

In old versions of ReactJS, we have `getInitialState`, i'm sure React developers will miss it very much.
And NextJS "steals" that idea to make our React component got its initial data server-side rendered !

If you still not use NextJS yet, try it out today !
Help break Quilt!
Tags: python, help
Published: 2019-01-03 13:45:11

---
title: Help break Quilt!
published: true
description: I need your help to try to break my programming library in order to expose bugs before release.
tags: python, help
---
I need your help to try to break my programming library, [Quilt](https://github.com/Richienb/quilt) in order to expose bugs before it is released.

To do so, simply execute any function in the library and try to make it perform something unexpected.

For example, if `add(True, True)` results in `2`, then that is unexpected.

Once you've found anything, simply [create a shiny new bug report](https://github.com/Richienb/quilt/issues/new?template=bug_report.md) in the handy-dandy issue tracker found [here](https://github.com/Richienb/quilt/issues).
PyCon X Italy: submit a talk for the Italian Python conference (Florence May 2nd - 5th)
Tags: python, pycon, conference
Published: 2019-01-03 13:44:30

---
title: PyCon X Italy: submit a talk for the Italian Python conference (Florence May 2nd - 5th)
published: true
description: Call for Proposals for the Italian Python conference that will take place in Florence on May 2nd / 5th
tags: python, pycon, conference
---

Even this year, the Italian Python conference will be organised in **Florence** and will take place between **May 2nd and May 5th** included.

It's an amazing opportunity to meet a lot of Python developers, listen to very interesting talks and visit one of the best cities in the world (I may be slightly biased on this last point :P )!

Subjects range from pure **Python**, **PyData**, **Machine Learning**, **web**, **DevOps**, **security** and **community** related talks and there will be a good number (usually they are the majority) of talks available in **english language**.

This event wouldn't be possible without our wonderful speakers: not just experts but especially **first time speakers are warmly encouraged to submit a proposal** for the conference.

If you are interested, you can find all the information on the official website https://www.pycon.it/en/call-for-proposals/

Please **hurry up** because the **deadline is January 6th**!
What Config Files Are & How They Work
Tags: programming, beginners, json, xml
Published: 2019-01-03 13:37:15

---
title: What Config Files Are & How They Work
published: true
description: Config files are the silent foundation of every project. But they can also be extremely dangerous if you don't know what they are.
tags: programming, beginners, json, xml
cover_image: https://thepracticaldev.s3.amazonaws.com/i/tmybbh0fh7iki7hgmgg4.jpeg
---

Those .config files can be magic box. You know that it needs to be there and that your project won't work if it's missing or damaged. One of the scariest things for a newbie and sometimes even experienced developers is messing with the .config files.

For starters, it would help to know exactly a .config file is. Like you can probably guess, config is short for configuration. These files hold any initial settings or parameters that your project is going to need to get started. An example of a setting in a web.config file could be how you handle the routing within your project. You might do that by using a rewrite line.

What makes .config files put developers on edge is the fact that one mess up in the config file can cause a project to come tumbling down. Not like you can't go back and undo your changes, but it could happen at one of those critical moments when you can't think of what you did.

You always want to know what you're doing when it comes to your code, although in the case of config files you need to know what you're doing. Right now there isn't a super strict way of writing config files. You could have some written with JSON, XML, YAML, or a combination. It just depends on how your project is setup.

Another thing you have to know about config files is that some programs only load config files when they start and others check the config files periodically. Knowing how the config files will be used will help you figure out how to work with them better and help optimize your project.

Having the right settings and parameters at the start of your project is the only way it's going to run successfully. So make sure you know what you're doing before you go changing things in your config files. They will literally make or break a project.

Have any of you guys done advanced work with config files? I've started digging around in them and they're weird right now.

<hr>

Hey! You should follow me on Twitter because reasons: https://twitter.com/FlippedCoding
Gatsby and WordPress: Creating an index page
Tags: wordpress, gatsby
Published: 2019-01-03 09:06:34

---
title: Gatsby and WordPress: Creating an index page
published: true
tags: wordpress, gatsby
canonical_url: https://booyaa.wtf/2019/gatsby-wordpress-index-page
cover_image: https://thepracticaldev.s3.amazonaws.com/i/5lxrq1yrytz87k7lg8t0.png
series: Gatsby x WordPress
---
_Photo by Billy Huynh on [Unsplash](https://unsplash.com/photos/saS98jKhVjA)_

## Order order! Let’s create an index to list our posts

Let’s visit http://localhost::8000/___graphql to fire up the builtin GraphQL explorer and paste the following query.

```graphql
{
  allWordpressPost(sort: {fields: [date], order:DESC} ) {
    totalCount
    edges {
      node {
        title
        excerpt
        slug
        date(formatString: "Do MMMM")
      }
    }
  }
}
```

Things to note here how to sort the collection of posts. If you’re wondering what fields are available,  the explorer provides documentation for any plugins you have loaded so in the case of WordPress Post we can explore this clicking on the hover dialogue for `allWordpressPost`.

Let’s update our index page (`src/pages/index.js`) to list our WordPress posts.

First, we import `graphql` and we can remove our import of `Image` component.

```jsx
import { Link, graphql } from 'gatsby'
```

Then we update IndexPage definition,  we use the `map` function transform each array item into an HTML fragment containing information about each post.

```jsx
const IndexPage = ({data}) => (
  <Layout>
    <SEO title="Home" keywords={[`gatsby`, `application`, `react`]} />
    <h1>Welcome to the Gatsby demo</h1>
    <h3>There are {data.allWordpressPost.totalCount} posts</h3>

    {data.allWordpressPost.edges.map(({ node }) => (
      <div key={node.id}>
        <Link to={node.slug}>
          <h4><span dangerouslySetInnerHTML={{ __html: node.title }}/> - {node.date}</h4>
        </Link>
        <div dangerouslySetInnerHTML={{ __html: node.excerpt }} />
      </div>
    ))}

  </Layout>
)
```

Finally, we add our pageQuery that we tested in our GraphQL explorer at the start of the post.

```jsx
export const pageQuery = graphql`
  query {
    allWordpressPost(sort: { fields: [date], order: DESC }) {
      totalCount
      edges {
        node {
          id
          title
          excerpt
          slug
          date(formatString: "Do MMMM")
        }
      }
    }
  }
`
```

## Checkpoint: Index page rebooted

If we visit `http://localhost:8000` we should see a different page to what we started at the beginning of this blog post series

![Index](https://booyaa.wtf/img/gxw-index.png)

If you got stuck, you can check out the following Git hash: [`2249ea842a18e4da39c6e3abcf8eeabd78a17116`](https://github.com/booyaa/wordsby/commit/2249ea842a18e4da39c6e3abcf8eeabd78a17116)

_To go to the next part of the series, click on the grey dot below which is next to the current marker (the black dot)._
difference between isNaN and Number.isNaN
Tags: javascript
Published: 2019-01-03 13:23:59

---
title: difference between isNaN and Number.isNaN
published: true
description: I am really confused between these two JavaScript methods. As far as my understanding, Number.isNaN returns true only if the value is both NaN and a number. How can a value be NaN and not a number at a single point ?
tags: javascript
---
Cleaner Clojure Functions with the :pre Special Form
Tags: programming, clojure
Published: 2019-12-01 17:04:37

---
title: Cleaner Clojure Functions with the :pre Special Form
published: true
tags: programming,clojure
canonical_url: https://kevgathuku.wordpress.com/2019/01/03/cleaner-code-with-clojures-pre-special-form/
---

In the course of programming, it's fairly common to face a scenario where you want to ensure that a function's arguments fulfil some condition(s), and if not, to throw an error. In this post, we're going to see how Clojure provides a handy special form that greatly simplifies this task.

One such scenario that I've come across recently is trying to come up with a function that would compute the 3x + 1 problem (Collatz conjecture). The problem is as follows:

> Take any positive integer n.

> If n is even, divide n by 2 to get n / 2.

> If n is odd, multiply n by 3 and add 1 to get 3n + 1.

> Repeat the process indefinitely.

The conjecture states that no matter which number you start with, you will always reach 1 eventually.


The task at hand was to write a function that takes a number as an argument and returns the number of steps it takes for the number to eventually be 1.

You'll also notice that the first condition for the number to be passed in is that it has to be a positive integer. Therefore, given any value less than 1, the function should throw an error.

A typical solution in Clojure would look as follows:

{% gist https://gist.github.com/kevgathuku/c9398fef53074f6cb70f7ea4b1a1bad8 %}

While this definitely works, I found out that Clojure provides a much more elegant way to accomplish this, with the help of the [`:pre` special form](https://clojure.org/reference/special_forms#_fn_name_param_condition_map_expr_2)

This form enables specifying conditions about the arguments that should be met before the rest of the function body is evaluated. If any of the conditions is not met, an assertion error is thrown.

This is how we could rewrite the function making use of the `:pre` condition:

{% gist https://gist.github.com/kevgathuku/5cc24d170e8ba1c37adf800439dbc812 %}


In this case, if the function is called with 0 or a negative number, an assertion error is automatically thrown.

I think you would agree that the second version looks much nicer 🙂
How to automate Slack invitations?
Tags: slack, googlesheets
Published: 2019-01-03 10:09:49

---
title: How to automate Slack invitations?
published: true
description: How to connect email, Google Sheets and Slack?
tags: slack, google-sheets
---

Hi community, 

Anyone knows how to automatically send invitations to a Slack work space based on a growing list of emails in a Google Sheet?
Auditing Open Ports in AWS EC2 Security Groups Using AWS Console 
Tags: aws, howto, devsecops, security
Published: 2019-01-03 09:36:17

---
title: Auditing Open Ports in AWS EC2 Security Groups Using AWS Console 
published: true
description: Even as we think of regular security audits, sweat droplets just pours out of the forehead. AWS EC2 Security Groups open to 0.0.0.0/0 are known nightmares. This Dev lost his youth to auditing these open ports. Our sympathies with him.
tags: AWS, howto, devsecops, Security 
---
<img class="wp-image-1114" src="https://thepracticaldev.s3.amazonaws.com/i/4z5s3hfja4s84r9uac7r.jpg" alt="Auditing Open Ports in AWS EC2 Security Groups Using AWS Console" width="610" height="470" />

<span style="color: #000000;">Even as we think of regular security audits, sweat droplets just pours out of the forehead. AWS EC2 Security Groups open to 0.0.0.0/0 are known nightmares.</span>
<blockquote>
<h2><span style="color: #000000;">If there are hundreds of instances running on your AWS cloud, auditing for open ports '0.0.0.0/0 allow` rule on AWS EC2 Security Groups using AWS console is an arduous task.</span></h2>
</blockquote>
<span style="color: #000000;">This Dev lost his youth to auditing these open ports. Our sympathies with him. Well, he wasn’t aware of a visual tool like TotalCloud where he could spot these ports at a glance!!</span>

<a href="https://totalcloud.io/user-signup.html" target="_blank" rel="noopener">Sign-up for TotalCloud and try this new flagship feature.</a> <span style="color: #000000;">Want to know more before signing up?</span> <a href="https://totalcloud.io/securityview.html" target="_blank" rel="noopener">Visit here.</a>

<span style="color: #000000;">Also share how you perform security audits on AWS?</span>

<blockquote>
<h2><span style="color: #000000;"> Originally published at <a href="https://blog.totalcloud.io/auditing-open-ports-aws-ec2-security-groups-using-aws-console/" target="_blank" rel="noopener"> blog.totalcloud.io </a> on November 23, 2018.
</span></h2>
</blockquote>
Are you learning a new language in 2019? Share your story.
Tags: discuss, programming, career
Published: 2019-01-03 09:25:15

---
title: Are you learning a new language in 2019? Share your story.
published: true
description: Share your next programming language journey.
tags: discuss, programming, career
---

My next is Go. I've been having more "maker" than "manager" time recently, so getting back into prototyping potential new [Semaphore](https://semaphoreci.com) features.

Ruby has been my go-to language for years, but when the use case is system software, it's hard to beat a tiny, self-contained, portable binary. Or a 10MB Docker image.

What about you?
Save Your Changes
Tags: git
Published: 2019-01-03 07:40:38

---
title: Save Your Changes
published: true
description: Commit everything to the database. 
tags: git
---

Git likes change, it wants to keep your changes safe. When changing branches git will keep your working tree changes during the switch, but  if it needs to modify one of those files it will not switch branches. 

Git wants to keep your changes safe so it emphasizes that you commit, stash (you can do that too). It gives tools to make your Commits clear. Interactive rebase is your best friend.

Because git knows the file tree well, you never need to clone a clean folder. There is almost always a command to cleanup a mess you made. When in doubt, commit and switch branch. It fact git is so good at this if you add a completely unrelated repo as a remote you can work out of a single folder. Not recommended.

Do not use guis, they just pop-up dialogs when they will destroy changes without warning. In the command line you run the safe operation then rerun with --force when verified the destruction was desired.
Three Ways To Take On Imposter Syndrome
Tags: learning, personalgrowth, entrepreneurship, advice
Published: 2019-01-03 07:22:14

---
title: Three Ways To Take On Imposter Syndrome
published: true
description: How to use reflection to keep Imposter Syndrome at bay.
tags: learning, personal growth, entrepreneurship, advice
---

![Three Ways To Take On Imposter Syndrome](https://thepracticaldev.s3.amazonaws.com/i/60ndvres21t374xdc9zw.jpg "Three Ways To Take On Imposter Syndrome")

I've noticed how Imposter Syndrome started to become the next big thing on the web. A lot of people seem to struggle with this confidence related issue somehow. 

IMHO, the term Imposter Syndrome has become this umbrella term that is being used for anything wildly related to the actual syndrome. Which is fine actually, since I really think you can take on most of these issues by reflecting on your own experiences and achievements.

I started to contemplate how I went through life, and how I never seemed to be really suffering from Imposter Syndrome (for long). I somehow managed to always keep optimistic and think about the things in my character and in what I managed to accomplish to build just enough confidence to keep going strong.

To help other entrepreneurs, developers, and creators, I wrote this article that provides three ways to use reflection to take on Imposter Syndrome and keep any confidence issues at bay:

https://www.shipharder.com/imposter-syndrome-three-ways-to-take-it-on/

#shipharder #sharingiscaring #feedbackiswelcome #learn #selfimprovement