teleren/devto huggingface dataset:
Sinatra CRUD MVC Project
Tags: ruby, sql, mvc, crud
Published: 2020-10-29 20:34:10

29 October 2020


At the start of the week, it seemed as if ideas were flying all over the place. Of course, with that, questions and curiosities followed suit. I was overwhelmed with the possibilities when I realized I was given freedom to do my project on anything. It was like last time, but somehow much different. Maybe because I did not have to rely on an API for data and therefore, structure.  So, the ideas continued but sort of failed to become a reality. Also, what failed was my realization that simplicity is a virtue, not that patience stuff they are always talking about. I thought to myself, I need to be simple and succinct and not fall to the idea that more is more.

How often do us westernized folks participate in this notion? We love “more”. We  love gluttony. We love extravagance. So, we usually take something simple and make it a monster out of fear that we did not do enough. I realized this when I started to plan out an application that produced a color swatch based off a nail color input. So, that one may match their outfits to their nails and vice versa (Patent pending... just kidding.)(But seriously, do not take my idea!).  I took a few steps back… because simply I was out of my league. I do not know how to do that at all! After the denial limped away and reality hit, I broke down my idea into its simplest form: let me just catalog nail polish colors. From my experience, and from similar stories of others , I can never remember what color I got and often make it my life’s quest to find it until I eventually find a new color I really adore. I was content with my idea and (sort of) content with doing “less.”

I started my project and I was surprised at how easy it felt to code. I feel as if I did not struggle as much as last month’s project. The idea of my personal progression in code still feels really new to me, but I am hoping that blossoms into confidence, an area I really need to work on. I also really love project weeks as it holds the moments where the imposter syndrome idles and instead comfort lives freely.
Chaos Engineering your onboarding experience
Tags: devops, opinion, productivity, programming
Published: 2020-10-29 20:28:33

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

# Introduction

Today I did something very stupid: I nuked my database. After I finished my foul-mouthed tirade (sorry mum), I started to pick up the pieces of my broken dev environment. It was at this point that I started thinking of chaos engineering.

For those not in the know: chaos engineering is a practice where you purposely kill or maim parts of your system (e.g. services, databases) in order to evaluate how fault tolerant your system is. By making system failures a part of daily life, you are forced to adapt and make your systems more resilient.

# What does this have to do with me knackering up my database?

By nuking my own database, I had inadvertently began a chaos engineering experiment on the developer onboarding experience for my current project. How long it would take to recover from this would be indicative of how good the onboarding experience was.

I was applying the principles of chaos engineering, usually reserved for computer systems, to a "real world" process. Luckily I was back on my feet in under 5 minutes, which in my opinion is a win.

# What did I learn from this experiment?

Firstly, I need to double check **EVERYTHING** that I execute in SQL Server Management Studio. This entire thing could have been avoided if I'd have simply not been so trigger happy with a `DROP DATABASE` command.

Perhaps the biggest lesson however was that the onboarding experience for a project can have a great impact on productivity. We often judge the quality of a code base on factors such as code coverage, or adherence to coding standards, but perhaps we should start including the onboarding experience in that. 

I've worked on systems that were fantastic on paper: very high code coverage, adherence to SOLID principles, trendy front-end technologies - but they sometimes took over a week to get up and running!

I won't go as far as automatically nuking my database at random intervals, but this whole experience taught me the importance of a good onboarding experience.
Using Dev.to as a CMS with Next.js
Tags: react, nextjs, cms, devto
Published: 2020-10-29 20:25:59

---
slug: dev-to-cms-with-next
canonical_url: https://cvr.im/blog/using-dev-to-as-a-cms-with-next-js
---

