teleren/devto huggingface dataset:
Django Cheat Sheet: Keep Credentials Secure with Environment Variables
Tags: python, learning, beginners, webdev
Published: 2019-09-17 17:05:30

---
title: Django Cheat Sheet: Keep Credentials Secure with Environment Variables
published: true
description: How to use environment variables to keep secure keys out of your code.
tags: python, learning, beginners, webdev
cover_image: https://source.unsplash.com/Uf-c4u1usFQ/1600x900
---

Tl;DR
Hard coding config values and credentials is convenient but makes your code less secure and less portable. Use environment variables to make your code more secure and easy to deploy in different environments.

Bad:
```
TWILIO_SECRET_KEY = "iamverysneaky"
twilio_client = Twilio(key=TWILIO_SECRET_KEY)
```

The problem:
If someone gets access to your code, now they have access to your Twilio account too! Two problems for the price of one!

Good:
```
from dotenv import load_dotenv

load_dotenv()

twilio_client = Twilio(key=os.getenv("TWILIO_SECRET_KEY"))
```

If someone gets access to your code, at least your Twilio account (and user data!) is still safe.

To illustrate how this works, we'll move the auto-generated `SECRET_KEY` value out of `settings.py` and into an environment variable.

From this:
```
SECRET_KEY="thisismyunsecuredsecretkey"
```
To this:
```
SECRET_KEY=os.getenv("DJANGO_SECRET_KEY")
```

Do these things:
1. Download the dotenv package. ```
$ pip install python-dotenv
```
2. Create a file named `.env` in the same directory as `settings.py`. ```
$ touch .env
```
3. Add the `.env` file to your `.gitignore`. This is the most important step bc it keeps `.env`, and thus your secret values, outside of version control/Git. ```
$ echo .env >> .gitignore
```
4. Add your config values and credentials to .env. ```
$ echo 'DJANGO_SECRET_KEY="thisismyunsecuredsecretkey"' >> .env
```
5. Import and load`os` and `dotenv` into `settings.py`. This makes the values accessible. ```
import os
from dotenv import load_dotenv
...
load_dotenv()
```
6. Replace the original `SECRET_KEY` value with an environment variable lookup. ```
SECRET_KEY=os.getenv("DJANGO_SECRET_KEY")
```
7. Profit! By not getting sued by your users for letting their data get stolen. GDPR goodness!
Buy or Build a Test Case Management Platform?
Tags: discuss, testing
Published: 2019-09-17 16:25:30

In today's swift moving software development space there are lots of tools & services for helping a Software QA team manage their test case library. The key needs for one of these systems is to have a way to easily curate the creation, maintenance and organization of the test cases and track their execution progress over time.

Here are my questions: 

1. Did you buy or build a TCM?
2. What did your company/team do?
3. What was the driving force behind your decision?


Looking forward to your insights.
Code Story E7: Jonathan Campos on How Women Have Different Ride-Sharing Experiences
Tags: codestory, podcast, techtalks
Published: 2019-09-17 16:18:22

{% youtube blVzTNa3To0 %}

After getting his masters, Jonathan Campos found himself working with clients, listening to their pain points, and creating software to meet those needs. He worked his way through a handful of startups and agencies, before landing at Bottle Rocket as the chief architect, growing their web and backend practice. Not too long after, a former boss reached out about an opportunity to up-level the ride-sharing experience, focusing on simple billing, safety, and control over the experience. This opportunity was to become the CTO of Alto.

In the clip above, Jonathan Campos discusses how he learned about women having different ride-sharing experiences. If you like what you hear, check out the full episode below.

