teleren/devto huggingface dataset:
Do your own Python's @property
Tags: python
Published: 2020-05-18 13:06:02



After reading this chapter in "Expert Python Programming" - 
Advanced Attrbiute Access patterns - https://subscription.packtpub.com/book/application_development/9781789808896/4/ch04lvl1sec39/advanced-attribute-access-patterns
decided to implement @property partially.
Here is the final result - https://gist.github.com/mzsrtgzr2/46975900b8d7a8e6f8cc51d1a40ca940

```
class myproperty:
    def __init__(self, func):
        self.f = func
        
    def setter(self, func):
        self.setter_func = func
        return self # (1) why do we need this? read below on 
    
    def __get__(self, instance, klass):
        return self.f(instance or klass)
    
    def __set__(self, instance, value):
        self.setter_func(instance, value)
          

class Foo:
    def __init__(self):
        self._val=0
    
    @myproperty
    def temperature(self):
        return self._val
    
    @temperature.setter
    def temperature(self, value):  # (2) why need same name as getter?
        print('setting to', value)
        self._val = value

ins = Foo()

print(int.temperature)  # 0
ins.temperature = 6
print(int.temperature)  # 6
```

It's important to understand how decorators work. This is the key to understand this code. The *decorated* function is REPLACED with an instance of your decorator (or a function in case you use a decorator function and not class). That being said, you can add functionality to your decorator class like `__get__` and `__set__`, like in the code above.
`__get__` - doing a "read" operation on the decorator class.
`__set__` - doing a "write" operation on the decorator class.

This is another way to look at decorators - it can be used for "data descriptors" (when you access a field, as in `ins.temperature`) and not just as function wrappers (implemented with `__call__`, as in `ins.temperature()`).


Important - why is the `decorated set method` should also be named `temperature`?

A decorator works like this:
```
@dec 
def func1:
   pass
```
actually converts to 
```
func1 = dec(func1)
```
so the name of the function is important.

What happens if we don't use the same name in (2) or drop the `return self` statement at the end of our decorator: what used to be `temperature` in our class is overridden to `None` - losing all the functionality we thought we built. We really happens:
```
class Foo:
    def __init__(self):
        self._val=0
    
    def temperature(self):
        return self._val
    temperature = myproperty(temperature)  # instantiating myproperty class
    
    def temperature(self, value):  # (2) why need same name as getter?
        print('setting to', value)
        self._val = value

    temperature = temperature.setter(temperature)

```
In this example, the property field `temperature` is always the `reference name` and can't change it.
dialog for creating Modals
Tags: html, css, javascript, modals
Published: 2020-05-18 13:03:02

Have you ever had trouble creating modals in UI?

Are you asking these questions to yourself:

1) How should I create overlay for the modal?
2) Will the div wrapper be absolute position?
3) Should I use jQuery to open and close the modal?

Has this issue constrained you to use Bootstrap?

##All your questions are answered here

So let's spare you of some of this misery!

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

You can play around here in this pen:
{% codepen https://codepen.io/harsh07/pen/VwvVPEO %}
Doesn't it feel magical to overcome all your positioning & overlay issues!
Now let's deep dive!

You can make a dialog with or without overlay but toggling between these two cases is pretty simple.
Without overlay (banners):
```javascript
dialog.show();
dialog.hide();
```
With overlay(modals):
```javascript
dialog.showModal();
dialog.close();
```

##Attributes & customisations

1) open : Dialog has an 'open' attribute to signify if it's open or not.
```html
<dialog>
  I'm closed.
</dialog>

<dialog open>
  I'm open.
</dialog>
```

You can even add animations while opening. Here is a small one for you where the modal fades in from slight left of final position:
```css
dialog[open] {
  animation: appear .15s cubic-bezier(0, 1.8, 1, 1.8);
}

@keyframes appear {
  from {
    opacity: 0;
    transform: translateX(-3rem);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
} 
```

2) ::backdrop : This pseudo-selector in CSS can be used to customise the overlay of the dialog.

```css
dialog::backdrop {
  background: linear-gradient(45deg, rgba(0, 0, 0, 0.5), rgba(54, 54, 54, 0.5));
  
}

```
You can even add a blur to this backdrop by adding 'backdrop-filter' CSS property like this:
```css
backdrop-filter: blur(3px);
```

##Browser & Polyfill support