> Thanks to @swyx for the idea and most of the logic. Check [his post](https://www.swyx.io/devto-cms/) out.

Dev.to is a great place to share and learn from others. 

It can get pretty tedious if you're busy posting blogs in two places. Luckily, Dev.to provides an [API](https://docs.forem.com/api/#tag/articles) that allows you to get all your posted content for free!

> If you want a full implementation, check out [my website code](https://github.com/cevr/me)

Here's the code I used to get it working. It has some minor changes from Swyx's code.

```ts
// postsApi.tsx

let normalizePost = (post: Post): Post => {
  const { data, content } = matter(post.body_markdown);
  return {
    ...post,
    // remove the last bit (its a 4 digit identifier, not needed here)
    slug: post.slug.split("-").slice(0, -1).join("-"),
    matter: { data, content },
  };
};

let sleep = async (ms: number = 0) => new Promise(resolve => setTimeout(resolve,ms))

export let query = async () => {
  // next does parallel builds
  // dev.to doesnt allow more than 2 requests per second (as far as I can tell
  // we gotta slow it down
  await sleep(1000)
  // we cache the response
  // otherwise we'll hit the 429 error "Too many requests" during build times
  let cached = cache.get<Post[]>();
  if (cached) return cached;

  let posts: Post[] = [];
  let page = 0;
  let per_page = 30; // can go up to 1000
  let latestResult = [];

  do {
    page += 1; // bump page up by 1 every loop
    latestResult = await fetch(
      `https://dev.to/api/articles/me/published?page=${page}&per_page=${per_page}`,
      {
        headers: {
          "api-key": process.env.dev_token as string,
        },
      }
    )
      .then((res) =>
        res.status !== 200 ? Promise.reject(res.statusText) : res.json()
      )
      .then((x) => (posts = posts.concat(x)))
      .catch((err) => {
        throw new Error(`error fetching page ${page}, ${err}`);
      });
  } while (latestResult.length === per_page);
  posts = posts.map(normalizePost);
  cache.set(posts);
  return posts;
};
```

Here you can see it's a simple loop aggregating all of our posts. 

I've added a cache because, on my website, Dev.to would return a `429` status code because the requests were happening too fast. 

This is fine since there's almost no chance our posts will become stale while we are building.

After that I call `query` to get a list of my posts:

```ts
// pages/blog.tsx

