teleren/devto huggingface dataset:
The cost of boolean flags
Tags: architecture, codequality
Published: 2020-02-11 21:18:37

# TL;DR

APIs that use boolean flags extensively have reasons to be refactored.

# Boolean flags are convenient

Most of the time boolean flags are the way to go for making the behavior of objects configurable.  They are convenient for partially hiding text in a UI component or changing the way an entity handles incoming requests a bit. But do they come at a cost?

In the simplest case when an interface or a method has one or two flags they don't make any difference. Especially if all the combinations are actually used in a codebase. Things get more complicated as the number grows.

# The cost of convenience

The first consequence of having a lot of flags is that **APIs** designed in this way **might be difficult to understand**. It forces an engineer to read more code at once, slowing them down and increasing the risk of misconfiguration. 

**Another consequence is tests**. Ideally, all combinations of flags should be covered with tests which means the number of tests that should be written can grow rapidly. 

And lastly, these **APIs will probably keep getting more boolean flags**, therefore, violating the Single responsibility and Open-closed principles. Instead of extending the system by adding new entities, the APIs will get more and more flags. 

# Improving the architecture

Inheritance and polymorphism can help to improve the architecture.

```ts
// Before
class LogEntry {
  constructor(private isError: boolean, private text: string)
  getColor() {
    if (this.error) {
      return 'red';
    } else {
      return 'black';
    }
  }
}


// After
abstract class LogEntry {
  constructor(private text: string) {}
  abstract getColor(): string;
}

class DebugLogEntry extends LogEntry {
  getColor() {
    return 'black';
  }
}

class ErrorLogEntry extends LogEntry {
  getColor() {
    return 'red';
  }
}
```

Composition can also be a good fit in other cases.


```ts
// Before
function getText(isMainView: boolean) {
  const additionalText = isMainView ? 'additional text' : '';
  return 'text' + additionalText;
}


// After
function getText() {
    return 'text';
}

function getAdditionalText() {
   return 'additional text';
}

function getMainViewText() {
  return getText() + getAdditionalText();
}
```
Will you hire me?
Tags: discuss, javascript, beginners
Published: 2020-02-11 21:08:27

Me - CodeNewbie learning React/ Angular/ VueJs from React /Angular/ VueJs docs website.
You - Hiring Manager 
What questions will you ask me?
Will you consider to hire me?
Will you ask me to code ?
Are you fine if I answer with pseudocode during whiteboard interview?
f-Strings in Python
Tags: python, beginners
Published: 2020-02-11 20:58:39

If you programmed in <a href="https://python.org">Python</a> before, you probably know how to use <a href="https://pythonbasics.org/strings/">strings</a>. You also know that formatting can be quite cumbersome, using <a href="https://docs.python.org/3.8/library/string.html#formatspec">%-formatting</a> makes it look not elegant:

```python
$ python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> name = "Veronica"
>>> "Hello %s" % name
'Hello Veronica'
```

To use multiple variables, it already starts looking cryptic

```python
>>> name = "Veronica"
>>> age = 25
>>> "I am %s and I am %i years old." % (name,age)
'I am Veronica and I am 25 years old.'
>>>
```

**%-formatting** isn't that great, it becomes unreadable with a lot of parameters. Consider this example with manay parameters:

```python
>>> name = "Veronica"
>>> age = 25
>>> lastname = "Sofia"
>>> job = "Teacher"
>>> relation = "Single"
>>> "Im %s %s, Im %i years old and a %s. Im %s" % (name,lastname, age,job,relation)
'Im Veronica Sofia, Im 25 years old and a Teacher. Im Single'
>>>
```

## f-Strings

In Python >= 3.6 there's <a href="https://www.python.org/dev/peps/pep-0498/">f-Strings</a>. They make life much easier. To define one, you need to put an f in the beginning.

Take a look at these examples using f-Strings:
For two variables:

```python
>>> f"Hello {name}. I am {age}"
'Hello Veronica. I am 25'
```

With multiple variables:

```python
>>> f"Im {name} {lastname}, Im {age} years old and a {job}. Im {relation}"
'Im Veronica Sofia, Im 25 years old and a Teacher. Im Single'
>>> 
```

**Related links:**
* <a href="https://www.python.org/dev/peps/pep-0498/">More on f-Strings</a>
* <a href="https://python.org">Python website</a>
Generate beautiful SVG polygons
Tags: codepen, mvg
Published: 2020-02-11 20:57:00

---
title: Generate beautiful SVG polygons
published: true
tags: codepen, mvg
---

<p>Back in 2016 I loved SVG - still do!</p>