Below is the browser support table from MDN :
 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/wz6zvhg0exbb6c4l7x2c.png)

[Polyfill support Link](https://github.com/GoogleChrome/dialog-polyfill)

Please comment if you have any additions. Would love to lear something new!
How to setup MongoDB and robo3t
Tags: database, mongodb, robo3t
Published: 2020-05-18 10:41:55

I am assuming that mongodb is installed in your system.

To start the mongodb server we need to open the command prompt and give the below command:
 /Users/sunny/mongodb/mongodb/bin/mongod.exe --dbpath=/Users/sunny/mongodb-data

The first part is the folder location of your mongodb file and the second part is the folder location where you want to store all the data which you will create in future.

Next we need to download robo3t which is a GUI to manage our mongodb database.

step 1:download robo3t
step 2:open and click on create button
step 3:Give any name
step 4:let it run on local host with port unchanged as it is the same port in which we started our mongodb server.you can go back and chcek in the command prompt there you can se the message : "Listening on 127.0.0.1
2020-05-18T15:44:25.282+0530 I  NETWORK  [listener] waiting for connections on port 27017".
step 6: click on test to check whether your connection has been established and access to database is provided.
step 6:Your database has been created, now to check whether robo3t is connected to mongodb we need to open shell command from robo3t (right click on db and click on open shell)
step 7:give the command-db.version() and it should return the correct version of mongodb which ensures that your connection has been established.

step 6: click on save.

There you go with mongodb and robo3t setup.

In my next post I will be sharing how to integrate mongodb with node js application.

Thank you.
May 18 — Daily CodeNewbie Check-in Thread
Tags: codenewbie, checkin, beginners, discuss
Published: 2020-05-18 13:01:41

---
title: May 18 — Daily CodeNewbie Check-in Thread
published: true
description: A daily thread to ask questions, share progress, and stay accountable!
tags: codenewbie, checkin, beginners, discuss
series: Daily Checkin
---

You are encouraged to use this daily thread to:
- Ask for help (all questions encouraged)
- Explore topics you’re curious about
- Share something you’ve written or read
- Celebrate your wins
- Stay accountable to your goals
- Support your fellow programmers

Happy Coding!

---

_Interested in joining the twice-weekly live [#CodeNewbie Twitter chats](https://twitter.com/search?q=codenewbie)?  You can find us [on Twitter](https://twitter.com/search?q=codenewbie) each Wednesday at 9pm ET (1am GMT on Thursday) and Sunday at 2pm ET (6pm GMT)!_
Laravel built in Medium clone. Join me 
Tags: laravel, medium, opensource, github
Published: 2020-05-18 12:54:33

Hi everyone. I have built laravel based medium clone LARAMEDIUM using another 2 packages mediumish and dante medium editor. Next i plan to add user registration and create post and follow system. 
I hope who is excited to built laravel based medium blogging will join me. here is the repo. 

https://github.com/Alionides/laramedium
On.NET Episode: Scaling .NET for Apache Spark processing jobs
Tags: dotnet, azure, bigdata, spark
Published: 2020-05-18 12:50:11

When you are processing gigs or terabytes of data, it's important to have resources that will help you scale to fit your data processing needs.

In this episode, Brigit Murtaugh joins us again to show us how Azure Synapse can help us power our .NET for Apache Spark data processing jobs.

{% youtube sI1Q1_Iv_-Q %}

If you liked this video and would like to see some more of our .NET content, please subscribe to our [.NET Developers YouTube Channel](https://www.youtube.com/channel/UCvtT19MZW8dq5Wwfu6B0oxw).


## Useful Links
<ul>
<li><a href="https://dotnet.microsoft.com/apps/data/spark?WT.mc_id=ondotnet-devto-cephilli" target="_blank">.NET for Apache Spark</a></li>
<li><a href="https://docs.microsoft.com/dotnet/spark?WT.mc_id=ondotnet-devto-cephilli" target="_blank">.NET for Apache Spark documentation</a></li>
<li><a href="https://channel9.msdn.com/Series/NET-for-Apache-Spark-101?WT.mc_id=ondotnet-c9-cephilli" target="_blank">.NET for Apache Spark 101 videos</a></li>
<li><a href="https://github.com/dotnet/spark" target="_blank">.NET for Apache Spark on GitHub</a></li>
<li><a href="https://devblogs.microsoft.com/dotnet/an-introduction-to-dataframe?WT.mc_id=ondotnet-devto-cephilli" target="_blank">An Introduction to DataFrame</a></li>
</ul>
What was your first laptop/pc for your programming job？
Tags: watercooler, webdev, discuss
Published: 2020-05-18 12:44:12

My first was my own 12-inch Macbook which I brought it before I decided to go for programming. Sooo, it survived for the Bootcamps and some small freelance works for me. Then soon I'm using the work laptop on 13-inch Macbook Pro. 

![Alt text of image](http://i0.kym-cdn.com/photos/images/original/000/211/305/tumblr_lurs1bRsfm1qcbhpc.jpg)

Many of my co-workers in the company actually switch from macOS to Windows Linux. I am still considering switching for how amazing processer and the RAM they have.

What about you? What's your first working laptop or laptop devices provided by your company?
Easy Data Validation For Your Python Projects With Pydantic
Published: 2020-05-18 12:43:36

<p>One of the most common causes of bugs is incorrect data being passed throughout your program. Pydantic is a library that provides runtime checking and validation of the information that you rely on in your code. In this episode Samuel Colvin explains why he created it, the interesting and useful ways that it can be used, and how to integrate it into your own projects. If you are tired of unhelpful errors due to bad data then listen now and try it out today.</p><p><a href='https://www.pythonpodcast.com/pydantic-data-validation-episode-263/'>Listen Now!</a></p>
Where to find those who need a CRM solution
Tags: startup, saas
Published: 2020-05-18 12:38:31

Hi guys, we recently built a CRM (Customer Relationship Management) software.
It solves issues of current CRMs on the market. These issues include: complexity of usage, catered for only medium and large size businesses and difficulty in learning to use it. 

Here it is: 
https://neckline.space

We know the type of customers we are looking for: solo founders, a business with a small team, and a business looking for a simple to use CRM.

We are currently cold emailing potential customers.
Perhaps, someone knows where we can meet these potential customers apart from cold emailing. If you could offer us some advise or help, we would be greatful.
Thank you
GitHub PROJECT or REPO?
Tags: github, tutorial, womenintech
Published: 2020-05-18 12:31:39


#A guide for those who are (_were_) as confused about the terminology as I am (_was_).

I'm sure as a new programmer, you took a few online tutorial MOOCs or watched a few YouTube Bootcamps and then deceided to get cracking on a project yourself - since that's what all of the experienced devs always seem to emphasize. _"Don't get trapped in tutorial purgatory._

I've heard it all too many times. 

Then you whip out your password manager and log into good ol' GitHub hoping to upload something of a project you started all on your own, but then realize something very odd...

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

#But which do you choose...

Don't decide that programming isn't for you. Trust me. You're fine. You just need a guide is all.
I hope I can be that little guide sprite in your GitHub journey..
Lemme break it down simply. 

#New `Repository`
Think of this as a folder for all of your project files. It's your project, but you can see everything inside and others can read what it's about in your `README` and clone it if they wanna see your project on their machines. 

#Import `Repository` 
Same thing but you import it from somewhere else. 

#New `Gist`
A gist is not to be confused with a repository... but it can be stored in one. 

Where a repo contains all of your files in your project, a `gist` is more of an excerpt of a certain part of your project, such as a line of code you want to explain more thoroughly. It could also be a technique or solution you wish to highlight as well, among other things. 
_KISS: Keep it simple, stupid._

#New Organization
This option is for creating a new, _well_, organization, which is an account which has many linked user accounts and that owns those repositories. 
  
#New Project
This term is pretty bad. _Let's be honest..._ Don't think of this as a project, _per say_, but as a Project MGMT System. If you make a Project you can base it on certain repositories that you have. It helps you get all of your tasks in order that you have to still add to your projects' repository. 

##And that's a wrap. 
I hope that helped straighten things out for you a little. 
It sure helped me. 

If there are any errors or mods, please let me know in the comments. 

_Happy Coding!_
Power Up Your PostgreSQL Analytics With Swarm64 - Episode 133
Published: 2020-05-18 12:29:27

<p>The PostgreSQL database is massively popular due to its flexibility and extensive ecosystem of extensions, but it is still not the first choice for high performance analytics. Swarm64 aims to change that by adding support for advanced hardware capabilities like FPGAs and optimized usage of modern SSDs. In this episode CEO and co-founder Thomas Richter discusses his motivation for creating an extension to optimize Postgres hardware usage, the benefits of running your analytics on the same platform as your application, and how it works under the hood. If you are trying to get more performance out of your database then this episode is for you!</p><p><a href='https://www.dataengineeringpodcast.com/swarm64-postgresql-analytics-episode-133/'>Listen Now!</a></p>
Use model.populate()
Tags: mongodb, mongoose
Published: 2020-05-18 12:19:37

## Introduction
When you're designing your schemas, you may want to reference the data of one document in another  document. This is where model.populate() comes in. 
It is especially useful when you have a one to many relationship between entities.
To see this in action, we'll need two schemas where one schema is kind of a parent to the other. In this post, I'll be using a Post and a Comments schema.

### Let's jump in!

In post.model.js:

```JavaScript
const mongoose = require('mongoose');
const { Schema } = mongoose;

const postSchema = new Schema({
  username: String,
  post: String,
  comments: [{type: mongoose.Types.ObjectId, ref: Comment}]
});

module.exports = mongoose.model('Post', postSchema);
```
When you look at comments in the above model, you'll see its of type ObjectId, that's because we'll e pushing ids of the comment to it.
The ref is a reference to the Comment document.

In comment.model.js:
```JavaScript
const mongoose = require('mongoose');
const { Schema } = mongoose;

const commentSchema = new Schema({
  comment: String,
  By: String
});

module.exports = mongoose.model('Comment', commentSchema);
```
Having done that, lets now see how we add the comment to a post.

Having the comment below:
```JavaScript
const comment = {
  _id: 5d53612dc952f76e446d7d9b,
  comment: 'Well, it may have escaped your notice, but life isn’t fair.'
  By: 'Severus Snape'
}
```

To add it to a post:
```JavaScript
let addCommentToPost = async (id, comment) => {
  let post = await Post.findById(id);
  post.comments.push(comment);
  await post.save();
  return post;
}
```
The returned post collection:
```JavaScript
{
    _id : 5d73622dc452f69e446d2d9b,
    username: "Hermione Granger",
    post: 'I’m hoping to do some good in the world!',
    comments : ['5d715243c252f08e235d1d9c']
}
```

To retrieve a post with all the comments:
```JavaScript
function getPost(id) {
  return post
    .findById(id)
    .populate("comments")
    .exec()
}
```
The returned post:
```JavaScript
{
   _id : 5d73622dc452f69e446d2d9b,
   username: 'Hermione Granger',
   post: 'Im hoping to do some good in the world!',
   comments : [{
     _id: 5d53612dc952f76e446d7d9b,
     comment: 'It may have escaped your notice, but life isn’t fair.'
     By: 'Severus Snape'
     }]
}
``` 
## Conclusion
The model.populate() method is an essential method to use when referencing one document in another. Just use type ObjectId and a ref to the document you want to get data from and you're set!
Understanding Kubernetes: part 26 – Deployment Rolling update
Tags: kubernetes, devops, docker, beginners
Published: 2020-05-18 12:15:35

---
title: Understanding Kubernetes: part 26 – Deployment Rolling update
published: true
description: Serie of sketchnotes about Kubernetes. Explaining in a visual way Kubernetes principles.
tags: Kubernetes, DevOps, Docker, beginners
series: Understanding Kubernetes in sketchnotes
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/5decioi3x1lgtw845c0p.jpg
---

Understanding Kubernetes can be difficult or time-consuming. In order to spread knowledges about Cloud technologies I started to create sketchnotes about Kubernetes. I think it could be a good way, more visual, to explain Kubernetes (and others technologies).

We continue the serie of Sketchnotes about Rolling update  of a deployment and the kubectl rollout command.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/5decioi3x1lgtw845c0p.jpg)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/2tbpe2lrz6vc12k0zmyh.jpg)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/clw9f4o59uy5zlkrwux9.jpg)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/svm4932s0igi2mkvzf5o.jpg)

