teleren/devto huggingface dataset:
Making simple HTTP requests in NodeJS
Tags: node, xhr, http, https
Published: 2021-08-08 10:42:00

Of course, there are numerous [npm](https:///npmjs.org) packages available to make HTTP requests. Just to name a few, you can use 
 - [Axios](https://npmjs.org/package/axios)
 - [Request](https://npmjs.org/package/request)
 - [SuperAgent](https://npmjs.org/package/superagent)
 - [Got](https://npmjs.org/package/got)

many more. These all are super fantastic libraries which bring in array of capabilities on how to make HTTP request and handle various responses and errors. 

But sometimes, all we need is, a simple HTTP/S request and response handler. This can be easily done with NodeJS's built-in packages [http](https://nodejs.org/api/http.html) / [https](https://nodejs.org/api/https.html) with a very simple lean piece of code. Lets see it in action.

NOTE: Since `Promise` is fancy, so I am gonna use it for this.

```javascript
// SimpleHttp.js

const { URL } = require('url'),
    http = require('http'),
    https = require('https');

/**
 * Simple function to make HTTP / HTTPS request.
 *
 * @param {String} url The url to be scraped
 * @param {Object} config The configuration object to make HTTP request
 *
 * @return {Promise}
 */
module.exports = function fetch (url, config = {}) {
    const u = new URL(url),
        secure = 'https:' === u.protocol,
        handler = secure ? https : http,
        options = {
            method: config.method || 'GET',
            host: u.hostname,
            port: u.port || (secure ? 443 : 80),
            path: u.pathname,
            query: config.query || {},
        },
        isHeadRequest = 'HEAD' === options.method;

    return new Promise((resolve, reject) => {
        const request = handler.request(options, function (response) {
            const status = parseInt(response.statusCode, 10);

            if ([301, 302, 307].includes(status)) {
                resolve(load(response.headers.location, options));
            } else if (status < 200 || response >= 400) {
                reject(new Error(`Unexpected response, got HTTP ${status}`));
            } else {
                if (isHeadRequest) {
                    resolve({ headers: response.headersn} );
                } else {
                    const chunks = [];
                    response.on('data', function onData (chunk) {  
                        chunks.push(chunk);
                    });
                    response.on('end', function onEnd () { 
                        resolve({
                            status,
                            body: Buffer.concat(chunks).toString('utf8')
                        });
                    });
                }
            }
        });

        if (options.postBody) {
            request.write(postBody);
        }

        request.on('error', reject);

        request.end();
    });
}
```

And that will be all.

EDIT: Added support to follow if server responds with _HTTP redirect_.
reduce() - Remove duplicate items in an array
Tags: codesandbox, javascript, beginners
Published: 2021-08-08 10:41:35

Time to play with `reduce()` 🥳 
I will try some functions with `reduce()` to deepen my understanding about `reduce()`

[Array.prototype.reduce() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)

## Remove duplicate items in an array

![Image 2021-08-08 at 7.37.08 PM](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2fy4oo9srv7qo84s8jr.jpg)

## Play it by yourself

{% codesandbox fz36r %}
Some useful points when caching with Redis in a Laravel app
Tags: redis, laravel
Published: 2021-08-08 09:57:12

Generic redis db use is done in keyspace (db) 0 and the caching is done in keyspace (db) 1. 

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3hre3qzcx8hj0xdza8te.png)

Once in the redis-cli to select a specific keyspace (db) use the `select` command e.g. `select 1`.

Use the `KEYS *` command to show all of the keys in that key space (db). 

Then to view the value associated to a key in that keyspace type the following: `MGET enterkeyhere`

Redis-cli command to monitor all requests to the redis server is: `MONITOR`.

Redis-cli command to clear out a redis keyspace/db is: `FLUSHALL`.

Note that the network tab will not tell you that a response has been taken from a redis cache. E.g. the first is with a redis cache and the second is after a `FLUSHALL`. 
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kgu8jfea800fotn5zi37.png)
 
Note that if a browser is using its own caching it is shown in the size column of the network tab (disk or memory cache):
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dh5f6gysqxy97gaet380.png)
All Advance twitter search features 
Tags: twitter
Published: 2021-08-08 09:43:03

Let's make it **Quick** and **To the Point**

1. from: user_name
============
→ will get all tweets of that user.
![from](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/klxmyt59ezzwqyzq4bwm.jpg)

2. from:user_name since:starting_date until:ending_date
============
→ will get all tweets of that user in between these time frame.
![from-since](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c12d7jqvx6sgsp3uhnke.jpg)

3. from:user_name "keyword"
============
→ you will get that keyword's related tweet from the user.
→ you can also use AND , OR operator with keywords
![word](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/31cgd2uh7v609dfalkov.jpg)

4. finds only popular tweets
===============
 → min_faves:500 (minimum 500 likes on tweet)
 → min_replies:500 (minimum 500 retweet on tweet)
 → min_retweet:500 (minimum 500 retweet on tweet)
![likes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jy0xj37kqy9g9sw347ak.jpg)
![replies](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4za39eexigav3hehu2dc.jpg)
![retweet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sq5ka1ygibkg0qq2tcp7.jpg)

5. exclude:replies
===============
→ adding this with from:user_name will give you user's only main tweets not replies tweet. Means only main contentGrimacing face
![exclude](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r87u89opu3f2hzdomrps.jpg)

6. combination
===========
and lastly you can play permutation and combination with all this features . here some examples -
![c1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lcovfdahyaus6tlp098i.jpg)
![c2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l0bjsp9h24d4ugfdmu4i.jpg)
![c3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4vl2tmis820a2d2k1e46.jpg)
![c4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rhvdi5ppikyz2bc7j3mn.jpg)

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

That's it for today **and connect with me on [twitter](https://twitter.com/Sahilsaif2002)**
A short story about the dark side of being a founder and how insecure I was with Job Titles
Tags: career, mentalhealth, startup, productivity
Published: 2021-08-08 09:38:01

---
title: A short story about the dark side of being a founder and how insecure I was with Job Titles
published: true
description: The risk of unknowingly tying your self worth to your job title and how a concept of Buddhist philosophy helped me seeing things differently.
tags: career, mentalhealth, startup, productivity
//cover_image: https://direct_url_to_image.jpg
---

I used to be obsessed with Job Titles. It was very hard to have an honest conversation with me about roles and responsibilities in the founding/management team. I simply had to have that C-Title. But I did not really know why 🤷‍♂️

This meant that I was blind to make good decisions on management responsibilities, because I always kept thinking about myself and not about the companies best interest. Looking back, that is one of the clearest signs of a dysfunctional management team. And it was my fault!

And it wasn’t until a year later, when I had drinks with someone that I realized why: My social life depended on it! He wasn’t meeting me because of “me”, he was meeting me because of my C-Title! For him it was networking, for me it was more than that!

And it dawned on me how much I had neglected my social life over the past years! And instead of having friends and family around me I took my sense of belonging and self worth from my job and title.

Feeling lost inside I needed to reorient my inner compass. What worked for me was diving into Philosophy, especially [Thich Nhat Hanh](https://en.wikipedia.org/wiki/Th%C3%ADch_Nh%E1%BA%A5t_H%E1%BA%A1nh)

What I learned from him is the concept of “interbeing” which in essence says it’s hard to draw the line between you and your environment as you are not constant but at all time changing, because of your breathing, metabolising, essentially consuming your surroundings.

And if it’s so hard to actually define what "you" are, because you are constantly changing (literally speaking!), then why worry about your ego and title? Instead, isn’t it better to think about the part you play in your environment?

Now instead of titles, I focus on one question: *How can I be helpful?*

I’m constantly looking for the role that I can contribute the most and try to set up things in way to achieve the best outcome, which might be by removing myself from the equations. And that's okay!

Which does not mean that sometimes these old feelings won’t come back. But at least this time it’s easier for me to recognize them and not get blindsided again.

And when those feelings come back, I try to take a break and reach out to people who care about my happiness more then about my job, to ground myself put things into perspective again.

Or hang out with dogs. They're always happy to see you as long as you give them attention (and snacks) 😉

If all of this sounds familiar and you’d love to talk some more. Comment, or for a more private discussion reach out to me on [Twitter](https://twitter.com/_vsaw). My DMs are open!
Implementing Wildcard Subdomain (Part 1)
Published: 2021-08-08 09:32:00

When building a multi-tenant application like slack, most times, there is always a requirement for all tenants to have their subdomain, e.g olumide.slack.com.

This article explains how to do that with zero cost on Netlify. Based on a Netlify [support](https://answers.netlify.com/t/wildcard-subdomains-redirects/469) response, this feature is accessible on the Netlify pro plan, which cost about $19/month/user as of the time of writing this article.

![Netlify Pricing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vxoej2efw3ozvorim8sy.png)

I will show you an alternative approach to doing that without using a Pro account. Thereby; saving you about $230 per annum.

1. Get a domain, and use **"let's encrypt"** for a wildcard SSL certificate.

2. Point your DNS to your [Netlify](https://docs.netlify.com/domains-https/netlify-dns/delegate-to-netlify/
) app. it might take a while to propagate. You should see a tag with **“Netlify DNS”** on that domain when done.
![DNS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7rjxb280bddmbojyld4s.png)

3. Create a new CNAME wildcard DNS record from the Netlify **“DNS Panel”** if none is created automatically after step 2.
![New-CNAME](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lid8nvu8ap7rb297vhdz.png)

4. From your netlify dashboard, go to domain management, and then select **“Add domain alias”** to manually add a new domain alias. 
![Alias](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3beaapk03ndv845s6vx4.png)

You should be able to access your new subdomain immediately it’s saved on Netlify.

> Watch out for Part2 if you are interested in learning how to create subdomains on the fly, without doing it manually.
How to make SolidJS application work from a subfolder
Tags: solidjs, javascript
Published: 2021-08-08 09:09:34

In this article, I'll show how to make [SolidJS](https://www.solidjs.com/) application work from a subdirectory - for example, deployed on GitHub pages.

# Code
First, let's generate code following [the documentation](https://www.solidjs.com/guide):

```sh
$ npx degit solidjs/templates/js solid-subfolder
npx: installed 1 in 0.785s
> cloned solidjs/templates#HEAD to solid-subfolder
```

# The problem
After installing with `npm install` & build with `npm run build`, your output will fail if you access it from a subdirectory. So, in my case, I try to access it on `http://localhost/github/solid-subfolder/dist/`, and I get:
![solid-subfolder-fail.png](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t23mzqgu7bv8fshis3pg.png)

As you can see, by default, `index.html` tries to load assets from the domain root - for example, it tries loading `http://localhost/assets/index.1b7ca044.js`.

# The fix
Vite controls the base imports on the HTML side. As it's shown in [the documentation](https://vitejs.dev/config/#base) the default value is `/`. We can change it in `vite.config.js`:
```js
 export default defineConfig({
   plugins: [solidPlugin()],
+  base: "./",
   build: {
     target: "esnext",
     polyfillDynamicImport: false,
```

With this change in place, the application works as expected:
![working-app.png](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z2epj8rko7fu0ubves2s.png)

# Links
Here you can find the [repo](https://github.com/marcin-wosinek/solid-subfolder) & the [working app](https://marcin-wosinek.github.io/solid-subfolder/dist)

# Summary
In this article, we have seen how to make the SolidJS app work when deployed to a subfolder.
5 useful CSS resources
Tags: frontend, css, resources
Published: 2021-08-08 08:59:54

---
title: 5 useful CSS resources
published: true
description: 5 useful CSS resources
tags: frontend, css, resources
cover_image: https://images.unsplash.com/photo-1589149098258-3e9102cd63d3?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1237&q=80
---

# Introduction
Hello there!
CSS is like magic and there are tons of resources out there. I want to share 5 of them that I find very useful when working with CSS and I hope you will also find value in them.

# 1:  [CSS Tricks](https://css-tricks.com/)
One of the best and well-known websites when it comes to CSS. Here you can find guides, tips and tricks and articles all around CSS. The articles are very well written and detailed.

# 2:  [CSS Minifier](https://cssminifier.com/)
The name says it all. A very simple but useful little website where you can copy your well-structured CSS code and get it minified. It also offers an API.

# 3:  [CSS Grid Cheatsheet](https://grid.malven.co/) 
CSS Grid is super useful when it comes to building layouts on a website. I'm a big fan of it and prefer it over complete frameworks like Bootstrap because you have full control and it's very easy to build a layout with it. And on this website you have a lot of examples of well-known layouts that you can copy to your clipboard in one click.

# 4:  [CSS Flexbox Cheatsheet](https://darekkay.com/flexbox-cheatsheet/) 
CSS Flexbox is like a CSS Grid a tool integrated into CSS to build layouts on a website. Often you will use only one of them (preference) but they are really good if you combine them. On this website, you have an overview of the most basic and important properties with a little image next to them to see what they are doing.

# 5 :  [CSS Gradient](https://cssgradient.io/) 
Gradients are very popular these days and on this website you can create it very easily with point&click and then copy the code to your clipboard.

# Conclusion
I hope you will find these resources as useful as I do and they will help you in your development process.

Stay connected to me and my content on [Twitter](https://twitter.com/danytulumidis).

I love to improve myself every single day even if it's just a tiny bit!

Stay safe and healthy guys!

And as always: develop yourself!
Flutter drawer sidebar menu
Tags: flutter, dart
Published: 2021-08-08 07:18:11

As far as navigations go in mobile applications, we have two main options:

- TabBar
- Drawer side menu

We already created a [Flutter tabbar](https://daily-dev-tips.com/posts/flutter-tabbar-the-basics/) in a previous article, and in this article, we'll look at how we can make a drawer.

By the end of this article, you'll have the following result.

![Flutter drawer sidebar menu](https://cdn.hashnode.com/res/hashnode/image/upload/v1628407046223/MHIMGr-2X.png)

If you want to follow along, I'm taking my [Flutter hello world app](https://github.com/rebelchris/flutter/tree/hello-world) as a starting point.

## Setting up a drawer side menu in Flutter

Let's start by changing the root entry point of our application. Before, we used to Scaffold the body in the primary function. However, we need to use the scaffold for the drawer.

```dart
void main() async {
  runApp(
    MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyApp(),
    ),
  );
}
```

As for the app, we can change this to return a drawer.

```dart
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Drawer menu')),
      body: const Center(
        child: Text('Click on the menu icon'),
      ),
      drawer: Drawer(
        child: ListView(
          padding: EdgeInsets.zero,
          children: [
            const DrawerHeader(
              decoration: BoxDecoration(
                color: Colors.blue,
              ),
              child: Text(
                'Drawer Header',
                style:
                    TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
              ),
            ),
            ListTile(
              title: const Text('Item 1'),
            ),
            ListTile(
              title: const Text('Item 2'),
            ),
          ],
        ),
      ),
    );
  }
}
```

If we render this, we get a basic drawer that we can open, and it will have two items in it.
Then we also add a drawer header item on top.

We can also click on the right-hand side of the menu to close the drawer; however, we also want to close it when clicking on a menu item.

We can do this by adding the onTap event to the list tiles.

```dart
ListTile(
  title: const Text('Item 2'),
  onTap: () {
    Navigator.pop(context);
  },
),
```

This tap will close the navigation drawer menu as it was pushed on top of the existing stack.

And with that, we have our basic drawer setup in Flutter.
You can find the complete code example on [GitHub](https://github.com/rebelchris/flutter/tree/drawer).

### Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on [Facebook](https://www.facebook.com/DailyDevTipsBlog) or [Twitter](https://twitter.com/DailyDevTips1)
Are you ready for collaboration ?
Published: 2021-08-08 07:16:23

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

Hi everyone,

I am working on implementation of Gossip protocol over HTTP. for both broadcast data in cluster and also failure detection.I am using Python (aioHTTP and asyncio ) to make the system asynchronous. if anyone interested , please collaborate , it will be great experience .

also I am open to any good project idea . if anyone has think of anything and need someone to collaborate , I am available. 

I think its all about sharpening your skills.
What not do when you get an idea for a project
Tags: webdev, tips
Published: 2021-08-08 07:09:22

---
title: What not do when you get an idea for a project
published: true
tags: webdev, tips
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/axvn2u6lwam0oueqfygs.jpg 
---

Great ideas come in the moments you least expect them. I am sure every developer has had one of those moment of enlightenment. The first few steps after getting the idea can be crucial for the success or at least seeing the project even progress.

![undraw_researching_22gp](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jxy80a1opn0gt7qq189j.png) 

The first thing that might come to mind after coming up with the next big idea is to research whether it has been done before and how well it has been done. You could be wasting your time if the idea you have envisioned has already been done the exact same way you had picture it. It is completely ok to still pursue your idea even it has been done before. At the end of the day what matters most is the execution.

When I come up with an idea the first thing I would do is look for a good available domain. This is before I even do anything else to vet weather it is a good idea to pursue. My top priority was always to get a good or clever `.com` domain. It had to be `.com` and it would have to make some sense when you read it. Mind you that this this was before we had all this TLDs we have today. Looking back now I realized how useless this way of thinking was. The visibility of your projects in the web goes beyond having a good domain name.

![question-mark-1495858_1280](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vf6s4pr4gb8amb73w091.jpg)
 
Over the years I must have accumulated dozens and dozens of domains. I never accomplished anything for most of these domains. They were lucky to even get a "coming soon" page. After some light research I would come to the conclusion that the project was not worth the time, weather there wasn't a real need or it had already been done even better than what I had envision it. I did manage to sell some of the domains for a profit but for most I just let the registration expire. There are a few domains which I really like and I will probably keep holding on to them. One day I will give them meaning.

I got to finish very few of the projects I have wanted to do. There are some projects you do for yourself and there are others you want be something more than just your hobby. It can be discouraging when those projects you had high hopes for just flop. They just don't attract the interest of the users you want.

Don't do what I did for years. Don't get useless domain names for your projects that are still ideas or are in their infancy. Nowadays your projects can live anywhere in the web and people don't need to remember their unique domain names. In terms of visibility all that matters is how you spread the word and drive attention to your project. A domain name can always come later.

Let me know if you can relate in anyway in the comments. My next post will probably be how one of my domains is finally getting a "coming soon" page after 8 years of ownership.