teleren/devto huggingface dataset:
What’s your alternative solution? Challenge #35
Tags: challenge, javascript, codenewbie, learntocode
Published: 2020-05-05 21:37:45

# About this series

This is series of daily JavaScript coding challenges... for both beginners and advanced users.

Each day I’m gone present you a very simple coding challenge, together with the solution. The solution is intentionally written in a didactic way using classic JavaScript syntax in order to be accessible to coders of all levels.

Solutions are designed with increase level of complexity.

## Today’s coding challenge

```
Create a function that will return the number of words in a text

```

(scroll down for solution)

## Code newbies

If you are a code newbie, try to work on the solution on your own. After you finish it, or if you need help, please consult the provided solution.

## Advanced developers

Please provide alternative solutions in the comments below. 

You can solve it using functional concepts or solve it using a different algorithm... or just solve it using the latest ES innovations.

By providing a new solution you can show code newbies different ways to solve the same problem.

## Solution

```javascript
// Solution for challenge31a

function countWords(text)
{
    var wasSeparator = true;
    var words = 0;
    
    for(var c of text)
    {
        // if current character is separator then advance and
        // set that the previous character was separator
        if (isSeparator(c))
        {
            wasSeparator = true;
            continue;
        }

        // if current character is not separator
        // ... but if previous was separator...
        if (wasSeparator)
        {
            words++;
            wasSeparator = false;
        }
    }
    
    return words;
}

function isSeparator(c)
{
    var separators = [" ", "\t", "\n", "\r", ",", ";", ".", "!", "?"];
    return separators.includes(c);
}

println(countWords(""));
println(countWords("            "));
println(countWords("JavaScript!!!   "));
println(countWords("     JavaScript"));
println(countWords("    JavaScript is cool      "));
println(countWords("I like to learn JavaScript with codeguppy"));

```


