teleren/devto huggingface dataset:
Python 'is' vs '=='
Tags: beginners, python
Published: 2019-09-06 20:29:19

---
title: Python 'is' vs '=='
published: true
tags: beginners, python
canonical_url: https://wangonya.com/blog/python-is-vs-==/
---

A lot of times when I'm doing `if`s in Python, I find myself wondering whether to use `is` or `==` for the check.

```
# do I do
if a is b:
    ...

# or
if a == b:
    ...
```

It can be a bit confusing if you're new to Python, and it's easy to assume the two can be used interchangeably. So, what's the difference?

## `is`

The `is` operator checks if both elements point to the same object. Let's fire up a python console to help illustrate this:

```
$ python3
Python 3.7.4
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> a = []
>>> b = []
>>> c = a

>>> a
[]
>>> b
[]
>>> c
[]
>>>
```

So, we've declared three variables and assigned them values. `a` and `b` are both empty lists, and `c = a`. We can see that all three variables contain an empty list. Using `is` to compare them:

```
>>> a is b
False
>>> b is c
False
>>> a is c
True
```

Despite the fact that `a` and `b` seem identical (in that they're both empty lists), the variables `a` and `b` do not point to the same object, therefore `a is b` evaluates to `False`. The same goes for `b is c`.

Conversely, because we assigned the variable `a` to `c`, they both point to the same object, thus `a is c` is `True`.

## `==`

`==` on the other hand checks if both elements contain equal values. Whether or not they point to the same object doesn't matter here.

```
>>> a == b
True
>>> b == c
True
>>> a == c
True
```

All checks using `==` evaluate to `True`, because the values of `a`, `b` and `c` are all equal. If `d = [1, 2, 3]` is introduced, `a == d`, `b == d` and `c == d` would all be `False`, because the values are not equal.

So if you want to check that elements point to the same object, use `is`. If you're only interested in the equality of the values, use `==`.
Smooth transition with text styles in Flutter
Tags: flutter, dart
Published: 2019-09-05 23:56:53

---
title: Smooth transition with text styles in Flutter
published: true
description: 
tags: flutter, dart
---

Hey folks! In this short article, I'll be showing you how to add a smooth transition between styles of the same text widget for example.

 First let's declare the initial style:

```
final TextStyle initialStyle = TextStyle(
  fontSize: 20.0,
  color: Colors.grey,
  fontWeight: FontWeight.bold,
);
```

Then the final style:

```
final TextStyle finalStyle = TextStyle(
  fontSize: 22.0,
  color: Colors.black,
  fontWeight: FontWeight.bold,
);
```
We'll also use a boolean to handle the state of our text widget, whether it's tapped or not:

`var isTapped = false;`

Then, wrap the text widget inside `the AnimatedDefaultTextStyle` widget to enable a transition between your styles. Last, you can wrap all this in the `InkWell` widget with the boolean to switch between the styles on tap. 

```
InkWell(
        onTap: isTapped = !isTapped,
        child: AnimatedDefaultTextStyle(
          style: isTapped ? finalStyle : finalStyle,
          duration: const Duration(milliseconds: 500),
          child: Text(
           "Hello World"
          ),
        ),
      )
```

The image below summarizes all.


![Imgur](https://imgur.com/qwTYOUj.png)


That's all for this post. Thanks for your attention :)
Fantasy Football Team Names for Developers (and other geeks)
Tags: watercooler, offtopic, discuss
Published: 2019-09-05 21:31:49

After seeing [Ben's post](https://dev.to/ben/who-wants-to-join-the-dev-fantasy-football-league-48j2) regarding a DEV Fantasy Football League, I started brainstorming nerdy team names for a developer league.

Here's what I've come up with so far - feel free to chime in with any more suggestions. 

- Computer Zeke
- Zeke Squad
- MIT Smith
- Black Gurleys Code
- sudo win
- Code Beasley
- Automated Dak-ups
- dd($westbrook);
- DEVante Adams
- DEVonta Freeman
- Odudeyouregettingadell Beckham Jr.
- Hooli-o Jones
- Patrick MaHomeScreen
- RTFM Sanders
- Los Angeles RAM Limits
- Los Angeles I Forgot My Chargers
- Houston RichTexansFormat
- Arizona Memorycardinals
- Green Bay Hewlett Packers
- Kansas City CTOs

The season starts tonight! Good luck to everyone out there playing in a league. 🤓🏈
Welcome to the Big Thread Club, stereobooster. You are the latest winner of the Big Thread Badge. 🎉
Tags: meta, bigthreadbadge
Published: 2019-09-05 22:17:20

Stereobooster joins @liyasthomas, @emmawedekind, @neilonsoftware, @andrewbrown, @mjraadi, @room_js, @iam_timsmith, @fullstack_to, @espoir, @helenanders26, @philnash, @florinpop17 and @lauragift21 in the club as the 14th winner of this badge.

{% user stereobooster %}

The Big Thread Badge is awarded to the person who creates a discussion thread on the site that sparks the most collective comment love (e.g. score as determined by total ❤️ reactions and adjacent ranking factors).

This was Stereobooster' thread:

{% link https://dev.to/stereobooster/apple-wants-to-remove-scripting-languages-2l0i %}

Entry is simple: Start a thread that is bound to spark a lot of comments. Ask the community to tell a certain kind of story and get lots of comments! Even if these threads aren't always answering _the deep questions_, they are often great for seeing what the broader community thinks of a topic and are usually a lot of fun!

Use the #discuss tag to signal that the post is a discussion thread.

{% tag discuss %}

_DEV employees are not eligible for the Big Thread Badge. 🙂_

## **Happy Coding!**
If you could travel back to when you started learning programming... what advice would you give yourself?
Tags: discuss
Published: 2019-09-05 20:58:38

---
title: If you could travel back to when you started learning programming... what advice would you give yourself?
published: true
description: What piece of advice would you give to your younger self if you had the chance?
tags: discuss
---

Time travel is not possible, yet, but it's always a fun thought exercise to think about these types of situations.

What nugget of wisdom have you gained over the years that you'd give your younger self? Share it with the community, that way others who're just starting out can benefit as well!

I'll start: if I could, I'd tell myself to never give up game development, and as an added bonus, to start questioning the status quo way earlier. _What about you?_
What have you built/automated with headless browsers (e.g. Puppeteer)?
Tags: discuss, watercooler, vscode
Published: 2019-09-05 19:37:50

---
title: What have you built/automated with headless browsers (e.g. Puppeteer)?
published: true
description: 
tags: discuss, watercooler, vscode
---

Hey All! I’ve been recently exploring [Puppeteer](https://github.com/GoogleChrome/puppeteer) in order to automate simple tasks for myself (e.g. capturing screenshots and PDFs). I'm extremely amazed by how easy it is to drive the browser UI, as well as inspect network requests/performance data/etc., and I can only imagine how powerful headless browser automation can be, not only for E2E tests, but also business processes (e.g. automate data collection/entry) 🚀

I'm curious to hear from others, in order to learn whether you've used headless browsers for automation, and if so, what for? (e.g. end-to-end tests, automating a business process, etc.) In particular, it would be awesome to know what tasks you're automating, which specific tools/frameworks you've used (e.g. Selenium), and what your experience was like building/maintaining the automation scripts. Thanks!
Three things from today - 9/5
Tags: devjournal, kubernetes, spark, datascience
Published: 2019-09-05 20:42:11

#9/5/2019
###Spark it up!

Today has been rough, but it's looking up. Three things incoming - ALL Spark related :)

##1.  [cnvrg.io - spark-on-kubernetes webinar](https://info.cnvrg.io/spark-on-kubernetes)

I hope to finish this tonight it seems like a nice intro to Spark on Kubernetes and I'm digging it so far.

Cnvrg.io seems to be a botique data science platform similar to Databricks, I'll definitely have my eye on them.

##2. Spark tuning for shuffles

[Found this gem for spark tuning - a great outline on why shuffles occur and what you can do to tune them.](https://stackoverflow.com/a/30801877/2184401)

##3. Spark exit status and exit codes.

Another great StackOverflow find regarding [Spark exit status and exit codes](https://stackoverflow.com/questions/45428145/do-exit-codes-and-exit-statuses-mean-anything-in-spark/45524760#45524760).


See you party people tomorrow!
HashiCorp Vault+AWS Secrets+Rotation tool?
Tags: vault, aws, secrets, hashicorp
Published: 2019-09-05 20:06:54

In the process of implementing HashiCorp Vault and utilizing the AWS secrets engine. We have LDAP set up as an auth method and users are able to curl the vault endpoint to pull credentials:

    curl --request POST --data @payload.json https://vault-api.test.com/v1/auth/ldap/login/me | jq '.'
    
    curl --header "X-Vault-Token: mytoken" --request GET https://vault-api.test.com/v1/aws/creds/grp-aws-r-usersrole | jq

Access keys are granted - does anyone know of a script/tool that's already in place that:

1. Securely creates the payload.json with your LDAP password
2. CURL's the Vault endpoint with the payload
3. Deletes the payload file
3. Retrieves the token
4. CURL's the Vault endpoint with the token to retrieve the ephemeral access keys
5. Loads the access keys in the .aws/credentials store

I've used https://github.com/Fullscreen/aws-rotate-key before we moved to Vault but it's no longer applicable.

Should I write something and share?
What do you wish to know about JavaScript when you were in university?
Tags: discuss, help, javascript
Published: 2019-09-05 19:56:27

Hey guys!

I was asked if I would like to make a couple of lectures at the university about plain JavaScript (basics). And I would love to but I'm not sure where to start.

So here we are. Some of us are years after school/uni and some of us are still there. What do you wish to know about JavaScript when you were in university? And what would you like to say to students right now?

Any tips, help, ideas or even articles are welcome! 😁
My first Code Review as a newbie
Tags: webdev, beginners, firstyearincode
Published: 2019-09-05 19:55:07

Hey fellow developers,

I just experienced my professional code review session and listed below are my thoughts. 

1. IMHO, it will be wise to have a more experienced developer speak on your behalf when it comes to translating technical details to business stakeholders.
2. If the session is on some sort of conference call, Prepare to experience every technical difficulty that could ever arise under the sun lol.
3. Make sure to review your user stories before the code review, FYI( Thank me later).

If you're reading this post, feel free to let me know your stories or inputs about your first code reviews.
A better WordPress admin title.
Tags: wordpress, posts, editor, theme
Published: 2019-09-05 19:18:51

---
title: A better WordPress admin title.
published: true
canonical_url: https://www.adampatterson.ca/2019/a-better-wordpress-admin-title/
description: 
tags: WordPress,Posts,Editor,Theme
---

At the moment I have 5 posts open to edit.  Looking at them, all I see is "**Edit Post < Adam Patterson - WordPress**".

Sure 5 tabs aren't that many and not that hard to sort through but I began to wonder why WordPress wouldn't simply show the post title for pages and posts.

Lucky for me, it wasn't that hard.

First, we need to create a new filter that will be called when the admin page title is generated. This filter is called `admin_title`.

Next we will pull a few variables out of the global scope `$post, $title, $action, $current_screen`.

After we check that we are on the admin page and that the action is edit and not add. All that is left to do is make sure we are in the context of editing a post or a page. I supposed you could go farther by doing some experimenting here but this suited my needs just fine.

Lastly, structure your page title to suit you.

I ended up with "**Edit Post < Post Name - Adam Patterson**" or "**Edit Page < Post Name - Adam Patterson**".

I suppose the purists might want to keep WordPress in the title, but it's long enough that I don't see it as is so I am good without.

Simply add the following code to your themes `functions.php` file and you are all set!

```
add_filter('admin_title', 'better_admin_title', 10, 2);

function better_admin_title($admin_title, $title)
{
    global $post, $title, $action, $current_screen;
    if (is_admin() and $action == 'edit' and in_array($current_screen->id, ['post', 'page'])) {
        return $title . ' ‹ ' . $post->post_title . ' — ' . get_bloginfo('name');
    }

    return $admin_title;
}
```

Read more about [admin_title](https://developer.wordpress.org/reference/hooks/admin_title/)
Dev.to is presenting Hacktoberfest?!
Tags: meta, hacktoberfest
Published: 2019-09-05 19:17:46

---
title: Dev.to is presenting Hacktoberfest?!
published: true
description: 
tags: meta, hacktoberfest
---

I just saw the Hacktoberfest pre-lauch site and noticed that the DEV logo was there!

![dev logo](https://thepracticaldev.s3.amazonaws.com/i/6qrnxwgos8goye4rczls.png)


This awesome! Congrats to Ben and the team!!

I can't wait for Hacktoberfest!
JavaScript syntax: event listeners
Tags: javascript, syntax
Published: 2019-09-05 19:15:27

People learn in a wide range of different ways. The easiest and most logical path to one person might seem a confusing puzzle to another. Luckily for the coding community, the code that we write can be varied and flexible. I stumbled across a great example of this in a recent JavaScript lesson regarding event listeners that were added to buttons.

To add an event listener to a button is simple. We can write it as such:

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/0f3vr0iiciwe0wtgebi2.png)

In this example, whenever the "click" event happens to our designated button, the function "myFunction()" will fire. You can then go on to write out what that function will do when it is triggered. This approach is what was introduced to me at first, but then my instructor showed me a different way to do things that made much more sense to me.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/ctc2o36iyehwvphbvajq.png)

In this example, I add my event listener to my button by appending ".onclick" to the variable that I have designated for the button itself. By then calling my event, "e", I use an arrow function to dive into what function the button will have once it's clicked without stopping to define another function.

Both of these examples accomplish the same thing, and both function as intended. Some of my classmates preferred one way over the other. What I have come to love about coding the most is that there are a near limitless ways to go about finding a solution to a problem. Some might be more cumbersome and convoluted than others. Some might be far cleaner and utilize fewer lines of code. Each of us will have our own styles and ways of navigating through problems. Every path taken will be correct, as long as the solution is achieved.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/pr0e6vum0hx55c7edn8l.jpg)
Testing iframes in React with Enzyme
Tags: testing, javascript, react, webdev
Published: 2019-09-05 19:07:42

I recently worked on an unusual and somewhat anachronistic requirement, presenting a marketing/sales form using an [iframe](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe) inside a [React.js](https://reactjs.org/) app, with a seamless UX to boot. The integration uses [postMessage](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) for cross-domain page communication, which proved an interesting challenge for unit-testing.

The stripped down example below demonstrates the use of a React [function component](https://reactjs.org/docs/components-and-props.html) and a [callback ref](https://reactjs.org/docs/refs-and-the-dom.html#callback-refs). The component sends a message to the page within the iframe once it has loaded.

```javascript
function IframeComponent({ domain, path }) {
  let iframeRef;
  const post = (msg) => iframeRef.contentWindow.postMessage(JSON.stringify(msg), domain);
  const onIframeLoad = () => post({foo:'bar'});
  const getRef = (el) => iframeRef = el;
  return (
      <iframe
        ref={getRef}
        src={domain + path}
        onLoad={onIframeLoad}
      />
  );
}
```

I wanted to test the load behaviour without having to load the contents of the iframe, my solution (after a lot of digging around on the internet) was to use a test double for the iframe by gaining access to, and invoking the ref callback.

The test below is written with [Mocha](https://mochajs.org/), [Chai](https://www.chaijs.com/api/bdd/), [Enzyme](https://airbnb.io/enzyme/) and [Sinon](https://sinonjs.org/)

```javascript
describe('IframeComponent', () => {
  it('should invoke load message correctly', () => {
    const domain = 'https://my.domain.com';
    const wrapper = shallow(<IframeComponent domain={domain} path="/page"/>);
    const iframe = wrapper.find('iframe');
    const spy = mockIframePostMessage(iframe);
    const props = iframe.props();

    expect(props.src).to.be.equal(domain + path);
    expect(spy.called).to.be.equal(false);
    
    iframe.simulate('load');

    expect(spy.called).to.be.equal(true);
    expect(spy.args[0][0]).to.be.equal(JSON.stringify({ foo: 'bar' }));
    expect(spy.args[0][1]).to.be.equal(domain);
  });
});
```

And below shows how, using Enzyme we can find the iframe React node and invoke its ref callback, providing the simple test double.

```javascript
function mockIframePostMessage(iframe) {
  const postMessage = sinon.spy();
  const iframeMock = {
    contentWindow: {
      postMessage,
    },
  };
  iframe.getNode().ref(iframeMock);
  return postMessage;
}
```
> Note: I believe `getNode` has now been replaced by `getElement` in the latest version of Enzyme.

This approach provides a nice, simple way to write fast tests for iframes in React :rocket:
Performance: Tree-Shake with environment.ts
Tags: angular, performance
Published: 2019-09-05 18:47:31

You probably get to the point where you only need modules that has to be there during development but not in the production build.

For example:

I use `@ngrx/store-devtools` nearly all the time while developing. 

In order to not have this module on my production build, I thought, the solution was *easy*-ish, just use the environment-condition to exclude it from the build.

```ts
import {environment} from '../environments/environment';
import {StoreDevtoolsModule} from '@ngrx/store-devtools';

const additionalImports = [];

if (!environment.production) {
  additionalImports.push(StoreDevtoolsModule.instrument({
    maxAge: 25
  }));
}


@NgModule({
  import: [
    ...additionalImports
  ]
})
```
<figcaption>app.module.ts</figcaption>

But the compiler still adds the module to production build: about `18 kb` added for this module, sure its not "that" much but this adds up to the loading+parsing/eval-time, which you probably don't need.


## Using `environment.ts` the better way :)

Since angular adds a default `fileReplacements` config for `environment.ts` and `environment.prod.ts` those will be only compiled into during development/production build. 

We can also use this to add different modules for our development phase / or to production vice versa.

```ts
import {StoreDevtoolsModule} from '@ngrx/store-devtools';

export const environment = {
  production: false,
  modules: [
    StoreDevtoolsModule.instrument({
      maxAge: 25
    }),
  ]
};
```
<figcaption>environment.ts</figcaption>


```ts
import {environment} from '../environments/environment';


@NgModule({
  import: [
    ...environment.modules
  ]
})
```
<figcaption>app.module.ts</figcaption>

## :tada: Now that module is only added during development and not in your production build :tada:

Maybe in the future it will be possible to tree-shake these kinds just by using `if (environment.production)`, but until then we have a nice workaround. 

### `Protip 1:` Use an interface for your environment files.

Have a `environment.def.ts`-File which is something like:
```ts
export interface Environment {
  production: boolean;
  modules: any[];
}
```

That way both (or more?) environments will be at least consistent on the properties.

### `Protip 2:` Use a path-alias
```json
  "compilerOptions": {
    "paths": {
      "@myApp/env": ["apps/myApp/src/environments/environment"]
    }
  }
```
<figcaption>tsconfig.json</figcaption>

Then you can import your environment in any file just by `@myApp/env` instead of `../../../..and/so/on../../environment` 

<hr>

### I really would like to know, if you have/use modules only during dev/prod?
Since it's Friday again
Tags: weekendlearning
Published: 2019-09-05 18:33:08

A lot of people are waiting eagerly for Friday and why not?
It's that part of the week where we get into groove and celebrate our life. 
But...and a big but,it's again the time for picking up your side project that you started 2 weeks ago and hope to finish within one weekend.
Enough of blabbering,this being my first post on Dev.to,I am going to make a statement here. This weekend,I will add **Redux** to my coding arsenal. What are you guys gonna do? Would love to know about your weekend. Everyone is welcome to share.
With Love,From India.
Why you should add Generative Art to your resume
Tags: beginners, python
Published: 2019-09-05 18:26:44

For those that aren't familiar with generative art, it is the process of creating something visually appealing through code. With truly endless possibilities, using code to create art has become one of my favorite hobbies outside of work. I think generative art promises many benefits, both personally and professionally, and I've tried to list a few of the ones I've experienced below.

 * **Impress Recruiters:** I think it's very important to have at least a few projects that result in something physical or visual. Explaining your side projects to a recruiter is an extremely important part of the hiring process and generating interest quickly is paramount. With a generative art project, I get to talk about my programming process alongside an intriguing **visual product**. I'm not saying you should only have art projects, but having at least a few couldn't hurt.

 * **Motivate Yourself:** In my personal experience with programming, most of my work never really manifests into something physical that I can appreciate. With generative art, I'm able to create my own prints and appreciate the output of my code in an entirely new way. It's cheesy, but seeing these reminders of what I've created encourages me when tackling new problems.

 * **Expand Your Knowledge:** Working on these projects has exposed me to types of problems that I don't generally encounter in my regular job. Most of these problems are rooted in mathematics, and you're guaranteed to have that familiar relief when you finally start to understand exactly what is happening. 

 * **Make Some Sales:** There are plenty of people that have found some measure of success selling prints of their projects. It's completely fine to just appreciate your work on your own, but you never know...

 * **Have Fun:** Definitely the most important part. If it isn't at least a little fun, why do it?


If you're interested in learning more about Generative Art and how to make your own, I've included links below to two basic tutorials that utilize [Processing](processing.org). 

For examples of my projects (and the code for them), check out [this repository](https://github.com/erdavids/Generative-Art).

{% youtube Kg6YIDZ-JpY %}
{% youtube 0emj42Bn-_Y %}

I hope this has been somewhat helpful, thank you for reading!