If you are interested, I published all the sketchnotes on Kubernetes (and new ones!) to make a "book" of 120 pages: ["Understanding Kubernetes in a visual way"](https://gumroad.com/aurelievache#uCxcr).

As usual, if you like theses sketchnotes, you can follow me, and tell me what do you think. I will publish others sketchs shortly :-).
Argument Evaluation Order in C++
Tags: cpp, developer
Published: 2020-05-18 12:03:07

I am here discussing about "Don’t depend on order of evaluation of function arguments". Now I think you may worry, what i am talking about because many of Developers assumed that the order of the evaluation of function arguments is left to right. Wrong! You have no guarantees!

**Reason** Because that order is unspecified.

**Note** C++17 tightens up the rules for the order of evaluation, but the order of evaluation of function arguments is still unspecified.

Now take simple example:
```cpp
//test.cpp

#include <iostream>

void foo(int a, int b) {
    std::cout << "a: " << a << " " << "b: " << b << std::endl;
}

int main() {
    int i = 0;
    foo(i++, i++); // (1, 0) | (0, 1) | (0, 0)

    return 0;
}
```
If you understand what I am saying why this comment then you actually on the way. If not then get move to the explanation.

Here is my proof. The output from gcc and clang differs:

- gcc

`g++ -std=c++2a -O3 -Wall test.cpp -o test && ./test`
```
test.cpp: In function ‘int main()’:
test.cpp:9:15: warning: operation on ‘i’ may be undefined [-Wsequence-point]
    9 |     foo(i++, i++); // (1, 0) | (0, 1) | (0, 0)
      |              ~^~
test.cpp:9:15: warning: operation on ‘i’ may be undefined [-Wsequence-point]
a: 1 b: 0
```
- clang