<p>This pen I am happy about. Random points are generated. A number of the closest points are used to draw a polygon. First I find them, then I sort them by angle related to current point. All based on another pen I made before.
You can regenerate with current settings or tweak the settings. You can also get the SVG ready for pasting into say Affinity Designer, and work further with the figure.
UPDATED: Option to animate
UPDATED: Option to have random colors :-) + zero width strokes (was min 1)
UPDATED: The colors are now based on Adobe Color CC (Kuler) themes
UPDATED: Removed Adobe Kuler colors (They have removed a RSS feed required)
UPDATED: You can now click form to get new colors+form</p>

{% codepen https://codepen.io/netsi1964/pen/PZJEQe %}
AppleTV apps list using lit-element
Tags: codepen
Published: 2020-02-11 20:48:28

---
title: AppleTV apps list using lit-element
published: true
tags: codepen
---

<p>Playing around with Netlify cloud functions which can be used among other as a fast track to fetch data avoiding cross domain issues. Here I fetch list of AppleTV apps from Apple, and render them using lit-element.</p>

{% codepen https://codepen.io/netsi1964/pen/vYOEemr %}
Email Signup Forms Design Inspiration & Code Snippets
Tags: ux, css, html
Published: 2020-02-11 20:40:31

Email signups forms are the first step to converting your visitors to email subscribers, a well-designed form can influence your visitor’s decision to signup for your emails.  

HTML, CSS Code Snippets for email signup forms

https://codepen.io/errafaiy/pen/REqKvz
How to learn to code faster?
Tags: refactorit, productivity, code
Published: 2020-02-11 20:35:18

Remember your brain is not fixed. It adapts to what you feed to it. Enjoy the process of learning. Make #mistakes. Don't focus on only results. Start with your strengths. Double in on #programming languages you know. Master them.

Patience is the key. Did you fail? Learn more. Apply it. And try again. Talent is a myth. #Hardwork pays off better. #Challenge yourself. Apply for hackathons, competitive programming.

Go breadth-first. Then go deep into a single topic. Don't #technology-hop. Pick one programming language. Stick to it. Pair with peers. Get them to critique your work. Most important - cultivate #perseverance.


--- 

I write about programming and personal finance, so click the **+FOLLOW** button if it interests you!
Get Object's Keys and Values The Easy Way
Tags: javascript, tutorial
Published: 2020-02-11 20:20:18

By using Object methods keys(), values(), and entries(), you can get an array containing object's keys, values, and key values arrays respectively.

Mithilfe der Objektmethoden keys (), values ​​() und entries () können Sie ein Array abrufen, das die Schlüssel, Werte und Schlüsselwert-Arrays des Objekts enthält.

Here is the syntax👇

```javascript
const obj = {
    name: 'codehood',
    type: 'channel'
};

//Get array of object keys
Object.keys(obj); // ['name', 'type']

//Get array of onject values 
Object.values(obj); // ['codehood', 'channel']

//Get array of key/value arrays
Object.entries(obj); 
// [['name', 'codehood'], ['type', 'channel']]
```

👉Follow me on Twitter: https://twitter.com/islam_sayed8
What's your audio player?
Tags: watercooler
Published: 2020-02-11 20:04:25

When I switched from Windows to Mac to learn code, I missed using the audio player I had. It was a small app called Billy (https://www.sheepfriends.com/index-page=billy.html), and it was this freeware audio player that honestly didn't do much other than the basics.

Anyway, now that I'm on a Mac I use something called Vox (https://vox.rocks/), but am curious what you all use!
What happens when you add a wrong "remote origin URL" to your GitHub project?
Published: 2020-02-11 20:02:10

*I must mention, this just happened to me this evening on Tuesday 11th February 2020 and I spent about 15 minutes or so working on that.*

A friend has been asking me for some code that was just locally on my PC, so after he persisted, I just realised all I could do is put it on Github for him to find.

For those that don't know how to push a local project to GitHub, hopefully, these following can help:-
1. Go to your GitHub account on your browser, login(if you aren't logged in).
2. Create a repository with the same name as that of your local project e.g cats
3. Open your terminal & browse to your project directory e.g
```
lailah@DESKTOP-VDD8TTR:/mnt/e/ikowapi$ 
```
then do the following commands
```
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/lailahgrant/cats.git
git push -u origin master
```
Now back to our main question!!!
let's say
instead of the above, you end up doing the following,
```
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/lailahgrant/cat
git push -u origin master
```
I know this can happen because it happened to me today and this is what I did :-
```
lailah@DESKTOP-VDD8TTR:/mnt/e/ikowapi$ git remote add origin https://github.com/lailahgrant/ikowap
lailah@DESKTOP-VDD8TTR:/mnt/e/ikowapi$ git push -u origin master
Username for 'https://github.com': lailahgrant
Password for 'https://lailahgrant@github.com':
remote: Repository not found.
fatal: repository 'https://github.com/lailahgrant/ikowap/' not found
```
 Then after realising my mistake, I now tried to put the correct URL and I got the following errors:-
```
lailah@DESKTOP-VDD8TTR:/mnt/e/ikowapi$ git remote add origin https://github.com/lailahgrant/ikowapi.git
fatal: remote origin already exists.
```
> At this point I was so desperate & I tried every solution in the --help but all in vain.

I finally got a solution from the popular saviour -  *[Stack overflow](https://stackoverflow.com/questions/25463839/git-fatal-will-not-delete-all-non-push-urls)* and all I did was run the following:-
```
lailah@DESKTOP-VDD8TTR:/mnt/e/ikowapi$ git remote rm origin
```
The above command removed all the remote origin URLs I had put.

Now it was safe for me to run the other commands...

```
lailah@DESKTOP-VDD8TTR:/mnt/e/ikowapi$ git remote add origin https://github.com/lailahgrant/ikowapi.git
lailah@DESKTOP-VDD8TTR:/mnt/e/ikowapi$ git push -u origin master
Username for 'https://github.com': lailahgrant
Password for 'https://lailahgrant@github.com': 
Counting objects: 185, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (180/180), done.
Writing objects: 100% (185/185), 1005.56 KiB | 3.63 MiB/s, done.
Total 185 (delta 32), reused 0 (delta 0)
remote: Resolving deltas: 100% (32/32), done.
To https://github.com/lailahgrant/ikowapi.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
lailah@DESKTOP-VDD8TTR:/mnt/e/ikowapi$ 
```

***Hopefully you found this helpful, Thanks for reading through***
Compile Python3.7 on Solaris 10
Tags: python, opensource
Published: 2020-02-11 19:57:36

Today I've spent some hours fighting with Solaris 10 trying to compile Python3.7 from sources with openSSL support.

The process is quite simple so I'll write it here so it can help someone with the same problem.
```
pkgadd -d http://get.opencsw.org/now
/opt/csw/bin/pkgutil -U
/opt/csw/bin/pkgutil -y -i libssl_dev
/opt/csw/bin/pkgutil -y -i libssl1_0_0
/opt/csw/bin/pkgutil -y -i libreadline6 
/opt/csw/bin/pkgutil -y -i libreadline_dev 
/opt/csw/bin/pkgutil -y -i libncurses_dev 
/opt/csw/bin/pkgutil -y -i libssl_dev 
/opt/csw/bin/pkgutil -y -i libsqlite3_dev 
/opt/csw/bin/pkgutil -y -i tk_dev 
/opt/csw/bin/pkgutil -y -i libgdbm_dev 
/opt/csw/bin/pkgutil -y -i libbz2_dev 
/opt/csw/bin/pkgutil -y -i libffi_dev 
/opt/csw/bin/pkgutil -y -i tk 
/opt/csw/bin/pkgutil -y -i pkgconfig 
/opt/csw/bin/pkgutil -y -i libsodium_dev # for paramiko
wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tgz
gunzip -c Python-3.7.6.tgz | tar xvf -
cd Python-3.7.6
```
tip: edit Modules/socketmodule.c 

```
$ diff -u ../socketmodule.c Modules/socketmodule.c
--- ../socketmodule.c   Wed May 15 16:36:32 2019
+++ Modules/socketmodule.c      Wed May 15 15:34:50 2019
@@ -5212,6 +5212,10 @@
 extern int sethostname(const char *, size_t);
 #endif

+#if (defined(__sun) && defined(__SVR4))
+extern int sethostname(const char *, size_t);
+#endif
+
     if (!PyArg_ParseTuple(args, "S:sethostname", &hnobj)) {
         PyErr_Clear();
         if (!PyArg_ParseTuple(args, "O&:sethostname",
```
To avoid an error related to sethostname.

Also, yo avoid problems with ctypes module you need to add the PKG_CONFIG_PATH option in the configure statement as follow:


```
  ./configure --prefix=/opt/python3 --with-openssl=/opt/csw/ --enable-optimizations LDFLAGS='-L/opt/local/lib -I/opt/csw/include -L/opt/csw/lib  -R/opt/local/lib' PKG_CONFIG_PATH=/opt/csw/lib/amd64/pkgconfig/ CPPFLAGS='-L/opt/local/lib -I/opt/csw/include -L/opt/csw/lib  -R/opt/local/lib'

 gmake
 gmake install
 PATH=/opt/python3/bin/:$PATH
```

You won't be able to use pip3 without adding such openssl flag to the configure step. And you need to install exactly the version 1.0.0 of libssl from CSW.

With all of this we will have python3 installed and pip3 working!

If you need to install pandas or numpy or somilar software I would recommend: 

```
/opt/csw/bin/pkgutil -y -i gcc5g++ libffi_dev libssl_dev libbabl_dev cython automake autoconf libsodium_dev jq pkgconfig cswpki libatlas_c++ libatk_dev
pip3 install --upgrade cython
pip3 install pandas
```


Best regards.
the elvis operator
Tags: groovy
Published: 2020-02-11 19:09:24

---
title: the elvis operator
published: true
description: 
tags: groovy
---

I was reading through Groovy 3.0 release notes

https://groovy-lang.org/releasenotes/groovy-3.0.html

Lots of stuff but what caught my eye was the elvis operator

```groovy
// original elvis operator
?: 

// shortened elvis operator
?=
```

Looks longer to me. :)

More on the elvis operator here at wikipedia if you have not encounter such a thing before: https://en.wikipedia.org/wiki/Elvis_operator
Angular Code Generation and injecting CSS
Tags: angular, typescript
Published: 2020-02-11 18:59:27

One aspect of code generation is injecting CSS at run time.  Angular does this automatically by employing [View Encapsulation](https://angular.io/guide/component-styles#view-encapsulation) which is just a fancy name for 'Use the component view's CSS first'.

But let's assume we are creating our components based on JSON only; which means we are bypassing the Angular component CSS system, like this:

```javascript
     { 
       propertyName: "Log Errors", 
        type: "checkbox", 
        checked: false },
     { 
       propertyName: "Send Email on Failure",
        type: "checkbox",
        checked: false
     },
     { 
       propertyName: "Job 4 max duration",
        type: "duration",
        time: "01:02:10",
        style: { height: "6em" }
     },
```

Our *duration* control looks like this when rendered:

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

It needs to have a height specified because the auto-generated HTML markup looks like this:

```html
<div *ngIf="control.type === 'duration'">
   <div [ngStyle]="control.style">
      <input
         type="number"
         min="0"
         max="24"
         placeholder="HH"
         (change)="onHoursChanged()"
         value="{{ onGetHours(control.time) }}"
      />
      <input
         type="number"
         min="0"
         max="59"
         placeholder="MM"
         (change)="onMinutesChanged()"
         value="{{ onGetMinutes(control.time) }}"
      />
      <input
         type="number"
         min="0"
         max="59"
         placeholder="SS"
         (change)="onSecondsChanged()"
         value="{{ onGetSeconds(control.time) }}"
      />
   </div>
</div>
```
If we don't have a height then the next control in the layout will override the view area of the duration control.

We use [ngStyle] to inject the height based on the control.style property, which is shown in the JSON above.  It's simply an object which contains style markup like this:

```css
style: { height: "6em" }

```
It's not intuitive that it should work like that but this is how Angular's nGstyle works! The brackets [nGstyle] means to interpolate the string that follows, e.g use the value of control.style as control.style is NOT a literal string representation it's the name of a variable.

JWP2020
Understanding Dependency Injection in .NET Core
Tags: dotnet, dependencyinjection, programming
Published: 2020-02-11 18:19:33

---
title: Understanding Dependency Injection in .NET Core
published: true
description: Learn what Dependency Injection and IoC are and what .NET Core provides you to support them.
tags: #dotnet #dependencyinjection #programming
canonical_url: https://auth0.com/blog/dependency-injection-in-dotnet-core/
---
TL;DR: Dependency Injection is one of the most known techniques that help you to create more maintainable code. .NET Core provides you with extensive support to Dependency Injection, but it may not always be clear how to apply it. This tutorial will try to clarify the various Dependency Injection concepts and will introduce you to the support provided by .NET Core.

[Read on 📖](https://auth0.com/blog/dependency-injection-in-dotnet-core/?utm_source=dev&utm_medium=sc&utm_campaign=di_dotnet)
Top 5 DEV Comments from the Past Week
Tags: bestofdev
Published: 2020-02-11 18:10:02

---
title: Top 5 DEV Comments from the Past Week
published: true
description: Highlighting some of the best DEV comments from the past week.
tags: bestofdev
cover_image: https://res.cloudinary.com/practicaldev/image/fetch/s--7VrAA2ln--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://thepracticaldev.s3.amazonaws.com/i/qmb5wkoeywj06pd7p8ku.png
---

This is a weekly roundup of awesome DEV comments that you may have missed.  You are welcome and encouraged to boost posts and comments yourself using the **[#bestofdev](/t/bestofdev)** tag.

@bcnzer shares their most commonly referenced search in **[What do you have to Google? Every. Single. Time.](https://dev.to/helenanders26/what-do-you-have-to-google-every-single-time-2o8a)**:
{% devcomment la9d %}

@cristinaruth adds some extremely helpful feed back directly to the DEV Team in the **[Hello again. It's time to do some work!](https://dev.to/devteam/hello-again-time-to-do-some-work-3b6o)** thread:
{% devcomment l67c %}

@ivannmg offers a hilarious and somewhat tragic anecdote in response to **[Tell me something funny about your first DEV job](https://dev.to/pachicodes/tell-me-something-funny-about-your-first-dev-job-3hb4)**:
{% devcomment l8p7 %}

@ghostcat provides a great list in reply to **[What are your favorite portfolio sites for devs?](https://dev.to/mocasalter/what-are-your-favorite-portfolio-sites-for-devs-21bc)**:
{% devcomment l8an %}

Finally, @craigmc08 expands with an enlightening comment and some helpful visuals in **[Improve Your Algorithms with this Simple Equation](https://dev.to/nielsenjared/improve-your-algorithms-with-this-simple-equation-3g1c)**:
{% devcomment l8ke %}

See you next week for more great comments ✌
How to add podcast to dev.to
Tags: discuss, help, podcast
Published: 2020-02-11 17:59:35

---
title: How to add podcast to dev.to
published: true
description: Did you know there is a page of podcasts? 
tags: discuss, help, podcast
---

I recently started a podcast and would like to have it feed into dev.to, is this issue still the best method?

https://github.com/thepracticaldev/dev.to/issues/955

For those who have not seen the link:
https://dev.to/pod
My first PR approved to the Flutter SDK
Tags: dart, flutter
Published: 2020-02-11 17:52:13

So, this was a fun experience submitting my first [PR](https://github.com/flutter/flutter/pull/49148) of the year and it was very small, not going to lie. I've dabbled with supporting open source projects from time to time, but I've never submitted a feature patch to a repo as big as the [Flutter SDK](https://github.com/flutter/flutter/). Let alone anything tied to Google.

It was definitely an experience, because I don't have that much experience with the testing library. There's a lot that I feel is undocumented and the testing library is actually cool as hell. The google flutter dev that assigned themselves to my repo showed me that you can actually drag the ui from the testing lib and find specific things within the screen view and actually detect if you've properly hit a specific widget. That level of integration testing is fascinating and honestly I hope someone writes more on it because there's just so much I want to understand from the testing library. 

_(All the testing code is credited to Shi-Hao)_

```dart
customController.animateTo(
    40.0,
    duration: const Duration(milliseconds: 200),
    curve: Curves.linear
);

await tester.pumpAndSettle();
Offset listViewTopLeft = tester.getTopLeft(
    find.byType(ReorderableListView),
);

Offset firstBoxTopLeft = tester.getTopLeft(
    find.byKey(firstBox)
);

expect(firstBoxTopLeft.dy, listViewTopLeft.dy - 40.0);
```

I'm definitely used to simple unit tests, that's easy, but integration tests for actually testing how the the UI responds and works as intended is very cool and there's just so much to learn.

As for the PR I added, [`ReorderableListView`](https://api.flutter.dev/flutter/material/ReorderableListView-class.html) didn't expose the scroll controller like the ListView builder did. So you were forced to wrap it in a [`PrimaryScrollController`](https://api.flutter.dev/flutter/widgets/PrimaryScrollController-class.html) to pass your own scroll controller which seemed like a tedious step. So I decided this would be my chance to hit one of my goals this year, which was to contribute more to open source and damn was this a big first step starting with this PR.

Now whenever this gets added, I'll be able to use one of my favorite packages called [**Flutter Speed Dial**](https://pub.dev/packages/flutter_speed_dial) without a `PrimaryScrollController` that allows me to auto hide the dial visibility when I move the scroll view. :)

This was definitely an intimidating PR because of the people behind it, but damn if I can do it so can you :)!
Laravel 6 Ajax Image Upload with Preview Using Base 64
Tags: laravel, ajax, imageupload, base64
Published: 2020-02-11 17:47:22

Hello Artisan 

Today, I am going to show you How to image or file upload using jquery Ajax in our Laravel application using base 64. I won't use image intervention before store it into database, but you can use it if you want.

In this laravel 6 jquery ajax Image upload tutorial i will show you how to upload image using ajax request.  Also we will see how to validate the image before uploading it into server.

https://www.codechief.org/article/laravel-6-ajax-image-upload-with-preview-using-base-64