To quickly verify this solution, copy the code above in this coding [editor](https://codeguppy.com/code.html) and press "Run".

> Note: The solution was originally designed for [codeguppy.com](https://codeguppy.com) environment, and therefore is making use of `println`. This is the almost equivalent of `console.log` in other environments. Please feel free to use your preferred coding playground / environment when implementing your solution.
Creating a JAMstack blog using Contentful and Nuxt with fetch()
Tags: Nuxt, Contentful, Netlify
Published: 2020-05-05 20:37:34



Sarah Drasner (@sarah_edo) recently posted [a great tutorial][1] on how to build a blog with Nuxt and Contentful hosted on Netlify.  Sarah is a great teacher and I have learned a lot from her tutorials.  I used this tutorial to build a quick blog and it was super easy.

In the tutorial, she uses Vuex to store the blog posts for the summary page and the individual dynamic blog pages.   However, I noticed that in the 2.12 release of Nuxt, they updated how the fetch() method works (there is a great [blog post][2] on their site that explains all the details).  Using this updated method makes building a blog even easier --- and you  don't have to involve Vuex at all.

In Sarah's tutorial, she created an action in her Vuex store like this...

```
export const actions = {
 async getPosts({ commit }) {
   try {
     if (!client) return;
     const response = await client.getEntries({
       content_type: "blogPost"
     });
     if (response.items.length > 0) commit("updatePosts", response.items);
   } catch (err) {
     console.error(err);
   }
 }
};
```

 But with the new fetch method, you can move this logic into a Vue component as follows...

```
<script>
import cms from "~/plugins/contentful"

export default {
  async fetch() {
    try {
      if (!cms) return
      const response = await cms.getEntries({
        content_type: "blog"
      })
      if (response.items.length > 0) this.posts = response.items
    } catch (err) {
      console.error(err)
    }
  },
  ...
```



Similarly, you can use fetch in the dynamic post component as follows...

```vue
import cms from "~/plugins/contentful"
export default {
  async fetch() {
    try {
      if (!cms) return
      const response = await cms.getEntries({
        content_type: "blog",
        "fields.slug[in]": this.$route.params.slug
      })
      if (response.items.length > 0) this.post = response.items[0].fields
    } catch (err) {
      console.error(err)
    }
  },
  ...
```

Notice, since I don't have access to the post id, I grab the posts that match the slug in the params and use the first (and only) item in the returned array.

One of the nice features of this fetch method is that it exposes a `$fetchState` object with three useful keys...

```
$fetchState = {
  pending: true | false,
  error: null | {},
  timestamp: Integer
};
```

For example, you can add some conditional logic in your Vue template to show while the posts are being fetched from Contentful...

```vue
<p v-if="$fetchState.pending">Fetching posts...</p>
```

I'm really enjoying building things with this combination of Nuxt, Contentful and Netlify (I also use TailwindCSS for styling).  And this new `fetch()` method makes Nuxt even easier to use with third-party data sources.

Hope this helps!



[1]: https://www.netlify.com/blog/2020/04/20/create-a-blog-with-contentful-and-nuxt/
[2]: https://nuxtjs.org/blog/understanding-how-fetch-works-in-nuxt-2-12
Covid-19 Tracking App
Tags: react, node, javascript, computerscience
Published: 2020-05-05 21:03:17

Coronavirus disease (COVID-19) is an infectious disease caused by a newly discovered coronavirus. Corona Virus is, unfortunately, spreading through the entire world. As far as of today we don't have any vaccines for this infectious disease. Scientists all around the world are trying their best to develop a vaccine for this disease. Government around the world are trying to limit the cases in their countries so as to flatten the curve and prevent further infection into its people.

What can we, as developers, do to make the situation better? We can help to spread awareness by visualizing the data. 
This is my small effort to develop a COVID-19 Tracking app based on react.
It is a COVID-19 Tracker/Stats Application. I have used React with the addition of Charts.js, Material UI, and many different modules. The data is fetched from the API and cards are created displaying the statistics as well as Charts. This project/application is created using the most modern JavaScript syntax. Along the way, I have used Material UI, Charts.js, React Hooks, API data fetching, all of it in React JS!

App Link: https://covidtrackerglobe.netlify.app/


Here are few of the screenshots of the App
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ky8olsfhv2wbfvc7fav1.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/2jjxfbc4zrb44cnpm2p3.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/5nct7nr2pempfpq6ne1k.png)


API: https://covid19.mathdro.id/api
Github: https://github.com/maaz1996/covid-19
How to automate nuget updates?
Tags: dotnet, csharp, help
Published: 2020-05-05 20:59:31

In the company I work for we host a nuget service, containing mostly infrastructure Dlls and stuff like that.

Every once in a while someone makes a braking change to a service one of these Dlls is talking with (not necessarily the same Dll every time), so that all applications and services using that dll must update the nuget reference, update their own version, rebuild, and either be published to nuget themselves, or installed as services on the client's server.

Currently, we do that manually - opening each solution in VS, and as I'm sure you can guess, that process is both extremely annoying and time consuming. 

I'm looking for a way to automate this entire thing - preferably using c# to do all the heavy lifting for us - update the relevant package, update the version number, and rebuild. Of course this should be configurable - what projects to handle and what packages to update.

So before I start making suggestions to my team leader about wanting to build such a thing - I thought I'd better ask around if anyone knows of such a tool already existing out there (doesn't even have to be a free tool), preferably an open source c# so that we could mess around with it's internals if need to.

Thanks in advance,
Zohar.
Learning Web - 02
Tags: webdev, css, beginners, javascript
Published: 2020-05-05 20:43:45