export async function getStaticProps() {
  let posts = await postsApi.query();
  return {
    props: {
      posts,
    },
    revalidate: 1,
  };
}
```

Tada! It was much smoother than I expected. Thanks a lot dev.to!
My hacktoberfest journey!!
Tags: hacktoberfest, opensource
Published: 2020-10-29 20:14:59

Due to COVID-19 pandemic i got to spend more time at home obviously because of the virtual classes. During this time i came across the word open-source contribution. Being a curious person i wanted to know more about it and how to begin with it. Read plenty of blogposts, YouTube videos and what not. 

All of the above pointed to one direction i.e. "to begin with the open source contribution best is to start with hacktoberfest held in the month of October every year." Waited for the month of October to arrive and until then brushed up my version control skills i.e. git. 

So on September 30th i came to know that the contest had started and one can start contributing and that will count towards the 4 PRs which needed to be submitted. 

Luckily i was working on a project on github and modified it a bit to add some features that i wanted for my project. Then i thought why not make this idea a PR for that repo and make this count in the fest. So did the changes and created my first pull request. Same day the reply came from the maintainer that he liked the idea and suggested few changes. I made the changes and he asked for some more changes. So this kept on going for like 2 weeks but was finally able to merge this on 14th of that month.

That repo had high number of forks and stars so it was ok the maintainer to be choosey about the details, test condition, environment settings, formatting, etc.

But when this PR was merged it was really like a milestone for me because it was my first PR.

Did my rest of the PRs in between and finally completed it till 30th October (including the maturation time for the PR).

It was my first online contestand that too an open-source one. Really pleased with the experience I received and am looking forward to participate in more events like this one.

P.S. : sorry for the long read but i like writing blogs, do follow me on LinkedIn :  https://www.linkedin.com/in/parikshit-singh-rathore-1a0964194

Cheers!!
New Improvements & Product Hunt Launch
Published: 2020-10-29 20:11:41

Upvote us on Product Hunt! https://www.producthunt.com/posts/airsend-3

We've been working hard on AirSend over the past few months, and we wanted to share some of AirSend's biggest improvements and best functionalities.

You can now take advantage of:

Unlimited free voice/video calls and screensharing - Call your team members and clients directly in AirSend Channels.

Public Channels for customer support - Startups, SMBs, professionals, or anyone else can easily make a public chatroom to gather feedback and answer questions on their products or services.

Built-in Wiki to keep notes - Each Channel has a built-in Wiki with full Markdown and Latex support to create perfectly formatted notes.

Built-in file storage (free up to 100GB) - Store and organize your files directly within Channels with unlimited automatic versioning.

Desktop apps for Windows, Mac and Linux - Enough said here. :)

G-Suite and Office 365 integration - Easily send emails from Gmail to AirSend with our free G-suite add-on, and collaborate on documents with AirSend’s Office 365 Integration.

And that’s what we’ve been working on over the past 6 months. Thank you again for your continued support!

In other news, we've launched on Product Hunt! Please head over to Product Hunt and upvote us so that more people can find and enjoy AirSend!

https://www.producthunt.com/posts/airsend-3
Credential Stuffing vs Password Spraying
Tags: security
Published: 2020-10-29 17:53:39

At my [employer](https://www.iteratec.com) we use Office 365. I'm not an Microsoft advocate. My friends and colleagues rather know me as Apple-Fanboy and BSD-Geek. But I have to admit that Office 365 works good enough. Even in these pandemic times when we work from home Teams and such serves very well.

As part of our security team we also encounter attacks against our user accounts. Maybe you read about that in the press: There are _credential stuffing_ and _password spray_ attacks going on this year against Office 365 accounts. Today I wondered what the concrete difference is between these two types of attacks. Until today I used the terms interchangeably: Its all a kind of brute force, right? No, it's not that easy.

## Credential Stuffing

This is an attack where an adversary uses a **known pair of username and password** to gain access. Eg. there is a password leak from the site foobar.com: They stored username and password in plain text. Lot of users use the same username password across many sites. So one could try to use the username and password from foobar.com at Facebook, Twitter or whatever to gain access.

So _credential stuffing_ uses a list of known username password combinations to brute-force against an authentication.

## Password Spraying

In contrast this is an attack where the adversary **only knows the username** and tries a list of [common or weak passwords](](https://en.wikipedia.org/wiki/List_of_the_most_common_passwords)) with it. Eg. you know that the usernames at foobar.com are same as the email addresses and you can harvest some of them from the website. Then you use a list of commonly used or weak password (eg. `test1234`, `password` etc.) together wit the usernames to gain access.

So _password spraying_ uses a list of known usernames in combination with commonly known and/or weak passwords to brute-force authentication.

First posted at <https://blog.weltraumschaf.de/blog/Credential-Stuffing-vs-Password-Spraying/>
Block IPs on all ports with fail2ban on a docker host
Tags: fail2ban, docker, security, howto
Published: 2020-10-29 19:41:33

Playing around with fail2ban on a local docker host I found that when blocking a host, all docker containers with open ports where still accessible.

I tried several different ways of getting the IP block to really block everything.

This is some notes from the steps I took to solve the problem.


- Update your package lists

```
apt update
```

- Install fail2ban

```
apt install fail2ban
```

- We do not edit the default jail.conf since it can be overwritten by updates. So we create a new config for fail2ban.

```
vim /etc/fail2ban/jail.local
```

For this simple demonstration we are going to block all failed attempt over SSH. And we want to block the remote IP for 600s, for all services and ports. 

```
[sshd]
ignoreip = 127.0.0.1
enabled = true
port = 22
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
bantime  = 600
findtime = 600
action = iptables-allports[actname=sshd,name=sshd,protocol=all]
         iptables-allports[actname=sshd-docker,name=sshd-docker,protocol=all,chain=DOCKER]

