teleren/devto huggingface dataset:
Install packages globally without sudo on Linux / MacOS
Tags: npm, linux
Published: 2020-05-10 23:40:55

>Originally published at [makraz.com](https://www.makraz.com/posts/npm-global-without-sudo/).

# `npm`  -- Install packages globally without sudo on Linux / MacOS

By default `npm` installs packages locally in the folder nodes_modules within your projects.
But sometimes with need to install packages globally for command-line as example. 
For Linux / MacOS users npm will ask you to run it with elevated privileges,
which mean use the command `sudo` to be able to install globally (`sudo npm install -g <package>`) 
and this may create permission(s) issue(s) for many users.
However there is a way to install packages globally for a given user without `sudo`.

For that we will follow these steps:  

###### 1. Create a directory for global packages

```sh
mkdir "~/.npm_packages"
```

###### 2. Tell `npm` where to store globally installed packages

```sh
npm config set prefix "~/.npm_packages"
```

###### 3. Ensure `npm` will find installed binaries and man pages

Add the following to your `.bashrc` / `.zshrc`:

```sh
NPM_PACKAGES="~/.npm_packages"

export PATH="$PATH:$NPM_PACKAGES/bin"

# Preserve MANPATH if you already defined it somewhere in your config.
# Otherwise, fall back to `manpath` so we can inherit from `/etc/manpath`.
export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"
```

---

NOTE: If you are running macOS, the `.bashrc` file may not yet exist, and the terminal will be obtaining its environment parameters from another file, such as `.profile` or `.bash_profile`. These files also reside in the user's home folder. In this case, simply adding the following line to them will instruct Terminal to also load the `.bashrc` file:

```sh
source ~/.bashrc
```

---

See also: `npm`'s documentation on ["Fixing `npm` permissions"](https://docs.npmjs.com/getting-started/fixing-npm-permissions).
5 VScode Shortcuts for MacOS
Tags: vscode
Published: 2020-05-10 23:34:33

I enjoy learning and implementing new shortcuts into my coding workflow because it speeds things up. You can use some of these shortcuts even when your not coding! 

### 1. option + shift + left/right arrow key
This will allow you to highlight a word one by one

### 2. cmd + shift + left/right arrow key
Highlight the whole line you're currently on.

### 3. ctrl + cmd + g
Will highlight all the instances of whatever you have highlighted.

### 4. cmd + d
Sometimes you don't want to highlight all instances. You can use this shortcut to highlight one instance at a time.

### 5. option + up/down arrow key
It allows you to move a line, up or down. All you have to do is put ur cursor on the line you want to move and use the command.

### Bonus. option + shift
This duplicates the current line ur cursor is on

I hope you enjoy these shortcuts. I use 1 and 2 frequently outside of VScode. What are some of your favorite shortcuts? Let me know in the comments.
Keep updated your gitignored sample files
Tags: git, go, gitignore, github
Published: 2020-05-10 23:27:25

---
title: Keep updated your gitignored sample files
published: true
description: Samplr is Auto-generate and keep updated your gitignored sample files
cover_image: https://res.cloudinary.com/practicaldev/image/fetch/s--5l_3ggs2--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://static.timbercode.pl/images/covers/gitignore-2-sztuczki.png
tags: git, go, gitignore, github
---

For sure we all have repositories for services we haven't updated in a while. Services that we set up locally, test, deploy, and that's it. May be see it again in some time when it's time to patch or add new features.

Some weeks ago I was working with my team in one of those projects, and a new teammate was assigned a small task there, but he couldn't spin up locally. We spent almost 2-3 hours, just to find out that some configs in the local YAML files were missing, and other ones had changed the key name.

Sounds familiar?

# Samplr

That was my motivation to build this command:

{% github unmultimedio/samplr %}

Samplr is a small command that takes a file with a path that matches with a regex in your config, and scans the content for some keywords to generate a copy of the file, obscuring the secrets you're not supposed to check in your repo.

Imagine having something like:

```yaml
# conf.yaml that's gitignored
foo: foo value
secret: S3CR3T
bar: var value
```

And a git hook that automatically updates the sample copy every commit with:


```yaml
# conf.sample.yaml that will be checked in
foo: foo value
secret: REPLACE_ME
bar: var value
```

Well, now all of our projects magically update our sample files everytime there's a change in the configuration files.

## Gotchas

If you read carefully the README, you'll find that this is a command that's not really tied to git or gitignored files, it's just the use case I've found and what I'm using it for at the moment. But in reality, is a file copier with a way to obscure content.

Happy sampling!
Leetcode - Two Sum algorithm (with JavaScript)
Tags: javascript
Published: 2020-05-10 22:49:50

Today I am going to show how to solve the Leetcode Two Sum algorithm problem. 

Here is the problem:
![problem](https://raw.githubusercontent.com/Urfan196/MyFIles/master/two%20s.png?token=AMQWY7C6S4233GUYR5PQMYC6XB65A)

The simplest solution is just comparing every single possible pair. So we could just have 2 for loops. The first one (i loop) is scanning whole numbers (nums) and the second one (j loop) is starting from i + 1. We will be testing all of them until the sum is equal to the target.

But this solution would be inefficient and time  consuming (O(n^2)).

So that we don’t waste as much time, we need a faster approach to determining the solution. For this purpose, we can use a hash table which supports fast lookup in near constant time. ( O(1) - best case; O(n)- worst case)

Note: In the hash table I’m going to map each element (as a key) to its index (as a value). 

1) For creating a hash table, I’m using a new data structure called Map, which was introduced in ECMAScript 2015.

```javascript
var twoSum = function(nums, target) {
    let map = new Map(); 
}
```
2) Next, I iterate through all of the numbers using for loop.

