teleren/devto huggingface dataset:
Django ORM Optimization Tips #2 prefetch_related
Tags: python, django, sql, database
Published: 2020-09-21 20:16:48

>This has a similar purpose to **select_related**, in that both are designed to stop the deluge of database queries that is caused by accessing related objects, but the strategy is quite different.

>**select_related** works by creating an SQL join and including the fields of the related object in the SELECT statement. For this reason, **select_related** gets the related objects in the same database query. However, to avoid the much larger result set that would result from joining across a ‘many’ relationship, **select_related** is limited to single-valued relationships - foreign key and one-to-one.

>**prefetch_related**, on the other hand, does a separate lookup for each relationship, and does the ‘joining’ in Python. This allows it to prefetch many-to-many and many-to-one objects, which cannot be done using **select_related**

###lets go to our favourite part examples: 
In this we have users and languages tables, each user knows more than one language and we want to list users with their languages

```python
# models.py
class Language(models.Model):
    name = models.CharField(max_length=63)
    code = models.CharField(max_length=7)


class User(models.Model):
    fullname = models.CharField(max_length=127)
    languages = models.ManyToManyField(Language, related_name="users")
```

```python
# serializers.py
class LanguageSerializer(serializers.ModelSerializer):
    class Meta:
        model = Language
        fields = ('id', 'name', 'code')


class UserSerializer(serializers.ModelSerializer):
    languages = LanguageSerializer(many=True)

    class Meta:
        model = User
        fields = ('id', 'fullname', 'languages')
```

```python
# views.py
class UserListView(ListAPIView):
    serializer_class = UserSerializer
    queryset = User.objects.prefetch_related('languages')
```


####According to [prefetch_related](https://docs.djangoproject.com/en/3.0/ref/models/querysets/#prefetch-related) documentation:
>To avoid the much larger result set that would result from joining across a ‘many’ relationship, **prefetch_related** does a separate lookup for each relationship, and does the ‘joining’ in Python

So queryset `User.objects.prefetch_related('languages')` will be divided into 2 queries:
```sql
SELECT "user"."id", "user"."fullname" FROM "user"
```

```sql
SELECT "user_language"."user_id","language"."id", "language"."name",
"language"."code" 
FROM "language" INNER JOIN "user_language" 
ON ("language"."id" = "user_language"."language_id") 
WHERE "user_language"."user_id" IN (...);
```

And last thing is matching these queries with `Python` code
How can I understand JS?
Tags: javascript, webdev, learning
Published: 2020-09-21 19:18:37

So I have been learning JS for a little over a week. I have been using W3Schools, FreeCodeCamp, and YouTube tutorials, and StackOverFlow, and of course, DEV. I am having a hard time understanding how and when to know what code to use when making websites. 


MY QUESTION:
What are some things you have done to better study and help retain and practice JS, as a beginner? 


For me learning HTML & CSS for the past 9mo as well as SASS and Bootstrap the past week, is pretty straight forward overall. However JS feels like a steeper learning curve for the basics. I understand it takes years and you are always learning, but any tips or tricks would be great! 

Thanks
"Why I decided to learn software development"
Published: 2020-09-21 19:06:05


Hello, everyone my name is Conner Fortner I am 23 years old. The reason I decided to learn software development is because I have a 6 month old son named Elliot. I wanted to stop working temperary jobs and look for a career that would help me support my new family. I've always had an interest in technology so software engineering seemed like the logical path. I wanted a career that would challenge me and allow me to support myself and my family so my cousin pointed me in the direction of flatiron. He himself works in the industry and told me that he thought I'd be a good fit, so I decided to check out the curiculum and apply. I didn't know if I'd be accepted considering my lack of coding experience, but much to my disbelief I was accepted so here I am. I struggled a bit in the beginning but I figure thats to be expected. So far I've absolutely loved my experience even though theres been times this last two weeks I wanted to bang my head on my desk from not understanding a particular lab or subject. I am excited to continue learning and pushing myself to get better and faster at writing and reading code.
Install maven wrapper
Tags: maven
Published: 2020-09-21 18:53:46

---
title: Install maven wrapper
published: true
description: 
tags: maven
//cover_image: https://direct_url_to_image.jpg
---
Install maven wrapper with maven wrapper plugin
```mvn -N io.takari:maven:wrapper```

