teleren/devto huggingface dataset:
Make it, just to get it out of your head.
Tags: tips
Published: 2020-04-12 22:01:34

---
title: Make it, just to get it out of your head.
published: true
description: 
tags: #tips
---

Now I've been the guy who just throws out repositories right left and center, hasn't completed projects and mostly have them on pending for a really long time unless something really motivates me to work on that project again. 

I still end up making these things again and again just because I think that it's good to get that thought out of your head and out into code because you get to the point where you realize whether that project is actually going to be something you yourself would use. 

I ended up building a lot of stuff that I do personally use and maybe no one else does because I haven't published anything about those projects anywhere and I'm the only one who knows about their existence. On the contrary there's double the number of repos that even I don't care about anymore.

The whole process of thinking and getting it out into the world of code gets you through scenarios that get you to realize and also sometimes learn about things that you might be doing wrong. 

I've got this really old music player that I built using RiotJS, 0 folder structure, 0 modularity, just plain working code.When I went back to it to make changes or add features, I realized that I don't plan out my projects and jump straight to prototyping, the next time I built the same thing on Vanilla JS, the code was a 100 times better because I had a mental image of things I needed to separate and things that need to be maintained to avoid having spaghetti code in the later stages of maintenance. 

These subconscious decisions help you out in the later stages a lot. 

I don't use that player anymore but it's taught me something.
so did the todo list(which everyone has built at some point in their coding life)
and so did the other 100 repos that I have on my github

and after all of this reading, the moral was basically the title of this post.
Rails Backend: Slug Endpoints
Tags: rails, webdev, tutorial
Published: 2020-04-12 21:58:26