`clang++ -std=c++2a -O3 -Wall test.cpp -o test && ./test`
```
test.cpp:9:10: warning: multiple unsequenced modifications to 'i' [-Wunsequenced]
    foo(i++, i++); // (1, 0) | (0, 1) | (0, 0)
         ^    ~~
1 warning generated.
a: 0 b: 1
```
The call will most likely be foo(0, 1) or foo(1, 0), but you don’t know which. Technically, the behavior is undefined. In C++17, this code does not have undefined behavior, but it is still not specified which argument is evaluated first.

I compile in C++20 or give best possible error in compilation with optimization with compiler flag.

If you want to learn more about this then follow these link:
https://isocpp.org/blog/2016/08/quick-q-why-doesnt-cpp-have-a-specified-order-for-evaluating-function-argum
https://en.cppreference.com/w/cpp/language/eval_order
https://stackoverflow.com/questions/621542/compilers-and-argument-order-of-evaluation-in-c
Terminal Setup on macOS
Published: 2020-05-18 03:59:27

Originally posted on my [blog](https://pradipta.github.io/terminal-setup-on-mac/)
This is what the default terminal looks like on a Mac:

![Terminal on a Mac](https://github.com/pradipta/pradipta.github.io/raw/master/posts/zsh/images/terminal.png)

And this sucks. It looks bad, it is hard to read, and differentiate. And there are no fancy colors.

To boost it up and level up the terminal game we’re going to use use the following:

    iTerm2
    ZSH
    Oh My ZSH

Steps:

Install Homebrew. For that, run:

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

You may need to install Command Line tool for X-Code before that.

    xcode-select --install

Download and install iTerm2 from here or run:

    brew cask install iterm2

Install ZSH and oh-my-zsh

    brew install zsh
    sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

To run zsh shell, run:

    zsh

We’re also going set up Auto Suggestions and Syntax Highlighting to make the experience friendlier and easier to use. To do that we need to edit the .zshrc file (located at `~/.zshrc`). This is where most of our configuration is going to take place.

Install zsh-autosuggestions and zsh-syntax-highlighting:

    brew install zsh-syntax-highlighting
    brew install zsh-autosuggestions

You can set your ZSH theme by putting in this line into your `.zshrc` file. Make sure you import the `.zshrc` after any change for it to reflect.

    ZSH_THEME=robbyrussell

At this point your terminal/iTerm2 should look something like:

![iTerm2 with ZSH](https://github.com/pradipta/pradipta.github.io/raw/master/posts/zsh/images/zsh.png)

And this is much better. Notice the short git commands that I’ve used? Well, those are configurable too. Follow this [repository](https://github.com/pradipta/Terminal-Setup-for-Mac) for the complete guide and .zshrc file with all the configurations, aliases and functions.

Thanks for reading.

Originally posted on https://pradipta.github.io/posts/zsh/

Find all my blogs at [OmniaCode] (https://pradipta.github.io/)