Can also specify the version of maven
```mvn -N io.takari:maven:wrapper -Dmaven=3.6.3```

Ref:https://www.baeldung.com/maven-wrapper
ShadowGas - Store
Tags: blockchain
Published: 2020-09-21 18:45:31

I have finished the *Store* feature of the ShadowGas contract. 

Interaction with the contract can be done via *buidler tasks and the console*.

# Install
```sh
git clone https://github.com/TraylorBoy/ShadowGas.git

cd ShadowGas

yarn install
```

**After installing, you will need to create a `.env` file and modify the `shadow.config.js` and the `buidler.config.js` files**

## .env
```sh
SHADOWGAS="" - Contract Address
WALLET="" - Wallet Address
PRIVATEKEY="" - Wallet Private Key
KOVAN="" - Kovan Infura url
ROPSTEN="" - Ropsten Infura url
MAINNET="" - Mainnet Infura url
ETHERSCAN="" - Etherscan API Key
ETH_GAS_STATION="" - EthGasStation API Key
```

## shadow.config.json
```sh
RefuelChiAmt - Mint Chi Amount
RefuelLgtAmt - Mint Lgt Amount
EmptyChiAmt - Transfer Chi Amount
EmptyLgtAmt - Transfer Lgt Amount
EmptyChiTo - Address to transfer Chi to
EmptyLgtTo - Address to transfer Lgt to
GasLimit - Gas Limit
GasSpeed - Gas Speed ("fast", "average", "slow") 
```
Gas Price is retrieved from:

https://ethgasstation.info/ 
https://etherscan.io/gastracker

*I am working on a Gas Oracle which may change this feature*

```sh
buidler.config.js

...

module.exports = {
  defaultNetwork: "Kovan",
  ...
 }
```

You may modify the exported properties in the `buidler.config.js` file.

# Store

*`<GAS_TOKEN>` should be either: Chi or Lgt*

### Refuel
```sh
npx buidler refuel --token <GAS_TOKEN>
```

Mints either Chi or Lgt tokens and stores them at contract's address

### Tank
```sh
npx buidler tank --token <GAS_TOKEN>
```

Retrieves Chi or Lgt token balance at contract's address

## Examples

### Refuel 13 Chi and Lgt tokens

*Refuel amount can be modified via the `shadow.config.js` file*

```sh
npx buidler refuel --token Chi
```

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

```sh
npx buidler refuel --token Lgt
```

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

### Retrieve Chi and Lgt tank balances

```sh
npx buidler tank --token Chi
```

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

```sh
npx buidler tank --token Lgt
```

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


I will post the `Transfer` feature tomorrow!

The repo for the project is located here: https://github.com/TraylorBoy/ShadowGas
So many things to learn...
Tags: webdev, beginners, career, motivation
Published: 2020-09-21 18:35:23

The path to web development seems to have a lot of steps. HTML, CSS, JavaScript, Bootstrap, Tailwind, not to mention getting into the back-end programming and languages.

It's very easy to end up in the rabbit hole of learning. I initially started out trying to absorb everything I could about every language I could find. This quickly became overwhelming and caused a brief moment of panic. Will I be able to do this? If so, when?

Once that panic subsided I set out to find a clear path through the haze. I've never been one to want to put the time in early, always instead preferring getting to the "good stuff". But I've seen that concentrating on HTML/CSS initially will help in the long run. My goal has since shifted slightly, focusing on becoming very proficient in these two languages. I know JavaScript will need to be added as well but it feels like having a solid foundation in HTML/CSS now will make learning the other aspects that much easier.  

And then I read about CSS preprocessors, frameworks and utility classes. Just when I was starting to get a feel for CSS I see so many other ways to write my styles. Those will come eventually as well, I'm sure, but trying to keep myself calm and moving forward has become the new goal.

For others out there starting this journey too - don't panic! Everyone moves at a different pace and will find their own best way forward!
Do Github stars matter?
Tags: github, productivity, codequality, python
Published: 2020-09-21 18:34:14

Pretty sure most developers have thought about this when building their open-source projects and then after a while realizing that their project got barely 2 to 3 stars and sometimes not even that. 
Well, the answer is clearly yes. Stars do matter on Github projects. The stars project confidence and quality on a project, but it doesn't necessarily mean if a project doesn't have stars, it's not good or anything like that. However, a project with lots of stars is most likely a good quality project and something worth contributing to and to use in your project.