```

The trick was to setup two actions. One for the normal chain/traffic and one for dockers CHAIN.

Doing this block sessions not only to the host but also all containers.
Done Hacktoberfest
Tags: hacktoberfest
Published: 2020-10-29 19:39:13

### About me

I have been part of this community for about a year but this is my first time participating in Hacktoberfest. So I am super thrilled to have completed it. 

I am what you call a loner. I do projects on my own and software development is not my main job. But I love building things. When this challenge came about last year, I was hesitant to participate and did not know how I would start.  

### Growth Mindset

This time my mindset was let's just do it. At this point, I have completed 4 PRs. I really enjoyed working on codebase that belongs to other people and it has been great to see some many contributing to one project. I enjoyed the whole process from start to finish. Learned a thing or two about Git as well 

### Contributions

I was looking for a React project with TypeScript. In particular I was looking for a project where I could contribute by writing automated unit tests. So I came across a great project to be able to do that.   


### Reflections
I will definitely continue contributing to the project I chose beyond Hacktoberfest. It is great for me to continue to develop the skill of understanding other people's code and collaborate on one codebase with multiple people. It is good for growth.
Multiuser on the Canvas
Tags: multiuser, socket, zimjs
Published: 2020-10-29 19:33:49

ZIM Socket handles multiuser without any server code!  Here are examples https://zimjs.com/socket.  And here is an app we just made in a morning at https://codepen.io/danzen/pen/jOrzNyp.  You can see the code and fork the app on codepen.

Here is the code for a shared ball!  Who doesn't like to share their balls!  Okay - strike that statement.

```javascript
// load in these urls
// https://zimjs.org/cdn/2.3.0/socket.io.js
// https://zimjs.org/cdn/zimserver_urls.js
// https://zimjs.org/cdn/zimsocket_1.1.js

// Make a single Ball that multiple people can drag around
// In the ZIM Frame here is the preparation and the code

const socket = new Socket(zimSocketURL, "sharedball");

// For the first parameter:
// The zimSocketURL comes from zimserver_urls.js 
// and points to the ZIM Socket server.
// This way, if we change the server, the app will still work.

// For the second parameter:
// Went to this URL https://zimjs.com/request.html 
// from the ZIM Socket page
// and requested a keyword "sharedball" for this app
// do not use a keyword that is already in use

// When the socket is ready we get this event
// It receives a data event of all the current data
// or just ask socket.
// There is also a history of any data stored in history
// like for a chat.

socket.on("ready", ()=>{
   const ball = new Circle(100, red).drag(stage);

   // We will get the lastest x and y of the ball
   // all latest values are automatically loaded by Socket
   let x = socket.getLatestValue("x");
   let y = socket.getLatestValue("y");

   // if someone has moved the ball then start at that position
   // otherwise, tell others to come where the ball is located
   if (x != null) {
      ball.loc(x,y);
   } else {
      ball.center();
      // we can set a single property like:
      // socket.setProperty("x", ball.x);
      // but each time we do it is a call to the server
      // so it is better to set multiple properties like so:
      socket.setProperties({x:ball.x, y:ball.y});
   }
   stage.update();

   // here is the event for when we receive data from others
   // so set the ball to the latest value
   // we can also grab this information from the data parameter
   socket.on("data", data=>{
      let x = socket.getLatestValue("x");
      let y = socket.getLatestValue("y");
      if (x != null) ball.loc(x,y);
      stage.update();
   });

   // send data when ball is moved
   ball.on("pressmove", ()=>{
      socket.setProperties({x:ball.x, y:ball.y});
   });

});

