teleren/devto huggingface dataset:
Matt's Tidbits #60 - Cleanly handling null values in Kotlin
Tags: mattstidbits, android, kotlin, tidbittuesday
Published: 2020-03-17 13:00:41

[Last time I wrote about some strange, unexpected lint errors I encountered when upgrading to Android Gradle Plugin 3.6.1.](https://medium.com/@matthew.b.groves/matts-tidbits-59-unexpected-new-lint-features-dd962326fb64) This week, I have a quick tidbit to share about cleanly handling null values in Kotlin.

Cleanliness is at the top of mind for a lot of people right now, but this concept applies to your code too! Dealing with lots of dirty/complicated/bad code is a big contributor to technical debt.

I'm sure you've probably seen (or written) code like this before:

```
fun getResource(): Resource {
  val resource = Repository.getResource()
  return resource?.run {
    if(resource.isValid()) {
      resource
    }
    else {
      getPlaceholderResource()
    }
  } ?: getPlaceholderResource()
}
```

Isn't it annoying that in this code you have to write `getPlaceholderResource()` twice? Good news - there's a better way!

Kotlin has a really powerful feature, called Extension Functions, which let you add additional functionality to existing classes. Under the hood, they work a lot like a traditional Java static method. The best part is, that allows us to call them, even if we don't have an instance of the object they're being called on!

Take, for example, this sample extension function:
```
fun Resource?.safeIsValid(): Boolean {
  return this != null && this.isValid()
}
```

The magic of this is at the very beginning - the `Resource?` part - this specifies that we are defining this extension function for possible null values of `Resource`. Kotlin calls this an ["Extension function with nullable receiver"](https://medium.com/the-kotlin-chronicle/null-safety-through-kotlin-extension-functions-9a4c6ff10765). With this in place, we can simplify our code to look like this:
```
fun getResource(): Resource {
  val resource = Repository.getResource()
  return if(resource.safeIsValid()) {
    resource
  }
  else {
    getPlaceholderResource()
  }
}
```

Notice how when we use this extension function, we don't have to use the safe call operator `?.` to call our new method, but can instead just use the regular `.` notation.

I think this is much more maintainable and easy to use, what about you? Original credit for this idea comes from this article: https://medium.com/the-kotlin-chronicle/null-safety-through-kotlin-extension-functions-9a4c6ff10765

I hope you learned something helpful, and stay safe out there! How is your project using extension functions with nullable receivers? Do you have any cases where you don't use this? Let me know in the comments below! And, please follow me on Medium if you're interested in being notified of future tidbits.

Interested in joining the awesome team here at Intrepid? [We're hiring!](https://www.intrepid.io/careers)

*This tidbit was originally delivered on September 13, 2018.*
Daily Developer Jokes - Tuesday, Mar 17, 2020
Tags: jokes, dailydeveloperjokes
Published: 2020-03-17 13:00:13

---
title: "Daily Developer Jokes - Tuesday, Mar 17, 2020"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
cover_image: "https://private.xtrp.io/projects/DailyDeveloperJokes/thumbnail_generator/?date=Tuesday%2C%20Mar%2017%2C%202020"
published: true
tags: #jokes, #dailydeveloperjokes
---

Generated by Daily Developer Jokes, a project by [Fred Adams](https://xtrp.io/) ([@xtrp](https://dev.to/xtrp) on DEV)

___Read about Daily Developer Jokes on [this blog post](https://xtrp.io/blog/2020/01/12/daily-jokes-bot-release/), and check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/).___
### Today's Joke is...
![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1259d336eb5.png)

---
*Have a joke idea for a future post? Email ___[xtrp@xtrp.io](mailto:xtrp@xtrp.io)___ with your suggestions!*

*This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit.*

<!-- 
Joke text:
___Q___: What good can come of 2989 witches casting a hex?

___A___: None, it is always 0xBAD
 -->
The largest IT companies in the world published a joint statement regarding COVID-19
Tags: google, microsoft, news
Published: 2020-03-17 12:54:23

On March 17, 2020, the world's largest IT companies, including Microsoft, Facebook, Google, LinkedIn, Reddit, Twitter and YouTube, published a joint statement on the current and complex information situation with the spread of coronavirus (COVID-19).

“We work closely in response to COVID-19. We help millions of people stay connected while combating virus fraud and misinformation, distributing reliable content on our platforms, and sharing critical updates in coordination with government health facilities around the world. We invite other companies to join us, as we work to maintain the health and safety of our communities, ”says a joint and global IT communiqué.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9675uq9idzdxjfcyio1p.jpeg)
The joint industry statement on COVID-19 from Microsoft, Facebook, Google, LinkedIn, Reddit, Twitter and YouTube ,Microsoft (@Microsoft) March 17, 2020


“We jointly counteract fraud and the dissemination of knowingly false information about the coronavirus, post reliable content on our networks, and also provide important new information,” the general statement of IT companies on the Facebook page continued . 

Microsoft, Facebook, Google, LinkedIn, Reddit, Twitter, and YouTube called on other companies around the world to follow suit, coordinate their efforts to disseminate reliable information about COVID-19, and use only verified and true information on this topic, especially regarding data from the field. health care.

Earlier in February 2020, senior management and top managers of more than a dozen IT companies, including Facebook, Amazon, Google, Twitter and YouTube, discussed with representatives of the World Health Organization (WHO) measures to prevent the spread of false information about an outbreak caused by a new coronavirus. Consultations took place in Menlo Park, California, where the Facebook headquarters are located.
Vue 101 จาก Elm
Tags: elm, vue
Published: 2020-03-17 12:43:49

หากจะทำแบบนี้ใน Vue โดยเทียบกับ Elm จากตัวอย่าง counter app https://ellie-app.com/8kChZLnNmfta1 

Elm mount app โดยใช้

```
var app = Elm.Main.init({ node: document.querySelector('main') })
```

Vue ก็ทำโดยสร้าง Vue instance โดย

```
new Vue({ render: h => h(App) }).$mount('#app')
```

view ใน Elm เป็น function ที่รับ data (หรือเรียกว่า Model)

```
view model =
    div []
        [ button
            [ onClick Increment ]
            [ text "+" ]
        , p
            []
            [ text <| String.fromInt model ]
        , button
            [ onClick Decrement ]
            [ text "-" ]
        ]
```

ใช้ Vue แบบ single file component จะใช้ tag template

```
<template>
  <div>
    <button @click="increment()">+</button>
    <p>{{ count }}</p>
    <button @click="decrement()">-</button>
  </div>
</template>
```

Elm ต้อง initialize data ผ่าน `init` และ manage logic ด้วย update function 

```
init =
    0


update msg model =
    case msg of
        Increment ->
            model + 1

        Decrement ->
            model - 1
```

ส่วน Vue ก็คล้ายกันโดยมี `data` และ `methods`

```
<script>
export default {
  data: () => ({
    count: 0
  }),
  methods: {
    increment() {
      this.count++
    },
    decrement() {
      this.count--
    }
  }
};
</script>
```

แต่สิ่งที่มันต่างกับ Elm คือ update ของ Elm ใช้ update view ทั้ง application ส่วน Vue update เพียงแค่ใน component ถ้าอยากจะให้ update ทั้ง component ต้องใช้ `vuex` ช่วยโดยแยก data และการ update ออกมาจาก component

```
Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    count: 0
  },
  mutations: {
    increment(state) {
      state.count += 1
    },
    decrement(state) {
      state.count -= 1
    }
  }
})

new Vue({
  store,
  render: h => h(App),
}).$mount('#app')
```

จากนั้นใช้วิธีการ commit mutation เข้าไปจากใน component

```
<script>
export default {
  name: "App",
  computed: {
    count() {
      return this.$store.state.count;
    }
  },
  methods: {
    increment() {
      this.$store.commit("increment");
    },
    decrement() {
      this.$store.commit("decrement");
    }
  }
};
</script>
```

ลองเทียบ state จาก state debugger

ของ Elm

![Elm Debugger](https://dev-to-uploads.s3.amazonaws.com/i/f6gkj5y10me8sho75g3a.png)

ของ Vuex

![Vuex Debugger](https://dev-to-uploads.s3.amazonaws.com/i/2s2ky1drxx1kh8xqobpu.png)
Why Microsoft buys NPM ?
Tags: npm, opensource, github, css
Published: 2020-03-17 12:36:41

The npm package manager becomes part of GitHub. Announcements about this appeared on both the GitHub blog and the npm blog . 

On the npm blog, project founder Isaac Schlüter emphasizes "npm, which you know, does not go anywhere." He expresses confidence that for the project this is a change for the better, and says that he will continue to work on it.

And in a post from GitHub head Net Friedman, it says: 

“For millions of developers using the npm public registry every day, it will always be available and will always be free. After the transaction is completed, we will focus on:

Investing in registry infrastructure and platform. The JavaScript ecosystem is massive and rapidly evolving. She needs a reliable registry. We will make the necessary investments to ensure npm is fast, reliable and scalable.

Improving the experience of its use . We will work to make developers and maintainers more comfortable, and we will support the excellent work already begun on the npm v7 CLI, which will remain free and open. Among the big features that inspire us are Workspaces , as well as improvements in publishing and multi-factor authentication.
Community engagement .
 We will work closely with the JavaScript community to get your ideas to help shape the future of npm.

And looking further into the future, we integrate GitHub and npm to increase the security of the entire open source logistics chain and allow you to track the change from Github’s pull request to the npm package version with the fix. ”
Two Components are Better than One
Tags: react, javascript
Published: 2020-03-17 12:29:17

Component based libraries like React are great in part because they allow us to encapsulate a piece of UI, and reuse it across our application. This allows us to have consistent UI, and makes tweaking styles easy. But, reusability can be taken too far. It might be tempting to only have one `Button` in your component library that can handle everything, but you can easily end up with something like:
```jsx
<Button
  icon="gear"
  iconPosition="left"
  size="small"
  variant="outline"
  isLoading
  fullWidth
  {...andManyManyMore}
/>
```

{% twitter 1002110517094371328 %}

What was once a simple `Button` now has props for every imaginable use case), making it hard to maintain or change. 

Sometimes, it's better to have a few more components for specific use cases instead of one component that handles everything. Here are a few examples where I've created multiple components instead of adding more props to one:

Instead of a `Button` that can have text or just an icon, create a normal `Button` and a separate `IconButton`. This way, you won't have to special case spacing when there is text with an icon, and you can easily build an API that forces you to add a label for accessibility in your `IconButton`. 

Instead of a `SelectMenu` component that can handle both single selection and multiple selection, split into `SelectMenu` and `MultiselectMenu`. The logic around these is different enough that maintenance and styling is much simpler when they are kept separate.

What are some other examples of components trying to do too much?
Old post surging?
Tags: meta
Published: 2020-03-17 12:22:23

EDIT: Aha:

{% devcomment mk9k %}

That'd sure do it.  Thanks!  There's a bunch of good robot vacuum  commentary there, and a few people calling me an asshole for disrespecting my significant other (it was a *joke*, really).

Just curious here, mostly.

DEV posts in general have an incredibly short lifetime - a few hours for most, maybe a few days if you managed to hit on something interesting.  Generally, after that time, I stop seeing any new reactions entirely by the third or fourth day after posting.

This week though, I've received a flurry of activity in the form of reactions, new comments, and even direct messages to my email address, on a post I made *last July*:

{% post deciduously/i-am-mesmerized-by-our-new-robotic-vacuum-10pc %}

How and why is that happening?  Are we all just spending more time at home and deep diving through DEV links?  If so, why *that* post in particular?  Was it linked somewhere externally?  Is there any way for me to tell?

It doesn't matter, really, this has just never happened to a DEV post of mine.  Some of my more popular articles will get an intermittent "heart" every so often well after publishing, but this has almost felt like it's been back on the feed.

*Photo by bruce mars on Unsplash*
GitHub acquires npm, Inc.
Tags: webdev, github, npm
Published: 2020-03-17 11:54:06

Yesterday, March 16th, Isaac published on the [npm blog](http://blog.npmjs.org/post/612764866888007680/next-phase-montage) that GitHub will be acquiring the package manager. Also, there's a nice blog post on [GitHub's blog](https://github.blog/2020-03-16-npm-is-joining-github/), written by Nat.


### And, practically, what does that means for us?
Well, after seeing the acquisition of [GitHub by Microsoft](https://github.blog/2018-06-04-github-microsoft/) - where people changed their VCS to GitLab or BitBucket - I believe people may replace npm to [yarn](https://yarnpkg.com/). yarn is on the game since 2016 and in the past few years it has overlaped npm on usage, security and speed (as theirselves claims). Back in the day I remember to see those posts about _"how yarn is faster than npm"_ or _"how yarn is more secure than npm"_.

Competition always lead to improving services, and personally I see npm getting better and better as time time flies. Today, most people yet think about technology/tools itself, and not what you can do with them.


### In my opinion...
Today I don't see a huge difference between the managers, and I believe npm is on the rise of overlap yarn - [Isaac said](http://blog.npmjs.org/post/186983646370/npm-cli-roadmap-summer-2019) that npm's v7 (it's getting close!) and v8 are already being planned, and they'll be focused on experience and speed. So we can expect nice things on the move.

In 2020, I see a bright future for npm - talking about the startup and the service as well. 🎉
Wrapper over AWS Session Manager to SSH using Public/Private IP
Tags: ec2, aws, ssm, ssh
Published: 2020-03-17 11:50:06

Previously on AWS, we had two problems with establishing SSH sessions to EC2 instances.

1. It's hard to manage SSH keys, especially if when we have a lot of servers.
2. It was hard to open sessions to private instances as you need the bastion host to do so.

AWS Session Manager solved both of these issues for us. Moreover, it is an AWS-centric solution so we preferred it.

Moreover, we needed a way to establish an SSH connection to instances using public IP or private IP as we were doing ssh using IPs before. AWS CLI doesn't support it out of the box (it supports only instance-id). I wrote this wrapper script over AWS CLI to achieve the same.

Repository link: https://github.com/MrHassanMurtaza/ec2-ssh/
Subscribe to my newsletter!
Tags: dart, webdev
Published: 2020-03-17 11:38:07

You can subscribe to my blog's newsletter at [carmine.dev/newsletter](https://carmine.dev/newsletter)!

At the moment it's more a mailing list I'll use to send handcrafted emails about new posts, and at the moment I'm not even doing input validation as I can filter the emails manually when I send the email since I don't expect a huge amount of subscribers (I'd be very glad to be proven wrong, though). In case you're wondering, you can't do an SQL injection attack on that form. I'm lazy but I'm not mad, and being vulnerable to SQL injection in 2020 is a sign madness and recklessness, not ignorance.

For that I've built  a little Flutter web app using Cupertino Widgets so that, when I want to show people what Flutter for the Web looks like, I also have a demo of that given that my [carminezacc.com](https://carminezacc.com) Flutter home page uses Material Design widgets.

Check it out at [carmine.dev/newsletter](https://carmine.dev/newsletter) and subscribe if you'd love to receive emails about new Flutter tutorials I'll post! As always, [follow me on Twitter](https://twitter.com/carminezacc) if you prefer to get new posts delivered to you that way.
🎓Review 5: GitHub Cool Projects with React, Developer: Saad | #elefDoesCode
Tags: review, github, coder, react
Published: 2020-03-17 11:24:07

⬇️I will review your... 

🤓The process:
1. Every week I will do a live stream on my youtube channel reviewing your site
2. I will give feedback and suggestions according to your needs. 
3. If I have a way to contact you, I'll gladly do so :)
4. If you have any question don't hesitate to contact me!

Take part [here](https://forms.gle/9AxiCUQ8YudTVYzs9) (I only need a URL and your name).

It doesn't matter if you are a beginner or more advanced. 
You can submit as many sites as you want.

🙏Thank you for taking part with your website into my live streams.
It takes courage to let someone you don't know to review your work...
But remember feedback is important and all of us need it...
 
🤗The review is FREE. You don't pay for anything. I won't be paid by anyone.

----------------------------

In particular, in this video you'll find:

🤓The developer: Saad Pasta | https://twitter.com/SaadPastaDev
💪The project:  https://github.com/saadpasta, https://saadpasta.github.io/, https://saadpasta.github.io/react-blog-github/#/

⌨Previously 
- [review 1](https://dev.to/eleftheriabatsou/review-1-tribute-page-by-freecodecamp-developer-kyle-elefdoescode-4006)
- [review 2](https://dev.to/eleftheriabatsou/review-2-personal-portfolio-developer-diego-elefdoescode-4g36)
- [review 3](https://dev.to/eleftheriabatsou/review-3-portfolio-and-airshare-project-developer-rajitha-elefdoescode-3gop)
- [review 4](https://dev.to/eleftheriabatsou/review-4-personal-portfolio-developer-jatin-elefdoescode-4i52)

----------------------------

👋Hello, I' m Eleftheria, an app developer, master student, freelancer, public speaker, and chocolate lover.


😎Top 3 list:
- How to stay motivated | A developer's edition | @BatsouElef: https://youtu.be/qMvEtb5OxNo
- How to be a Better Problem Solver | Tips and solutions: https://youtu.be/dELt7yKIxIA
- Simple Tips to Build a Personal Brand as a Developer (+ personal examples): https://youtu.be/7s0o1gi0iP0

🥰If you liked this video please share

🍩Would you care about buying me a coffee? You can do it here: [paypal.me/eleftheriabatsou](paypal.me/eleftheriabatsou) but If you can't that's ok too!


**************************************

🙏It would be nice to subscribe to my [Youtube](https://www.youtube.com/c/EleftheriaBatsou) channel. It’s free and it helps to create more content.

🌈[Youtube](https://www.youtube.com/c/EleftheriaBatsou) | [Codepen](https://codepen.io/EleftheriaBatsou) | [GitHub](https://github.com/EleftheriaBatsou) | [Twitter](https://twitter.com/BatsouElef) | [Site](http://eleftheriabatsou.com/) | [Instagram](https://www.instagram.com/eleftheriabatsou/)
Git ignoring a directory like it doesn't exist?
Tags: git, ignore, directory, monorepo
Published: 2020-03-17 11:15:23

You have a cloned repo. There's a directory, call it a/b/c that used to be its own repo, i.e. there was a/b/c/.git/ etc.

Now you want the files managed in the main repo. You don't care about the history in a/b/c, so you deleted the .git dir in a/b/c

But the problem is that git status is ignoring a/b/c completely. You can't git add it. It's as though you'd put the path into .gitignore (You haven't).

You have no idea what the problem was or how it arose (v. annoying), but here is how You can fix it:

```console
git rm --cached a/b/c
git commit -m "removed phantom a/b/c dir"
git add a/b/c
git commit -m "finally able to add a/b/c"
```

Cheers! 🍻
How to work in pajamas
Tags: remote, remotework, officefromhome
Published: 2020-03-17 10:47:56

---
title: How to work in pajamas
published: true
description: A brief description of tools for work from home
tags: #remote #remotework #officeFromHome
---

1. Zoom
Zoom is everything, that is Skype should be. With a free account, you can create meetings limited to 40 mins if you have more than 2 participants. After 40 mins, you can recreate a meeting. Also, it supports every important feature like share screen, recording and everything is free...

2. Krisp
A combination with popular tools for communication works as noize cancelation. 
Krisp cancels out all background noise and helps you always have the perfect sound quality. Awesome tool.

3. Loom
A great tool to record yourself, your monitor, yourself and your monitor and share to the cloud. Ideal tool for presentation.
Facelock Authentication for Linux
Tags: linux, machinelearning, python, security
Published: 2020-03-17 10:44:51


Typing in passwords can often be a headache when you have to put it over and over. Life would be so easy if it just unlocks with your faces and you do not have to type in every time to get authenticated. Well Facelock does what you want, it authenticates user through the face.   
## Intro  
Facelock provides you with a fast face recognition system which can be used for authentication purposes. It authenticates users at logins, sudo commands on shell, and many other places where you need passwords for authentication.Everything you need to do is to show your face in webcam (which you already are) instead of typing a password.  
## Features  
Facelock can have as many faces as you want to authenticate and stored such that no one(except you) can tell who all are allowed to access it without passwords. It has a very simple installation(two or three commands) provided at my [github repo](https://github.com/anish-kmr/facelock#readme).  


Facelock has a very intuitive and easy commands (Like facelock enable,facelock add label, ....) listed in readme of the repo.  


You might think, ***what if Facelock does not recognise your face ?*** (maybe you look different sometimes....Just Kidding) <br>  
 Don't worry , Facelock will try to recognise your face for a couple of minutes and if not found correct, it jumps back to password authentication.  
## Future plans  
For now, it authenticates user if his picture is shown in webcam but it will corrected in future releases.  
## Install   
Try it now : [Facelock](https://github.com/anish-kmr/facelock)