teleren/devto huggingface dataset:
Kotlin safe casting
Tags: kotlin, android, fragment
Published: 2021-04-14 13:12:04

![Kotlin safe cast operator](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fjg8xsdjcx33aj10rwh8.png)

In multiple cases you might've came across the situation where you have to cast a global variable and check the instance beforehand.

A most common case in Android environment is to check whether the (hosting) activity implements a callback or extended from Specific one.

### Before
```kotlin
if (activity is BaseActivity) {
   (activity as BaseActivity).hideKeyboard()
}
```

### After
Same can be written in sweet Kotlin syntax in a single line

```kotlin
(activity as? BaseActivity)?.hideKeyboard()
```

From the official doc
> Use the safe cast operator as? that returns null on failure.


## How this is better?
In surface it might not look like a better code overhaul. As calls to activity increase in numbers, it gets better.

```kotlin
// CreateTweetFragment.kt
fun submit() {
  
  // Fire and forget API call

  if (activity is BaseActivity) {
     (activity as BaseActivity).hideKeyboard()
  }
  
  if (activity is TweetSubmittedCallback) {
     (activity as TweetSubmittedCallback).onTweetSubmitted()
  }
}
```

We could easily cast the activity to the exact subclass and invoke both methods.
```kotlin
// CreateTweetFragment.kt
fun submit() {
  
  // Fire and forget API call

  if (activity is TwitterActivity) {
     (activity as TwitterActivity).hideKeyboard()
     (activity as TwitterActivity).onTweetSubmitted()
  }
}
```

But it enforces the *CreateTweetFragment* to be attached to the *TwitterActivity* to execute both statements. Anything that is just a BaseActivity or TweetSubmittedCallback won't execute the statement even though the implementation is in place.

> Prefer composition over inheritance

Now with the `as?` operator, both statements can be executed independent of each other.

```kotlin
fun submit() {
  
  // Fire and forget API call

  (activity as? BaseActivity)?.hideKeyboard()
  (activity as TweetSubmittedCallback)?.onTweetSubmitted()
}
```
🐛 How to quickly spot errors in your JavaScript code in VS Code
Tags: javascript, vscode, typescript, bugs
Published: 2021-04-14 13:06:12

# Hello again 👋

### This is a very amazing way to use the powers of Visual Studio Code in your JavaScript files to quickly spot errors. 

> You might know about  [TypeScript](http://typescriptlang.org/) . It's a wonderful superset of JavaScript which gives JS the power of types and helps in debugging right inside your IDE (especially VS Code). This simple trick will even help you if you are not a fan of types and TypeScript.

Most of the times, there are very small and silly bugs in our JavaScript code which we can't catch in the development process and can cause high impact in production. A simple example is this 👇

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618394258949/UibX9tbeK.png)

In this example above, we are using Vanilla JavaScript where we cannot spot the error which is on **line 7**. We could've used TypeScript here, but if you want to use JavaScript, you can easily spot errors by adding only a comment on the top.


![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618394650705/msRXzwE2I.png)

As you can see the warning we got by hovering over the parameter in the function is telling us that this parameter is of `any` type which is not good at all. So how can you expect only a `string` into the function without TypeScript? 

The easiest way to do it is to add the `string` argument in the function call and then do this 👇.

> Arrow function

![jsdoc 1.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1618395013649/cJocHis3K.gif)


> Normal function

![jsdoc 2.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1618395128939/0knhLk7ng.gif)


The 2nd way looks neater to me. 

Besides, you can also spot silly bugs which are very bad. Some are listed below:

> Without `// @ts-check`

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618395257971/zMKf3in7s.png)

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618395313031/OHcfyK8JV.png)

> With `// @ts-check`

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618395398986/xhpZv5Z-r.png)

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618395411067/EkfjfMpau.png)

> TIP: To enable `// @ts-check` for every `.js` file, you can simply enable this setting in VS Code.
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1618395578363/8QriPysit.png)

And to ignore checking in any file, just use `// @ts-nocheck` on the top of the file.