After following through the first tutorials on the basics of javascript and DOM I've done this second project/exercise to practice stuff before moving on to the more advanced lectures. 
I did a very simple (and at the moment buggy :P) task management and time tracking tool. 
[here is the result on my githubpage](https://vguerreiro.github.io/tasker-webdev-xperiment-01/) .Now it's time for more learning!
About Ruby Hash#fetch
Tags: ruby, hash, documentation
Published: 2020-05-05 20:28:52

---
title: About Ruby Hash#fetch
published: true
description: 
tags: ruby, hash, documentation
---

Get more information and more examples at my AboutRuby project:
* [AboutRuby project](https://github.com/BurdetteLamar/AboutRuby/blob/master/core/Hash/api/markdown.md#fetch)

Here's the write-up over at the Ruby project:
* [Ruby project](https://ruby-doc.org/core-2.7.0/Hash.html#method-i-fetch)
Gostaria de fazer um app?
Tags: help, contributorswanted, design, javascript
Published: 2020-05-05 20:17:42

---
title: Gostaria de fazer um app?
cover_image: https://vignette.wikia.nocookie.net/rickandmorty/images/3/30/Glootie.png/revision/latest?cb=20190720005839 
published: true
description: 
tags: help, contributorswanted, design, javascript
---

Em 2010 eu estava aprendendo a programar para MacOS/iOS e decidi tentar implementar uma versão 360° do clássico "jogo da cobrinha", onde você controla uma serpente que vai aumentando de tamanho conforme você pega umas pelotas espalhadas pelo cenário, e precisa cuidar para não colidir com as paredes e com o próprio corpo.

Link para um vídeo demonstrativo: https://www.facebook.com/filipe.roberto.beck/videos/326847864065401

Na época, usei basicamente C e C++. Agora, quero refazer (e terminar) em Javascript. Se alguém quiser contribuir com as imagens, ficarei muito agradecido. A príncipio, as imagens necessárias serão:

- 1 Cabeça
- 1 Escamas
- 1 Fundo (disposto em mosaico)
- 1 Bloco para parede (disposto em fila)

Também seria legal algumas imagens para o logo e tela de recordes.

Caso alguém queira contribuir, é só me enviar uma mensagem :slightly_smiling_face:. Se não souber português, não tem problema. Podemos usar um `Dependency Inversion Pattern` e nos comunicar através da interface `Google Translator` :clown_face:
Leadershipt in dev teams, how to become a tech leader?
Tags: leadership, techleader, career
Published: 2020-05-05 20:12:55

---
title: Leadershipt in dev teams, how to become a tech leader?
published: true
description: How to become a tech leader?
tags: #leadership #techleader #career
---

Hello, I've been working as a developer for just over 9 years, and I realized for a while that I like the leadership part, even without being a tech leader, I end up taking responsibilities for myself, managing, giving feedbacks, etc., I would like tips on how to specialize in this area, content (video, books, podcasts) and I would also like to hear your experience with this subject! : D
Change Ant Design Theme dynamically in React Create-React-App
Tags: cra, antd, theme
Published: 2020-05-05 20:01:59


Recently I had a project where I needed to change Ant Design theme dynamically to support different business brands. In this article, I will show you how to do it generally step by step and save your time.

Based on I search, there are two mature libraries can be used to build this function:

antd-theme-generator
antd-theme-webpack-plugin

I have tried both libraries and have many problems during the implementation. In this article, I will show you how to use antd-theme-generator to implement this function.

Check more:

https://annacoding.com/article/gVcF6qCZkfnM3JOnPxBqx/Change-Ant-Design-Theme-dynamically-in-React-Create-React-App
TIL about Ruby command line execution
Tags: ruby, commandline, todayilearned, microlearning
Published: 2020-05-05 20:01:22

---
title: TIL about Ruby command line execution
published: true
description: You don't need irb at all!
tags: ruby, command_line, TIL, microlearning
series: Learning while Doing
cover_image:
---

_This is a walk-with-me-while-I-do-things series, I'm going to tell you what I learned while I'm learning_

You can execute a Ruby file by passing it on as an argument to the `ruby`. What if I told you you can require a library and give executable code directly to the command on the terminal? 

The `ruby` command supports two options among others:
`-r` stands for `require` and receives as an argument the name of the Ruby file you want to load
`-e` stands for `execute` and receives as an argument a script

Let's have a file in the current directory called `hello.rb` that defines the Hello class like this:

```ruby
class Hello
  def greet
    puts "Hello there!"
  end
end
```

By running
```bash
ruby -r "./hello" -e "h = Hello.new; h.greet"
```
the prompt will present you with the following output

```
Hello there!
```

You can even write a multiline script as if you were writing in a file

```bash
➜  first-repo git:(master) ✗ ruby -r "./hello" -e "
dquote> h = Hello.new
dquote> h.greet
dquote> "
Hello there!
```

Here is [the documentation](https://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/options.html) for all the options you can feed to the `ruby` command
What I learned from finishing Udacity's four-month Blockchain nanodegree in one month
Tags: blockchain, motivation, womenintech
Published: 2020-05-05 19:53:49

Udacity was offering a one month free promotion due to the coronavirus, and I wanted to take advantage of it.  I signed up on the website, entered my credit card info, and took note that I would have $400 dollars charged to my account if I didn't graduate (finish the program) or cancel my subscription before my month was up.  (To put things into perspective, the program is designed to take four months to complete.)

Perhaps Udacity was looking to build their customer base, but renewing my subscription was not a viable option for me.  I couldn't spare four hundred dollars when the same amount would pay for eight units of college tuition.  

It wasn't really a choice.  I could either go partway through the program and possibly never finish it, or I could try to complete it in a month.

Since I can't live without challenges, I chose the latter.  And here's what I learned from it.

# The beginning may be easy, but it's the end that counts.

At first, putting in three to six hours a day, six days a week in this one thing was *fun*.  But after the first or second week, I began to feel drained.  

The content became more difficult.  The projects took a lot of time.  I had midterms for school coming up, and a magazine design deadline to meet.  I had so much on my hands - but then I learned my second lesson.

# You have to push yourself.  No one else is going to do it for you.

I wanted to do this.  So I had to force myself to sit back, watch hours of videos on blockchain, and work through debugging a bunch of errors (many due to old code).  My brain literally felt dead in the middle of the afternoon.

What got me through was the knowledge that *I wanted this* and could do it, and the fact that I wasn't going to get anywhere if I didn't tell myself to start working.  *I* had to push myself.

# Sometimes you should take a break...or not

On the third week, I became so exhausted I unintentionally took two days off.  Sure, it was great to have a day when Blockchain wasn't on my mind.  But on the other hand, I lost valuable time.  I ended up having to stay up late to finish the last two projects, which made me pretty sleepy during class those days.  Not ideal, but bearable.

# Cramming isn't fun

I wished I'd had more time to absorb and explore the material on Solidity, Ehtereum, Truffle, and more I was presented with.  But since I was on a time crunch, I missed out big time.

# Community matters

My family totally supported me during the whole thing.  They gave me alone time to finish up the projects I needed to submit, encouraged me along the way, and celebrated with me...

# ...at the end...

I felt absolutely WONDERFUL when I received the completion certificate.  I'd done it!  Maybe I wouldn't start a career in blockchain, but I'd always remember the moment and what it took for me to get there.
Stack Overflow Command Line Search Tool
Tags: ruby
Published: 2020-05-05 19:51:22

---
title: Stack Overflow Command Line Search Tool
published: true
description: A stack-overflow terminal search tool
tags: ruby
---

# Why StackOverflow?

StackOverflow has been around for many years and it has been really a powerful tool for my every technical role. So i decide to make this site available for my use in terminal. For my current role I get to work with server Maintenance, Monitoring and Backup. This will be a great search tool when working with remote servers and you don't have to open a browser to search for errors fix ideas. 

Finished Tool: https://github.com/jenzzly/jenzzly


## 1. Stack Overflow API customization

You will need to customize your search to your liking on this ' https://api.stackexchang.com/docs/answers' remember there is a limit on how much to hit the request. 

Example: https://api.stackexchange.com/2.2/answers?order=desc&sort=activity&site=stackoverflow 

## 2. Ruby Script 

Here is my ruby script but remember your can write your own as well and change however you want it.

{% github jenzzly/jenzzly %}

## 3. Publish as Gem CLI

I chose to publish as gem mostly because it was easier and I like ruby anyway. For creating a gem please follow this repo below. 

{% gist https://gist.github.com/ahcode0919/9cd476c8ce7bccb5eafae679f5754267 %}

## 4. Usage

Once done with Installation you can use your new tool like this: Mine is called "jenzzly" and my search will be
"jenzzly your_key_word_search_text".

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/urgqa273u97b6d078zk1.png)
### Results
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/v8832ybn0e3noefajp8v.png)
Write a 10-minute Go app to serve video from a web page
Tags: go, cloudstorage, tardigrade, tutorial
Published: 2020-05-05 19:38:09

---
title: Write a 10-minute Go app to serve video from a web page
published: true
description: Write a fast, easy app in Go in 10 minutes that uploads, downloads and serves video  from the Tardigrade storage platform in a web page. JT Olio narrates a short live-coding demo you can follow along. 
tags: go, cloudstorage, tardigrade, tutorial
---

This is a livecoding demo video I helped my friend/colleague JT produce for the company Town Hall that I put on every quarter. Basically, it shows - in golang -  how to upload, download and serve video from our S3-compatible cloud storage platform. 

you may obtain the sourcecode via https://gist.github.com/jtolio/9faad0981ece6d8427aa6903081d281c

I spent a lot of time working out the timestamps for the various steps, because I myself really like to be able to jump to specific spots in a video, especially when I want to check that I haven't skipped a step. So if thats also helpful to you too, here they are: 


0:00 Intro
0:30 Create your account
0:50 Make an API key (end-to-end encryption)
1:14 Make an access grant with Uplink tool
1:17 Set up the Uplink tool and set Access Grant name
1:32 Enter encryption passphrase
1:49 Make a bucket and name it
1:55 Share bucket with a Go program
2:07 Put the access grant into a Go program
2:17 Create "demo" folder with document called "main.go"
2:33 Define the access grant
2:45 Define a main method to handle basic bookkeeping
3:06 Parse the access grant
3:19 Open a project and make a small web interface to show files (listener MUX)
4:10 Hello World
4:20 Run go main.go to test the web serve is working
4:54 List the videos in the bucket (root endpoint)
5:32 List all the objects in bucket and make an iterator
6:04 Step through the iterator
6:38 Execute page template
7:04 Connect the HTML form element so files can be uploaded
7:10 Add upload target, add upload method
7:22 Stream data straight from the bucket into the Uplink Library via multipart reader
7:52 Loop though the mulitpart responses for the form element called "file"
8:14 Call UploadObject on the Uplink library
8:18 Pass the filename that was uploaded
8:25 Copy the data in and commit the object
8:37 RECAP: what we just wrote
8:56 Upload a sample file to the live network, to test the app
9:10 Serve the data via a serve endpoint
9:45 How to download 
9:55 Get the context
10:00 Get the object
10:45 Run the code 

I manage the technical community at Storj Labs/Tardigrade so naturally I also made a forum thread there, if you'd care to visit: https://forum.storj.io/t/demo-code-to-upload-serve-and-download-video-from-a-web-page-jt-video/6093
Joy Inc
Tags: career, management, motivation, agile
Published: 2020-05-05 19:38:08

Hey guys, 

I'm sorry if it is offtopic, but I've started blogging about books I've been reading. 

This is my perspective from Joy Inc, which brings a unique framework for software development including pair programming, pen and paper management and no coding marathons. I hope you enjoy it.

[Blog post] (https://blog.simbioseventures.com/2020/03/31/together-we-stand-divided-we-fall/)

Cheers