When following [RESTful routes](http://www.restular.com/) design pattern, if you want to see data associated with a specific item, you need to provide its id. For instance, if we have a `Snail` model and we'd like to see information about garden snail, we'd need to know that its id is 1 in our database to get data from this endpoint:

`/snails/1`

This is not perfect because while it's understandable by our database that 1 stands for the garden snail entry, we humans don't find it too straightforward. Wouldn't it make our life and frontend design much easier if instead we could call:

`/snails/gardenSnail`?

This kind of endpoint is what we call `slug` or `vanity url`. Let's build one!

## 1. Controller

In our controller, we need to specify now that the attribute we will use to look for a snail is no longer `id` but `name`. 

``` ruby
class SnailsController < ApplicationController
   before_action :find_snail, only: [:show]

    def show
        begin
            render json: @snail, status: 200
        rescue StandardError => e  
            render json: {"error": ("#{e.message}") }, status: 400
        end
    end

    def find_snail
        @category = Category.find_by(name: params[:name])
    end
end
```

**note:** It doesn't have to be a name, it can be anything you want as long as it's an attribute in the database. If you want to create a very confusing slug (e.g. to obfuscate it), then you could add `slug` attribute and make the `to_param` method return a random string e.g. by using [uuid gem](https://rubygems.org/gems/uuid/versions/2.3.8).

## 2. Routes

Now, let's overwrite the RESTful `id` with `name`:

``` ruby
Rails.application.routes.draw do
   get '/snails/:id', to: 'snails#show', as: 'snail', param: :name
end
```

Or, if you are fond of using resources:

``` ruby
Rails.application.routes.draw do
   resources :snails, param: :name, only: [:index, :show]
end
```

Aaaaand... that's it! Here's a picture of the garden snail:
![garden snail on a green big leaf](https://images.pexels.com/photos/209074/pexels-photo-209074.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260)
Singleton Pattern in JavaScript
Tags: node, javascript, closure, singleton
Published: 2020-04-12 21:55:39

If you come from Java or C++ background, you are probably used to classic OOP model, and it is hard to imagine how you can implement singleton in JavaScript. The answer to this question is to use closures!

It is the same idea as module patterns, and comes from functional programming. The essence of closure, is creating an inner function in a scope of an outer function. If you know JS, you know that inner function has access to data members that are in the scope of the outer function. So, as long as you preserve a reference to the inner function, you can access enclosed members of the outer function, even when the outer function finished its execution. It may take some time to get your head around this definition!

Anyway, it is often easier to show something in code than explain in natural language!

Here is an example of singleton http client, which wraps an axios library:

```javascript
let http = (function () {
  let axios = require('axios')

  return {
    get: function(url) {
      return axios.get(url)
    },
    post: function(url) {
      return axios.post(url)
    }
  }

}())
```

As you can see we create an [IIFE](https://developer.mozilla.org/en-US/docs/Glossary/IIFE), holding instance of axios client in its scope. IIFE immediately resolves to a function containing get, and post methods. This way, we not only create a singleton instance of http, but also encapsulated axios from the rest of out program. 

We still however, can access methods of axios instance using get and post functions, returned from closure:

```javascript
http
  .get('https://baconipsum.com/api/?type=all-meat&paras=1&start-with-lorem=1')
  .then((res) => console.log(res.data))
```

I know it is a lot of information for only few paragraphs of text. If you want to learn more about closures, or JS in general, I highly recommend watching [FrontendMasters course by Douglas Crockford](https://frontendmasters.com/courses/good-parts-javascript-web/). It is free for all students, under [GitHub Student Pack](https://education.github.com/pack)!
Rediscovering the Power of JavaScript in the Browser
Tags: todayilearned, javascript, html, 100daysofcode
Published: 2020-04-12 21:54:50

I've been doing JavaScript off-and-on for a long time, over 20 years. Periodically I forget that JavaScript is very powerful. That it's not the too-quickly-built language stapled into browsers anymore, that forces DOM hackery mitigated by jQuery. That I **must** use tools like Vue.js, React, etc. to make it work in the browser.

So when I rediscover yet again for the umpteenth time that JavaScript is powerful and works great natively with the DOM without frameworks, it's fun and exciting.

Let's explore a snippet of code I just wrote. I received a list of zip codes to be displayed in a dropdown list. First, I convert the zip codes to an array:

``` javascript
const zipCodes = `90004
90005
90006
90007
90008
<snipped for brevity>
`.split('\n');
```

Then I get the `select` element from the DOM:

``` javascript
const select = document.getElementById('grid-zip');
```

With the `zipCodes` array and `select` element ready, I construct the loop that adds the available zip codes to the form. Each line is commented t explain what I'm doing:

``` javascript
// Loop over the `zipCodes`, assigning each value to `zipCode`
// Python users take note I'm using a `for...of` loop to iterate
//   because `for...in` doesn't work as you would expect.
for (let zipCode of zipCodes) {
  // Create new option element, value and displayed text set to zip code.
  let option = new Option(zipCode, zipCode);
  // Inject the new option element into the select element.
  select.appendChild(option);
}
```

Altogether it looks like this:

``` javascript
// Convert the zip codes from a multiline string to an array
const zipCodes = `90004
90005
90006
90007
90008
<snipped for brevity>
`.split('\n');

// Get the select element from the DOM
const select = document.getElementById('grid-zip');

// Loop over the `zipCodes`, assigning each value to `zipCode`
// Python users take note I'm using a `for...of` loop to iterate
//   because `for...in` doesn't work as you would expect.
for (let zipCode of zipCodes) {
  // Create new option element, value and displayed text set to zip code.
  let option = new Option(zipCode, zipCode);
  // Inject the new option element into the select element.
  select.appendChild(option);
}
```
Hi Folks, Good to be Back!
Tags: devjournal, watercooler, covid, jobhunting
Published: 2020-04-12 21:26:06

---
title: Hi Folks, Good to be Back!
published: true
description: saying hello from quarantine and fresh from a covid layoff
tags: devjournal, watercooler, covid, jobhunting
cover_image: "https://media1.tenor.com/images/0cad29174f903830ecb11059448ced34/tenor.gif?itemid=5702456"
---

### Hi, Dev.to folks! Hope you’ve all been well and are staying safe!

I wanted to do an update/retrospective after my first few months of working at my first software engineering job…but a little while ago, it was part of the big wave of COVID-related layoffs. 

Luckily, I learned a HUGE amount during my 2 1/2 months there, so I’m here to share and explore those lessons!

### There are three things I plan to write about:
* I learned a lot of patterns and techniques for working with Rails and Vue—and I’m currently starting a project, QueerHub, to re-implement them on my own, entirely from scratch!
* Both last year and this year, I’ve accumulated some jobhunting advice, much of which comes from answering questions from other coding bootcamp graduates—I want to share my strategies, especially with respect to navigating mental health issues, queerness, and the current US quarantine
* One of the reasons I love Dev.to is that it’s a place to be my whole-ass queer self—I’m here to share my perspective as a queer trans woman, and ways to be a better ally to people like me while at work, while networking, and in general!

Good to be back, everyone—glad you’re all here, and looking forward to catching up! (And picking up some new video game and/or trashy TV recommendations to keep me sane!)

![anime gif of two characters hugging and crying](https://i.pinimg.com/originals/7f/76/10/7f76102bedf6de4e34065709d16a9ef8.gif)
*Accurate representation of how much I want to hug right now. <3*
A Small COVID-19 Initiative
Tags: covid, gridsome, netlify, ecommerce
Published: 2020-04-12 21:02:43

Hi all, hope everyone is holding up fine and staying strong.

I found that it's been a bit challenging in addressing the current climate as we all have been affected to different degrees and facing different challenges during this time.

I have taken a crucial decision to not consume news daily as it was starting to weigh on me. Although, I am staying hopeful as we are seeing collective essential actions from communities to help stop the continued spread of the virus. We all have a huge stake in this and need to show solidarity in working together as one. The societal, economic impacts are starting to take an enormous toll on everyone alike, and that is why we need to all lift each other out of this unprecedented time.

Under the circumstances, I am fortunate in that I am able to continue working but have been welling over how I can do my small part in contributing aside from WFH and social distancing. After seeing forum discussions and social media threads of people asking where to find a list of local businesses, merchants, artisans who have been affected by the current climate to support, I wanted to bootstrap together a simple but hopefully impactful listing directory. It is still a work-in-progress. I have a backlog of businesses from docs and spreadsheets that I will continue to add. Please share if you know anyone who might be in need of this listing, want to contribute a business, or perhaps may need some help with eComm efforts.

Please get in touch!

https://support-vancouver.netlify.com/
⬡ Hive — Team notes on web pages, stored in Airtable
Tags: opensource, showdev, vue, webdev
Published: 2020-04-12 20:59:40

I just open-sourced my very first project 🥳 https://github.com/seifip/hive-notes

**Hive** is an internal company browser extension that lets your team attach tips and warnings to any web page.

Notes are stored in your own company Airtable, so you're always in control of your data.

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

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/70z3emaypl293eggwvpn.png)

This extension was originally created for the buying team at White Rabbit Express, but it could be invaluable for any group or organization repeatedly interacting with different websites.

What's the most impactful or creative use case that you can think of?
My New New Web Series
Tags: video, programming
Published: 2020-04-17 12:33:43

---
title: My New New Web Series
published: true
date: 2020-04-12 20:48:27 UTC
tags: Video,Programming
canonical_url: http://wildermuth.com/2020/04/12/My-New-New-Web-Series
---

![](https://wilderminds.blob.core.windows.net/img/youtube.png) With the pandemic, I'm getting bored at the house. And if you know me, you know I need a project. My wife has already heard all of my stories, so I have to start recording myself.

The idea with this series is to talk about the inner world of developers. I might dig into some technology, but usually in a more general way. I'm still getting used to shooting in my office, so bear with the giant head.

<iframe src="https://www.youtube.com/embed/0CzGpYGVZHk" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>

I'm going to do my best to do one of these each week. If you have some things you'd like me to rant about, please comment below!

[![Creative Commons License](http://i.creativecommons.org/l/by-nc-nd/3.0/88x31.png)](http://creativecommons.org/licenses/by-nc-nd/3.0/)

          This work by [Shawn Wildermuth](http://wildermuth.com) is licensed under a [Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License](http://creativecommons.org/licenses/by-nc-nd/3.0/).  
          Based on a work at [wildermuth.com](http://wildermuth.com).

* * *

If you liked this article, see Shawn's courses on [Pluralsight](http://shawnw.me/pscourses).
 ![](http://feeds.feedburner.com/~r/ShawnWildermuth/~4/dcu5TOCsJ-c)
Priority Queue
Tags: javascript, webdev
Published: 2020-04-12 20:32:42

A priority queue does not work on First in First Out principle rather it returns item with highest priority.
We will be designing a priority queue in which we add elements to the queue according to its priority(ie;first item in queue has highest priority)

##Properties of our Priority Queue
1.Each item has a priority number associated with it.
2.Items added to queue as per their priority.
3.Items with lowest priority numbers are removed first(first item in queue).

##Implementations
1.Create item and queue class

```javascript
class Item {
  constructor(data, number) {
    this.data = data;
    this.number = number;
  }
}

class PriorityQueue {
  constructor() {
    this.items = [];
  }
//add methods
}
```
The item class stores the item data and it's priority number.
The the priority queue class instantiates an array used to store items.

2.Add methods to class

**Enqueue**
```javascript
enqueue(data, number) {
   //create new item
    let item = new Item(data, number);
    let addedFlag = false;

      //loop through array, to end of array
      for (let idx = 0; idx < this.items.length; idx++) {
        //if new item has a lower number
        //add new item before current item
        if (this.items[idx].number > item.number) {
            this.items.splice(idx, 0, item);
            addedFlag = true;
            break;
        }
    }
//default action is to add item at the end of queue
    if (!addedFlag) {
      this.items.push(item);
    }
    }
```
The enqueue method adds item to queue according to it's priority. A higher number given to item means the item has a lower priority compared to item with a lower number. 
Example;
item A with priority number 2 and item B with priority number 1. Item B is of a higher priority than A. Hence A is pushed to end of queue and B front of queue.

**Dequeue**
```javascript
dequeue() {
        //if empty do nothing else remove first item in queue
        if (this.items.length === 0) {
            return;
        }
        this.items.shift()
    }

```

**peek**
```javascript
peek() {
        //if not empty return first item in queue
        if (this.items.length === 0) {
            return "Empty queue";
        }
        return this.items[0].data;
    }
```

**Test Code**
```javascript
const queue = new PriorityQueue();
queue.enqueue(3, 4);
queue.enqueue(6, 5);
queue.enqueue(7, 3);
queue.enqueue(8, 1);
queue.dequeue()//removes 8 from queue
console.log(queue.peek()) //prints 7

console.log(queue);
```
Upgrading React Native to RN0.60+, React/RCT***.h file not found[Solved]
Tags: reactnative, ios, javascript, react
Published: 2020-04-12 20:23:06

Hi, i just went through some issues while upgrading from RN59 to RN0.61 to i though i may want to share my thoughts and how i managed to solve those issues . 
https://medium.com/@hamoudaarfawi/upgrading-react-native-to-rn0-60-react-rct-h-file-not-found-solved-e9bd65fc4ee6
libusb backend for adb on macOS
Tags: android, todayilearned, todayisearched
Published: 2020-04-12 20:23:06

---
title: libusb backend for adb on macOS
published: true
description: The Android Studio option that took away my sleep for a week
tags: android, todayilearned, todayisearched
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/tfn8liy4h52oska9omuy.png
canonical_url: https://fdo.cr/libusb-backend-for-adb-on-macos/
---

For the past week I was stuck on what felt like a dead end. Although a bit more comfortable now than where I stood a few weeks ago I'm still learning the ropes of Android development, and this problem caught me outside my comfort zone.

## device not found

At first it took me by surprise because the device was detected as usual.

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

However, Android Studio failed to install when trying to run/debug because "the device was not found" (as shown in the article cover photo). The device was no longer detected after that.

"It was just right there 🤔" - Me

None of my ideas worked, ranging from updating/reinstalling everything to a factory reset for the phone (twice because one isn't enough to be sure).  I quickly found myself in the 'Google Failure' side here:

{% twitter 1225203007442366464 %}

Just the week before I was able to debug flawlessly from within Android Studio. Using Gradle to install directly from the terminal was still working though, something wasn't right.

## Android Debug Bridge (adb) & libusb

I finally stumbled with [this SO answer](https://stackoverflow.com/a/58492367/3462026). Even if the error wasn't an exact match with mine it happened to fix the problem along with a clean build.

The solution was to uncheck the option that enabled the use of [libusb](https://github.com/libusb/libusb/wiki) as backend for [adb](https://www.developer.com/ws/android/using-android-debug-bridge.html).

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1bdjox2u28dvm4ki0j63.png)

I'm not sure if this option was enabled "silently" after an update, or if this was always enabled and something broke. At least I'm more aware now of lower level tools like libusb that work (or don't work) with adb on macOS.

I only hope this write-up gives this option a bit more visibility for anyone that may encounter the same problem in the future. Pura Vida!
Kotlin - Smart Solutions #0
Tags: kotlin, beginners
Published: 2020-04-12 20:15:58

Hello World, this is the first post of a series in which I want to share to you some cool Kotlin features. 

# The Problem (Make Array Consecutive)

I've faced this problem at [Code Signal](https://codesignal.com/) (it's a code challenge site). The code challenge description is the follows:

- "Ratiorg got statues of different sizes as a present from CodeMaster for his birthday, each statue having a non-negative integer size. Since he likes to make things perfect, he wants to arrange them from smallest to largest so that each statue will be bigger than the previous one exactly by 1. He may need some additional statues to be able to accomplish that. Help him figure out the minimum number of additional statues needed."

<b>There is one example to make things more clear</b>
> For statues = <b>[6, 2, 3, 8]</b>, the output should be
<b>makeArrayConsecutive</b>(statues) = <b>3</b>.

Ratiorg needs statues of sizes <b>4</b>, <b>5</b> and <b>7</b>.

# The Solution 💡

So basically, we need to <b>sort</b> all statues and <b>count</b> the number of missing statues between each one, but how? Take a minute to think about it and then check the solution in the code snippet below.  

![The Solution](https://dev-to-uploads.s3.amazonaws.com/i/07q2tb5or50gps5i9782.png)

# Debugging and Understanding 👨‍💻

- First thing, we need to sort all statues to guarantee that <br><code>[6, 2, 3, 8]</code> will become <code>[2, 3, 6, 8]</code>

- Next, I used <b>subtract()</b> method to remove the original list items from a new list which consists in a range between <b>statues.first()</b> and <b>statues.last()</b>, which is: <code>statues.first()<b>..</b>statues.last()</code><br>
> This range operation will return an int iterable like: <br><code>[2, 3, 4, 5, 6, 7, 8]</code><br>Then, after <b>subtract()</b> it will result in this list: <br><code>[4, 5, 7]</code>, and that's awesome, these are the missing numbers in the original statues list.
<br>
- Now, we need to <b>count()</b> the returned list and we have the final result. Simple no? :D

# Conclusion

In this article, we explored <b>range operator</b>, <b>subtract</b>, and <b>count</b> functions of Kotlin, how to use it and apply it in a problem. 

And if you have some questions, any suggestions, a better solution or even some new ideas for the next <b>Kotlin Smart Solutions</b> post, don't be shy, let me know and leave me a comment. ;D   

I hope you learned something new around here.
Thank you!
<b>#KeepLearning</b>