teleren/devto huggingface dataset:
AsciiDoc(tor) for Technical Documentation
Tags: asciidoc, asciidoctor, pdf
Published: 2021-03-20 23:23:51

Writing is never an easy task, everybody knows. It is even harder for technical documentation since some pictures, diagrams, and technical drawings are meant to be in the documentation - with some explanatons of course. In software world, those things are also the main problems. 

Some people think, and this is the majority, just use Word Processor software - be it in the desktop or in the cloud. This might work, of course, but might lead to inconsistency. So, we at Zimera Systems has the policy to use open and free tools to power our technical documentation. For this purpose, we find it easier to use Markdown + Pandoc but lately we move to AsciiDoc format and uses Asciidoctor and Asciidoctor-pdf. They are very easy to customize and creating PDF file is a piece of cake with [complete theming guide](https://github.com/asciidoctor/asciidoctor-pdf/blob/master/docs/theming-guide.adoc). 

The documentation title can be as simple as logo and the author, but can also takes full image so that we can use the whole picture when we really need to. Here's the simple title without the whole picture:

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

Table of contents will be organized automatically:

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

We love the picture and the admonium:

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

For us who are really passionate in coding, we especially love the callout:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/08asjo0kbq6q0w52zuy0.png)

We make our template open and you may get them at [our repository](https://github.com/zimera-school/book-template-asciidoc). 

Enjoy writing!
Class Variables in Python
Tags: python, oop
Published: 2021-03-20 23:05:59

---
title: Class Variables in Python
published: true
description: Python Class Variables
tags: python,oop
//cover_image:
---

## Class / Static Variables in Python
Consider the following python class

```python
class Cat(object):

    # class / static variables
    is_mammal = True
    genus = "felis"

    def __init__(self, name="daisy"):
        # instance variables
        self.set_name(name)

    # set / get methods
    def set_name(self, name):
        self.name = str(name)

    def get_name(self):
        return self.name
```

Class variables can be used without needing to instance the class

```Python
print(Cat.is_mammal)
# True
```


## Why Class Variables are Bad
A good guiding rule is, do not use class variables unless absolutely necessary. The reason is simple; they break the most basic principle of Object
Oriented Programming, which is that data should be __encapsulated__. Other instances of a class should not have direct access to other instance's data members (variables). That would defeat the very purpose of creating separate instances with their own values to begin with.

######Example

You can change a class' static variable like so

```Python
Cat.is_mammal = "yes"
print(Cat.is_mammal)
# yes
```

However, note that if you do, you will change the value for any existing instances, as well as future instances of the class.

```Python
daisy = Cat()
print(daisy.is_mammal)
# True
Cat.is_mammal = "yes"
sophie = Cat()
print(daisy.is_mammal)
# yes
print(sophie.is_mammal)
# yes
```

## Only Use Class Variables For Constants
 Class variables exist at the __class scope__. All instances of the class have access to these variables. In this regard they are similar to global variables and should only be used for storing global values that all instances of a class agree on (i.e. constants).

 In the cat class example, having a reference to the genus of the cat is probably fine as a class variable, since that is constant and should never change. However, you should designate these values as constants by typing them in upper case.

 The fact that class variables are similar to global variables should be enough of a deterrent to use them with extreme caution. Any variable that can be changed or read by many instances at any time creates a fundamentally unpredictable program.
Day 002: Why are hashes cached in dictionaries?
Tags: 100daysofcs, python, computerscience, todayilearned
Published: 2021-03-20 23:03:29

Taking a closer look at [how key-value pairs are stored in Python dictionaries](https://dev.to/rj722/day-001-how-do-python-dictionaries-work-5aa2) yesterday, I noticed that alongside storing the key+value, the hash of the key is also stored.

Why would that be?

It can't be to speed up the lookup, as we cannot get to the data (the tuple where the hash+key+value is stored) until we know it's address, and address can only be known by computing the hash first.

Why then?

Turns out that when resizing the `addresses` vector, the hash for all the keys in `items` needs to be recomputed. This is expensive to calculate, thus slowing down the resize operation. Caching the hash speeds things up:

```python
def resize_to(n):
    new_addresses = [None] * n
    for index, entry in enumerate(entries):
         h = perturb = entry[0]  # No need to compute the hash.
         addr = h % n
         while new_addresses[i] is not None:
             addr = (5 * addr + 1 + perturb) % n
             perturb >>= 5
         new_addresses[addr] = index
    return new_addresses
```

Other than this, storing the hash has another benefit -- during lookup, there's an inequality test required, which ensures that we've arrived at the correct hash+key+value pair, and need not probe any further.

The lookup code from the earlier post:

```python
def lookup(key):
    perturb = h = hash(key)
    address = addresses[h % n]

    while items[address][1] != key: # <- inequality test

        address = (5 * address + 1 + perturb) % n
        perturb >>= 5
    return items[address][2]
```

Comparing two objects for [in]equality can be an expensive operation. The solution here is to rely on the fact that "if two objects have unequal hashes, then the objects must be unequal as well", and use an equality checker like below:

```python
def fast_is_equal(
    key, target_key, key_hash, target_key_hash
):
    if key is target_key: return True  # Identity implies equality
    if hash_key != hash_target_key: return False
    return key == hash_key
```

And then during the lookup:

```python
# ...
    while not fast_is_equal(
        # reference: items[address] -> (hash, key, value)
        items[address][1], key, items[address][0], h
    ):
# ...
```

So, my initial guess was right in a way: it does indeed speeds up the lookup, just not in a way I thought it'd be.
Is Web Scraping Legal?
Published: 2021-03-18 08:13:37

The short answer to this question is. It depends.

"Depends on that?" you ask.

Well, it depends on your intent. How did you get here? Look around you. How did you get on this beautiful blog post? You got here from Google, which scraped MY DATA. But it helps me.

The intent of Google is just fine. It also makes money off of the services rendered, which I am fine with as well.

What about ethics?

What about it? Again it's intent. Suppose you download a few pictures of cats and entertain your kids with it, it's entirely ethical. But if the original owner wanted to make money off of it by selling it as quality photography and you started re-selling it on your website, that's just bad manners, and you should probably get sued.

Its also how you do it.

If you use a super-powerful bot to scrape a website that is not designed to handle all that many concurrent requests and bring down their web server, you are being mean and create a bad vibe for yourself and all web scrapers in general. Respect the users and the administrators of the website and try and make it as easy on them as possible.

Some people are panicky.

Some people are opposed to even Google scraping them. I would love to be one of those people and that cranky when I get to 90 years of age. So what should Google do to let them opt-out? Give them space to opt-out. Yeah. And so should you.

But even this is a grey area. You can argue that any data aired in public should be scrapable. Quite recently, sometime in the last quarter of last year, federal courts weighed in on this issue and simply declared that Scraping Public Data Doesn't Violate Hacking Laws. more here

Web Scraping Doesn't Violate Hacking Laws - New Federal court ruling.
Web Scraping legalities from the QVC case

Also, here is how to.

Stay clear of the legalities of Web Scraping with this 9 point checklist.
The grey area of Web Scraping Legalities Explored

In any case, if you are interested in web scraping and need to be sure not to get blocked by any web server, you will need a Rotating Proxy Service.

Our rotating proxy service Proxies API provides a simple API that can solve all IP Blocking problems instantly.

With millions of high speed rotating proxies located all over the world
With our automatic IP rotation
With our automatic User-Agent-String rotation (which simulates requests from different, valid web browsers and web browser versions)
With our automatic CAPTCHA solving technology
Hundreds of our customers have successfully solved the headache of IP blocks with a simple API.

A simple API can access the whole thing like below in any programming language.
Daily Developer Jokes - Saturday, Mar 20, 2021
Tags: jokes, dailydeveloperjokes
Published: 2021-03-20 22:32:44

---
title: "Daily Developer Jokes - Saturday, Mar 20, 2021"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
cover_image: "https://private.xtrp.io/projects/DailyDeveloperJokes/thumbnail_generator/?date=Saturday%2C%20Mar%2020%2C%202021"
published: true
tags: #jokes, #dailydeveloperjokes
---

Generated by Daily Developer Jokes, a project by [Fred Adams](https://xtrp.io/) ([@xtrp](https://dev.to/xtrp) on DEV)

___Read about Daily Developer Jokes on [this blog post](https://xtrp.io/blog/2020/01/12/daily-jokes-bot-release/), and check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/).___
### Today's Joke is...
![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e1258a63bab5.png)

---
*Have a joke idea for a future post? Email ___[xtrp@xtrp.io](mailto:xtrp@xtrp.io)___ with your suggestions!*

*This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit.*

<!-- 
Joke text:
___Q:___ What did the array say after it was extended?

___A:___ Stop objectifying me.
 -->
[BASICS] REACT.JS BEST PRACTICES IN PLAIN ENGLISH.
Tags: react, webdev, webpack
Published: 2021-03-20 22:28:08

1 . Component name must start with capitals letters.

2 . All the component must be small and function-specific.

3 . All the component must have small description  

```js
/**
*
* Author: {...}
* Description: {...}
* Dependencies: {...}
*
**/
const SampleComponent = () => {

  return (
    <div>
      Sample Component !
    </div>
  );
}

export default SampleComponent;
```

4 . All code must follow es6 coding standards.

5 . For variables that are NOT constants or constructors, multi-word variables and functions SHOULD be lowerCamelCased.

6 . Constants:- Pre-defined constants SHOULD be all-uppercase, and words separated by underscores: UPPER_UNDERSCORED.

7 . Typeof:- In type comparisons, the value tested MUST NOT be wrapped in parenthesis and use triple equals to.

```js
if (typeof myVariable === 'string') {
  // ...
}
```

8 . In simple condition, Ternary operator should be used instead of if else statement.

```js
// If-else Statement
if(condition) {
    //...
} else {
    //...
}

// Ternary operator
let myVariable = condition ? exprIfTrue : exprIfFalse
```

9 . fragments should be used instead of container div.

```js


render() {
  return (
    <Fragment>
       Some text.
      <h2>A heading</h2>
        More text.
      <h2>Another heading</h2>
       Even more text.
    </Fragment>
  );
}
```

10 . All files related to any one component should be in a single folder

11 . Functional components should be favored if we do not need to make use of React state.

12 . Anonymous functions should not be used as handlers.

13 . Inline styles should not be used inside component.

14 . For a component to hide itself return null from render.

15 . Higher Order Components should be used for cross-cutting concerns.

16 . Prefer state initialization in class member variable declaration over constructor

17 . Index should not be used as a key

18 . Short-Circuit evaluation should be used in jsx

```js
// Avoid
const sampleComponent = () => {
  return isTrue ? <p>True!</p> : null
};

// Recommended: short-circuit evaluation
const sampleComponent = () => {
  return isTrue && <p>True!</p>
};
```
Would love to hear from you guys if you could add up practices in my above list.
Comment down below 👇
Hacking the problems of Life with Technology 👨‍💻👩‍💻
Tags: computerscience, beginners, showdev, healthydebate
Published: 2021-03-20 21:45:26

We all live in a **Modern and High Tech** world but still, we have a lot of issues that are Unaddressed.

The world we have today is always dreamed off but as always with good things there comes some bad sides, so in this blog, I wanted to share about these problems and how can we _solve them with the help of technology, and **re-imagine our future**_
*****
# The Problem 🤔🤔

In the year 2015, United Nations had **17 Sustainable Development Goals (SDGs)** which are to be achieved by the year ***2030***.

![Goals](https://developers.google.com/community/images/dsc-solution-challange/un_goals_720.png)

These goals are agreed upon by _193 countries_ and these are some of the most ___fundamental blocks for a better and bright future___.
*****
# #hackthesolution

In the step to complete the goals, everyone is trying to do their part and it's time for ours, so to acknowledge this *Google* has started a **Solution Challenge** to get the involvement of students from different backgrounds, places, and ages.

![DSC](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7s1nme87omsyno707hcm.png)
To accompany this **Google Developers Student Club(DSC) of MAIT** has organized ***#hackthesolution***.


According to me [Hack The Solution](https://hackthesolution.tech/) is not like any Simple Hackathon, but rather it's a platform to use technology in problems that matter.

With some of the amazing mentors and participants ***Hack The Solution*** is the best place to learn and use technologies in a fun and exciting way.

I am really excited to be a part of **#hackthesolution** and learn some new cool tech and also share what I know.
*****
# The Solution 💡🧠

Now coming to the solution part, Personally, I am really fascinated towards topics including 
- **No Poverty**
- **Zero Hunger**
- **Responsible Consumption & Production**
- **Climate Action**

The above-mentioned four problems are the ones which always strike my mind, We all have seen that Fire in forests is increasing day by day and if we don't do something soon then it will be a big danger.

Also, Hunger is counted as one of the biggest killers of Humans which is a major concern, so to overcome this we can use various technologies and remove the barriers between the needy and the donor.
*****
In the end, I just wanted to say that **Possibilities are Endless all we need is the right way to utilize them.** ❤️‍🔥
A rap song about coders being in the zone
Tags: showdev, culture, programming
Published: 2021-03-20 20:43:10

---
title: A rap song about coders being in the zone
published: true
description: https://www.youtube.com/watch?v=Bo27L_QsTt8
tags: #showdev, #culture, #programming
---

Song url: https://www.youtube.com/watch?v=Bo27L_QsTt8

Quick background on the project: I'm a full time programmer and I love making rap music. I see a lot of humor in the profession/industry, and thought it would be fun to combine the two.
i have created a ML project
Tags: python, machinelearning, programming
Published: 2021-03-20 19:54:21

import pandas as pd
import numpy as np
import tensorflow as tf
from sklearn.preprocessing import LabelEncoder
from keras.utils import to_categorical

df = pd.read_csv('iris.data')

X = df.iloc[:, :4].values
y = df.iloc[:, 4].values

le = LabelEncoder()

y = le.fit_transform(y)
y = to_categorical(y)


from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Sequential

model = Sequential()

model.add(Dense(64, activation='relu', input_shape=[4]))
model.add(Dense(64))
model.add(Dense(3, activation='softmax'))

model.compile(optimizer='sgd', loss='categorical_crossentropy',
              metrics=['acc'])


model.fit(X, y, epochs=200)


from tensorflow import lite
converter = lite.TFLiteConverter.from_keras_model(model)

tfmodel = converter.convert()

open('iris.tflite', 'wb').write(tfmodel)
Rawbits- A Guild of Nerds
Published: 2021-03-20 19:45:53

Geek Week Local

A great initiative by GFG Vit Bhopal Chapter. We were asked to be a part of the guild and then solve challenges.

The first thing of joining a guild was fun when we searched and interacted with people to join a team. It was really fun to do that and pitch others and persuade them to join the guild.

Then the tasks began and the first day was light. But then it was escalated. Day 2 brought some tougher and interesting challenges
Throughout everyday we learnt something new and improves upon ourselves.

I learnt a lot. Learnt to create Portfolio, Github , Bootsrap, firebase and what not.

So its a hell of a experience till now and expecting more such events by GFG.

geekweeklocal
Geek Week Local- a journey
Tags: geekweeklocal
Published: 2021-03-20 19:43:13

What a rollercoaster of emotions! From the curiosity inducing challenges to sharing meals with our guildmates. The sheer competitiveness between different guilds just gave an adrenaline rush. And on top of that, the creative freedom with the memes we got.

This week-long event was a refreshing change from the monotonous online classes. The hype all over the college made me feel belonged, and even more encouraged to do well and come up at the leaderboard. 

I really think this event was a big success and was very knowledgable too! Kudos to GFG for this one!
Django-probes: wait until database is ready - Probes for Docker and Kubernetes
Tags: python, django, kubernetes, webdev
Published: 2021-03-20 19:39:41

## Concepts

Provides a Django management command to check whether the primary database is ready to accept connections.

Run this command in a Kubernetes or OpenShift Init Container to make your Django application wait until the database is available (e.g. to run database migrations).

## Installation

The easiest way to install django-probes is with pip

```python
pip install django-probes
```

## Basic Usage

1) Add django-probes to your Django application:

```python
INSTALLED_APPS = [
    ...
    'django_probes',
]
```

2) Add an Init Container to your Kubernetes/OpenShift deployment configuration, which calls the wait_for_database management command:

```bash
- kind: Deployment
  apiVersion: apps/v1
  spec:
    template:
      spec:
        initContainers:
        - name: wait-for-database
          image: my-django-app:latest
          envFrom:
          - secretRef:
              name: django
          command: ['python', 'manage.py', 'wait_for_database']
```

## Links

* [https://github.com/painless-software/django-probes](https://github.com/painless-software/django-probes)
STREAK on GeekWeek Local
Tags: codenewbie, computerscience, css, codequality
Published: 2021-03-20 19:39:32

What to start with? This week has been nothing but an exciting adventure at the start of my career in computer science. From writing a simple 'Hello World' program at the start till programming Data-Structures towards the end. It has helped me to learn a lot.

Let's start with the best thing the organizing team has done for us:
It was giving tasks not only to be a computer geek, but also to become a socially active and cultural geeks too. The tasks were never always to write a code and bore yourself for the whole day, but also to take a break and enjoy yourselves with the music and memes too. The task were not only to learn the specials of computer science, but also to learn how to work as a team.

The outcomes of this week challenge has been great. I have learnt how to code without stressing yourselves. I have learnt how to enjoy whether by going live on the mini-event or by playing with the teammates. I have learnt that taking a break from daily work and listening to music or doing what you love can never be a distraction, it is always a relaxation. I have learnt that being a complete stranger does not mean you cannot be open and be yourself to your stranger teammates; after all, they too are your friends just that you haven't met them until now. And lastly, I have also learnt, it is fun competing to get on top by putting extra efforts.

Honestly speaking, this week has been a challenge as well as a perfect learning opportunity I grabbed in my whole life. A disease outbreak can never be a hindrance to what we want to learn. We are united by the internet, and ladies and gentlemen that unity gave us the chance to a very cool learning opportunity.
Python Youtube Downloader.
Tags: python, automation, projects, scripting
Published: 2021-03-20 19:32:14

So, today let's write a Python Script to download videos from our favourite video streaming platform: Youtube.
**NOTE:** Please note that only the videos which are available for download only those can be downloaded.

Let's Begin:
First Let's Import all the required Modules:
```
pip install youtube_dl 
```

Importing the installed Module in Python:
```
import youtube_dl
```

Now, let's make a list of all the youtube videos i.e their url's to download the videos also let's make a dictionary to specify all the options that we need for our video download as follows:
```
links = ['Link of your Video', 'Link of another video....',]
options = {

  "format" : "bestvideo+bestaudio"

}
```
Here, in the options you can apply more filter's but I like to keep it simple by just specifying the format of the video.
The ' bestaudio+bestvideo' will download the best available format of that video file.
  
The next part is the main one:
```
with youtube_dl.YoutubeDL(options) as ydl:
	ydl.download(links) 
```
The youtube_dl.YoutubeDL.download() method will download all the videos from the links that you will provide to it with you desired options as declared earlier.
The Entire code is even less than 10 lines but using it you can easliy automate your task in Python.
Here is the entire code:
```
import youtube_dl 
links = ['https://www.youtube.com/watch?v=v4dROX2lRMw']
options = {

  "format" : "bestvideo+bestaudio"

}

with youtube_dl.YoutubeDL(options) as ydl:
	ydl.download(links) 
```

Hope this was useful :)