socket.on("error", ()=>{
   new Pane(600,300, "SORRY, COULD NOT CONNECT").show();
});
```

---

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).
Completed Hacktoberfest 2020!!
Tags: hacktoberfest
Published: 2020-10-29 19:30:56

<!-- ✨This template is only meant to get your ideas going, so please feel free to write your own title, structure, and words! ✨ -->


### Hi I'm Eqra and I Flutter!
<!-- If you are new to the DEV community, introduce yourself and share a bit about why you joined DEV and decided to participate in Hacktoberfest this year.  --> 
I'm a Developer Student Club lead at my campus. I am a Flutter developer. My GitHub profile: https://github.com/eqrakhattak
I decided to join DEV when I saw it was in collaboration with DigitalOcean and GitHub to bring Hacktoberfest to our door. Incentives of swags and learning a new thing gave me a push to participate in hacktoberfest 2020.

### Background

<!-- Are you brand new to open source? What about coding in general? Tell us about how you got here -->
A friend recommended me to take part in Hactoberfest and so i decided to give it a try. I'm new to open source and I very much intend to keep on doing it.

### Progress

<!-- Share a bit about where you’re at in your Hacktoberfest journey. What stage are you at? How has the process been?  -->
I completed 4 pull requests this year in Haktoberfest2020. The process is awesome. I recently got reviewed and completed my hacktoberfest journey.

### Contributions

<!-- This is where you can list the contributions you made and explain why you chose the projects you did. Don’t forget to add links!  -->
Here are the repos where I made my contributions:
https://github.com/m-hamzashakeel/Hacktoberfest-Flutter
https://github.com/AbhishekMaira10/Hacktoberfest2020
https://github.com/sd2001/HacktoberFest2020
https://github.com/tarunsinghofficial/HacktoberFest
As per my experience, I contributed in some of the basic repos.

### Reflections
<!-- Overall, how has your Hacktoberfest 2020 experience been? If you’re a first-timer, will you participate again? What have you learned? Have you made any interesting connections? What is your next step in open source?  -->
This was my first participation in Hacktoberfest. GitHub was something i always wanted to learn and know more about.. This festival gave me a chance to discover my hidden talents and bring forth a gitHub collaborator within. I loved to collaborate in the other people's repos.. Even though I was so excited I did some PRs that did not even had the "hacktoberfest" tag on it. It was an awesome experience and I look forward to Learning a great deal and make GitHub a habit. The Tee or Tree initiative gave a push to all this and i'm very thankful to DigitalOcean for bringing me this amazing opportunity. Can't wait to showcase the tee!
Linux Commands: env
Tags: linux, beginners, codenewbie
Published: 2020-10-29 19:27:02

`env` can be used to print the environment variables or pass environment variables to a utility/command without setting them in the current shell session. 

Let's run `env` without any argument and see what happens.

![Screenshot 2020-10-30 at 12.06.36 AM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1603996605316/4qP3UTvs9.png)

It simply prints all the environment variables in the current session. You can also run `env` with various options.

* -i: Runs a command with only specified environment variables and clears all the environment variables already set.
* -u: Runs a command by removing the specified environment variables while keeping the other values intact.
* -v: Prints the verbose output for each step of processing done by the env utility.

Let's try to print the environment variables inside a python script by passing it via the `env`. You can choose to run in any language of your choice.

```python
import os

print(os.getenv('BLOG'))
print(os.getenv('PATH'))
```
We will use `env -i /usr/local/bin/python3 main.py` to run our python script. You can't use the simple python command to run the code as the `PATH` value which specifies the binary path for executable will also be reset. The output should be as below.

```text
$ env -i /usr/local/bin/python3 main.py
None
None
```

As you can see in the above output that all the values are set to `None` because we have used the option `-i`. Even the system PATH variable is set to `None`.

Now let's run this `env -i BLOG=hashnode /usr/local/bin/python3 main.py` in the terminal.
```text
$ env -i BLOG=hashnode /usr/local/bin/python3 main.py
hashnode
None
```
In the above output, you can see that we have set the `BLOG=hashnode` and it gets printed in the output.

You can also use `-u` to unset certain environment variables.

```python
import os

print(os.getenv('HOME'))
print(os.getenv('SHELL'))
```
We will use this `env -u HOME /usr/local/bin/python3 main.py ` command to run the above code. Its output looks like this. You can see that `HOME` doesn't get printed while the `SHELL` value does.

```text
$ env -u HOME /usr/local/bin/python3 main.py
None
/bin/zsh
```

To print more verbose output of the `env` command and it's step. You can pass `-i` as an option.

```text
$ env -v -u HOME /usr/local/bin/python3 main.py
#env unset:     HOME
#env executing: /usr/local/bin/python3
#env    arg[0]= '/usr/local/bin/python3'
#env    arg[1]= 'main.py'
None
/bin/zsh
```

### Conclusion
You can use `env` in various scenarios like while debugging local code as well as some production issues to see the effect of each and every environment variable on your code or service.

> If you liked this post please share it with others so that it can help them as well. You can tag me on Twitter [@imumesh18](https://twitter.com/imuesh18). Also please follow me here and on Twitter for future blogs which I write over [here](https://blog.umesh.wtf)