```javascript
var twoSum = function(nums, target) {
    	let map = new Map();
    	for (let i = 0; i < nums.length; i++) {
       	}  
}
```
3) While I iterate  the elements, I also check if the current element's complement already exists in the table. If it exists, I have found a solution and return immediately. Otherwise, I insert an element into the table.
```javascript
var twoSum = function(nums, target) {
    let map = new Map(); //creating hash table
    for (let i = 0; i < nums.length; i++) {
        let complement = target - nums[i];
        if (map.has(pairNum)) {
            return [map.get(pairNum), i]
        }     
        map.set(nums[i], i); // insert an element into the table
    }
}
```
5 new challenges
Tags: javascript, computerscience
Published: 2020-05-10 22:36:51

I've added 5 new challenges to our ranked mode: 4 hard and one medium.
These challenges are related to combinatorics and matrix operations. Can you solve them? Give it your best shot @ https://nevolin.be/codr/

Preview:
```JS
function backtrack(list, tempList, nums, start) {
    list.push([...tempList]);
    for(let i = start; i < nums.length; i++) {
        tempList.push(nums[i]);
        backtrack(list, tempList, nums, i + 1);
        tempList.pop();
    }
}

function subsets(nums) {
    const list = [];
    backtrack(list, [], nums, 0);
    return list;
}

let out = subsets([2, 3, 1]);
// out.length == ?
```
Double & Triple Equals
Tags: beginners, javascript
Published: 2020-05-10 22:29:03

When writing Javascript code I've typically tried to steer clear of the double equals. This is because I can trust that the triple equals will evaluate strict equality. It seems that there are opposing camps as far as whether the double equals is ever valid, so I wanted to take a deeper dive and better understand the nuance. 

The double equals evaluates loose equality. This means it attempts to convert both values to a common type, then compares their values. This allows for comparisons of string numbers to integers and floats, and falsy values of different types.

If you wanted to check if a string contains a number, you could perform the following comparisons: 

```javascript
let x = "123"
console.log(Number(x) == x)

>> true

let y = "ab123"
console.log(Number(y) == y)

>> false
```

One way to avoid using the double equals to check if a string contains a number is to use the 'isNaN' function. This built-in JS function checks if a value is not a number while avoiding the double equals; it will return true if the value passed is not a number and false if the value is a number. It will evaluate the contents of a string appropriately. 

```javascript
let x = "123"
console.log(isNaN(x))

>> false

let y = "ab123"
console.log(isNaN(y))

>> true
```

The double equals also allows for comparing the following as equivalent: false, 0, "". Null and undefined also compare as equivalent to each other.
While it may be tempting to simplify code by utilizing a double equals to test equivalence of different types of falsy values, it is also very simple to include multiple conditions in a comparison to satisfy each falsy value you expect may arise. 

So instead of writing:
```javascript
if (x == false) {
...
```
You could write:
```javascript 
if (x === false || x === 0 || x === "") {
...
```
If you want to enter the 'if' statement for any falsy value you could write:
```javascript
if (!x) {
...
```

