teleren/devto huggingface dataset:
What is __name__ == '__main__' in python 🤯
Tags: python, programming, tutorial, beginners
Published: 2022-09-02 13:35:01

```python
if __name__ == '__main__':
    pass
```
Many people on YouTube and also in the in-built modules in python there is this statement which confuses the most of the beginners who are trying to learn python. In this post I will try to clarify about what is `__name__` and why it is used in python?

## What is `__name__`?
Before running any python script or file, python itself sets some special variables and this `__name__` is one of the variables. The beauty of this variable is that it sets the value of variable based on how we run the file. For example, if we run the file directly then it gets `__main__` as the value but if we run this file by importing it into other file and running that file it gets a the file name as the value and that other file will get `__main__` as the value.

## Let us see in deep :
Let us create two files named `first.py` and `second.py`
Add following code to `first.py` file 👇
```python
def main():
    print('first.py file __name__ :', __name__)

if __name__ == '__main__':
    main()
```

Above code is very simple that if `__name__` is equal to `__main__` only then we will run our `main()` method which actually means is that when the file is ran directly then the `__name__` variable will be equal to `__main__` only then our main() method will be executed.

try to run the `first.py` file alone, we will get the following output
```python
first.py file __name__ : __main__
```

Now Add the following code to second.py file 👇
```python
import first

print('second.py file __name__ :', __name__)
```

if we run the `second.py` file we will get the following output
```
second.py file __name__ : __main__
```

If we look carefully we are importing our `first.py` module into `second.py` but we are not getting any output from first main() method. this is because the first file is not ran directly so the `__name__` will not be equal to `__main__` it is actually equal to `first`.

then how can we get the `first.py` `__name__` variable?

to get that just change `second.py` code as below..

```python
import first

first.main()
print('second.py file __name__ :', __name__)
```

then we will get the following output 👇
```
first python file __name__ : first
second.py file __name__ : __main__
```


I hope you have got some basic idea about `__name__` variable..
Thank You for reading 💗
A Fully Functional and more than 50 times tested Voice Assistant using Python in Mobile! With Code
Tags: python, tutorial, programming, ai
Published: 2022-09-02 13:28:13

Hello Everyone
Today's topic is very helpful for those looking desperately how to make a voice assistant using Python in their mobile phones right away. Also I will give you the data used in each step. 

**Step 1: Install Termux And Termux:API but not from Google Play Store** 

So this step is gonna be very simple if I give you the links, so here they are.

Termux : https://f-droid.org/repo/com.termux_118.apk
Termux:API : https://f-droid.org/repo/com.termux.api_51.apk

Run the followong command in Termux upon installation. 
```shell
pkg update && upgrade
```

```shell
pkg install python espeak termux-api
```

Data usage: 150mb+ Approx(200mb maybe) 

**Step 2: Save file to termux**

Type the following command in Termux
```shell
nano Speak.py
```

And paste the following code, 
```python
#Created by Its Arun Stark on YT
#Modified by ProHarshit
import subprocess

class Speak:
    def __init__(self,engine='espeak'):
        self.engine = engine
        self.rate = 150 #Speed
        self.gender = "m"
        self.type = 3
        self.language = "en-gb" #en-gb for UK, en-us for US, en-in for Indi
        self.pitch = 250 #Pitch
    def say(self,text:str):
        subprocess.Popen([self.engine,"-s",str(self.rate),"-v",self.language+"+"+self.gender+str(self.type),"-p",str(self.pitch),text]).communicate()
```
**The settings here are customized for a fully robotic voice. You can change **

Press Ctrl then C the X and then press enter.

Data usage: Offline Step

**Step 3: Main Code**

Now let's move towards the main code. 

_**Import Modules**_
```python
import subprocess
from Speak import Speak
import datetime
import os
```

**_Define Speak Function_**
```python
def speak(text):
    s = Speak()
    s.say(text)
```
**Note:** _Keep the files Speak.py and this main file in same directory._

**_Define Speech Check Function_**
```python
def checkspeech()
    print("Listening...")
    result = str(subprocess.getoutput("termux-speech-to-text")) 
    print("Recognizing...") 
    print("User said", result)
```

**_Define set of commands(inside checkspeech())_**

Now let's move towards your code recognizing a few commands. 
Here is one example:

```python
    if "hello" in result:
        speak("hello")
    if "name" in result:
        speak("my name is jarvis")
```
**The output will come a voice saying hello and it's name respectively**

**_Define loop outside checkspeech()_**

```python
while True:
    checkspeech()
```

Data usage: Offline step

So thanks for visiting today's tutorial. Please tell if I missed something. 
Stay Tuned
Built with [Ansh Yadav(Pro-Ansh)](https://dev.to/proansh)
TOTP QR Code Generator
Tags: codepen
Published: 2022-09-02 13:20:36

**Zaman Tabanlı Tek Seferlik Parola Algoritması**, üretildiği zaman aralığının benzersizliğini alarak, tek seferlik parola üreten bir HMAC Tabanlı Bir-Zamanlı Parola algoritmasının uzantısıdır. İnternet Mühendisliği Görev Gücü standardı RFC 6238 olarak kabul edilmiştir


{% codepen https://codepen.io/harunpehlivan/pen/rNvNwpN %}
Optimise CI to make sure your test run for only modules changed and save avoidable computation minutes
Tags: testing, github, architecture
Published: 2022-09-02 13:19:29

We all profess test driven development and we should. Sometimes pushing MVP to the market in certain time is important and we skip tests at all. 

_Whatever the case, write tests for your code as soon as you can._ 

But with huge code base, and good test means you will have hundreds if not thousands of tests to run. And all those tests could include some preparation computation before we execution and clean-up after it. There are separate strategies to optimise that much in-nutshell: tests could take a lot of time to run. Often we run those test for automatically at merge and pull requests. 

**That require a lot of compassion on cloud and hence cost you fortune.**

Read about development pipeline strategies here. 

{% embed https://dev.to/lutif/strategies-to-ship-faster-and-keep-your-development-pipeline-unblocked-at-scale-3n32
 %}


So, it would be better to run only test related to the feature changed, if its UI test run test for the concerned page, and not for something that stay unchanged. 

Here we will see an example how to do that if you have your code hosted on Github and CI done via Github actions, but these strategies works for other tools too.

Lets, assume we are doing UI tests and our code is structured such that we have `scr/pages` folder that contains components for all pages eg: `src/pages/register` , there could be subdirs as well eg: `src/page/register/shared`, `src/page/register/styles` etc.

Now in your Github action where you run tests

1. Get files changed: For Github Actions you can use [Changed Files
](Changed Files) action from action market place
2. Filter files from your pages directory, get pages names keep unique only, that's where you UI components are right?
3. Pass this list to whatever testing library/suit/runner you are using, be it JEST, playwright. Let your runner only run those test only.


**Warning**: If you have shared components which are used on multiple pages, make sure if there are any changes in those, run all tests to be sure you are not breaking anything. 


Comment about your approach to tests and have you run into this issue of insane time to run tests.
How to debug an Azure App Service with Visual Studio 2022
Tags: azure, programming, csharp
Published: 2022-09-02 12:55:46

Sometimes (for me very often 🤣) when you deploy an app to Azure doesn't functioning properly. It happens.
The app still works on your machine and it's difficult to understand the reason behind.

![works on my machine](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ctn14mbo0pcbefu53k2.png)

With Visual Studio you can easily attach the debugger to the App Service process and debug the "remote" application as it's running locally.

From the main menu, click on **Debug** -> **Attach to process**.
From the new window, select **Microsoft Azure App Services** as Connection type.

![Microsoft Azure App Services](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ny14tzx4t8y765g6x7f1.png)

Click on the **Find...** button and in the new dialog, browse in your Azure subscriptions and select the right app service.

![select the app service](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i1iq3o6ixg0rajpr8ggx.png)

At this point, Visual Studio, starts to load assembly from the remote service and you should see the next screen.

![loading remote service](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7eiwqpy487yvwl88zg9s.png)

After a while, you should see the list on the processes on the remote service and the w3wp.exe process should appear in the list.

![w3wp.exe process](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mu5ujrndxtva05xz7lsz.png)

Select the process and then click to the **Attach** button on the bottom right of the window.

Enjoy your debugging session on the App Service 🙂
Minor Project For Electrical Engineering
Tags: javascript, webdev, beginners, programming
Published: 2022-09-02 12:50:18

Minor Projects serves as an excellent platform for Electrical engineers to showcase their skills and experiment with the theoretical concepts which they learnt in their academics.

Topic is the heart of any Mini Project. As every mini project starts with the selection of topic, one should have a clear idea about one's subject strengths. In addition, the Mini Project topic you select should satisfy your academic requirements and should help you boost your skills and widen your horizon of your thinking. Avoid choosing a topic, which is too broad or too narrow.

Do not select a topic, which has already been explored to the fullest. The selection of your [minor Project for electrical engineering](https://takeoffprojects.com/minor-project-for-electrical-engineering) should be in such a way that it should have very good scope for further study, it should be advantageous to the society as well as it should enhance your technical and managerial skills.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xtkd703082or48076kpd.png)

To do a good [minor Project in electrical engineering](https://www.youtube.com/watch?v=Bi5sAumbApQ) one has to select a topic in which they can learn and apply the theoretical concepts of their academics. In addition to that, availability of hardware's to build the mini project will also be an important factor influencing the mini project. In order to get good grades and to increase the chance of employability one has to make sure that they learn practically, understanding all the concepts involved.

Few Minor Projects For Electrical Engineering:

1. [A Low-voltage Ride-through Strategy Using Mixed Potential Function For Three-phase Grid-connected Pv Systems](https://takeoffprojects.com/project-details/a-low-voltage-ride-through-strategy-using-mixed-potential-function-for-three-phase-grid-connected-pv-systems--5657)
2. [Effective Grid Connected Power Injection Scheme Using Multilevel Inverter Based Hybrid Wind Solar Energy Conversion System](https://takeoffprojects.com/project-details/effective-grid-connected-power-injection-scheme-using-multilevel-inverter-based-hybrid-wind-solar-energy-conversion-system--5654)
3. [Improved Mppt Method To Increase Accuracy And Speed In Photovoltaic Systems Under Variable Atmospheric Conditions](https://takeoffprojects.com/project-details/improved-mppt-method-to-increase-accuracy-and-speed-in-photovoltaic-systems-under-variable-atmospheric-conditions--5664)
4. [Modeling Of An Intelligent Battery Controller For Standalone Solar-wind Hybrid Distributed Generation System](https://takeoffprojects.com/project-details/modeling-of-an-intelligent-battery-controller-for-standalone-solar-wind-hybrid-distributed-generation-system--5661)
5. [A Coordinated Control Of Hybrid Ac/dc Microgrids With Pv-wind-battery Under Variable Generation And Load Conditions
](https://takeoffprojects.com/project-details/a-coordinated-control-of-hybrid-acdc-microgrids-with-pv-wind-battery-under-variable-generation-and-load-conditions--5652)
Who is a PHP developer?
Published: 2022-09-02 12:48:37

The abbreviation comes from - Hypertext Preprocessor. It is a scripting language used to write scripts for web applications. Originated in 1995, the main task was to generate pages in html. Incorporated a lot of Perl. The language is interpreted, which means that compilation is not needed for its operation, the result of execution is visible immediately after execution. The threshold for entering the language is low, but this does not mean that without knowledge of mathematics, algorithms, you can quickly become a successful programmer. For example, as specialists from Dinarys [https://dinarys.com/php-development-services](https://dinarys.com/php-development-services)

And yet, you can start by studying CMS - this is a content management system, usually a set of ready-made modules to perform certain tasks. There are CMS for product and order management (prestashop, Magento), for blogs (Wordpress), news sites (DLE), etc.

CMS allow you to create websites without writing a single line of code, the disadvantage of this approach is the inability to make the necessary changes to the site (design, logic).

At Artjoker, this position is called CMS developer.

What you should know and be able to:

experience in developing for one of the popular cms (wordpress, modx, opencart, magento or others)
understanding of the principles of OOP / MVC - at the initial stage, only an understanding of these principles is necessary, but in the future, growth without practical application is impossible
knowledge of PHP and MySQL
basic knowledge of Git
[11/40 things about data] Learn SQL please
Tags: sql, database, data
Published: 2022-09-02 12:18:21

You may not like SQL based databases but the probability of dealing with a SQL based system in your career is so high that learning it as soon as possible will compound.

I didn’t like SQL, I still don’t like it even though I work with it every single day but I have to recognize it’s a really handy tool.
Getting Started with Python
Tags: python, beginners, programming, machinelearning
Published: 2022-09-02 12:06:32


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/70lmjewfwvwnty1yd3rn.jpg)

Programming with python has always been on my mind. However, I lacked the motivation to get started. Seeing the need to master this computer language especially with its integration in machine learning, I have to enroll in two bootcamps and I am committed to the process.
Putting the graph in GraphQL
Tags: graphql, apollo
Published: 2022-09-13 20:10:48

---
title: Putting the graph in GraphQL
published: true
date: 2022-09-01 19:44:00 UTC
tags: graphql, apollo
canonical_url: https://rachsmith.com/putting-the-graph-in-graphql/
---

It took me a while to understand how to design for the Graph in a [GraphQL](https://graphql.org/) API. Coming from [REST](https://www.redhat.com/en/topics/api/what-is-a-rest-api), I first added a lot of queries to the [Query type](https://graphql.org/learn/schema/#the-query-and-mutation-types).

For example, to get the comments on a [Pen](https://blog.codepen.io/documentation/pen-editor/), I added a `comments` query to the query type, and I passed in `item_id` and `item_type` as arguments.

##### Schema

```
type Query {
  "List of Item Comments"
  comments(input: CommentsInput!): CommentsPaginated
}

input CommentsInput {
  pagination: PaginationInput = {}
  filters: CommentsFiltersInput!
}

input CommentsFiltersInput {
  itemId: ID!
  itemType: ItemEnum!
}

```

##### Query

```
query Comments($input: CommentsInput!) {
  comments {
    id
    owner {
      id
      username
    }
    text
  }
}

```

##### Variables

```
"variables": {
  "input": {
    "filters": {
      "itemID": "hwvmeXVR"
      "itemType": "Pen"
    }
  }
}

```

This worked just fine, but there wasn't a good reason to put comments on the `Query` type in the API. There wasn't ever a time where we wanted to query for comments belonging to multiple Items, we only got the comments specific to an `Item` (aka a Pen, Project or Collection).

After some time, I realised I don't have to put all my queries on the `Query` type, I can put the queries on _any object in the schema_. So I moved the comments query to the `Item` interface. Now the comments are available on the `Pen`, `Project` and `Collection` objects.

##### Schema

```
"A CodePen Item - Pen, Collection, Post or Project"
interface Item {
  "List of Item Comments"
  comments(input: PaginationInput = {}): CommentsPaginated
}

```

##### Query

```
query CommentsQuery(
  $id: ID!
  $itemType: ItemEnum!
  $commentsPaginationInput: PaginationInput
) {
  item(id: $id, itemType: $itemType, token: $token) {
    id
    comments(input: $commentsPaginationInput) {
      records {
        id
        ...CommentDetails
      }
    }
  }
}

```

This is the whole point of the _graph_ in GraphQL. Rather than just thinking about what data models you can ask the server for, you instead think about how the nodes in your business logic connect and relate to eachother.

An upside of this new design choice is that it simplified the resolver for comments. Previously, we had to select the Item from the DB, check that that logged-in User had permission to access that item, then go and retrieve the comments. The new resolver is handed the Item record with the confidence that permission-checking has been completed further up the graph, meaning the `comments` resolver needs to do less work.
Wrangling financial inclusion data with JavaScript, D3 and Markdown
Tags: javascript, webdev, markdown, datascience
Published: 2022-09-02 11:47:11

Taken from my tweet: https://twitter.com/dextersjab/status/1546257828058345472

I wrestled with the recent Global Findex 2021 created launched by the World Bank. My aim was to update an interactive map I created for the 2017 dataset.

Tools: @observablehq (JS, Markdown, d3).

I also explained every step to myself (links included):

First, I opened the data in Google Sheets.

There are too many indicators to display at once (>7,000).

An example indicator: Financial institution account (% age 15+).

The rows are also grouped into years: 2011, 2014, 2017, 2021.

We'll need to restructure the data.

![raw data in Google Sheets](https://pbs.twimg.com/media/FXVpTdpVUAUkC8K?format=jpg&name=large)

The target shape for the data is easy because I'm using a schema I designed for my original project:

• Country Name
• Country Code
• Indicator Name
• Indicator Code
• 2011 data
• 2014 data
• 2017 data
• 2021 data

First, we import the data and extract indicator texts.

![JSON table data](https://pbs.twimg.com/media/FXVpT7DUsAAnKcj?format=png&name=900x900)

Rather than 4 rows per country, we make lookups simpler by having each row represent one combination of:

• country
• year
• indicator

The next step is to extract the unique values for each.

![JSON table data](https://pbs.twimg.com/media/FXVpUWKVQAAWcdR?format=jpg&name=medium)

Easy part over, now things get painful 😂

The shape of the data is one thing, but now we need to deal with the keys 🫠

After looking at the dataset, we can see that similar indicators have keys matching certain patterns. Code roughly handles this.

![screenshot from notebook](https://pbs.twimg.com/media/FXVpUwZUIAADPa4?format=png&name=small)
![screenshot from notebook](https://pbs.twimg.com/media/FXVpU8vUsAUPuzu?format=png&name=small)

For everything that the code doesn't neatly handle we do more manual work.

To minimise the boring stuff, we isolate data that's hard to work with and afterwards we put them back into mappings (JSON objects and d3 data structures).

![screenshot from notebook](https://pbs.twimg.com/media/FXVpVUlVEAAXe-W?format=png&name=small)

After fixing indicators, I created a tree structure.

I like to use the d3 hierarchy to do this so can always quickly use d3 tools like the tidy tree visualisation.

![screenshots from notebook](https://pbs.twimg.com/media/FXVpVrpUcAAYfAj?format=png&name=900x900)
![hierarchy screenshot from notebook](https://pbs.twimg.com/media/FXVpV6JUsAA9mIL?format=jpg&name=medium)

After some (relatively) simple mapping of population data, all that remained was to to rename some variables in the main project to match the newly wrangled data.

Now we can navigate our stats about financial inclusion here:

https://observablehq.com/@dextersjab/global-financial-access-findex

And the ugly behind-the-scenes data wrangling lives here:

https://observablehq.com/@dextersjab/global-findex-data

I'll make some improvements to both notebooks at some point, but sometimes I just like to publish my work as is 😬
A Node.js tutorial on building a PWA
Published: 2022-09-02 11:47:00

By profession, I am a Rust developer. However, I have some insight into how PWAs work and their benefits.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jlox6uxeivec6wtczyeq.jpg)
## Benefits of Using Node.js to build PWA

Through the use of service employees, manifests, and other platform characteristics, progressive web apps provide a native app-like experience for users. 

### Tools that you will need

1. Node.js to run the server
2. Express to run the HTTP server
3. Create a self-signed certificate using OpenSSL
4. Chrome to test the website and debug your PWA

Check the full guide by using this link.
[https://blog.landofcoder.com/build-a-pwa-with-node-js/](https://blog.landofcoder.com/build-a-pwa-with-node-js/)
How to add git works shortcuts to increase your productivity
Tags: git, productivity
Published: 2022-09-02 11:46:49

# Why create shortcuts
Shortcuts are essential in developer's routine, they greatly increase the productivity and, in this area, productivity is everthing. Many companies are looking people that have soft skills, and knowing how to save time without losing productivity is one of them. You might be thinking... "Oh but git shorcuts only save little time", yes you are right, but adding up all the time you save throughout the year, believe me, you save a lot of time. Moreover, why doesnt use git shortcuts for show to your friends that you know do this hahaha...

# Creating the shortcuts
So... let's add git shortcuts in windows.
Open your User folder, in my example the folder are located in `C:\Users\Vinicius`. Here you find a `.gitconfig` file, open it in a text editor of your choice.

Maybe this file can already contain some configurations, but the one we are going to create is the **alias** configuration. So, go to end and open a tag `[alias]`. Going to follow line and add the shortcuts that you want.
```bash
[alias]
    al = add .
	cm = commit -m
	ph = push
	pl = pull
	st = status
```
> C: > Users > Vinicius > .gitconfig

You are free to add any shortcuts that you want. The comands will still need the `git` prefix, but everything that comes after you can add a shortcut.
<img width="100%" style="width:100%" src="https://media.giphy.com/media/ymNNHpFS9ADDQwADRu/giphy.gif">