teleren/devto huggingface dataset:
Daily Challenge #146 - The Dollar Game
Tags: challenge
Published: 2019-12-27 17:00:20

---
title: Daily Challenge #146 - The Dollar Game
published: true
series: Daily Challenge
description: Redistribute the wealth so no one is in debt. 
tags: challenge
---
###Setup
You are given a list of people and their current net worth in U.S. Dollars. Some people might have a positive net worth, others could have a negative net worth (i.e. are in debt), while some are just broke. 

There are many friendships across these financial groups. No single person is alone typically, you can draw a friendship line from one person to any other person through x number of people. In this community, each person gives 1 dollar to each of their friends. Additionally, each person can take 1 dollar from each of their friends. 

Who should take or give a dollar so that everyone has a non-negative balance?

###Input 
Your function `giveAndTake` will pass two arguments
- `people` - a hash object with names as keys and net worth as value. 
- `friendships` - an array of pairs of names that are friends. 

###Output
Your function should return an array of 'moves'. Each 'move' is an array of two elements: The name of a person and the value 1 or -1. 1 indicates they should take a dollar from each friend. -1 indicates they should give a dollar to each friend.

For example: `[['David',1], ['Brian',-1], ['Alice',-1], ['Charlie',1]]`

###Tests
<pre>
people: {Adam: 1, Bob: -1, Carol: -2, Donna: 2, Eddie: 3}
friendships: [['Adam','Carol'],['Adam','Eddie'],['Bob','Carol'],['Carol','Eddie'],['Donna','Eddie']] 

people: {Adam: -4, Bob: 1, Carol: 2, Donna: 2, Eddie: 0}
friendships: [['Adam','Donna'],['Adam','Carol'],['Bob','Carol'],['Carol','Eddie'],['Donna','Eddie']]

people:{Adam: 0, Bob: 2, Carol: -2, Donna: 3, Eddie: -2}
friendships:[['Adam','Carol'],['Adam','Donna'],['Bob','Carol'],['Carol','Eddie'],['Donna','Eddie']]
</pre>

Good luck!