For more information about those types for parameters, you can refer to the  [JSDoc Documentation](https://jsdoc.app/).
Maintaining Ansible Collections
Tags: ansible, automation, ansiblecollections
Published: 2021-04-14 12:44:54

Integrating your product with Ansible can be overwhelming. **Make your life as an Ansible Collection maintainer easier with these tips and tricks:** 

1. Run sanity tests as often as possible in order to ensure your module and plugin documentation does not get out-of-sync with the implementation. 

2. Schedule a nightly integration test run that uses latest components (Ansible, your upstream product, helpers, etc.). Detecting incompatibilities early in the development cycle gives you a chance to report and fix bugs before they get into final releases of upstream components. 

3. Think twice before you start autogenerating modules. Instead, treat Ansible content as another abstraction layer for your product’s API that allows you to smoothen some of the rough edges and offer cross-product version compatibility. 

4. Get comfortable using your IRC client (or invest a few bucks for an always-connected solution with a backlog option) since most of the development-related discussions happen in #ansible-devel and #ansible-community freenode IRC channels.
Write your first test in Cypress
Tags: testing, javascript, webdev, tutorial
Published: 2021-04-14 12:31:36

In this tutorial, we will cover how to write your first test in Cypress. We will go over the basic Cypress syntax and run our tests using the Cypress Test Runner.

### Creating your Cypress Test

![Cypress Test](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v3chq74yhdu5gx3w5o1s.png)

- to go to any URL, you can use the `cy.visit()` command
- Cypress also provides various types of page assertions such as `cy.url()` and `cy.title()` to assert the URL as well as the title of the page

---

### Running your Cypress Test in the Cypress Test Runner
To open the Cypress Test Runner, you can execute the following command below:

`npx cypress open`

Once the Cypress Test Runner opens up, you can execute your test which will show results similar to this below:

- You can see all the Cypress commands listed below such as visit, URL & title
- All your successful assertions will show in Green and failed assertions in Red

![Cypress Test Runner](https://automationbro.com/wp-content/uploads/2021/04/Screen-Shot-2021-04-14-at-3.34.32-AM.png)

---

#### Check out the video below to see how to create your first test in Cypress:

{% youtube 1bLPnmZhwKs %}

---

📧 Subscribe to my [mailing list](https://automationbro.com/mailing-list) to get access to more content like this 

👍 Follow [automationbro](https://twitter.com/automationbro) on Twitter for the latest updates

...

I love coffees! And, if this post helped you out and you would like to support my work, you can do that by clicking on the button below and buying me a cup of coffee -

<a href="https://www.buymeacoffee.com/automationbro">![Buy me a coffee](https://dev-to-uploads.s3.amazonaws.com/i/4aw2ub3f4qkyjk0ivwt4.png)</a>

You can also support me by liking and sharing this content.

Thanks for reading!
What Code Editor Are You Using?
Tags: javascript, code, discuss, css
Published: 2021-04-14 12:25:13

What code editor are you using?
Why?

Also here are the best 3 code editors: https://www.youtube.com/watch?v=eC8mO6iqUCk&t


Don't forget to subscribe to my YouTube channel for weekly programming tutorials https://www.youtube.com/channel/UCFzeA3xC-_i4ZT-XwcwsJxQ
Discussion - Is Covid Impacting Developers Life?
Tags: healthydebate, productivity, javascript, discuss
Published: 2021-04-14 12:19:11

![giphy (6)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k8pco1g9nytd654gujsq.gif)

**Don't leave this article before taking this quick survey:**

Covid had the most impact on your...

❤: Social life
🦄: Work
🏷: Family 

---
 
`Hello World!` Today we will talk about a more serious topic answered to my others [#healthydebate](https://dev.to/devlorenzo/series/11376). I'm interested in how Covid is impacting your life as a developer. Also, by telling your experience, you have a chance to get featured in our [newsletter](https://worldindev.ck.page).


**Question of the week:** *How covid is impacting your developer life?*

--> Some starting points are the influence that the covid has had on you on a social level (how the covid has influenced your social life), at the family level, and at work (in your professional life). What has changed in your life since the start of the covid? What is positive and what is negative? What are some of the challenges you have faced during COVID-19? What advice would you give to others to keep their spirits up during the pandemic?

---

I will be building and updating this list directly with what you say, so...
**Remember the comment!**

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aqefvymp8s1dxngaeseu.png)

---

Last week's discussion was about what work would developers do if they weren't developers. An astronaut🚀, a cook👩‍🍳, a dancer🕺 (maybe not this one), a policeman👮, a footballer⚽ (only if I lose my brain)...
You can receive the weekly discussion recap [directly in your email](https://worldindev.ck.page
) or participate in the conversation [here](https://dev.to/devlorenzo/if-you-weren-t-a-dev-you-d-be-a-31c4)!

{% link https://dev.to/devlorenzo/if-you-weren-t-a-dev-you-d-be-a-31c4 %}

---

Read also:

{% link https://dev.to/devlorenzo/10-projects-to-become-a-javascript-master-giveaway-2o4k %}

---

Thanks for reading ❤️

And remember, ![giphy (4)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/idwg3981o7516ls0q93s.gif)

---

## **[Subscribe to my Newsletter!](https://worldindev.ck.page)**
A loooong, and fun, weekly recap for you 
Free PDF version of my articles
Highly customizable inbox
That's --> free <-- and you help me!

---

TL;DR
![giphy (5)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/89hulzy7tol0e645pmn8.gif)
Show off the swag you got (̿ ̿‿ ̿ ̿ ̿)
Tags: discuss, watercooler, showdev
Published: 2021-04-14 12:10:21

---
title: Show off the swag you got  (̿▀̿‿ ̿▀̿ ̿)
published: true
description: What the most recent swag you have received 
tags: discuss, watercooler, showdev
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rflj9x9f20i82ijpbjjk.jpg
---

We can all agree on one thing that swags are awesome. The happiness is unmatched when they arrive at your doorsteps.

Here is what I got recently. Swag from Girl Script Summer of Code 2020. I was a mentor on a project called Ovuli. Really loved it.   

 
{% twitter 1361634388824363008 %}


So, What did you got recently and what's the story behind it?

![](https://media.giphy.com/media/Vc5hyEl7k9ZO3E9skr/giphy.gif)

Also if any of you young sorcerers need mentorship you can always ping me on Twitter [@sarthology](https://twitter.com/sarthology/)
Debug Kubernetes Operator-sdk v1.0.0 locally in Goland
Tags: operatorsdk, vscode, kubernetes, debug
Published: 2021-04-14 12:02:11

---
title: Debug Kubernetes Operator-sdk v1.0.0 locally in Goland
published: true
description: how to setup the debug for the operator-sdk v1.0.0 in Goland
tags: #operatorsdk #vscode #kubernetes #debug
cover_image: https://thepracticaldev.s3.amazonaws.com/i/4n0nt3dyb3k20u8h7d7x.png
---

Wrote this [Debug Kubernetes Operator-sdk locally in Goland](https://dev.to/austincunningham/debug-kubernetes-operator-sdk-locally-in-goland-kl6) last year before the first major release of the Operator-sdk . Due to changes in the Operator-sdk it's not valid for version v1.0.0 and greater.

Here are the steps to get debug running with v1.0.0

- In Goland go to `Run\Edit Configurations`
- Select `Go Build\+`
- Give the configuration a name
- In Files add the path to main.go
- In Environment add `WATCH_NAMESPACE=your-operators-namespace`
 
![Setup goland debug](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljom1l0y2m0xyq18wfoq.gif)

You can then run the debug from the Run menu
- Go to run\debug
- Select the configuration name you just setup
- Debug will start and stop at break points
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/stwvuc360csp941liec0.gif)
Daily Developer Jokes - Wednesday, Apr 14, 2021
Tags: jokes, dailydeveloperjokes
Published: 2021-04-14 12:00:06

---
title: "Daily Developer Jokes - Wednesday, Apr 14, 2021"
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=Wednesday%2C%20Apr%2014%2C%202021"
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/5e1258836687f.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:___ How did the developer announce their engagement?

___A:___ They `return`ed `true`!
 -->
Kotlin SQLite example - Search with Listview | Android
Tags: kotlin, sqlite, listview, android
Published: 2021-04-14 11:58:17

https://grokonez.com/android/kotlin-sqlite-example-search-with-listview-android

In previous <a href="https://grokonez.com/android/kotlin-sqlite-example-crud-operations-with-listview-android">post</a>, we had known how to make CRUD operations with Android <code>ListView</code>. In this tutorial, we're gonna look at how to implement Search function with <code>SearchView</code>.

Related posts:
- <a href="https://grokonez.com/android/kotlin-listview-example-android">Kotlin ListView example | Android</a>
- <a href="https://grokonez.com/android/kotlin-sqlite-example-crud-operations-with-listview-android">Kotlin SQLite example – CRUD operations with ListView | Android</a>

<!--more-->
<h2>I. Technologies</h2>
- Android Studio 3
- Kotlin 1.1.51
<h2>II. Overview</h2>
<h3>1. Goal</h3>
We have had an Android App that supports showing, inserting, editing, deleting Notes from/to SQLite Database with <code>ListView</code>:

<img src="https://grokonez.com/wp-content/uploads/2017/12/kotlin-sqlite-goal.png" alt="kotlin-sqlite-goal" width="700" height="385" class="alignnone size-full wp-image-9793" />

In this tutorial, we will add Search function for this app:

<img src="https://grokonez.com/wp-content/uploads/2017/12/kotlin-sqlite-search-goal.png" alt="kotlin-sqlite-search-goal" width="327" height="561" class="alignnone size-full wp-image-9825" />
<h3>2. Search function</h3>
<h4>2.1 SearchView</h4>
<code>SearchView</code> widget is available from Android 3.0. It is recommended to insert the search widget as an action view in the app bar.

For example, enable the widget during the <code>onCreateOptionsMenu()</code> callback:
<pre><code class="language-java">
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
    menuInflater.inflate(R.menu.menu_main, menu)

    val searchView: SearchView = menu!!.findItem(R.id.searchNote).actionView as SearchView
    val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager

    searchView.setSearchableInfo(searchManager.getSearchableInfo(componentName))
    searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {

        override fun onQueryTextSubmit(query: String): Boolean {
            loadQuery("%" + query + "%")
            return false
        }

        override fun onQueryTextChange(newText: String): Boolean {
            return false
        }
    })
</code></pre>
We need to enable assisted search for each <code>SearchView</code> by calling <code>setSearchableInfo()</code> and passing it the <code>SearchableInfo</code> object that represents searchable configuration.

More at:

Kotlin SQLite example - Search with Listview | Android

https://grokonez.com/android/kotlin-sqlite-example-search-with-listview-android
#AdoptAPerlModule
Tags: perl, cpan, opensource
Published: 2021-04-14 11:48:52

### Do you have some time for open source (and Perl)?

Then [#AdoptAPerlModule](http://neilb.org/2013/07/24/adopt-a-module.html)! :grinning:

Maintaining module is a rewarding position where you can learn more about toolchains concepts and play a role in the Perl ecosystem.

Of course depending how much people depends on your module, it will require more work, reactivity and consistency. But a lot of "orphan" modules fall not in this category.

### Friendly CPAN module is looking for love and care
I listed below some links where you can find modules that **need help** or are **looking for a new maintainer** ("Adoptable").

As a starting point, see first the [adoption's list](https://neilb.org/adoption/) from **Neil Bowers** who integrates metrics like number of issues to extract "possible candidates".

Then there is the [ADOPTME](https://metacpan.org/author/ADOPTME) author on MetaCPAN.
Unfortunately the [HANDOFF](https://metacpan.org/author/HANDOFF) and [NEEDHELP](https://metacpan.org/author/NEEDHELP) search from MetaCPAN are not working well (and actually even the ADOPTME I mentioned you just above is incomplete). ~~Maybe I have to propose a code change to [MetaCPAN](https://github.com/metacpan/metacpan-web) :grinning:~~

EDIT: As shared in comments by @grinnz (thank you!!) we have correct lists in MetaCPAN using the *permissions* views:  [ADOPTME](https://metacpan.org/permission/author/ADOPTME), [HANDOFF](https://metacpan.org/permission/author/HANDOFF) and [NEEDHELP](https://metacpan.org/permission/author/NEEDHELP) :grinning:

You also go on [RT](https://rt.cpan.org/Public/):
- [ADOPTME](https://rt.cpan.org/Public/Dist/ByMaintainer.html?Name=ADOPTME)
- [HANDOFF](https://rt.cpan.org/Public/Dist/ByMaintainer.html?Name=HANDOFF)
- [NEEDHELP](https://rt.cpan.org/Public/Dist/ByMaintainer.html?Name=NEEDHELP)

Or on [CPANMeta](https://cpanmeta.grinnz.com/):
- [ADOPTME](https://cpanmeta.grinnz.com/perms?author=ADOPTME&module=&match_mode=exact)
- [HANDOFF](https://cpanmeta.grinnz.com/perms?author=HANDOFF&module=&match_mode=exact)
- [NEEDHELP](https://cpanmeta.grinnz.com/perms?author=NEEDHELP&module=&match_mode=exact)

And finally, there is also a GitHub organization that [gathers orphan modules](https://github.com/CPAN-Adoptable-Modules)

(If you know more links, please share in comments)

### River position
Take care of the "river" position, don't adopt modules with several dependent packages.
Kotlin methods – any(), none(), all(), contains() example
Tags: kotlin, any, none, all
Published: 2021-04-14 11:42:19

Kotlin methods – any(), none(), all(), contains() example

https://grokonez.com/kotlin/kotlin-methods-none-contains

In the tutorial, <a href="https://grokonez.com">Grokonez</a> will show you how to work with some Kotlin methods: <code>any()</code>, <code>all()</code>, <code>none()</code>, <code>contains()</code>.

<!--more-->
<h2>I. Kotlin methods - any(), none(), all(), contains()</h2>
<h3>1. any() vs none() methods</h3>
Kotlin has 2 signatures for <code>any()</code> method:

<pre><code class="language-java">
// 1. returns 'true' if collection has at least one element.
public fun <T> Iterable<T>.any(): Boolean

// 2. returns `true` if at least one element matches the given [predicate].
public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean): Boolean
</code></pre>
 
<code>none()</code> method is the opposite of <code>any()</code> method. <code>none()</code> method has 2 signatures:

<pre><code class="language-java">
// 1. returns 'true' if the collection has no elements.
public fun <T> Iterable<T>.none(): Boolean

// 2. returns 'true' if no elements match the given [predicate].
public inline fun <T> Iterable<T>.none(predicate: (T) -> Boolean): Boolean
</code></pre>
 
Practice:

More at:

https://grokonez.com/kotlin/kotlin-methods-none-contains
Kotlin Partition method – split List, Map of Objects example
Tags: kotlin, partition, list
Published: 2021-04-14 11:31:23

Kotlin Partition method – split List, Map of Objects example

https://grokonez.com/kotlin/kotlin-partition-method-split-list-map-objects-example

This Kotlin tutorial shows you example that uses <code>Partition</code> method to split <code>List</code>, <code>Map</code> of Objects.

<!--more-->
<h2>I. Technology</h2>
- Java 1.8
- Kotlin 1.1.2
<h2>II. Overview</h2>
- We will split List/Map of <code>Product(name,quantity)</code> objects into 2 Lists using <code>partition()</code> method:
<pre><code class="language-java">
inline fun <T> Iterable<T>.partition(
    predicate: (T) -> Boolean
): Pair<List<T>, List<T>>
</code></pre>
<code>predicate</code> is the condition for the <em>first</em> List of <code>Pair</code>, all remain items will be contained in the <em>second</em> List.
- We also use <strong>Destructuring Declaration</strong> syntax to destructure the <code>Pair</code> into 2 Lists.
<pre><code class="language-java">
val (positive, negative) = List.partition { predicate }
</code></pre>
<h2>III. Practice</h2>
<h3>0. Product Class</h3>

https://grokonez.com/kotlin/kotlin-partition-method-split-list-map-objects-example
You have to start somewhere?!
Tags: beginners, webdev, womenintech, introduction
Published: 2021-04-14 11:25:37

#Hi. 
My name is Aesprii and I would like to get good at designing websites. 
The goal is to make Websites that I can be proud of. Sites that have been built with my "bare hands"; thoughtfully treated with the love and passion they deserve. 

From design process to the finished product - everything (or at least the majority of the site - let's be real here ) should be made by me. 

Since it has been "good practice" to start a blog these days, I want to take this advice by heart and just try to document my journey as I dive deeper into the vast world that is programming.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 

So... *what am I hoping to accomplish here*?

1.) Connect with like-minded people
2.) Share my ideas, struggles and thoughts
3.) Keep track of goals I would like to achieve
4.) Learn HTML, CSS & Javascript to build some awesome websites
5.) ...?

I think this will do for my 1st blogpost.
Always remember: stop overthinking and start doing!

![alt text](https://images.unsplash.com/photo-1529101091764-c3526daf38fe?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1491&q=80 "Logo Title Text 1")

*Thanks for reading!*