Ultimately, through exploring the different use-cases for the double equals I remain unconvinced that I will need to use the double equals in the future. It seems that any time a double equals is practical, the triple equals could be used with slightly more code - but that extra code and strict equality likely makes the program easier to read. Lastly, because the double equals converts both values to a common type before comparing, the triple equals is typically more efficient. 



Sources:
[Codeburst - Double/Triple Equals](https://codeburst.io/javascript-double-equals-vs-triple-equals-61d4ce5a121a)
[2ality - Strict Equality](https://2ality.com/2011/12/strict-equality-exemptions.html)
Spotlight Story: Carlos Becker,
Creator of GoReleaser 
Tags: opensource, go
Published: 2020-05-10 22:13:39

*[Spotlight](https://deepsource.io/spotlight/) is a story series dedicated to creators and builders of open source software.*

***Where did you grow up?***
I was born in Marechal Cândido Rondon, a small town in South Brazil. I studied in another town nearby, and after I completed my degree I moved to Joinville, where I currently live.

***Are you currently working or have worked for a company in the past?***
I work remotely as a site reliability engineer for a company called TOTVSLabs. I worked in some open-source stuff there too, mostly monitoring-related. Nothing too fancy though!

![Carlos Becker GoReleaser](https://i.imgur.com/635JTFo.png)

***What is GoReleaser?***
GoReleaser is a release automation tool for Go projects — it handles the compilation for several platforms, packaging and archiving to several formats, signing and uploading the release artifacts to several places. All you need to do is write some YAML.

It is a single workflow you can use to release all your projects. Set them up once, and then just call goreleaser when you tag or wire it up to TravisCI, CircleCI, GitHub Actions or several others, so it's done automatically for you. You can choose and follow any of the installation methods listed here: goreleaser.com/install. The website also has extensive docs.

![GoReleaser Project Stats](https://i.imgur.com/QMmIHPl.png)

***What inspired you to join this project?***
I was just scratching my own itch really. I had a couple of projects and I hated to copy-paste release scripts around and how slow they were. So I did a proof-of-concept and named it “goreleaser”. It got traction right away and here we are now!

***Are there any success stories that you would like to share?***
I think that the first big project that migrated to GoReleaser was Hugo. It was a big deal for me and I remember they helped shape what GoReleaser is now. After that, a couple of other big projects migrated, like NATS, Fabio, InfluxDB, Traefik and golang/mock, just to name a few. To me those are all success stories, because I made GoReleaser initially thinking on my own, small projects requirements. Bigger projects bring a whole new deal to the table, and they are able to use GoReleaser. I think that’s awesome.

***What is your vision for the future of this project?***
I think the biggest issue we have now is that the configuration is a little confusing. There are various reasons for that and I think this is something that we can do better.

***If someone wants to support the project, where can they donate?***
You can donate on GoReleaser’s [OpenCollective](https://opencollective.com/goreleaser/) or via [GitHub Sponsors](https://github.com/orgs/goreleaser/people) to people that work on the project.

*You can also find Carlos Becker on [GitHub](https://github.com/caarlos0), [Twitter](https://twitter.com/caarlos0) and [LinkedIn](https://www.linkedin.com/in/caarlos0/).*

Link to the original [story](https://deepsource.io/spotlight/carlos-becker/).
Emmet Part 1 - Basics
Tags: webdev, tutorial, beginners, html
Published: 2020-05-10 22:11:10

Emmet is a FREE plugin for many popular code editors which helps you write HTML and CSS fast! Emmet has support for many editors, including Sublime Text, Atom, Visual Studio Code, and many others. VS Code comes with Emmet pre-installed.

When you start typing an Emmet abbreviation, you will see the abbreviation displayed in the suggestion list.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/6asyrbw74bp14u96xxgc.gif)

In this post we cover the following topics:
📌 Tags
📌 Siblings
📌 Children
📌 Class
📌 Id
📌 Id & Class
📌 Content
📌 Multiply⠀⠀⠀⠀⠀⠀

Part 2 coming soon!

## Tags

Basic abbreviations can be used to quickly create HTML tags.

- div
    ```html
    <div></div>
    ```

- p
    ```html
    <p></p>
    ```

- h1
    ```html
    <h1></h1>
    ```

## Siblings

To create a set of HTML tags as siblings just use `+` in between each abbreviation.

- hdr+sect+ftr

    ```html
    <header></header>
    <section></section>
    <footer></footer>
    ```

## Children

Child elements can be created by using `>` in between each abbreviation.

- sect>ul>li

    ```html
    <section>
    	<ul>
    		<li></li>
    	</ul>
    </section>
    ```

## Class

In order to create elements with classes just append the class to the abbreviation using `.`

- h1.center

    ```html
    <h1 class="center"></h1>
    ```

## Id

To add an Id to an element, append the Id to the abbreviation using `#`

- h1#header

    ```html
    <h1 id="header"></h1>
    ```

## Id & Class

You can include multiple attributes on an element abbreviation. 

- h1#header.center

    ```html
    <h1 id="header" class="center"></h1>
    ```

## Content

Text content of an element can be included by wrapping the content with `{ }`

- p{This is a paragraph.}

    ```html
    <p>This is a paragraph.</p>
    ```

## Multiply

We can create multiple elements by multiplying them using `*`

- ul>li*4

    ```html
    <ul>
    	<li></li>
    	<li></li>
    	<li></li>
    	<li></li>
    </ul>
    ```
Part 2 coming very soon! Check out the full video on my YouTube channel.
{% youtube EzGWXTASWWo %}

## **Thanks for reading!**

Say Hello! [Instagram](https://www.instagram.com/codeSTACKr) | [Twitter](https://twitter.com/codeSTACKr) | [YouTube](https://youtube.com/codeSTACKr)
Watch How I Create a YouTube Video and Thumbnail!
Tags: gimp, ffmpeg, youtube, linux
Published: 2020-05-10 22:08:22

{% youtube m0JR5cQ3T_A %}

Follow me on [YouTube](https://www.youtube.com/channel/UCTHij3Ac5GizLsn5yB4IX_Q/) and [Twitter](https://twitter.com/FeuryDonald) for more video editing tricks with **ffmpeg** and a little **python** now!

Even though I'm only about one month into my **YouTube** channel, I thought some people might interested about **how** I go about creating and uploading the videos and thumbnails.

To summarize the video above, the process goes like this:

1. Record the video using **OBS**, usually only involves one file but there are a few times I needed to start and stop again.

2. If multiple recordings were done, concat them together using the **demuxer** concat method.

3. Find the timestamp in seconds in my video for the *plug.* (a.k.a like, sub, blah blah)

4. Run the video through my finalize video script to add in the fade in and out, overlay the sub animation, and append the outro.

5. While its processing, take dumb snapshot with webcam.

6. Edit snapshot in **Gimp**
  * Do a little color correction and probably brighten the image.
  * Crop it down to 1280x720, keeping my face to the right side of the image.
  * Add text to the left side of the image, usually some variant of the video title.
  * Put a box behind the text to give them some contrast.
  * Apply an images if applicable. (ex. ffmpeg logo, YouTube logo)
  * ... Thats it, usually takes like five minutes.

7. Quickly check over video once its done processing.

8. Upload if it looks good.

9. Do the usual SEO stuff (tags, description, title)

10. Add thumbnail exported from **Gimp**

11. Once the video is processed on YouTube, add the end screen where the fade in starts.

12. Add any cards if applicable, such as references to other videos. I always add the relevant playlist to the start of the video.

13. Content!

Thats it for now. Once I get consistent lighting in my office, I'm gonna add proper color correcting to the finalization script.
Article Hub (DEV Clone)
Tags: go, webdev, sideprojects
Published: 2020-05-06 22:49:43

I believe that Learning by Doing  is the best learning strategy for me to learn anything, before the lockdown, I though about taking a break from Django and Try new Language where you can be more involved and creative since Django provide a minimal work for the developers or the programmer working with it to do and doesn't encourage creativity, I think that's why it's called a Framework for Deadlines so I decided up to give GoLang a shot since I read an Article about it and how it was designed, I was fascinated by it's elegance and eloquence, GoLang really is one of the cleanest language I had came across during my short span of experience as a student developer or programmer but I really love it and I think I will stick with it for some time, the latest side project I have been working on with GoLang is a Web-app which is a clone to DEV
and here are the link for the repo if anyone interested to see it :

https://github.com/12mohaned/article_hub

I am more than welcome to receive feedbacks

the project is not final yet I believe I will finish within the couple  next days, I am thinking about constructing a Recommender System with machine Learning so I am not sure if I am going to do this or not
First relaxing week - wfh edition
Tags: remote, webdev, development, watercooler
Published: 2020-05-10 21:42:39

---
title: First relaxing week - wfh edition
published: true
description: Continuous journey of working from home due to COVID-19 outbreak at the world. This is my journey, my challenges in trying to be productive and completely changing my work habits from office first to remote first. (Working from home Journey )
tags: remote, webdev, development, watercooler
series: working from home
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/0cao1ieiacpydi0ay44n.png
---
_Thanks for reading! I'm writing about my remote work journey thanks to covid-19 forced me to_ 😂 _ I'm writing now for 2 months_ 

First of all, time is moving fast! It's been 2 months now, since I started to write at Dev.to as a way to handle this (hopefully) once in a life time experience of living with a global pandemic.

After these 2 months, I can say that some of my Februar decisions seem to be related to Covid-19 but unconscious. 😅

Nevertheless, I received the [8-week writing strike](https://dev.to/badge/8-week-streak). I'm happy about me writing down my thoughts and a lot of learnings. Yet I don't feel the need for a daily blog. I'm rather switching now to a weekly one and have to see what cycle works.

This week at work is mainly about creating a new A/B-Test and also starting first architectural steps for some of our applications. After a short alignment with my Lead, we agreed in using the [C4-Model](https://c4model.com/).

I never used it before yet heard about it. We agreed that I start creating the first two levels of our architecture and continue with our Frontend chapter.

The biggest change this week was a good one. With my team we started doing weekly "watercooler" hangouts. Randomly chatting, learning each other better. Having a more personal, friendship-like relationship [helps](https://hbr.org/2017/08/having-work-friends-can-be-tricky-but-its-worth-it). 


## Personal

Mother's day is happening! And my lovely daughter is planning the whole week things. Like what kind of earrings to buy, what to draw, what kind of flowers to buy. It is amazing seeing her grow and doing all these things ❤️. 

As the last week was a short work week, we enjoyed the days going outside to playgrounds. They are officially open in Berlin, the weather is great and we are using this opportunity. Also we went to the berlin Zoo 🐘

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


And about Covid-19: 

As I said, we are getting back to a level of normality. This new situation definitely changed many things. I don't like crowds. I don't understand why people can't keep certain distances. Whenever I want to meet a friend now, I'm hesitating.

Take care!

Cheers,

Ferit
Learning Golang 108
Tags: go, beginners
Published: 2020-05-10 21:26:05

Here is a list of the go beginner courses.

| course | about |
|---|---|
|[101](https://dev.to/jiayanguo/learning-golang-101-5eg0)| Naming Conventions |
|[102](https://dev.to/jiayanguo/learning-golang-102-a05)|Control Structures|
|[103](https://dev.to/jiayanguo/learning-golang-102-2fhk)| Functions|
|[104](https://dev.to/jiayanguo/learning-golang-104-2ida)| Data Structure|
|[105](https://dev.to/jiayanguo/learning-golang-105-3kk4)| Structs & Pointers|
|[106](https://dev.to/jiayanguo/learning-golang-106-1cbl)| Interfaces|
|[107](https://dev.to/jiayanguo/learning-golang-107-g8l)|Routines & Channels|

## Package manager.
To see popularity of these tools, click [here](https://github.com/blindpirate/report-of-build-tools-for-java-and-golang#golang). `make` is the most popular tool. Here is an example.
`dep` is a more easy way, [dep] (https://golang.github.io/dep/docs/introduction.html).

   ```
   # Go parameters
   GOCMD=go
   GOBUILD=$(GOCMD) build
   GOCLEAN=$(GOCMD) clean
   GOTEST=$(GOCMD) test
   GOGET=$(GOCMD) get
   BINARY_NAME=mybinary

   deps:
	  $(GOGET) github.com/kubeless/kubeless/pkg/functions
   ```
Note, make is very picky, if you run issues, make sure you open it in `vi`. Then run `:%s/^[ ]\+/\t/g`.


## 3 dots
3 dots in 4 places
Take a look at this [post](https://yourbasic.org/golang/three-dots-ellipsis/)


If you are a beginner, I highly recommend this [Go course](https://www.udemy.com/course/go-the-complete-developers-guide/learn/lecture/7824514#overview) on Udemy.

Here are some sample [codes](https://github.com/jiayanguo/crashgo) for this course. 


Happy learning!