teleren/devto huggingface dataset:
For loops in Django
Tags: django, python
Published: 2019-08-14 04:42:27

Originally published at [pythoncircle.com](https://www.pythoncircle.com/post/685/for-loop-in-django-template/)

Demo of the code used below: [DjangoTemplateFiddle.com](https://www.djangotemplatefiddle.com/f/CftUNu/)

For loop is used to iterate over any iterable object, accessing one item at a time and making it available inside the for loop body.

For example, if you want to create a drop down of countries in Django template, you can use the below code.

```python
{% for country in country_list %}
    <option name="{{country}}">{{country|title}}</option>
{% endfor %}
```


To iterate over a dictionary of people's name and their age, just like you would do in Python, use below code.

```python
{% for name, age in data.items %}
    Name: {{name}}, Age: {{age}} <br>
{% endfor %}
```




###Checking if iterable used in for loop is empty:

Let's say you want to display new messages to logged-in user. You fetched all the new messages from the database and stored them in a list and passed to render function along with the template. 

Now you can either check if the message list is empty or not and then display the message accordingly. Example:

```python
{% if messages %}
    {% for message in messages %}
        {{ message }}<br>
    {% endfor %}
{% else %}
    <div>No new message for you</div>
{% endif %}
```

Or you can use `{% empty %}` tag along with `{% for %}` tag as below.

```python
{% for message in messages %}
    {{ message }}
{% empty %}
    <div>No new message for you</div>
{% endfor %}
```


###Break in Django for loop:
That might be a piece of bad news for you. There is no break statement in Django template For loop.

Depending on your requirement you can do one of the following.

**Option 1** - Iterate over the whole list but do not perform any action if the condition is not matched.

For example, you are printing numbers from a list and you need to exit the list as soon as number 99 is encountered. Normally this would be done as below in Python.

```python
for number in numbers:
    if 99 == number:
        break
    print(number)
```

But there is no break statement in Django template For loop. You can achieve the same functionality (almost) as below.

```python
{% set isBreak = False %}
{% for number in numbers %}
    {% if 99 == number %}
        {% set isBreak = true %}
    {% endif %}

    {% if isBreak %}
        {# this is a comment. Do nothing. #}
    {% else %}
        <div>{{number}}</div>
    {% endif %}
{% endfor %}
```

**Option 2** - You can create your [own custom template tag](https://www.pythoncircle.com/post/42/creating-custom-template-tags-in-django/). 


You can experiment with Django template or can create your own fiddle and share with others. [Django Template Fiddle](https://www.djangotemplatefiddle.com/).
Daily Challenge #40 - Counting Sheep
Tags: challenge
Published: 2019-08-14 14:22:02

---
title: Daily Challenge #40 - Counting Sheep
published: true
description: 
series: Daily Challenge
tags: #challenge
---

You're having trouble falling asleep, so your [challenge](https://www.codewars.com/kata/5b077ebdaf15be5c7f000077) today is to count sheep!

> Given a non-negative integer, 3 for example, return a string with a murmur: "1 sheep...2 sheep...3 sheep...". Input will always be valid, i.e. no negative integers.

Happy Coding!

***
_This challenge comes from joshra on CodeWars. 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 for a future post?  Email **yo+challenge@dev.to** with your suggestions!_
Using JWT-Authentication (Auth0) with NestJS 🔐
Tags: help, webdev, security
Published: 2019-08-14 14:21:37

I'm trying to secure my [NestJS](https://nestjs.com) based API with [Auth0](https:/auth0.com).

It doesn't feel right what I'm doing at this moment 🥴.

I tried to use the [NestJS documentation](https://docs.nestjs.com/techniques/authentication) and also the [Developing Backend APIs with Nest.js](https://auth0.com/blog/full-stack-typescript-apps-part-1-developing-backend-apis-with-nestjs/) from Auth0 but I don't know what I'm doing.

Did anyone of you solved this problem already?
Can you provide some good resources or advice?

Here is my strategy implementation:

```typescript
import { passportJwtSecret } from 'jwks-rsa';
import { ExtractJwt, Strategy, VerifiedCallback } from 'passport-jwt';

import { Injectable, UnauthorizedException } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
  constructor() {
    super({
      secretOrKeyProvider: passportJwtSecret({
        cache: true,
        rateLimit: true,
        jwksRequestsPerMinute: 5,
        jwksUri: '${DOMAIN}/.well-known/jwks.json'
      }),
      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
      audience: 'http://localhost:3000',
      issuer: '${DOMAIN}'
    });
  }

  async validate(payload: any, done: VerifiedCallback) {
    if (!payload) {
      done(new UnauthorizedException(), false);
    }

    return done(null, payload);
  }
}

```

In the controller I use an *AuthGuard*: 
```
@UseGuards(AuthGuard('jwt'))
```

I also want to retrieve the authenticated user's metadata from Auth0. Did anyone figure out how to do that?
Welcome to the Big Thread Club, Neil Green. You are the latest winner of the Big Thread Badge. 🎉
Tags: meta, bigthreadbadge
Published: 2019-08-14 14:11:11

Neil joins @andrewbrown, @mjraadi, @room_js, @iam_timsmith, @fullstack_to, @espoir, @helenanders26, @philnash, @florinpop17 and @lauragift21 in the club as the fourth winner of this badge.

{% user neilonsoftware %}

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 Neil's thread:

{% link https://dev.to/neilonsoftware/which-class-of-developer-are-you-2cg9 %}

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. 🙂_

## **The Big Thread Oplympics**

Andrew is our second winner from the USA. 🇺🇸

I'd been tracking how incredibly international the Big Thread winners had been. In the 11th week, Neil is the first repeat winner in terms of locale. We've had winners from all over the world, highlighting the global diversity of the community.

Europe and North America lead with three winners, followed by Oceania, Europe and Africa with two each, and one winner from Asia.

## **Happy Coding!**
Has anyone moved from London to another part of the UK for a tech job? 
Tags: discuss, career
Published: 2019-08-14 14:09:19

Our Director [Nick Boulton](https://www.client-server.com/consultants/nick-boulton) has [written as blog post](https://www.client-server.com/blog/2019/08/nick-boulton-why-im-bullish-about-the-uk-tech-market-outside-london) explaining why the tech market outside London is booming. 

Has anyone moved from London to another part of the UK to take up a tech job? What are your experiences with the tech scene outside of the capital?
The October Xamarin Best Practices Challenge
Tags: mobileapps, xamarin, challenge, bestpractices
Published: 2019-11-05 14:19:08

---
title: The October Xamarin Best Practices Challenge
published: true
date: 2019-08-14 13:50:31 UTC
tags: mobile-apps,xamarin,challenge,best-practices
canonical_url: 
---

### The October Xamarin Best Practices Challenge

![](https://cdn-images-1.medium.com/max/1024/1*XVBqABaVnDSouQsiafqQ8A.png)

As you may know by now, [Xamarin-related challenges](https://www.thewissen.io/introducing-xamarin-ui-july/) are very popular in 2019; so why not have yet another one.

This challenge would focus on **_proven best practices_** in **all aspects** of creating mobile apps (DevOps, project Structure, cross-cutting concerns, data, API, Testing, App Signing, etc).

### How does it work?

If you are already familiar with prior challenges — like the [Xamarin UI July](https://www.thewissen.io/introducing-xamarin-ui-july/) challenge from [Steven Thewissen](https://twitter.com/devnl), or the [Xamarin Month](https://luismts.com/blog/xamarin/xamarin-month-february-2019/), from [Luis Matos](https://twitter.com/luismatosluna)- You would know that the challenge is in the style of an [advent calendar](https://en.wikipedia.org/wiki/Advent_calendar), where an article about a particular topic is **posted every day,** by one of the amazing contributors. In this instance though, the article will be included in the Challenge [repo](https://github.com/claudiosanchez/SeptemberXamarinChallenge)as a Pull Request, and if also desired a brief blog post about the topic on the contributor’s own blog. The article should be in  **English**.

### What would I write about?

The [**Challenge Repo**](https://github.com/claudiosanchez/OctoberXamarinChallenge/) will contain a Table of Contents (ToC), with an outline of topics — you can either choose a particular topic from the **ToC** or add a brand new topic if the ones listed do not cover what you want to write about.

### How do I sign up for this?

As the challenges before, we would need at least 30 writers — one for each day- but we will certainly welcome additional contributions. Follow the steps below:

1. **Reserve a spot** by submitting a creating an issue on the repo. Once reviewed, we will update the Table of Content with your topic, as well as updating the **Calendar**.

![](https://cdn-images-1.medium.com/max/1024/1*XVBqABaVnDSouQsiafqQ8A.png)<figcaption>The article proposed by James Montemagno</figcaption>

2. **Submit a Pull Request.** Write the article in a markdown file inside of the [**challenge repo**](https://github.com/claudiosanchez/SeptemberXamarinChallenge) **.**

3. **Publish your blog post** linking back to the original article and your contribution in the repo.

4. **Post the links on Twitter** with the hashtag #XamarinChallenge.

### What happens next?

Similar to past challenges, we will have a special event shortly after the month of October to talk about all of the contributions. Stay tuned.

### The Calendar

Check out the [README.MD](https://github.com/claudiosanchez/SeptemberXamarinChallenge/blob/master/README.MD) File for an Up-to-date Calendar.
I got to the bottom of an infinitely scrolling website and found
Tags: ui, ux, justforfun, game
Published: 2019-08-14 13:43:15

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

A: A switch for turning on dark mode 🌝🌚
B: The wrong copyright year in the footer 🤦‍♀️
C: A Bitcoin 🤑

Or suggest your own answer.
10 Best Tips for Visual Studio Code
Tags: vscode, webdev
Published: 2019-08-14 13:27:53

There is no second thought that Visual Studio Code is the best Programming editor. Its strong editing, code intelligence, source code control features, and keyboard shortcuts are some of the best features of Visual Studio Code that can help you in boosting your productivity.

10 Best Tips for Visual Studio Code

In this article, we will walk you through 10 best tips for Visual Studio Code, which can help you and any [developers] (https://www.mindtechconsultancy.com/hire-asp-net-developer/) in improving your efficiency.

**1) Install a new theme in Visual Code**

Press CTRL + Shift +X Keyboard shortcut to access the extension panel.

**2) Edit multiple lines at once**

In case you want to add or delete multiple instances of text in a document, you would need to create multiple cursors. But in the VS code, you can do this action by merely pressing down “Alt” and clicking anywhere in between the text.

**3) Visual Studio Code CLI Tool**

VS Code comes with CLI tool out in the box, which is also known as Command Line Interface. It helps you in managing the launch of the editor. On Windows, this terminal appears as Command Prompt while On Mac and Linux, it crops up as a Bash prompt. You can easily open files, change the language of display; install extensions CLI Option (Switches)



**4) Live Share**

VS Code Live Share is a new feature that let you share your workspace in real-time and allow you to share your visual code instance. Currently, it is published as a plug-in and available in Developer Preview. 

**5) Use Convenience Commands**

You can also choose a command to quickly expand or contract a selection of text by selecting
Edit > Advanced > Expand Selection or Edit > Advanced > Contract Selection,
or Press Shift+Alt+= or Shift+Alt+-.

**6) GIT Integration**

**7) Debugging**

**8) Snippets**

**9) For Searching Files quickly**

**10) Make effective use of Command Pallet**

Read More and Source: [10 Best Tips for Visual Studio Code] (https://www.mindtechconsultancy.com/tips-for-visual-studio-code/)
Know Your Linux 04: Processes
Tags: linux
Published: 2019-08-14 13:12:09

---
title: Know Your Linux 04: Processes
published: true
description: The fourth entry in the “Know Your Linux” series. This time let’s talk about Linux's Processes.
tags: Linux
cover_image: https://thepracticaldev.s3.amazonaws.com/i/4c6k5sw260iwbajc1uel.jpeg
canonical_url: http://bassemmohamed.me/Post/know-your-linux-04-processes
---

Hello and welcome to the fourth entry in “Know Your Linux” series, This time let’s talk about Linux’s processes.

Before diving right in 🏄‍♂️, Make sure to check out the previous entry in the series.
{% link https://dev.to/bassemmohamed/know-your-linux-03-permissions-13ch %}

Now let’s get down to business, First off. WTF is a process?

#Linux’s Processes

A process is a running instance of a lunched executable program. That program could be a graphical application that the user is interacting with 💻 or a service that is running the background 🏃‍♂️. Every process must have :

* Pid. *You guessed it*🎉 Process id.
* PPid. *What now*🤔 Parent process id.
* The process state.
* Address space of allocated memory
* Allocated system resources
* Security properties like ownership and privileges.

Every process is created by its parent process and inherits its properties from the parent. Also, Any process has the ability to create child processes through a method called **fork**. Hmmm now, what about the first process? *Good question* 👏 All processes are descendants of **systemd** which is the first system process and has a Pid of 1.

#Process’s states

Every process must have some kind of state. That changes according to circumstances.


| State Code | State | State description |
| ------------- |:-------------:| -----:|
| R | Running 🏃‍♂️ | The process is either **running** in the CPU right now or waiting in the queue to run. |
| S | Sleeping (I) 😴 | The process is **interruptible**, which means it is waiting until a certain event (signal). Once it is satisfied it will return to running. |
| D | Sleeping 😴 | The process is **uninterruptible**, which means it will not respond to signals. Used only under certain conditions. |
| K | Sleeping 😴 | The process is **killable**. Same as D, but it only responds to the kill signal. *You know, Just in case* 🤯. |
| T | Stopped 🤚 | The process has been **stopped** usually by a user or another process. Could be resumed by another signal. *No worries.* |
| Z | Zombie 🧟 | The process is **exiting**. It released all its resources except the Pid. Just waiting to be terminated by the parent process.  |
| X | Dead | The process is **dead**. It exited successfully. *horraaaay* 🎉! |


A short post for a change, That’s all from my side. ✋
If you enjoyed the post, please let me know and check out the next entry. 🙄

{% link https://dev.to/bassemmohamed/know-your-linux-05-services-and-daemons-3i13 %}

As always,
**Happy coding 🔥🔥**
**“كود بسعادة”**
Weekly Picks #88 — Development Posts
Tags: webdev, react, css, javascript
Published: 2019-08-14 13:11:53

* [22 Miraculous Tools for React Developers in 2019](https://app.dailynow.co/r/0eaf8c718aed7a0ebdb697c768120a1b)
* [How to build a great CSS architecture? (with CSS guru Adam Argyle)](https://app.dailynow.co/r/bd313894d3507046139006e9cfceb3a8)
* [Generate random numbers in JavaScript using Crypto, without Math.rand()](https://app.dailynow.co/r/2c5ba592978d84957a192db147c3a4bb)
* [How I Boost My Productivity as a Programmer](https://app.dailynow.co/r/26a54269e4e6e627d218a88671715e77)
* [A Beginner’s Guide to NPM](https://app.dailynow.co/r/d5338496a1e495906902bb40942ca3bd)
* [Module Design in javascript](https://app.dailynow.co/r/7bb0b120aff168c7d9ee242e7ae9d255)
* [Space Browser — The first mobile browser made for power users.](https://app.dailynow.co/r/3d219dcef308128ff12a27d443e1783c)
* [Javascript Tips and Tricks You Should Know](https://app.dailynow.co/r/e6fcbd2aa0a4714bb466839939ecb896)
* [How to Create Web Animations with Anime.js](https://app.dailynow.co/r/ea75bed1721391f328c142c83a8b8b7e)
* [Real Dev — Real-life coding skill challenge](https://app.dailynow.co/r/7bb6e94b57a8a43ad49a320622e97b51)


* * *

[_Thanks to Daily_](https://www.dailynow.co/) _developers can focus on code instead of searching for news. Get immediate access to all these posts and much more just by opening a new tab._

[![Daily promotion cover](https://cdn-images-1.medium.com/max/1024/1*7bwIhcH467BKX5Ni8XWpQg.jpeg)](https://www.dailynow.co/)
ELI5: What the heck is Kubernetes?
Tags: explainlikeimfive, kubernetes
Published: 2019-08-14 13:00:15

---
title: ELI5: What the heck is Kubernetes?
published: true
description: k8s: What is it? What are they? Why is Gamora?
tags: #explainlikeimfive #kubernetes
cover_image: https://images.unsplash.com/photo-1552581234-26160f608093?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80
---

What is it? What are they? Help a girl out, I am so confused.
new Video(); Criando um visualizador de Links com REACT
Tags: javascript, react, node
Published: 2019-08-14 12:18:39

[![new Video(); Criando um visualizador de Links com REACT](https://thepracticaldev.s3.amazonaws.com/i/xis49w4rnzyaer0gme6n.jpg)](https://www.youtube.com/watch?v=p9aWx0QXGZw)

Sabe quando você coloca um link no post do facebook e ele busca as informações daquela página?

No vídeo de hoje eu vou ensinar como utilizar o Cheerio para fazer "WebScraping" e apresentar 
as informações usando React. 

Você vai aprender como começar uma aplicação em react do ZERO e  criar esse componente para visualizar links.


[➜ Participe da nossa lista de desenvolvedores](https://emersonbroga.com/e/participe/)
[➜ Aprenda ES6](https://amzn.to/2J4XnLg)
[➜ Veja as dicas no Instagram](https://www.instagram.com/emersonbrogadev/)
[➜ Assita nosso canal no YouTube](https://www.youtube.com/c/emersonbroga/)
[➜ Curta nossa página no Facebook](https://www.facebook.com/emersonbrogadev/)
[➜ Não perca as atualizações no Twitter](https://www.twitter.com/emersonbrogadev/)
[➜ Veja os repositórios no Github](https://www.twitter.com/emersonbrogadev/)

=)
My Side Projects
Tags: webdev, developers, website, news
Published: 2019-08-14 10:54:10

---
title: My Side Projects
published: true
description: I made a media and content website for developers
tags: #webdev #developers #website #news
---

Hello,

My name is Pedro, and I have a lots of experience in Web development, that I adquire in the last 10 years. 

In the last years I have been working, and improve my skills in frameworks like Laravel, VueJs, Angular, and others...

I'm a person with many ideas for platforms, websites and others business stuff. With the past of the years I think I lost many oportunities with ideas that never went into production, bacause of the fear of the insuccess!!

So, this month I decided, I will launch an website to share content dedicated to developers.

The website is not finished, and it's very simple for now. I will improve the website gradually.

Today it doesn't matter if the content is uninteresting, or very simple.

I hope people enjoy my work, and I will be grateful for the suggestions.


Visit: https://theargv.com/

Please follow me and the project: 
https://twitter.com/pedromladeira
https://twitter.com/theargv
5 Tips to Design Exceptional Mega Menus for Magento 2
Tags: magento, magentomegamenu, megamenudropdown, magentomenunavigation
Published: 2019-08-14 10:35:19

These days, Mega Menus have become the new normal when it comes to in-store navigation. You can see them everywhere while shopping through your favorite online stores. They add ease and comfort to the overall shopping experience in a subtle way. If used the right way, Mega Menus can transform your store’s usability by elevating the navigation! 

<b>To help you do that, here are 5 tips to design exceptional <a href="https://blog.magedelight.com/3-ways-mega-menu-magento-2-extension-can-help-enhance-cx/">Mega Menus for Magento 2 store</a>:</b>

<h3>Group like Items:</h3>
Knowing what goes where is the key to creating a great Mega Menu. Can a link to your “About Us” page placed under the “Products” section? Absolutely not. While designing the menu, you should ensure like items are grouped together so that it’s easy for users to quickly scan through your store. 

<h3>Avoid Overcrowding the Menu:</h3>
You should avoid the temptation of filling in all the empty space with unnecessary menus and links. Just because something can go in the menu doesn’t mean it should. Clean menus are easy to scan and go a long way in elevating the overall shopping experience. While designing the Megamenu, remember this: ‘unnecessary links’ will be regarded as ‘annoying distractions’ by your ‘task-oriented’ visitors!

<h3>Add Images as & when Needed:</h3>
If an image is worth a thousand words, why not place them in the main navigation itself?! Mega Menus have the capability to accommodate images. You can place images of categories so that users can easily get through to them with just a single click. Images will add elegance and beauty to your main navigation in a subtle way.

<h3>Label Them Meticulously:</h3>
You should be succinct while labeling your menu items. If required, you can provide brief descriptions on the menu. Avoid using creative labels that are not commonly used by your visitors. Make sure each menu item is easily recognizable and that your audience can easily recognize all the labels at a single glance.

<h3>Avoid Using Drop-down with More Than 2 Levels:</h3>
While designing mega-menu, this is probably the worst mistake anyone can make. Drop-down menu items any more than 2 will ruin the usability and bring down the shopping experience of your store. Thus, while designing your mega menu – do your best to avoid using multiple drop-downs beneath a single menu item. 

<b>Final Words:</b>
Navigation being an integral part of your store, you must ensure it’s seamless & exceptional. With a <a href="https://www.magedelight.com/mega-menu-magento-2.html">Mega Menu Magento 2 Extension</a>, you can design visually engaging menus that are easy-on-the-eyes and user-friendly! While there are several mega menu extensions available out there on the internet, MageDelight’s Mega Menu stands out for the kind of features it offers.

If you are ready to take your store’s navigation several notches above what Magento offers by default – grab MageDelight Mega Menu today!