***
_This [challenge](https://www.codewars.com/kata/5b8eef5574a4f499de000105) comes from hufftheweevil on CodeWars. Thank you to [CodeWars](<https://codewars.com/>), who has licensed redistribution of this challenge under the [2-Clause BSD License](<https://opensource.org/licenses/BSD-2-Clause>)!_

_Want to propose a challenge idea for a future post?  Email **yo+challenge@dev.to** with your suggestions!_
Running GatsbyJS app in Docker container
Tags: gatsby, docker, shopify, headless
Published: 2019-12-27 16:31:12


Here is an example configuration we use for testing while developing [Gatsby Shopify Storefront](https://gatsbystorefront.com) - lightning-fast Progressive Web App (PWA) storefront for Shopify.

A Dockerfile:

```Dockerfile
FROM node:13

WORKDIR /usr/src/app

COPY package.json .

RUN yarn global add gatsby-cli

RUN yarn install

COPY gatsby-config.js .

# Optionally, copy your .env file to the container filesystem
COPY .env .

EXPOSE 8000

CMD ["gatsby", "develop", "-H", "0.0.0.0"]
```
Though it is not the case with our setup, you might need to copy your project files to the container as well. Use `COPY . .` command for this.

Build your image:
```
docker build . -t gatsbystorefront:1.0.1
```

Run your container:
```
docker run -d -p 8000:8000 --name store gatsbystorefront:1.0.1
```

Though this one is short. Hope it will help, cheers! 🎅🎄
180 + Followers!
Tags: devlog, thankyou, webdev
Published: 2019-12-27 16:47:02

---
title: 180 + Followers!
published: true
description: thank you
tags: devlog, thankyou, webdev
---
I just wanted to say THANK YOU for all the folks following me here on Dev.to. I look forward to a new year with lots of great posts about gamedev on the web. My goal for this year is to post 50 articles, and double my followers to 360 by the end of the year. Thanks again so much! See you in 2020! 

(Thanks to https://dev.to/moopet for correcting my math LOL )
How do you manage your browser bookmarks?
Tags: discuss, bookmarks
Published: 2019-12-27 16:41:23

---
title: How do you manage your browser bookmarks?
published: true
description: Please share your way of staying sane without missing out
tags: discuss, bookmarks
cover_image: https://searchuh.com/wp-content/uploads/2016/05/bookmarks-1400x787.jpg
---

I'm stuck.
I have accumulated a decent set of browser bookmarks, both in the browser and in my notes. And I need to combine them somehow, comb a little and structure the whole set to make it more accessible. Like, `tools`, `articles`, `documentation`, whatnot.
Currently, I use default browser bookmarking capabilities and divide links by topics (in a deeply nested way). I don't use any specific tools, though I had taken a look at a bunch of them and didn't stop at anything.

What is your way of keeping your bookmarks in order? What tools do you use? How do you structure the whole system? What is your approach to fast access and synchronization?
Let's review each other's personal websites.
Published: 2019-12-27 15:57:35

---
title: Let's review each other's personal websites.
published: true
---

Hey, devs from all over the world. 😊

I have been working a lot lately on [my personal website](https://bassemmohamed.me). It is in no way done but I am really liking what I have done so far. 😎

I wanna get comments and feedback from you guys and possibly do the same for you. 🧐🙌

Come on now! 👏
Post your personal websites in the comments below! 🔥
How I made Google Forms automatically post submissions in our Discord server
Tags: javascript, googleappsscript, googleforms
Published: 2019-12-27 15:41:16

## Motivation

A friend of mine invited me to work on a game with him and I, of course, accepted. Early on, we decided that we want beta testers, and a way to apply as a tester. Google Forms immediately came into mind, and I took up the task of writing some code to make it automatically post answers to the form in our Discord server.

## Part 1: So... how do I even get started on this?

I knew I needed two things: A Discord webhook, and something to send the request to it with every form submission. I quickly found out about something called [Apps Script](https://developers.google.com/apps-script), which let me interact with a bunch of Google apps (including Forms), and which I could utilise to bring this idea to life.

## Part 2: Alright, let's jump into it

First, I wanted to figure out if I could even send an HTTP request from my Forms Add-on and found [UrlFetchApp.fetch](https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app#fetch(String))
```js
function onSubmit(e) {
  UrlFetchApp('somecoolurlidk')
}
```

## Part 3: But can I use the Discord Webhook?

Yes. The [Discord Webhook documentation](https://discordapp.com/developers/docs/resources/webhook) is **awesome**, and I was up and running within minutes.

```js
function onSubmit(e) {
  var discordPayload = {
    content: 'Form submitted'
  }
  UrlFetchApp('discordwebhookurl', {
    method: 'post',
    payload: JSON.stringify(discordPayload),
    contentType: 'application/json'
  })
}
```

## Part 4: Welp, time to actually hook it up to the form

By going to `Edit > Current project's triggers`, I could set up my form to trigger the `onSubmit` function when the form is submitted.
![Setting up the trigger](https://thepracticaldev.s3.amazonaws.com/i/mp4hr2kfbxwf9cgmsela.png)
![Webhook in action](https://thepracticaldev.s3.amazonaws.com/i/3zp3vt4s25vlzcsp37au.png)

## Part 5: Putting it all together

I don't have much to say here. Took about an hour of mindlessly browsing the Apps Script documentation, but somehow managed to write this final code:
```js
function onSubmit(e) {
  var discordPayload = { 
    content: 'Form submitted',
    embeds: [{
      type: 'rich',
      title: 'Form submission',
      color: 7506394,
      fields: []
    }]
  }
  e.response.getItemResponses().forEach(function(i) {
    var v = i.getResponse() || 'None'
    discordPayload.embeds[0].fields.push({ name: i.getItem().getTitle(), value: v })
  })
  UrlFetchApp.fetch('youknowwhatgoeshereanywaysandimnotinthemoodtoleakstuff', {
    method: 'post',
    payload: JSON.stringify(discordPayload),
    contentType: 'application/json'
  })
}
```
![The final webhook in action](https://i.imgur.com/e8YqlJG.png)
New Solidity & Vyper Cheat sheet launched
Published: 2019-12-27 15:29:46

Proud to announce [Solidity and Vyper cheat sheet](http://reference.auditless.com/cheatsheet). It's open source, meaning that you can edit the content and built-in compilers will check your code for accuracy.

Hopefully handy for those of you wanting to learn more Solidity and/or Vyper!

You can check it out [here](http://reference.auditless.com/cheatsheet).
Build charts with nodejs + canvasJS + mongodb
Tags: help, javascript, mongodb
Published: 2019-12-27 15:28:35

Hey everyone !! 

I'm working on my first real project and I have some trouble to show a chart with data from mongoDB..

This is what I have inside my handlebars with HTML

![Alt text of image](https://thepracticaldev.s3.amazonaws.com/i/2i40mz0iipi9xx78knz0.png)

And inside the same handlebar opened a script tag and inserted the following code
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/whub3rybnn047azpp6dk.png)

But on my routes folder, I have this ROUTER.GET and this way I can pass every expense from MongoDB inside Handlebars.
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/whub3rybnn047azpp6dk.png)

The way I have the preview code, it shows me a chart with the dataPoints I inserted in the script, but I don't know how can refactor and inside the router.get I can access the information and build the chart with the data from mongodb.. 

How can I use the router file to build the chart with mongodb data?
Create a Cron Job to Change Default Browser for Work-Life Balance
Tags: linux, productivity
Published: 2019-12-27 14:17:02

---
title: Create a Cron Job to Change Default Browser for Work-Life Balance
published: true
description: Maintaining a healthy work-life balance is important when you're a developer. Especially if you work remote. When I set up a new development environment, I create a cron job to change the default browser between work and 'play' hours.
tags: linux, productivity
canonical_url: http://jarednielsen.com/create-cron-job-change-default-browser-work-life-balance/
cover_image: https://thepracticaldev.s3.amazonaws.com/i/vka7ns5hm2jty282mpuk.png
---
_This article originally published on [jarednielsen.com](http://jarednielsen.com/create-cron-job-change-default-browser-work-life-balance/)_

Maintaining a healthy work-life balance is important when you're a developer. Especially if you work remote. When I set up a new development environment, I create a cron job to change the default browser between work hours and 'play' hours. I use Chrome professionally as much of my workflow is built around the Google ecosphere. But I use Firefox as my personal browser (and so should you) for several reasons, the most important being [Mozilla's emphasis on privacy](https://www.mozilla.org/en-US/privacy/principles/). 

## How to Create a Cron Job to Change the Default Browser

Here's the snippet I use to create a cron job to change the default browser between 8:30AM and 5PM:

```sh
30 8 * * 1-5 xdg-settings set default-web-browser google-chrome.desktop
0 17 * * 1-5 xdg-settings set default-web-browser firefox.desktop
```

Cron jobs follow the '5 Star' format: 

```sh
* * * * * command or commands to run
```

From left-to-right, each asterisk corresponds to the following: 

1. Minute (by the hour)
2. Hour (by 24-hour clock)
3. Day (of the month)
4. Month
5. Day(s) (of the week)

The stars are followed by the command, or commands, to be run at this specific time.

In my snippet above, the cron job I created will run at 8:30AM (30 8), but only on weekdays (1-5). This will set my default browser as Chrome.

```sh
30 8 * * 1-5 xdg-settings set default-web-browser google-chrome.desktop
```

At 5PM (0 17), the cron job will run and set my default browser back to Firefox.

```sh
0 17 * * 1-5 xdg-settings set default-web-browser firefox.desktop
```

I leave the day of the month and the month at their default values (*).

## Create a Cron Job to Change Default Browser

Creating a cron job on a Unix/Linux environment is easy. 

To _list_ the cron job for the current user:

```sh
crontab -l
```

To _edit_ the cron job for the current user:

```sh
crontab -e
```

What are your work-life balance hacks? Let me know on Twitter [@jarednielsen](https://jarednielsen.com)

---

I write a weekly newsletter where I share articles about programming, problem solving and lifelong learning. [Join now](http://eepurl.com/cP8CMn)
Starting here
Tags: firstpost, goals
Published: 2019-10-08 22:20:55

---
title: Starting here
published: true
description: My first post & how I hope to use this account
tags: #firstpost #goals 
---

I've seen this site for a while and signed up ages ago, but I never really knew how I'd use it. Twitter engagement isn't what it used to be, but I also feel really constrained by high follower counts, a feed that's useful for keeping up with the pulse of things, but lacks the sort of connection that it used to be really good for. 

I doubt I'll substitute that here. What I am looking for is a place to get ideas out, to connect, and push myself a bit to advance my practice. That used to be a blog and for a while, Tumblr provided other outlets. Lately, I haven't been able to find anywhere to substitute for that connection and working remotely has made it more acute. 

I'll consider it a win if I can start doing what I <i>used</i> to do online; writing and delving into ideas more fully. I'm working on a few things I'm sort of excited about, but I need to commit to actually working at them. Twitter will have its place, but I anticipate using it like other channels where I have a specific purpose for them, rather than hoping it'll continue like a catch-all.

Most of all, I want to feel like I'm making progress again. Maybe connect old work and revisit some thinking. It's weird how I was way more prolific when I knew less than I do now. I'd love to bridge that gap a bit.
What now?!
Tags: beginners, codenewbie
Published: 2019-12-27 13:44:20

Well, i've just finished a bootcamp on-line. While my understanding of the curriculum was better than i've expected. I'm somehow at a loss as how to implement everything what i've learned. 
Tried some easy projects to do completely on my own and most of the time drew a blank on where to begin. And since i have really high expectations of myself, this is not.. was not acceptable. 

<h2>So, what am I going to do now..</h2>

Well one of the 1st things I had to get into that stubborn head of mine was, that I've just picked up on a bunch of new knowledge.. and I mean A BUNCH! While doing the full course in about 35 days. I can't expect from myself to just remember everything in the 1st go. 
I took a few days off, done some article reading I've saved during that period. Afterwards I visualised and wrote down my plans on where to head from here. 

And the main thing I have to keep in mind.. remember, You have just begun!  

<h2>The enveloping darkness</h2>

I think it's important to keep reminding yourself to be patient. As it is a virtue we're not acustomed to anymore. But this has been my problem since my younger days. Always trying to reach for the stars. 
Or better yet, having the problem of seeing the bigger picture. This entails the awareness on how much I lack, instead of what I have learned and just continue on from there.

With that said I have this saying in mind when noticing where my mind is taking me. It helped me get through the workouts when I did competative sports and I think it applies here.

<i>The journey of a thousand miles begins with a single step</i>

<h2>GO!, GO!, POWER RANGERS!!</h2>

So after reading and ploting my voyage through the oceans of WebDev I noticed many articles write about keeping a journal of your voyage. 

I think the single hardest thing for me is writing my journey down.. I'm just not that guy. Most people have gone through the same things, so what do I have to contribute? 
After a few days of deliberation, just got to the undertanding that the question itself is moot. And doing something which isn't comfortable, usually helps you grow as a person.

So basically everything I do is an investment in me. And this serves as a tool for that. Learning via explanation. It's the same in sports. 
If you're aware of correct movement patterns, you will stick by them more thoroughly. And after a while, it just becomes second nature. 

Greatness is a practice, not a status. <i>- lol, sports sure do have a plethora of awesome quotes, don't they</i>
CodePen of this Week - A New Series
Tags: codepen, beginners, webdev, javascript
Published: 2019-12-27 13:39:33

Hi,
It's a new mini chunk series 😁, and it's not official or I'm not calculating it based upon most likes and views. It's based upon my reaction when I saw the pen first time.

There are so many pens to feature but I'll just put one every week.
New Episode will be out every Friday. So Stay Tuned
----

### TorchLight Show Password
{% codepen https://codepen.io/hexagoncircle/pen/zYxzQqa %}

It was first looking like a simple form but when I entered my password and clicked the show password, I jumped from my seat and my butt still hurts 😣. Devs are being so creative. So I decided to start the series with this pen.


Share this post on Twitter and don't forget to tag me 😉 [@justaashir](Twitter.com/justaashir)

Note: Please DEV, do something with emojis to make them more natural
Custom colors in oh-my-zsh themes
Tags: beginners, productivity, terminal, shell
Published: 2019-12-27 13:37:54

# Custom colors in oh-my-zsh themes


So, I was trying to configure my custom zsh theme. I wanted something minimal like displaying the current user, a shortened path and the git info of a directory (if there is).

After a few hours of tinkering, I pretty much got what I wanted but the only thing I didn't like was the colors available. 

I wasn't sure which file to look for that contains the `fg_bold` and `fg`.


I did try doing a ripgrep: `rg fg_bold` hoping that I would find a list of available colors. But all I found were `.zsh-theme` files that were using a fixed set of colors. Magenta, green, blue, yellow, cyan were the ones I found.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/z2y2plbzbfrodebb8p2o.png)

I wasn't satisfied with the colors available and I did some trial and error by doing `$fg_bold[orange]`, `$fg[pink]`, etc. But I had no luck.


I did some google search about defining custom colors in zsh and it led me to this GitHub issue: https://github.com/ohmyzsh/ohmyzsh/issues/1101#issuecomment-5450278


It seems that oh-my-zsh uses `Spectrum` under the hood. The source code can be found under `~/.oh-my-zsh/lib/spectrum.zsh`.

Upon checking the source code, I tried running `spectrum_ls` on my terminal and I was amazed by the output :asto

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/h70s2gr8ixj5v9sjwq7z.png)


I can now use custom colors on my custom zsh theme via `$FG[<0-255>]` e.g. `$FG[021]`


So, that's it! I just wanted to share how I managed to define custom colors in my zsh setup.

I mainly use Python and Javascript so I did add a few customizations like displaying the node and python version of the current environment.

I made a minimal version of the theme I was working on for those who might be interested: https://github.com/yujinyuz/dotfiles/blob/master/zsh/themes/jpro-minimal.zsh-theme

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/bfoqnvqv9dh6135xog1p.png)

You can check out the documentation on adding themes to oh-my-zsh: https://github.com/ohmyzsh/ohmyzsh/wiki/Customization#overriding-and-adding-themes

Thanks for reading! It was a great experience writing my first article here on dev.to after being a member for about 2 years now 😅
I'm giving away free copies of "The Little JavaScript Book"
Tags: javascript, beginners
Published: 2019-12-27 13:33:00

---
title: I'm giving away free copies of "The Little JavaScript Book"
published: true
description: I'm giving away free copies of "The Little JavaScript Book"
tags: javascript, beginners
---

Hello friends! To celebrate these holidays I'm giving away free copies of "The Little JavaScript Book". 

![The Little JavaScript Book](https://thepracticaldev.s3.amazonaws.com/i/sfx6qc6v3ii98qgfk2r2.png)

Follow [me on Twitter](https://twitter.com/gagliardi_vale/) and DM me for a free copy!

Happy holidays!
[SOLVED] Node.js ERR_SSL_VERSION_OR_CIPHER_MISMATCH
Tags: help
Published: 2019-12-27 12:39:26

Hello everyone,
I am using Node.js to host a webserver with both http and https, and I have generated my self signed certificate via the openssl commands:
```
$ openssl genrsa -des3 -out rootCA.key 2048
$ openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.crt
```

However when I try to connect to https://127.0.0.1:8080 or https://localhost:8080 or the machine's IP from another device I always get ERR_SSL_VERSION_OR_CIPHER_MISMATCH

What could it be? I have been trying to figure out for a while now and I can't understand what is the issue.

## Server code
```
.env

PASSPHRASE=dummyPass
HTTPS=true
HTTPPORT=8079
HTTPSPORT=8080
KEY=rootCA.key
CERT=rootCA.crt
```
```
server.js

const httpsEnabled = process.env.HTTPS == 'true' || false;
if(httpsEnabled)
{
  const httpsPort = process.env.HTTPSPORT || 8081;
  const httpsServer = https.createServer(credentials, app);
  
  const keyStream = path.resolve(`./${process.env.KEY}`);
  const certificateStream = path.resolve(`./${process.env.CERT}`);
  const privateKey  = fs.readFileSync(keyStream, 'utf8');
  const certificate = fs.readFileSync(certificateStream, 'utf8');

  const credentials = {key: privateKey, cert: certificate, passphrase: process.env.PASSPHRASE};
  
  httpsServer.on("error", () => {
    console.log(`Could not start the app on port ${httpsPort}`);
    process.exit();
  });
  httpsServer.listen(httpsPort, () => {
    console.log(`App listening for HTTPS requests to https://127.0.0.1:${httpsPort}/`);
  });
}
```

## Solved:

I'm stupid, I started the server before reading the credential. This is the fixed code:
```
server.js

const httpsEnabled = process.env.HTTPS == "true" || false;
if (httpsEnabled) {
  const keyStream = path.resolve(`./${process.env.KEY}`);
  const certificateStream = path.resolve(`./${process.env.CERT}`);
  const privateKey = fs.readFileSync(keyStream, "utf8");
  const certificate = fs.readFileSync(certificateStream, "utf8");
  const credentials = {
    key: privateKey,
    cert: certificate,
    passphrase: process.env.PASSPHRASE
  };

  const httpsPort = process.env.HTTPSPORT || 8081;
  const httpsServer = https.createServer(credentials, app);

  httpsServer.on("error", () => {
    console.log(`Could not start the app on port ${httpsPort}`);
    process.exit();
  });
  httpsServer.listen(httpsPort, () => {
    console.log(
      `App listening for HTTPS requests to https://127.0.0.1:${httpsPort}/`
    );
  });
}
```