teleren/devto huggingface dataset:
using superheroes for refresh my mind about Golang structs
Tags: go, code, programming
Published: 2020-10-17 20:02:03

After have followed [an amazing course about golang](https://greatercommons.com/learn/golang) one years ago, I had need to refresh my mind about the [Struct](https://golang.org/ref/spec) in golang, and for do it I had used some superheroes:

### First Example:
```
package main

import "fmt"

type skill struct {
	Power string
}

type hero struct {
	Name  string
	Alias string
	skill
}

func main() {
	h1 := hero{
		Name:  "Bruce Wayne",
		Alias: "Batman",
		skill: skill{
			Power: "a lot of gadgets",
		},
	}
	h2 := hero{
		Name:  "Tony Stark",
		Alias: "Iron",
		skill: skill{
			Power: "hi-tech armor",
		},
	}

	fmt.Printf("the best skill of %s is %s \n", h1.Alias, h1.skill.Power)
	fmt.Printf("the best skill of %s is %s \n", h2.Alias, h2.skill.Power)

	s1 := skill{
		Power: "velocity",
	}

	h3 := hero{
		Name:  "Barry Allen",
		Alias: "Flash",
		skill: skill{
			Power: s1.Power,
		},
	}

	fmt.Printf("the best skill of %s is %s \n", h3.Alias, h3.skill.Power)
}
```

### Second Example
```
package main

import "fmt"

type skill struct {
	Power string
}

type hero struct {
	Name  string
	Alias string
}

type heroSkill struct {
	hero
	skill
}

func main() {
	hs1 := heroSkill{
		hero: hero{
			Name:  "Clark Kent / Kal-El",
			Alias: "Superman",
		},
		skill: skill{
			Power: "a lot of cool superpowers",
		},
	}

	hs2 := heroSkill{
		hero: hero{
			Name:  "Steve Rogers",
			Alias: "Capitan America",
		},
		skill: skill{
			Power: "strong",
		},
	}

	fmt.Printf("the best skill of %s is %s \n", hs1.hero.Alias, hs1.skill.Power)
	// check the different way to call the struct, in this second Print, there no need to call the sub struct.
	fmt.Printf("the best skill of %s is %s \n", hs2.Alias, hs2.Power)
}

```
Implement a free no-effort database for your next side-project.
Tags: database, javascript, node, graphql
Published: 2020-10-17 19:58:11

# Ever wanted to start a side-project where you needed a database?

Of course, everyone has. Most of the time, when we are trying out a new framework or language, one of the key things is data.

In this short example, you will notice how easy it is to create a secure database which can be accessed via a simple and straight forward Javascript SDK. The service we will be using is named [Fauna](https://www.fauna.com).

## So what is Fauna?
Fauna is a data API which creates a global data store for your application in a couple of minutes. The database has GraphQL support. Using FaunaDB will help you focus on your application and will handle scaling, sharding, provisioning, latency and correctness for you and maybe the most important part, it has a free tier!

#### How to set up your database

1. Create an account at [Fauna](https://dashboard.fauna.com/accounts/register).
2. Press `new database`.
3. Choose a database name.
4. (optional) toggle the Pre-populate with demo data toggle.
5. Go to the security tab and create a new key.
6. Secure the secret in a separate file (we will use this secret).

## Code time already?
Yes! As you can see, there were 6 simple steps to create a data API for our application. Now we can start using the [faunaDB javascript client](https://docs.fauna.com/fauna/current/drivers/javascript?lang=javascript).

In the code snippet below you can find a simple example of fetching a `User` object from the `user` collection by id.

`index.js`
![code](https://dev-to-uploads.s3.amazonaws.com/i/1x0evfody5i21arvt08v.png)
 
`config.js`
![key](https://dev-to-uploads.s3.amazonaws.com/i/inatou3y3ty63mpb1hzr.png)

### Interesting links
1. [Source code](https://github.com/Joachimzeelmaekers/simple-faunadb-example) on Github. 
2. [FaunaDB](https://www.fauna.com).
3. Plugin for the code snippets from VS code [Polacode](https://marketplace.visualstudio.com/items?itemName=pnp.polacode)

**Consider using this service in your next side project and let me know your thoughts on FaunaDB.**
Quickly Open a File in the Browser from WSL
Tags: wsl, javascript, codenewbie, tutorial
Published: 2020-10-17 19:54:54

Mac users have this magic convenience of typing `open index.html` into their terminal to open a file from their current directory in the browser. Those of us on WSL aren't so lucky. If you're lucky, the `open` command will open a windows directory. Cool, I guess? But not exactly super helpful. The internet abounds with recommendations --- from trying `xdg-open`, configuring your `www-browser` defaults, and setting your `PATH` environments to some even more convoluted methods. But the question remains: what's the easiest way to open an HTML file in the browser from WSL?

The closest thing I've found is to use the Windows Subsystem for Linux's `explorer.exe` command. Assuming you've set your browser environment variable in bash, then typing something lile `explorer.exe index.html` should open the file `index.html` in your default browser. If that works, congrags! That's the simplest version of Mac's `open` command. Well, sort of...

Typing `explorer.exe` is still a little bit of a handful, and I'm lazy. I mean `open` is four characters, and `explorer.exe` is twelve. That's three times as many characters. No thanks!

Wouldn't it be nice if we could do something simpler? How about `see index.html`? Fortunately, we can leverage the ability to create aliases in bash to make this dream a reality. Just drop the following three lines directly into your terminal:
```bash
export BROWSER='/mnt/c/Windows/explorer.exe'
echo "alias see='explorer.exe'" >> ~/.bashrc
source ~/.bash_profile
```

You're done! No need to play around in your config files. 🙌 Next time you need to open that `index.html` file, all you need to do is type `see index.html` and watch the magic happen. And it's one fewer character than those Mac folks. Just imagine what you could do with that kind of time savings... 

![a bear is dancing happily](https://media4.giphy.com/media/tsX3YMWYzDPjAARfeg/source.gif)
In a Lean context, create a system that can evolve over time is a waste or worth in an early stage?
Tags: discuss, lean
Published: 2020-10-17 19:45:32

Imagine that you have already validated a possible need for a product and you start to create the first Minimum Viable Product, that's not a Prototype.

Even though you have less risk, you still need to try a lot of stuff. The system will be changing fast and often, and sometimes you need to replace the whole system.

In this context, do you think that investing in the next points is a waste or actually worth to do:

- Continuous Delivery System
- Good practices
- Automated testing
- Monitoring
- Analytics

If you think it's not worth at an early stage, then when you think it's worth?
Emotions of pushing to production in GIF's
Tags: funny, programming, laravel
Published: 2020-10-17 19:41:49

Who can relate?

    1.Spending a year on a new update
![Alt Text](https://media.giphy.com/media/26FL4BaDc1lgVpg52/giphy.gif)

    2. A month out from pushing the update
![Alt Text](https://media.giphy.com/media/l0IybQ6l8nfKjxQv6/giphy.gif)

    3. The wife asks me to change a color a week before the update
![Alt Text](https://media.giphy.com/media/xT39D7GQo1m3LatZyU/giphy.gif)

    4. About to push the update
![Alt Text](https://media.giphy.com/media/igi0dS20WxPJvroIgW/giphy.gif)

    5. Pushing the update
![Alt Text](https://media.giphy.com/media/WZ4M8M2VbauEo/giphy.gif)

    6. The update's been pushed
![Alt Text](https://media.giphy.com/media/snEeOh54kCFxe/giphy.gif)

    7. You realize an issue
![Alt Text](https://media.giphy.com/media/icUFYYZLZMgrOoMapI/giphy.gif)

    8. You fix the issue
![Alt Text](https://media.giphy.com/media/HvvpNczg8Dcw8/giphy.gif)

    9. We celebrate the update
![Alt Text](https://media.giphy.com/media/3oeSB36G9Au4V0xUhG/giphy.gif)

When it's time for new updates it repeats lol.
How to create faster smaller swap space
Tags: linux, tips, sysadmin, fedora
Published: 2020-10-17 19:37:00


Even though swap is not necessary for the most of use cases, but developers might need swap space when doing a big compilation, browsing on chrome or on slack. but it is a really painful experience using a swap partition on Disk space. ZRAM helps us allocate small storage from RAM as swap space and store 3,4 times of data on that space. its even faster than the SSD swap partitions because this is a ram drive.

Since [zstd](https://facebook.github.io/zstd) has an excellent compression ratio, 2GB of zram space will have total swap capacity around 6GB. please note that these commands are only tested on Fedora 32. All the changes will be lost in the next reboot.


```bash
$ modprobe zram num_devices=2
$ echo zstd > /sys/block/zram0/comp_algorithm
$ echo 2G > /sys/block/zram0/disksize
$ mkswap --label zram0 /dev/zram0
```

### enable the swap partition with higher priority
`$ swapon --priority 1 /dev/zram0`

### Tadaa! 🎉  now we can open another chrome tab ;-)

```bash
$ free -h
              total        used        free      shared  buff/cache   available
Mem:           15Gi       7.3Gi       1.8Gi       1.5Gi       6.4Gi       6.4Gi
Swap:         2.0Gi       5.0Mi       2.0Gi

```

### to disable the swap storage
`$ swapoff /dev/zram0`


update: zram is enabled by default
My First Contribution to Open Source
Tags: hacktoberfest
Published: 2020-10-17 19:36:11

## What I Learned From Hacktoberfest

I learned to fork Repositories of other Developers and also how to create pull requests after Contributing to their Projects. 

## Experience

It was a great experience showing off skills and helping out the developer community across the world.

Here are my contributions towards Open Source Community :
1.
https://github.com/Devansh2005/Text-Editor/pull/8

2.
https://github.com/Harshita248/Loading121/pull/2

3.
https://github.com/aniketsharma00411/algorithmsUse/pull/45

4.
https://github.com/andrejarrell/CatGifs/pull/23

I am very glad that I took part in Hacktoberfest because it help me kickstart my journey of Open Source Development and also helped me grasp all the basics of GitHub that are a crucial part of being a complete Developer.
My First ever Hacktoberfest
Tags: hacktoberfest
Published: 2020-10-17 19:33:55

## What I Learned From Hacktoberfest

I learned various types of Machine Learning models and many more skills due to Hacktoberfest.Github is a very good open source platform for developers and we should get into it.Doing 4 valid PRs in public repository was a challenging task and also a fun task. 
Really excited for the swags and next year challenge.
Github link :-
https://github.com/Sayansurya
HacktoberFest 2020 Success!
Tags: hackrtoberfest
Published: 2020-10-17 19:24:17

Glad to share my successful completion of -Hacktoberfest2020

I participated in the Hacktoberfest(2020) for the first time and learned a lot about how to contribute in the open source platforms. I have contributed in several projects and all of those are approved by the respective maintainers. Really excited to win a super cool Hacktoberfest T-shirt. Hopefully looking for the next year too!
Linux Commands: du
Tags: linux, beginners, codenewbie
Published: 2020-10-17 19:10:02

`du` is used to display disk usage statistics. It's a simple tool to calculate and print the disk space used by files or directories. Let's see how to use it.

You can simply type `du` or `du <directory-name>` in your terminal and it will print the size.


![Screenshot 2020-10-18 at 12.16.02 AM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1602960370350/h2UKm1weA.png)

In the above example, it gives you the size of the directory. The number `8` represents the size in bytes.

To print each and every file and their respective size we will need to use the `du -a` command. If you just want to print the sizes in the root of the directory and don't want to go deep inside each directory you can use `du *`.

![Screenshot 2020-10-18 at 12.17.09 AM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1602960433839/yxIW0IlTP.png)

You can apply various options to manipulate the output.
- -a: Display an entry for each file in a file hierarchy.
- -c: Display a total size.
- -d: Singnifes till what level deep this command should print the files.
- -h: Human-readable output.
- -g: Display the size in Gigabytes.
- -k: Display the size in Kilobytes.
- -m: Display the size in Megabytes.


![Screenshot 2020-10-18 at 12.15.21 AM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1602960327928/4DIQ2Gt59.png)

### Practical Usage
Suppose you want to print the top files that are consuming the most disk space. You can pipe the output of the `du` to sort and then print the head.
![Screenshot 2020-10-18 at 12.23.29 AM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1602960817453/SfCILRVt_.png)

### Conclusion

I have been extensively using this command to resolve production issues. Whenever we have an issue related to space on VM boxes I use this command to figure out what is exhausting the space. So it comes in handy in solving the real-world problem faced while debugging production issues which is related to disk space.

> 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)
Github-starcounter - Give a shout-out to your Github Stargazers
Tags: javascript, github, webdev, 100daysofcode
Published: 2020-10-17 18:53:27

Open-source is a beautiful thing. It fuels products big and small, promotes collaboration, and so much more. An open-source package, however, cannot thrive without its users. This is why Github Stargazers are valued as a measure of a package's healthiness and popularity.

In order to thank those who go out of their way to support open-source projects, I have created the following GitHub Star buttons with an Avatar showcase. It is a great way to give a shout-out to those devs that appreciate your work!

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

You can get yours at https://hodgef.com/github-starcounter/

Do you have feedback on how to improve the buttons? Feel free to share your insights on the GitHub repository: https://github.com/DevUnltd/github-starcounter
Mysterious ways of JSX
Tags: react, javascript, jsx
Published: 2020-10-17 18:27:32

I always wonder whenever I use React, why do I import React from react library whereas I never use it in my code?
A simple Hello World could be written the following way
```
function myComponent(){
return <p>Hello World</p>
}
```
I don't see React variable anywhere and code runs perfectly fine without any error. And when I don't import it, it throws a load of errors on my terminal window. So what's up with it?

After learning JSX and it's ways, I found that since it isn't native Javascipt code, it has to be first complied into Javascript by come compiler such as Babel.

The same code above then changes to
```
function myComponent(){
React.createElement("p", null, "Hello World")
}
```
And if we don't import it, React isn't in scope, the code can't run and importing it is a necessity.

But that's a lot of hassle if you are making many different components right?

Well React heard us and from React 17, there is no need to import React from the library since there is going to be a new helper which is going to be automatically injected at the time of compiling just like this 

```
import {jsx as _jsx} from 'react/jsx-runtime';

function myComponent(){
 return _jsx("p", null, "Hello World")
}
```

Now you know why do we import React. That's it for the post. Thanks for sticking till the end.
#Hacktoberfest: Thinking beyond the Tee 
Tags: hacktoberfest
Published: 2020-10-17 18:20:17

## What I Learned From Hacktoberfest
The power of Opensource community 

## Motivation
What drives me to work for open source is a sense of gratitude. I would have been nowhere without open-source. So it feels like it's my turn now to help the community that wants to learn from the knowledge which I have so that they don't struggle where I struggled.

## Get started with Opensource ❤️ 
The only thing you need to know is Git, Github, and have your domain knowledge. Just start using repos and critically see where it may fail and how it can be resolved. Go to issues and try resolving


<!-- What did you learn that can help others contribute to the project you worked on? What did you learn that can help the users of that project?! -->
Create Your Next NodeJS MicroService with Merver
Tags: express
Published: 2020-10-17 18:07:16

## What is Merver?

In my effort to better understand the NodeJS core libraries I started playing with the HTTP library trying to recreate many of the features I enjoy from frameworks like express, fastify and polka. In doing so I ended up creating a fairly useable micro-webframework that I call Mever.

## Getting Started

You can install the library and follow the documentation to get you started but I have a template you can scaffold that has all the initial setup done for you, just run the following command.

```npx merced-spinup merver projectName```

Change directory into the new folder and run ```npm install```

You have to two scripts

```npm run dev``` to run in development mode
```npm start``` to run in production mode

## Configuration

In the configuration folder you have two files...

#### configs/config.js

In this file you can configure your server such as cors headers, static folders and more.

#### configs/db.js

configure your database connection in this file

## middleware/globals.js

Here is where you can define global middleware, (route middleware is configured in your route objects). Pass any middleware into the addMiddlware function which you'll see in the existing examples.

What is going on is each middleware is being registered to a middler object which when invoked will run all the middleware registered to it passing the request and response object to each one.

The server runs a middler object before running a responder object with all the routes when handling a request.

By default a basic logger and bodyParser(json and urlencoded) middleware is already configured.

## controllers/responses/

In this folder create and export your response objects (routes). Each end point gets one object where you can make a handler for the particular verb like so...

```js
module.exports = {
    endpoint: '/',
    GET: (req, res) => {res.html(`<h1>It Works!</h1>`)},
    POST: (req, res) => {res.json({it: 'works'})},
    PUT: (req, res) => {res.json({it: 'works'})},
    DELETE: (req, res) => {res.json({it: 'works'})}
}
```

then import the object into **controllers/responder.js**

```js
const {Responder} = require('am-merver')
const responder = new Responder()

// Import Responses
const root = require('./responses/root')

// Register Responses
responder.newResponse(root)

// Export Responder
module.exports = responder
```

## That's it

Write your routes like you normally would. Url Params and Url queries work just like you'd expect them to work in express.
Completed Hactoberfest 2020
Tags: hactoberfest
Published: 2020-10-17 18:03:29

I learned to make pull requests and contribute my codes to the open source community. I came across many good Repositories and added my contribution to them.

I contributed some of my codes that I did in Java. Some of them are as follows :

1) Creating and performing several operations in BST.
2) DFS and BFS of a Graph.
3) Finding shortest path in a Maze.
4) Implementing Thread Pools in Java.
5) Implementing Queue using Linked List.
6) Contribution in making good READ.md files

I learnt the implementation of various Data Structures and Algorithms in Java and contributed for the same. Other users can use the same codes for their project or learning purpose.
HacktoberFest 2020
Tags: hacktoberfest
Published: 2020-10-17 17:54:38

## What I Learned From Hacktoberfest

<!-- What did you learn that can help others contribute to the project you worked on? What did you learn that can help the users of that project?! -->


what I learned in this hacktoberfest was that there are many projects that I can help with, and at the same time learn from other developers
Open Source Software Licensing.
Published: 2020-10-17 17:53:03


### The use of open-sourced code is inevitable. Whatever you may be working on, you will likely make use of code snippets from the web or some library that implements a sub-dependency relying on other people’s code.   

___

__Is it risky to use open source software:__

Some open-source licenses generally allow the use of their components as long as you maintain any copyright notices. But if you use a code with a restrictive license in your proprietary software, you might be legally obligated to release your software under the same license.

---

__What are the different types of open-source licenses:__

Public domain: It means that anyone can modify and use the software without any restrictions

__*Permissive:*__ contains minimal requirements about how the software can be modified or redistributed. Also known as “Apache-style” or “BSD style” another common variant is the MIT License.

__*LGPL:*__ The GNU Lesser General Public License allows you to link to open source libraries in your software. If you simply compile or link an LGPL-licensed library with your own code, you can release your application under any license you want, even a proprietary license.

__*Copyleft:*__ also known as reciprocal licenses or restrictive licenses, allow you to modify the code and distribute new works based on it, as long as you meet the requirements for redistribution under the same license. 

---

__What kind of risks are there using open-source licenses:__ 

*Low-risk:* Permissive licenses are considered low risk because it’s easy to meet their reuse requirements: Usually, you just have to retain the copyright notice, but you don’t have to expose your source code. Examples are the Apache and MIT Licenses.

*Medium-risk:* Semi-permissive licenses sometimes referred to as limited licenses, weak copyleft licenses, or simple copyleft licenses, are considered a medium risk because if you modify the code, you have to release the modifications, but not your whole application, under the same license. Different licenses define “modification” differently. Examples are the Mozilla and the Eclipse Public Licenses.

*High-risk:* Restrictive licenses carry a great deal of legal risk. If you use a component with one of these licenses, you might be legally obligated to release your entire application code. Examples are the GNU GPL and GNU LGPL.