{% podcast https://dev.to/codestorypodcast/e7-jonathan-campos-alto %}
TypeScript: Basic Workflow
Tags: beginners, tutorial, javascript, typescript
Published: 2019-09-17 15:41:08

---
title: TypeScript: Basic Workflow
published: true
description: TypeScript: Basic Workflow
tags: beginners, tutorial, javascript, typescript
series: Intro to TypeScript
---

## Intro

In this article, we will have a look at the basic workflow of writing TypeScript.

---

## Overview

3 Steps Are Necessary:

1. Write TypeScript Code
2. Compile It To JavaScript
3. Run The JavaScript Code

---

## 1. Write TypeScript Code

```js
// explicit typing
let myAge: string = 'thirty'; // set it explicitly to a string
myAge = 'thirty-one'; // that works

// implicit typing / type inference
let yourAge = 30; // typescript infers the type as number
yourAge = myAge; // trying to set it to a string, does not work

console.log(myAge);
console.log(yourAge);
```

---

## 2. Compile It To JavaScript

```
tsc index.ts // tries to create a file index.js from index.ts
index.ts:7:1 - error TS2322: Type 'string' is not assignable to type 'number'.

7 yourAge = myAge; // trying to set it to a string, does not work

Found 1 error.
```

Because there's an error, you have to fix the code.

---

## Fix it

```js
// explicit typing
let myAge: string = 'thirty'; // set it explicitly to a string
myAge = 'thirty-one'; // that works

// fix by using explicit typing
let yourAge: number | string = 30; // set it explicitly to a number or a string
yourAge = myAge; // trying to set it to a string, works

console.log(myAge);
console.log(yourAge);
```

Compile it again, until no errors are left.


---

## 3. Run The JavaScript Code

```
node index.js
thirty-one
thirty-one
```

---

## Next Part

We will learn how to configure the `TypeScript` compiler.

---

## Further Reading
[TypeScript Homepage](https://www.typescriptlang.org)
[TypeScript Wikipedia](https://en.wikipedia.org/wiki/TypeScript)
[TypeScript in 5 minutes](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html)
[Basic Types](https://www.typescriptlang.org/docs/handbook/basic-types.html)
[Various Samples](https://www.typescriptlang.org/samples/index.html)
Condicional mais legível com Array.includes()
Tags: javascript, productivity, codequality, typescript
Published: 2019-09-17 15:25:36

Você conhece a função Array.includes() do javascript? Essa função foi especificada no ES7 e é capaz de tornar uma condicional bem mais legível.

Essa função determina se um parâmetro está contido no array.

```js
const numbers = [1, 2, 3, 4]
const strings = ['Gabriel', 'Rufino']

numbers.includes(3) // true
numbers.includes(6) // false
strings.includes('Rufino') // true
strings.includes('Fernando') // false
```

Conhecendo essa função, agora você pode escrever condicionais que comparam uma variável com muitas possibilidades mais legíveis trocando o `or` pelo `Array.includes()` usando a variável como parâmetro. Veja o exemplo:

### Usando o operador `or`

```js
function get(request, response) {
  const access = request.access

  if (access === 'maintainer' || access === 'admin' || access === 'developer') {
    return response.json({ allowed: true })
  } else {
    return response.json({ allowed: false })
  }
}
```

### Usando `Array.includes()`

```js
function get(request, response) {
  const access = request.access

  if (['maintainer', 'admin', 'developer'].includes(access)) {
    return response.json({ allowed: true })
  } else {
    return response.json({ allowed: false })
  }
}
```

## Funciona com `NaN`

```js
NaN === NaN // false
[1, 2, 3, NaN].includes(NaN) // true
```
Rails 5.2 changes in callbacks
Tags: rails, ruby
Published: 2019-09-17 14:16:02

In version 5.1 you may see deprecation warnings in after_save callbacks (related to changes in ActiveRecord::Dirty module).
But since 5.2 these changes were applied.

For examples, I will use Rails 4.2.11 and Rails 5.2.3 and model User with email attribute. Let's do:

```ruby
u = User.new(email: 'old@domain.com')
u.save
u.email = 'new@domain.com'
u.save
```

and look at after_save callback in time of last save.

### 1.  attribute_changed?

**Rails 4**

```ruby
> email_changed?
=> true
```

**Rails 5.2**

```ruby
> email_changed?
=> false
```

but you can use `saved_changes?`

```ruby
> saved_change_to_email?
=> true
```

### 2. changed?

**Rails 4**

```ruby
> changed?
=> true
```

**Rails 5.2**

```ruby
> changed?
=> false
```

but you can use `saved_changes?`

```ruby
> saved_changes?
=> true
```

### 3. changes

**Rails 4**

```ruby
> changes
=> {"email"=>["old@domain.com", "new@domain.com"]}
```

**Rails 5.2**

```ruby
> changes
=> {}
```

but you can use `saved_changes`

```ruby
> saved_changes
=> {"email"=>["old@domain.com", "new@domain.com"]}
```

### 4. previous_changes

**Rails 4**

```ruby
> previous_changes
=> {"email"=>[nil, "old@domain.com"]}
```

**Rails 5.2**
Now, this method returns the changes that were just saved (like `saved_changes`).

```ruby
> previous_changes
=> {"email"=>["old@domain.com", "new@domain.com"]}
```

this method has no replacement.
React Developer Openings - Nashville, TN Area (1 remote opportunity) 
Tags: reactdev
Published: 2019-09-17 13:50:30

Good morning All. My name is Walt Reeves and I am a Technical Recruiter with IDR in Nashville, TN. I have two clients looking for a Full Stack Developer (React) to join their team. One opportunity MUST sit onsite in Franklin, TN and be able to begin work within the next week. The ideal candidate will have 3 years of hands on React Development experience and Responsive Design. This is a contract to hire with a conversion salary of 110k. There may be potential flex based off how the manager feels about their experience. 

The other is 100% WORK FROM HOME. This opportunity pays between 110k and 120K. They are seeking someone with at least 4 years of software development experience, with Javascript being the preferred language. This person will also need 2+ years of React Development experience. Once again, this is a great opportunity with an amazing company. Working from home is just the icing on the cake! 

If you or someone in your network is interested in learning more, please email me at wreeves@idr-inc.com and I would love to set something up. 

Thanks for all of your help!!!
Medical App Development: How to Build a Logbook App for Electronic Health Records
Tags: telehealthtelemedicinetelecare
Published: 2019-09-17 13:44:45

https://yalantis.com/blog/medical-app-development-how-to-build-a-logbook-app-for-electronic-health-records/

Not so long ago, patients’ medical information was in the form of paper records – handwritten, bound together, labeled, filed, and put on a shelf till the next visit. In fact, this is still how things are done in many countries. 

In the middle of the 2000s, the mass adoption of information technologies encouraged many healthcare businesses to start integrating electronic medical record (EMR) systems into their business processes as a more advanced alternative to paper records. EMR systems serve as a digital version of paper charts, containing all medical and treatment history of a patient within a practice.

As time went on, hospital app development started growing in popularity, making more and more providers around the US implement EMRs in their clinics, which made the US government recognize the necessity of enhancing communication between health providers by making their medical software interoperable. That’s how electronic health record (EHR) systems were born. 

What type of system best suits your business? 
So what exactly is an EHR system and how does it differ from an EMR system? 

While EMRs allow for collecting, keeping, and managing patients’ data in one safe place, this data can hardly cross the borders of a practice, meaning it’s not available to other establishments – or even to patients themselves.

Unlike EMRs, EHR systems are designed not only to collect and keep patient information but to share it with laboratories, emergency rooms, hospitals, pharmacies, and other healthcare institutions. EHRs can accumulate information from all providers involved in a patient’s care – as well as from patients themselves – to allow for coordinated, patient-centered care.
My personal dev.to wishlist - what's yours?
Tags: meta, discuss
Published: 2019-09-17 13:44:13

dev.to is pretty cool - I like the relatively stripped-down editing interface and very quick reading experience thanks to the team's amazing work with service workers and other fun stuff.

However no piece of software, or indeed no piece of design is ever perfect. I found a few places where dev.to could be made better - and this is the curated list.

## The post editor

I like how simple the post editor is, however in a few places where the "no simpler than it needs to be" principle doesn't quite hold up. For instance, saving drafts still triggers a full page reload that also takes you to the post draft - so if you want to save your post midway through writing or editing it, you will have to click 'Edit' again and find where you were. This is actually at odds with the Preview button which renders the post preview in place, but doesn't actually save your draft.

Wish: **Save Draft should not reload the editor** and definitely should not take me out of the editor.

I also like the simple image uploader, however in longer posts that can be a little cumbersome as I have to scroll up to find the image upload button.

Wish: **The image upload button should be floated next to the editor**.

While I'm in the image upload screen - I sometimes have to use dodgy connections and would like to know the progress of my upload. This is generally possible with XMLHttpRequest, and would help me judge whether the upload is just slow or if something's broken.

Wish: **Have a progress bar there!**

## The difficulty system

I like the idea of the difficulty system - perhaps you want to see fewer beginner articles and more in-depth pieces on the pros and cons of particular patterns - but as it stands it seems a bit limited and not very well documented. It's not intuitive when setting the difficulty level for a post - you have to go into the Manage Post menu - and definitely not intuitive when setting the difficulty level for your feed - you have to go into Settings > Misc to set your desired level. I don't think many people change it.

Wish: **Make the difficulty setting more prominent for reading**

Ideally I would like to see the difficulty slider right beside my feed, and possibly allow me to set specific difficulties for each tag - I might be quite experienced in Java or Vue, but not so much in Rust or hardware development.

Wish: **Indicate what you can do in the Manage Post page,** or add some of the widgets from it to the bottom of the post.

## Tags

Wish: **Suggested tags for draft posts**

This one's self-explanatory - suggest some tags for your post as you write it. Cool machine learning project for whoever ends up implementing it!

## Conclusion

I hope these suggestions end up reaching the dev.to team - after all, we'll all benefit from a better platform. I also don't think they are must haves, but would definitely be super nice to have.

What about you? What features would you really like to see on dev.to?
Base API: Periodic Jobs
Tags: cron, webdev, baseapi
Published: 2019-09-17 13:25:27

Did you need to implement periodic jobs in any of your projects? If you did you probably used some kind of a scheduler like [sidekiq](https://github.com/mperham/sidekiq) or [node-cron](https://github.com/kelektiv/node-cron) and you know that setting up a scheduler in any language can be tedious and get them running right is a hard task.

In [Base](https://www.base-api.io) you can now create **scheduled webhooks** in any of your projects to achieve the same thing easily and quickly.

## What are scheduled webhooks?

They allow you to specify a HTTP request which will be sent at the pre-defined schedule - a CRON expression to be more precise.

ℹ️ If you don't know what a CRON expression is then you can read about it in [this wikipedia article](https://en.wikipedia.org/wiki/Cron).

## Setting up a scheduled webhook

Head over to [www.base-api.io](https://www.base-api.io) and create a project.

Once you have the project, navigate to the **Scheduled Webhooks** section:

![Scheduled Webhooks Dashboard](https://thepracticaldev.s3.amazonaws.com/i/6mvb6skybxsrrr2262d3.png)

Then press the **"Create One"** button:

![Create Scheduled Webhook](https://thepracticaldev.s3.amazonaws.com/i/ubm7v6r6a267xxyvrosn.png)

Fill out the details of the webhook and press the **"Create"** button:

![Created Scheduled Webhook](https://thepracticaldev.s3.amazonaws.com/i/qo62fx5iojr81b5oiayr.png)

And that is it! The requests will be sent to the given URL at the specified times.

## Checking the runs

All of the requests are recorded for you and once the webhook runs a few times they can be viewed by clicking on the url:

![Scheduled Webhook Runs](https://thepracticaldev.s3.amazonaws.com/i/sb7kgx1rey9wmlt035tq.png)

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

I hope this will be useful for some projects!

As allways let me know if you have any question or ideas, and stay tuned for more awesome features coming in the next few weeks!📻
Web Development Illnesses
Tags: webdev
Published: 2019-09-17 13:21:35

---
title: Web Development Illnesses
published: true
description: In the same way that humans have illnesses that slow us down and make us feel terrible, software has illnesses in the form of anti-patterns and bad practices.
tags: webdev
canonical_url: https://alvaromontoro.com/blog/67842/web-development-illnesses-intro
cover_image: https://thepracticaldev.s3.amazonaws.com/i/3fgvndgjlbnwjex750yw.png
series: Web Development Illnesses
---

In the same way that we humans have illnesses that slow us down and make us feel terrible, software has anti-patterns and bad practices.  When these are implemented, they make our code struggle and suffer... and make us developers struggle and suffer too. 

The point of this series is to associate these bad practices with real life illnesses that we all know and that many of us may have suffered, so that we get a better idea of their severity and the consequences of suffering them.

## What is a Software Illness?

Before we start, let's define what a software illness is. Although the series posts will be mainly web-focused, these illnesses are not something that only affect web development, but development as a whole.

There could be a lengthier definition for what a software illness is, but we'll try to keep it nice and short:

> **A Software Illness is a bad software development practice that will negatively impact the normal execution of a software application.**

And now that we know that there are software illnesses and what they are, that raises another question: 

## Is the web sick?

And the answer is yes.

<small><sup>Otherwise this series would have been terribly short :P</sup></small>

I've been doing web development for 15 years, also I've checked web code for friends and colleagues, and reviewed thousands of questions as a moderator at the Spanish Stack Overflow site. I have noticed a common set of bad patterns and behaviors -of software illnesses- that repeat over, and over, and over again.

In this series, I will collect a list of the most common Web illnesses that I’ve seen, how to identify them, and how to _cure_ them. Many of them are well known, and some others are not so common.

I have divided them into two main groups: design web illnesses for those that affect the user facing interface and development; and security web illnesses, for those that may affect front- or back-end related to vulnerabilities.

Without further ado, let's start. I hope you enjoy the posts.

-----

This post was [originally published on my website](https://alvaromontoro.com/blog/67842/web-development-illnesses-intro)
Daily Challenge #69 - Going to the Cinema
Tags: challenge
Published: 2019-09-17 13:14:45

---
title: Daily Challenge #69 - Going to the Cinema
published: true
series: Daily Challenge
description: Should John pay for a cinema membership?
tags: challenge
---

Today's challenge is to help John make an important financial decision!

John likes to go to the cinema, but he wants to find the most cost-effective way to go. He can buy a ticket for $15, or he can buy a membership card for $500. Every time he uses the membership card, the ticket will be 0.9 times the price he paid for the last one.

Ex. If John goes to the cinema three times: 
`A : 15 * 3 = 45`
`B : 500 + 15 * 0.90 + (15 * 0.90) * 0.90 + (15 * 0.90 * 0.90) * 0.90 ( = 536.5849999999999, no rounding for each ticket)`

Create a function `movie` with three parameters: `card` (price of the card), `ticket`(normal price of a ticket), `perc`(fraction of what he paid for the previous ticket) and returns the first `n` such that `ceil(price of B) < price of A`

More examples: 
`movie(500, 15, 0.9) `should return` 43 `
    (with card the total price is 634, with tickets 645)

`movie(100, 10, 0.95)` should return `24 `
    (with card the total price is 235, with tickets 240)

Good luck!

***
_Today's challenge comes from CodeWars user g964. Thank you to [CodeWars](<https://codewars.com/>), who has licensed redistribution of this challenge under the [2-Clause BSD License](<https://opensource.org/licenses/BSD-2-Clause>)!_

_Want to propose a challenge idea for a future post?  Email **yo+challenge@dev.to** with your suggestions!_
Permanent Record - who's reading it?
Tags: discuss
Published: 2019-09-17 13:05:11

---
title: Permanent Record - who's reading it?
published: true
description: Edward Snowden memoir
tags: discuss
---

Today Edward Snowden's memoir, Permanent Record, was released. Who's got their copy?

Going to leave this post here for people to post their thoughts/insights. I'm always intrigued by his work!
How to add css from React folder?
Tags: javascript, react, nextjs
Published: 2019-09-17 13:01:05

Hello,

I'm working on next JS project. I want to add my own css file but I get error not found file in console. Can you help me ?

*code*
< link href="../assets/css/style.css" type="text/css" rel="stylesheet" />

*File Path*
assets
~ css
  ~ style.css
components
~ Layout.js
node_modules
pages
Do You Know Enough Swift to Jump into an App Tutorial?
Tags: ios, swift, beginners
Published: 2019-09-17 12:19:35

The biggest thing I see when mentoring new iOS developers is that they are struggling with basic Swift. The person might actually be able to construct a UI in a Storyboard, even with complex auto-layout, and get it working, but then not be able to add anything beyond the most basic features.

This is because a typical starting point for many new app developers is to find a tutorial that will take you step-by-step to building an app. These tutorials will actually do that, but when you have finished it, you haven't actually written any Swift. There's Swift code, of course. But, you didn't write it—you read it and copied it. And reading Swift, while important, isn't enough.

Like many things, there is a progression from knowing absolutely nothing to expert level. I don't think you need to be anywhere near an expert, but before jumping in to an app tutorial, start with [Apple's official Swift book](https://docs.swift.org/swift-book/index.html). I wrote a post recently on [what I thought were the essentials](https://app-o-mat.com/post/start-with-swift).

The important thing is that you don't just read the book. Open up an Xcode playground and actually write code while you are reading.

Over my next few posts, I'm going to go through the Apple Swift book chapter by chapter and offer some exercises to try in an Xcode Playground. By the time you are done with the series, you should know enough Swift to try out tutorials and then actually progress from there to your own app.

If you have any areas in Swift programming that you struggle with, let me know.