teleren/devto huggingface dataset:
Null coalescing in TypeScript
Tags: typescript
Published: 2020-01-31 00:00:00

---
title: Null coalescing in TypeScript
date: "2020-01-31T00:00:00.000Z"
tags: ["typescript"]
---

The [null coalescing operator](https://en.wikipedia.org/wiki/Null_coalescing_operator) has been a long requested feature in TypeScript. Indeed, when I began using TypeScript a few years ago, I assumed it was available and was suprised to find this wasn't the case.

Null coalescing remained unsupported until recently  because the TypeScript team (rightly) wanted to mantain compatibility with any eventual [TC39](https://tc39.es/) decisions regarding implementation and semantics.

Given the [ECMAScript proposal is now at stage 4](https://github.com/tc39/proposal-nullish-coalescing), the TypeScript team have responded by adding support for the `??` operator in [TypeScript version 3.7](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#nullish-coalescing).

The null coalescing operator is useful when you want to use a _'default'_ value in an expression. In TypeScript and JavaScript you will find the following pattern regularly used:

~~~javascript
const a = b || c;
~~~

While this appears to achieve the same end (and in many cases, will) the logical OR operator (`||`) applies for any [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy) value i.e. `null`, `undefined`, `""`, `0`, `NaN`, `false`:

~~~javascript
const b = 0;
const c = 42;
const a = b || c;

console.log(a); // 42
~~~

The null coalescing operator (`??`) is more strict; it only applies where the value is `null` or `undefined`:

~~~typescript
const b = 0;
const c = 42;
const a = b ?? c;

console.log(a); // 0
~~~

This additional strictness can be useful in scenarios where subtle errors may otherwise be introduced due to unintended falsy evaluation i.e. where `0`, `NaN`, or `""` are valid values in your application data or state.
Minumum Number Of Jumps [Python]
Tags: algorithms, python, interview, dynamicprogramming
Published: 2020-05-21 15:52:52

---
title: Minumum Number Of Jumps [Python]
published: true
date: 2020-01-31 00:00:00 UTC
tags: algorithms, python, interview, dynamic programming
series: Coding Challenge
canonical_url: https://avinsharma.com/min-num-jumps/
---

`Sample Input: [1, 5, 1, 1, 2, 1, 2]``Sample Output: 2 (1 -> 5 -> 2)`, we jump from index 0 to 1 (1 -> 5) because we can jump 1 unit far from there and then we jump from index 1 to 6 (5 -> 2) because we can jump 5 units from there and we reach the end in 2 jumps.

## O(n^2) Time | O(n) Space

My first thought was, this looks like a dynamic programming question. So I basically wanted to maintain an array of the same size as the input which would contain what is the minimum jumps to reach any particular index.

How do we do that? First we initialize the shortest array with infinity. The idea was to have two loops `i(0 -> n-1)` and `j(0 -> i)` and check if we could reach i from j and if we can, is `shortest[j] + 1 < shortest[i]`. If `shortest[j] + 1 < shortest[i]` then `shortest[i] = shortest[j] + 1`. After both the loops are done we return last element of the `shortest` array.

## O(n) Time | O(1) Space

Yes this can be done in O(n) time and constant space. It is hard to come up with, but this kind of looks like one of those dynamic programming problems which could be done in a single pass.

Let's take a look at the problem once again. At any given index we have the maximum distance we could jump if we were standing there. So basically we might have two choices, to either continue the previous jump(let's say we were jumping from index 0 to 5, instead of stopping at 3 we continue our jump to 5) or to start a new jump from the current index.

So at any given point we have our maximum reach, and we keep updating our maximum reach as we keep moving forward. We also maintain a steps variable which is there to basically keep track of how many steps do we have left before we can commit to a jump. When steps reach 0, we assign the current maximum reach as the num of remaining steps because when steps reach 0 that means we are standing at that index and the largest jump from here would be the maximum reach we have been maintaining.

```python
def minNumberOfJumps(array):
    # Time: O(n)
	# Space: O(1)
	
	if len(array) == 1:
		return 0
	
	max_reach_index = array[0]
	steps = array[0]
	jumps = 0
	
	for i in range(1, len(array) - 1):
		steps -= 1
		max_reach_index = max(max_reach_index, i + array[i])
		
		if steps == 0:
			jumps += 1
			steps = max_reach_index - i
	
	# Because we are going till the second last index
    # we will either have previous unfinished jump or
    # a new jump starts at second last index either way
    # we need to add a jump.
	jumps += 1
		
	return jumps
```
Celebrate our first Opt Out Tools meetup!
Tags: ai, nonprofitorganizat, meetup, technology
Published: 2020-03-11 00:16:24

---
title: Celebrate our first Opt Out Tools meetup!
published: true
date: 2020-01-31 00:00:00 UTC
tags: AI,Non Profit Organizat,Meetup,Technology
canonical_url: https://cheuk.dev/2020/01/31/first-oot-meetup/
cover_image: https://cheuk.dev/assets/images/oot-meetup-photo.jpg
---

Last week (23 Jan 2020) we had our first Opt Out Tools meetup at Mozilla Berlin! Attendees compile of a team of international experts from different fields: data scientists, web engineers, project managers, digital marketers etc. It was a fruitful discussion as we have consolidated the goal for Opt Out Tools in 2020 and have formed workgroups to work towards our goals.

## Goals for Opt-out in 2020

**Stable release:** We aim to release our first stable version of the Opt Out Tools browser extension in the 4th quarter of 2020 on Firefox add-on for the general public to use. But before, there will be beta versions for people who are interested to test and give us valuable feedback.

**Funding:** Having stable financial support for Opt Out Tools is important for the development of the tools and the community. We will keep on actively looking for funding to apply for and potentially launch a crowd-funding scheme later in the year.

**Community building:** In 2020, we will keep on having more meetups and workshops for building the team and educating people about online misogyny. Hopefully, we will continue to have a strong partnership with Mozilla Berlin for community events.

**Web capability:** With our strong team of web engineers, we will have a better browser extension interface and support more features. We will also improve our website so that our users have better experiences.

**Stronger model:** Our data science team is massive; with them, we can have a more thorough study on the data and have a stronger AI model in detecting online misogyny. Our research team is also studying different types of abusive text in different cultural contexts.

**GDPR compliance:** We are fully aware of the importance of privacy and GDPR, we have reached out to professionals and seek advice. In 2020, we will continue using the data that we have for good (not for the bad)!

* * *

## Opt-out workgroups

To make sure that we apply our expertise and work efficiently towards our goals, we have formed workgroups:

1. Data Science / Modeling: researching on performing machine learning on our data and deploying the best AI model we have for detecting abusive messages.
2. Research: researching definitions of misogyny and message context across cultures.
3. Web engineering: developing and maintaining the browser extension and the website.
4. Brand and Marketing: out-reaching and promoting Opt Out Tools, also managing our social media presence.
5. Funding: sourcing and apply for suitable fundings, preparing our future crowdfunding campaigns.

* * *

If you are interested in Opt Out Tools and want to volunteer or sponsor us, we would love to hear from you. Also, show us some love on [GitHub](https://github.com/opt-out-tools/) and [Twitter](https://twitter.com/optoutools).
Apply Cut or Copy to blank lines when there is no selection
Tags: visualstudio, tips, dotnet, csharp
Published: 2020-01-31 12:30:40

---
title: Apply Cut or Copy to blank lines when there is no selection
published: true
date: 2020-01-31 00:00:00 UTC
tags: visualstudio, tips, dotnet, csharp
canonical_url: 
---

I mostly code in [Visual Studio Code Insiders](https://code.visualstudio.com/insiders/) on either macOS or Linux but on the occasion that I develop on windows, I do like to use the old faithful Visual Studio.

And today I fixed a slight annoyance that I have with Visual Studio 2019.

If you cut or copy on a blank line accidentally which does happen you will lose your clipboard contents.

To fix this in the search bar at the top enter `Apply Cut or Copy to blank lines when there is no selection` and open its’s dialog.

Uncheck that box for your language (or all languages as I did).

![vs dialog](https://i.imgur.com/s2Hn38e.png)

Success 🎉
Day 77 : Gone
Tags: hiphop, code, coding, lifelongdev
Published: 2020-01-30 23:36:09

_liner notes_:
- Professional : Where has the time gone?! Today went by super quick! Did some research on writing tests for the Web Components I created for a sample application. I'm using StencilJS so I've been looking through their documentation for any best practices they have. Also worked with a team member to see if he could recreate the error I was getting yesterday. After some time, he was able to verify that he go the same error. Told my manager and we are going to escalate it tomorrow. Pretty good day.

- Personal : Did not feel up to heading downtown to go to a meetup. Want to try and get some work in for the radio show this week. I'm going to another event tomorrow so I want to make sure I get as much as I can done tonight. I also want to do some more research into writing tests. It's been a topic I've been wanting to get better at. Also, put together a quick demo to show a friend who site I will be making in the future. We'll see what she has to say so we can move forward.

![Huacachina, Peru desert sand dunes](https://dev-to-uploads.s3.amazonaws.com/i/h7xeeba7o9xwygeeazud.png)

Tomorrow, I'm looking to get a bunch of the tests written. At least get a good start. I want to be able to share what I have so that others can give me feedback. Going to get a head start with laundry so I don't have to do it during the weekend, so I can focus on side projects.

Have a great night!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube F2UBjozJS6w %}
My first close encounter from the third kind... of React with Gatsby!
Tags: gatsby, react, beginners
Published: 2020-01-30 22:20:58


# What is Gatsby?

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

> Gatsby is a free and open-source framework based on React that helps developers build blazing-fast websites and apps

You can build seriously fast static websites very quickly with Gatsby. Gatsby also uses GraphQL which is a really nice query language that just might replace REST for my personal projects. Another great thing about Gatsby is all of the plugins available! There are so many great ones that can really make Gatsby shine. 

Being a new developer I try to not get to distracted by the new shiny technologies, but I can say that I am really glad I got distracted by Gatsby. It has not only helped me understand React on a larger scale but has also really helped me understand query languages and API development. After finishing Scott Tolinksi Pro Gatsby 2 tutorial on [Level up Tutorials](https://www.leveluptutorials.com/tutorials/pro-gatsby-2) I fell in love with the way Gatsby handles not just API calls but the way you can build multiple pages very quickly using Markdown files.

---
# Getting started

You can download the Gatsby CLI to get started very fast, just run `npm install -g gatsby-cli`
Gatsby comes equipped with a `create-react-app <appName> ` clone of its own in `gatsby new <appName>`.
After that `cd <appName>` and run `gatsby develop` and see your base site appear at localhost:8000

One really cool thing that `gatsby new <appName>` does for you is after the app is running on localhost:8000, you can go to localhost:8000/__graphiql (thats two _ _) and have your own mini Postman built-in. It makes it really easy to write your queries and confirm the data is what you want. Then you can simply copy and paste the query you wrote in graphiql into your code! Pretty great in my opinion.



Next, I want to become more familiar with GraphQL, as it has been fairly simple to pick up given my previous knowledge of REST. I would also like to learn about implement Apollo into my stack because I recently attended a React JS Meetup and really like hearing what the speaker was able to do with Apollo. If anyone has any resources for strengthening these skills I would appreciate any advice!
Should devs unionize?
Tags: discuss
Published: 2020-01-30 21:55:54

I recently came across a lot of devs (especially web & mobile developers) that suffer from increasing competition, low barriers to entry and quite frankly amateurism in the industry.

Will it be smart for Devs to start protecting their jobs, expertise and service quality?

Maybe unification behind a standard defining rules to operate in the sphere, or even a union might be beneficial?

When you think about it, devs expose their clients to substantial risks when it comes to data security and plain bad service (money invested that lead to nothing). It might be beneficial for everybody to set a standard for web-mobile dev that is followed across (or part of) the community in order to be able to justify decent levels of income and reassure clients that they actually pay for quality.

What do you think?
The Monorepo Song
Tags: humor
Published: 2020-01-30 21:33:31

---
title: The Monorepo Song
published: true
description: Because a dev with root access is like a mule with a spinning wheel
tags: humor
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/1gwecfd4ed3nf07pjlee.jpg
---
(apologies to The Simpsons)
originally posted on the twitters at https://twitter.com/mattstratton/status/1222989536243920904

**Stranger:** Y'know, a developer with root access is like a mule with a spinning wheel. No one knows how they got it and danged if they know how to use it!
The name's Jacob. Adam Jacob. And I come before you good people tonight with an idea. Probably the greatest... Aw, it's not for you. It's more of a *Netflix* idea...

**CTO:** Now wait just a minute! We're twice as agile as the engineers at Netflix! Just tell us your idea and we'll prioritize it in the backlog!

**Stranger:** All right, I tell you what I'll do. I'll *show* you my idea! I give you the Monorepo!" 

*(audience gasps)* 

**Stranger:** I've sold monorepos to Facebook, Lyft, and Jim's Discount Tires, and by gum, it put them on the conference circuit!
Well, sir, there's nothing on earth
Like a genuine,
Devopsified,
Agilified,
Observafied
Monorepo! ...

What'd I say?

**Scrum master:** Monorepo!

What's it called?

**SREs:** Monorepo!

That's right! Monorepo!

**Product Owner:** I hear that pattern is out of date
**Stranger:** Ignore thought leaders, it's really great!

**CFO:** Is there a chance of incidents?
**Stranger:** Just ignore the alerts, don't be so tense!

**Tester:** What about the QA team?
**Stranger:** TDD makes your life a dream!

**DevOps Engineer:** Were you sent by [Corey Quinn](https://www.twitter.com/quinnypig)?
**Stranger:** No good sir, I play to win!

**Security Engineer:** My CPU is spinning loud!
**Stranger:** Shut down Slack and launch the cloud!

I swear it's your dev team's only choice, write up the user stories, raise your voice!

**Customer Service Manager:** But prod is still down and broken!
**Staff Engineer:** Sorry boss, thought leaders have spoken!

**All:** Monorepo...monorepo....monorepo!
Learn How to Create a Vertical Slick Slider with Custom Dots and Arrows
Tags: css3, javascript, latestposts, css
Published: 2020-01-30 21:33:40

---
title: Learn How to Create a Vertical Slick Slider with Custom Dots and Arrows
published: true
date: 2020-01-30 21:27:02 UTC
tags: CSS3,JavaScript,Latest Posts,CSS
canonical_url: http://robdoylecreative.com/learn-how-to-create-a-vertical-slick-slider-with-custom-dots-and-arrows/
---

In this post, we are going to learn how to create a vertical slick slider with custom dots and arrows using your own images to replace the default buttons provided by slick. Before we start the slider, files need to be installed into your working project. These can be downloaded from the official site: https://kenwheeler.github.io/slick/ […]

The post [Learn How to Create a Vertical Slick Slider with Custom Dots and Arrows](http://robdoylecreative.com/learn-how-to-create-a-vertical-slick-slider-with-custom-dots-and-arrows/) appeared first on [Rob Doyle Creative](http://robdoylecreative.com).
How do you convince clients that security is not an option?
Tags: security, webdev, help
Published: 2020-01-30 21:26:37

Hello everybody,

Today at work, I've been facing an issue : 

Client want a way to reset user's password for a web application. Classic.

For context, their is already a mechanism for every users to reset their password by receiving an unique link by mail.

However, he wants a way to choose the user's password when they ask to reset their password on support center (over phone)

Client argue that some of its clients, not tech people, have trouble using this mechanism or that email is not a reliable way to reset password (delay, possible loss of email when sending it, user unable to access their mailbox...). He also add that its clients have money and  when something is wrong and they can't access their account, he want to provide them a way to allow an immediate login. 

From my perspective, this involve some downsides :

- The probability that the user will change its password after getting one is close to 0. Or, as client said, if they are not tech people, they will always call support center asking for another password reset.
- This will overload support center and will make them less available for real requests.
- User password is no longer known by the user himself/herself. At least both admin/support center **and** user know it now. *I'm attached to user's privacy, so this is a big one for me*. I would not like to use a system where an admin can change my password as he'd like (of course, an admin can always change a password if he access database, run a custom script on server or whatever but this **should not be a feature**)
- If for any reason, a bug allow to run this unauthenticated, all users' account are compromised. This could not be possible if this *feature* was not asking to be implemented.


One alternative could be to generate a link for a one-time login and give them to the client, so they can log in and change their password (exactly the pattern of initial password reset, except we don't send it by mail) but as I said, support center is made over the phone, and asking an user to enter a 64 char random string to log in is not very convenient and will certainly lead to typo errors.

Also, as I said : 

> "He also add that its clients have money and  when something is wrong and they can't access their account, he want to provide a way to allow an immediate connection."

From my perspective, this is because its user's have money that security should not be an option and we should reduce risk their private data from being accessible. Not the opposite.

Am I the only one wondering why this request ? What do you think about it ? Is there an alternative I could provide to my client ? Or at least others argument to convince him that this is not a good idea?

Or at the opposite, is this request perfectly fine and I am being too much paranoid ?

Thanks a lot for reading, I'm looking forward to read your answers ! Apologize my English, I'm not a native speaker.
Quick Recipe for creating DSLs in Kotlin
Tags: kotlin, android, beginners
Published: 2020-01-30 21:10:45

A pretty cool feature in Kotlin is the ability to construct custom DSLs. And you need just four things in order to write them.

- Infix Notations
- Extension Methods
- Lambdas
- Lambda with Receiver

Let’s go through these one by one.

### Infix Notation

_Remove brackets & dots!_

```kotlin
class Car {
   fun drive(miles: Int) {
      ...
   }
}
val car = Car()
car.drive(10) // normal stuff
```

Just add infix notation before method declaration for it to work

```kotlin
class Car {
   infix fun drive(miles: Int) {
      ...
   }
}
val car = Car()
car drive 10 // no brackets! no dots!
```

### Extension Methods

_Add new functions to any class without having to inherit!_

```kotlin
val name = "Ahmed Riz"
name.shout() // won't compile as shout() is not part of String class
```

In order to make it a part of String class (without inheriting), create shout method prefixed with “String.”

```kotlin
fun String.shout() {
   println("$this !") // this refers to the value of string itself
}
val name = "Ahmed Riz"
name.shout()  // works! and prints out: Ahmed Riz !
```

Extension methods are project-scoped — you can access them anywhere inside the project.

### Lambdas

_Pass anonymous function literals (to higher order functions)!_

```kotlin
// a higher order function
fun process(value: Int, operation: (Int) -> Unit) {
    operation(value)
}
// when calling, we can pass in a lambda expression
process(10, { value -> println(value) })
// and because it's the last param, we can extract it out
// just to clean things up even further 
process(10) { value -> println(value) } 
```

### Lambda with Receiver

_Pass anonymous function literals (to higher order functions), but with a receiver type!_

```kotlin
// slight change to the previous higher order function
// now instead of operation: (Int) -> Unit
// we'll do operation: Int.() -> Unit
// This makes Int the receiver type
fun process(value: Int, operation: Int.() -> Unit) {
    value.operation()
}
// usage now becomes
process(10) { println(this) } // prints out: 10
```

### Combining These!

![Captain Planet](https://miro.medium.com/max/870/1*KxKZMuoTx-YOSW_3bTM9OA.gif)

Let’s now create a DSL of our own. Just to demonstrate:

```kotlin
val myProfile = "Ahmed Rizwan" profile {
    age = 90
    phone = "123 456 789"      
}
```

Code in order to make it a valid DSL is as simple as this

```kotlin
class Profile(
    val name: String,
    var age: Int? = null,
    var phone: String? = null
)

infix fun String.profile(create: Profile.() -> Unit): Profile {
    val profile = Profile(this)
    profile.create()
    return profile
}
```

And that’s it!

Although the DSL above might not be a very useful one in real world — but hopefully it gives you an idea of how we can utilize these different Kotlin features to create some custom DSLs of our own.

Happy coding!