# How do you get stars in the first place?

I was at the same place four weeks back ( still am in a way ) when I made the codebase for my coding platform ( DomeCode ) open-source because I felt like closed-source is more like an artificial barrier, and people should be able to use my code for their free and open-source projects. 

Even though I have proven that I'm close to a saint, I should also state that this feeling is subject to change in the future, but presently, my project is well open-source and has gotten 47 stars so far. Technically, ~12 stars a week. 

Either way, the point is it's good to have stars just like it's good to have money. In similarity with fiat currencies, the stars don't mean everything, but they do certainly mean something, and you got to have that if to ease your way through. 

Cutting the shit and getting straight to it, these are the strategies to deploy in order to get stars:

- Beg
- Blog
- Shit post everywhere
- Ask your closest friends to do the same

Eventually, you'll get to 100k stars, and to be clear, this is what I want with [DomeCode](https://domecode.com/).

Oh, and DomeCode](https://domecode.com/) is essentially a platform that improvises over existing "code to learn" platforms by making the process of going from point A ( picking a language ) to point B ( getting good at it ) easily than ever by including tools and resources along with the whole-some community to make your experience better.

Feel free to support me in my journey by starring [DomeCode](https://github.com/the-domecode/domecode-opensource) on Github.

My Github - https://github.com/arthtyagi/
DomeCode - https://domecode.com/
DomeCode's Github - https://github.com/the-domecode/
My personal website - https://arthtyagi.me/
Discord - https://discord.gg/ZwTJPNB/

P.S This was partly satire for those of you who didn't get it. This post script, on the other hand, deems the whole motive of satire pointless.
Earn crypto from watching videos.
Tags: blockchain, money, video, coinbase
Published: 2020-09-21 18:20:37

##How to get over $100 in crypto
[Coinbase](https://www.coinbase.com/join/askew_sx)! They know that crypto can seem complicated, so to make it easier to understand, and provide people with incentives to learn that they have partnered with some of the most popular blockchain projects to build [Coinbase Earn](https://www.coinbase.com/join/askew_sx).

By watching short and clear informative videos and then answering a multiple choice question, Coinbase Earn is an convenient way for verified Coinbase users to earn free crypto from famous blockchain projects.

##What do I need to do?
**1. Watch videos** - To inform you about various cryptocurrencies, they have produced informative videos.

**2. Complete a quiz** - After each video you will receive a simple quiz testing what you’ve learned.

**3. Earn** - You will receive a simple test after each video, checking what you have learned.

**4. Start today!** - Only a select group of customers can receive opportunities for a limited period of time. So join before all the crypto is claimed.

####Start now: [Coinbase](https://www.coinbase.com/join/askew_sx)

*caveat*
Please be aware that some countries are unable to participate in the program, and that you might be placed on a waiting list to start a course on a specific coin.
What I Learned Writing A Podcasting Book- The Building an Indie Business Podcast
Tags: podcast, writing
Published: 2020-09-21 18:12:10

[Listen Here](https://baib-podcast.com/podcasting-book-lessons.html)

In this episode, I discuss lessons from writing the book. I discuss what I learned about publishing, e-commerce platforms, releasing products, email marketing, using tools, AND SO MUCH MORE

**Show Notes:**

[Buy the book I wrote](https://openpodcast.xyz/)
[Revenue Research](https://revenueresearch.co/)
The .NET Docs Show: Azure and all things mobile 📱
Tags: dotnet, xamarin, mobile, dotnetdocsshow
Published: 2020-09-21 17:59:08

---
title: The .NET Docs Show: Azure and all things mobile 📱
published: true
description:  The .NET Docs Show is joined by Matt Soucoup for a discussion about .NET mobile development.
tags: dotnet, xamarin, mobile, dotnetdocsshow
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/9l3ahtdzx7ssd59qfqwo.png
---

In this episode of [The .NET Docs Show](https://dotnetdocs.dev), Matt Soucoup (<a href="https://twitter.com/codemillmatt" target="_blank">@codemillmatt</a>) demonstrates Xamarin.Forms / Xamarin.Essentials and how easy it is to transition your .NET skills to mobile development. As part of this week's #CheckUp, we shared a Microsoft Learn module - [Create a mobile app with Xamarin.Forms](https://aka.ms/learn-xamarin-forms). Additionally, we learned that a lot of the Xamarin University content that sat behind a paywall has since been ported over to a [Microsoft learning path](https://docs.microsoft.com/en-us/learn/paths/build-mobile-apps-with-xamarin-forms) and is entirely free 🤑! 

The #HallwayTrack was amazing! We learned a bit about Matt's career, and how he started with Mono Develop. After talking about Objective-C, Matt recounts:

> Apple decided that developers were using too many square brackets, so they went to Swift 🤣

Matt details how it was a tooling solution to lift his C# skills and apply them to mobile. Matt showed off live reload, where the iOS simulator would immediately refresh the application with XAML changes - this greatly tightens the feedback loop...thus making the developer more productive. We discussed Android and iOS, as well as MAUI - Matt shared his perspective on Android.

> Everything about Android is weird! 😵

{% youtube pzZHJ60uqsw %}

If you liked this video and would like to see some more of our .NET content, please subscribe to our [The .NET Docs Show YouTube Channel](https://www.youtube.com/channel/UCvtT19MZW8dq5Wwfu6B0oxw) and [follow us on Twitter](https://twitter.com/dotnetdocsshow).

# #CheckUp

- [MS Learn: Create a mobile app with Xamarin.Forms](https://aka.ms/learn-xamarin-forms)

# Useful links

- [Matt's URL list](https://www.theurlist.com/the-dot-net-docs-show-matt-soucoup-mobile)
- [The .NET Docs Show](https://dotnetdocs.dev)
Learn ReactJS with TensorflowJS & Firebase in 10 hours
Tags: javascript, react
Published: 2020-09-21 17:32:31

# ReactJS full course for absolute beginner to advanced
This course is going to cover from what is React to Deploying it using Netlify

This course is about **10 long** with the timestamps so you can directly jump into the section you want.

# 🌟 Technologies Covered 🌟
🔸 Tensorflow JS
🔸 Netlify
🔸 Reactjs from scratch
🔸 Formik form library
🔸 Framer Motion for Animation
🔸 UnSplash API
🔸 Firebase Authentication

{%youtube I6tbhNUU96Y %}

# 🌟 Who can watch it 🌟
🔸 For totally Beginners
🔸 If you know react but want to understand how it works
🔸 For Reactjs Professionals who want to integrate tensorflow
🔸 If you know other Javascript but migrating to reactjs

# All Hooks and Advanced reactjs topics

🔸 We will cover most of the important hooks like useRef, useState, useContext, useLayoutEffect, useEffect and also going to create some custom hooks like useDebounce

🔸 Typechecking with PropsType: Here we cover how we can validate the props for any component and using propstype library

If you want to more content for reactjs, you can visit https://indepthreact.com or just DM me on twitter or shoot an email
In Depth Reactjs is the course I am working which holds 30-40 hours of react content only

I hope this rich content makes your life easier while learning ReactJS
What is this?
Tags: javascript
Published: 2020-09-21 17:51:37

In javascript, you have access to `this` keyword at any time. Unless there are certain conditions met `this` will always refer to the global object `Window`. `console.log(this)` in your console to see the `Window object`.

# Methods and thisBinding
One use case where `this` will change is in an object method. [A method is a function stored as an object property](https://www.w3schools.com/js/js_object_methods.asp), like `displayObject` below. If you run the code block in your console you'll first see the window object like before and then the updated value for `this`, our new object. 

```javascript
console.log(this)

const myObject = {
   type: 'Object',
   purpose: 'Give an example.',
   displayObject: function() {
       console.log(this)
   }
}

myObject.displayObject()
```

If you understand the process for an execution context than `this` will be easy to understand. Every time a new execution context is created `thisBinding` is evaluated. If it's called on a method, `this` becomes the object that owns the method. Otherwise, it remains the `Window` object. [There are other circumstances where `this` can change,](https://dev.to/digitalocean/understanding-this-bind-call-and-apply-in-javascript-dla) and if you're interested in learning more [other users go into a much deeper dive in the topic than I do in this article.](https://dev.to/skaytech/what-is-this-in-javascript-3d3i)
The Coding Cheat Sheet
Tags: reactnative, ios, android
Published: 2020-09-21 17:38:38

I’ve always been curious about the development of mobile applications. A large majority of people across the world always have their cell phones either in their hand or in their pocket at all times, including myself! After graduating from Flatiron School’s Software Engineering program, Pedro (a member of my Flatiron cohort) and I decided to dive into React Native and scratch the curiosity itch about IOS and Android application development. 
	We loved the idea of creating a cheat sheet like app for developers to have the ability to quickly look up syntax or tips about different programming languages.  After agreeing on what we wanted to create, we started researching how we would need to create it! We decided to use the Expo framework because of how simple it makes it to get right to developing! I see it as like a mobile version of “Create React App”. 
It was pretty interesting seeing how similar React and React Native are but since they both follow component based architecture, it wasn’t much of a surprise. It was nice how simple it was to transition from ReactJS into the React Native framework but in the future I would like to learn Swift so I can get a deeper understanding behind what is actually happening in an IOS application. I say that because it felt like a lot of things are abstracted away when using Expo and React Native. However, using these frameworks helped get a taste for developing applications for cell phones and now I want to dive deeper! I think for my next learning experience, I’m going to dive into Swift and see what all the fuss is about! 

Here is a link to the repo, feel free to check it out! 
https://github.com/TeamNativeDev/CodingCheatSheetApp

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/rdnf7rbc2hn54wui8vws.png)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/n7p3rknvc3px83ql4rxm.png)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9l4dwb2uw872gn0qj4ug.png)![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/gwkva4qf5b3t14c1w1u7.png)
Javascript infinite scrollbar html section (Tutorial with practice)
Tags: html, css, javascript, tutorial
Published: 2020-09-21 17:32:16

---
title: Javascript infinite scrollbar html section (Tutorial with practice)
published: true
description: 
tags: html,css, javascript, tutorial
//cover_image: https://direct_url_to_image.jpg
---
Hi Friends,
We will continue our short tutorial, 
today we are going to make a infinite scrollbar html section with the help of javascript getBoundingClientRect Method.
**Let's begin**

First html,

```
 <div class="wrapper">
        <section></section>
        <section></section>
        <section></section>
        <section></section>
        <section></section>
    </div>
```

and second css

```
   section {
            height: 400px;
            background: linear-gradient(red, green);
            margin: 3rem;
        }
```

our basic setup is ready.

now coming to the main point of javascript.

```
window.onscroll = (() => {
            let section = document.querySelectorAll('section')
            let wrapper = document.querySelector('.wrapper');
            let rect = section[section.length - 1].getBoundingClientRect()
            console.log(window.innerHeight)
            console.log(rect.y)

            if (rect.y < window.innerHeight) {
                for(let i = 0; i < 5;){
                    wrapper.innerHTML += `<section> </section>`
                    i++;
                }
            }
        })
```

The onscroll event occur when the scroll down, so
we setup the section, wrapper variable and rect.

For rect variable with the help of getBoundingClientRect has "y" position of the window.
so we have make a condition

```
if (rect.y < window.innerHeight) {
                for(let i = 0; i < 5;){
                    wrapper.innerHTML += `<section> </section>`
                    i++;
                }
            }
```

this condition occurs when the rect.y less than window.innerHeight.


for full code, you can follow my [Codepen](https://codepen.io/nikhilroy2/pen/QWNJrYg?editable=true)

if you interested like this short tutorial please like, share, follow me so that in the future I can make more tutorials just like this.
Thanks.
Jest Tutorial: Unit Tests
Tags: javascript, node, jest
Published: 2020-09-21 17:16:49

---
title: Jest Tutorial: Unit Tests
published: true
description: 
tags: javascript, nodejs, jest
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/x19lpauoblay342wgdsd.png
---

Hello everyone 👋! A new video is released on my YouTube channel! **Waldev** channel is mostly focused on tutorials about JavaScript and Web related technologies. 🚀 

This time I decided to make tutorial about **Jest**. Since there are not so many tutorials about Unit Testing. This topic deserves more views, please watch it here:

{% youtube qQfB_y7jlyc %}

Please subscribe to my [Waldev channel](https://www.youtube.com/channel/UCWOcBjKEbegNxJmGtqxniyQ) if you are interested 🎥. Thank you!

<hr/>

I appreciate any support and feedback you can give, otherwise I can't improve and be better. 💖