teleren/devto huggingface dataset:
Decorator Factory - How to pass arguments to decorators
Tags: python, decorator, oop
Published: 2020-03-20 04:18:15

_Skip to [pass arguments to decorators](#pass-arguments-to-decorators) if you already know what a decorator is_

## What is a decorator?

A decorator allows the user to add functionality to an existing function without modifying its structure. 

For example, 
We might need a way to authenticate an API call, and only then allow some data to be returned. We can streamline the authentication process by abstracting it into a decorator function.

Consider the following function that needs to be authenticated,

```python
def foo(user_id):
   # perform some DB calls
   # perform some DB writes
   pass
```

We can use a decorator as follows,

```python
def authenticate(func):
   def wrapper(*args, **kwargs):
       # perform auth checks
       if auth:
          func(*args, **kwargs)
       else:
          raise Exception('not authenticated')
   
   return wrapper
```

And hence, authenticating `foo` is as simple as,

```python
@authenticate
def foo(user_id):
   # perform some DB calls
   # perform some DB writes
   pass
```
<hr>

## Pass arguments to decorators

Now that we have some knowledge of decorators, let us proceed to something more interesting. How would we pass arguments to decorators?

This is where it gets a little confusing - we will need to create a decorator factory that returns a particular decorator based on the arguments passed.

A simple use case could be when we want to **call a function multiple times**, but we do not want to write it in an explicit for loop, and neither do we want to use a for loop inside the function itself.

For example, we would want to call the function `foo` below, 10 times:

```python
def foo():
   print("Hello World")
```

In this scenario, we can create a decorator factory that takes in a `number` and returns a decorator that calls a function a `number` of times.

```python
def call(number):  # Decorator factory
    def decorator(func):
        def wraps(*args, **kwargs):
            for i in range(number):
                func(*args, **kwargs)

        return wraps

    return decorator
```

And to use the decorator factory above,

```python
@call(10)
def foo():
   print("Hello World")
```

When we call `foo` now,

```
>>> foo()
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
```

Thanks for reading! Please hit me up at sanjay.rohit2@gmail.com for any feedback :)
Mar. 20, 2020: What did you learn this week?
Tags: weeklylearn, discuss, weeklyretro
Published: 2020-03-20 04:02:28

It's that time of the week again. So wonderful devs, what did you learn this week? It could be programming tips, career advice etc.

![A hamster taking notes](https://media.giphy.com/media/tHufwMDTUi20E/giphy.gif)

Feel free to comment with what you learnt and/or reference your TIL post to give it some more exposure.

{%tag todayilearned %}

And remember, if something you learnt was a big win for you, then you know where to drop it as well.👇👇🏻👇🏼👇🏽👇🏾👇🏿

{% link https://dev.to/jess/what-was-your-win-this-week-4dld %}

![A contestant excited after winning on Wheel of Fortune](https://media.giphy.com/media/3ohhwtf6F4tpnQ2HpS/giphy.gif)
Introducing Mathematical Concepts for Confronting a Crisis
Tags: math, blog, ideas
Published: 2020-03-20 03:36:47

Times are **not** [normal](https://www.merriam-webster.com/dictionary/normal). Evidence of the changing world around us can be found in every news source, every social media channel, every shared photo of a stripped grocery store surfacing around the world. The start of this “not normal” is not evenly distributed. You might be someone who has already been through the first storm, and now you are returning back to a cautious new social pattern. You might be adjusting your expectations to a new daily routine, with constant interruptions or disturbances that were previously not there. Or, maybe you haven’t felt the impact personally yet.

Our ability to see, process, and work through crisis are all as unique as our individual brains and experiences. In a previous life, I spent years training to be the person who had to absorb all of the inputs and react tactically with brilliance and care in moments of crisis. I trained for it, I excelled at it. Unfortunately, not all of my previous experience and mental frameworks I developed that allowed me to be highly effective in a crisis apply here. This is … *hard*. 

What do you do when your previous experience has not adequately prepared you for the current situation? Personally, I’ve been slowly sifting through all the tools I do possess to figure out which ones work best right now. 

After unsuccessfully trying a few techniques, I found clarity. When I was in college, I really struggled with some specific areas of study which were highly math-based but always explained through application. It wasn’t until I turned the table and focused on the problem as **a math problem** (rather than, say, an electrical engineering problem) that I was able to hold the methodology in my head. We do this in other ways: drawing parallels between the things we know how to handle and what we are dealing with now.

This is working best for me now: breaking problems down into mathematical concepts to ground decision making and understand the world around us. As I try to extend this to explain what I am thinking to other people, I realize that my math experience covers concepts that are not as widely studied but are critical to parsing much of the research and recommendations during a global, multifaceted pandemic. 

So, as my one creative idea in a time of survival, I’m starting a series explaining these concepts I use from [network science](https://en.wikipedia.org/wiki/Network_science), [nonlinear dynamics](https://www.youtube.com/watch?v=MizhVorgywY), and [chaos](http://www.stevenstrogatz.com/books/nonlinear-dynamics-and-chaos-with-applications-to-physics-biology-chemistry-and-engineering). I hope these help encourage you to explore more the frameworks that ground you, and give you a better understanding of the amazing work around the world that is fueling the changes we are feeling.
Spinner 33
Tags: graphics, xml
Published: 2020-05-14 06:44:05

---
title: Spinner 33
published: true
date: 2020-03-13 13:24:00 UTC
tags: Graphics,XML
canonical_url: https://drmsite.blogspot.com/2020/03/spinner-33.html
---

```html
<svg xmlns="http://www.w3.org/2000/svg" 
     xmlns:xlink="http://www.w3.org/1999/xlink" 
     viewBox="0 0 265 265">
  <g transform="rotate(28.3063 132.5 132.5)">
    <circle cx="132.5" 
            cy="172.5" 
            r="22.5">
    </circle>
    <path fill="none" 
          stroke="#000" 
          stroke-width="5" 
          d="M98.318 7.105l4.403 168.758c1.81 15.065 14.583 26.407 29.756 26.422 15.173.014 27.968-11.302 29.808-26.363l4.4-168.695">
    </path>
    <path fill="none" 
          stroke="#000" 
          stroke-width="5" 
          d="M87.024 10.793l5.77 166.191c2.413 20.088 19.444 35.212 39.675 35.232 20.232.02 37.294-15.069 39.746-35.152l5.766-166.18">
    </path>
    <path fill="none" 
          stroke="#000" 
          stroke-width="5" 
          d="M75.828 15.615l7.04 162.492c3.013 25.11 24.303 44.016 49.594 44.041 25.29.025 46.617-18.839 49.68-43.943l7.037-162.52">
    </path>
    <path fill="none" 
          stroke="#000" 
          stroke-width="5" 
          d="M64.765 21.672l8.174 157.557c3.613 30.136 29.163 52.828 59.515 52.858 30.352.03 55.946-22.612 59.618-52.741l8.172-157.61">
    </path>
    <path fill="none" 
          stroke="#000" 
          stroke-width="5" 
          d="M53.877 29.105l9.137 151.245c4.218 35.155 34.024 61.625 69.432 61.66 35.408.035 65.266-26.376 69.554-61.524l9.135-151.302">
    </path>
    <path fill="none" 
          stroke="#000" 
          stroke-width="5" 
          d="M43.21 38.12l9.878 143.35c4.824 40.176 38.887 70.423 79.35 70.463 40.464.04 74.586-30.14 79.49-70.306l9.874-143.383">
    </path>
    <path fill="none" 
          stroke="#000" 
          stroke-width="5" 
          d="M32.829 49.07L43.16 182.592c5.423 45.201 43.745 79.235 89.27 79.28 45.526.044 83.916-33.914 89.427-79.104l11.356-132.352">
    </path>
    <circle cx="132.5" 
            cy="132.5" 
            r="130" 
            fill="none" 
            stroke="#000" 
            stroke-width="5">
    </circle>
    <animateTransform attributeName="transform" 
                      begin="0s" 
                      dur="3.33s" 
                      type="rotate" 
                      from="0 132.5 132.5" 
                      to="360 132.5 132.5" 
                      repeatCount="indefinite">
    </animateTransform>
  </g>
</svg>
```

{% jsfiddle https://jsfiddle.net/annoyingmouse/hnypftLr/ result %}

I saw this the day before yesterday so finished the above last night:

{% twitter 1237155463139074048 %}

It's not quite right, but it's getting there - I'll revisit, once I've got some more time. It's also supposed to be rotating but I've tried and failed, to figure out how to add animated SVGs here.
Using Web Components in React - Video Tutorial
Tags: react, webcomponents
Published: 2020-03-20 03:19:13

---
title: Using Web Components in React - Video Tutorial
published: true
description: Learn how to integrate and use Web Components in React by using props and events.
tags: react, web-components
canonical_url: https://coryrylan.com/blog/using-web-components-in-react-video-tutorial
---

This is a sample video from my Video Course [Web Component Essentials](https://webcomponent.dev). In this video you will learn how to integrate and use Web Components in an React application. To get the written blog tutorial check out this post,["Using Web Components in React"](https://coryrylan.com/blog/using-web-components-in-react). Also check out the [Stackblitz Demo](https://stackblitz.com/edit/react-bwbueq)
One feature GitHub should have to implement🤔💭
Tags: github, opensource, webdev, discuss
Published: 2020-03-20 03:11:10

<p>👋Hello to all Please Read below article and let me know what is your 💭
I mailed this following feature request to GitHub team 3to4 times they doesn't properly reply to me except thank you .they doesn't explain me anything once they replied but after that everything is robot created reply that is sad thing:(🔽
</p>
**What is My feature request to GitHub**
explanation:-<p>Hello GitHub team i have one insight feature request to our GitHub team
details how and where the feature is applied
I created one GitHub repository after that i commit my code to repository then after sometime i go to my GitHub repository insights and in that i go in traffic i can view only how many clones i have to my repository can github add one feature there who cloned that repository it is going to be a good feature hope GitHub team can work on my feature request
thank you for opensource</p>
**If anyone doesn't understanding where this section is 👀🔽**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/wmybc9vobbnogips426b.png)
**My own solution/basic idea how they can implement this thing**
<p>hello GitHub research and development team i have one idea also for how to show who cloned repository if we go to any Repository in GitHub we have to sign in for that means only GitHub user can access/clone/fork/star that particular repository if GitHub team implementing this
feature then they can only add one drop down button over their and they can show which user cloned repository from that users database of GitHub simply do view operation in database query if GitHub thinking for privacy concerns but in opensource platform their is no privacy issue for regular GitHub users means for developers or students GitHub have to implement this feature and because of privacy issue for organizations GitHub do not apply this feature.i hope GitHub can work on this please let me know what GitHub team thinks on this insight feature .</p>
**if any member from GitHub see this please inform to the GitHub and open GitHub repo for only app/web app/desktop GitHub related issues there guys can create issues/feature request and GitHub team/contributors can work on those things.**🐱‍💻
<br>
Thank you
krishna kakade 
**Please Let me know what you guys think on this feature request in comment section🙏**
**And if you think this things GitHub should have then share more &support this article then GitHub can see this. god bless stay safe/clean**
[MyTwitter](https://twitter.com/krishnadevz)
[MyGithub](https://github.com/krishnadevz)
Careful when using Python Generators!
Tags: python, generators, trick
Published: 2020-03-20 02:59:14

# Yes, they are memory efficient!
* Python generators may prove themselves extremely useful in cases when you have large amounts of data and are trying to feed it to an iterator. In short, generators return a lazy iterator that does not store their contents in memory. WOW! Great, sounds like you save yourself the trouble of running into a `MemoryError`, right?

# But, they hide something...
```python 
nums = (x for x in range(10000000000000))
for num in nums:
   print(num, end=" ")
>>> 1,2,3,4....
for num in nums:
   print(num*2, end=" ")
# What do you think is the output of the above for loop?
```
# Generators are hungry hungry!
* When iterating over a generator, the elements at each location are essentially being "consumed" and "discarded".
* In other words, if you try to iterate AGAIN over the generator, it will look like all of your elements vanished!

# Answer to the code above:
* **You will see no numbers printed to the console.**

## Leave your comments below!
Practice English Easily
Tags: android, education, english, study
Published: 2020-03-20 02:35:22

Hello guys, as most of us are stuck at home nowadays, I would like to share my latest personal project:
https://play.google.com/store/apps/details?id=net.speak24

It is a free and ad-free app to find people to practice English or just talk, you can find people from all around the world. Thank you!
Is it okay if my app is not microservices-based?
Tags: microservices, monolith, spring, java
Published: 2020-03-20 02:15:41

I have a bad habit of throwing myself into analysis paralysis over issues that I shouldn't be thinking so hard about.

I also tend to hop on bandwagons and then get lost in the technobabble.

To be clear, this post is not so much seeking to give advice, but to ask:

Is it okay if my app is not microservices-based? At least, at the start?

Do you recommend any articles I can read about the topic and when to split the app into microservices?

I am developing an application that is highly ambitious -- it aims to teach languages, but also to be a social platform for those learning the languages. In its future, it aims to be a dating platform and also offer e-commerce services.

For now, we just want to get off the ground.

I decided to go with Spring Boot and with that I also decided that to go with microservices from the ground up.

Now, in development, I have to run 6 apps just to test a few routes and it's quickly becoming unmaintainable and I'm certain there are people on the verge of imploding with Cringe(TM) as they read that.

I'm coming to the understanding that for an app to be properly split into microservices, each microservice actually needs to be able to run on its own and stand alone. If for example one goes down, that would not affect the entire application as a whole.

In my case, if one goes down, the entire thing goes belly up. So really, what I'm doing is running a complex monolith...with separate code-bases. Would you agree?

I'm generally just looking for some guidance here. I'm seriously considering going with a single Spring Boot (monolith) project to seriously simplify the project, my life, my productivity, and my stress levels.

**Is that okay?**
Day 98 : Spent a Lot of Time
Tags: hiphop, code, coding, lifelongdev
Published: 2020-03-20 01:58:25

_liner notes_:
- Professional : Got quite a bit done today. Reviewed some changes that the education team did to my blog post. Had our team meeting. Worked on revising a tutorial on the site to include the new capability that I did a demo on.

- Personal : So yeah, I published and added my first official Web Component to my personal site https://lifelong.dev . It is the Currently @ section below the contact info. It pulls my location which I can set from my https://dwane.in site. So that way, I can update my location when I go to different places (once this pandemic is over. Hopefully soon!) So I updated my site to include the Web Component and once I did, I went to push it to my GitLab instance. Got an error that my SSL Certificate had expired. That then led me to having to update my GitLab, which was not as easy as I would like. haha After much research and trying random commands, I finally got it all working! Spent a lot of time. Felt good. Like an actual DevOps person. haha

![Arial view of The Dead Sea, Israel](https://dev-to-uploads.s3.amazonaws.com/i/71nmeoc739vjc6zjkvhu.png)

I see going through tracks for the radio show in my future for tonight. haha Maybe some coding...

Have a great night!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube AD2r-e8Fa7E %}
I keep getting "hello" in the console, and not the "ID" I would expect. 
Tags: react, reactnative
Published: 2020-03-20 01:24:27

I'm currently trying to follow the great Traversy media page and I'm writing some code in react. I keep getting "Hello" in the console instead of the array "ID," and I cant figure out why. I have 3 files I'm working from, TodoItems.js, Todos.js, and App.js, and of course index.js which houses the root div to display everything. Any help would be appreciated! Here is my code:

TodoItem.js:
import React, { Component } from 'react'
import propTypes from 'prop-types';



export class TodoItem extends Component {
 getStyle = () => {
     return {
         background: 'gray',
         padding: '10px',
         borderBottom: '1px #ccc dotted',
         textDecoration: this.props.todo.completed ? 
         'line-through' : 'none'
     }
 }
    
    render() {

        const { id, title } = this.props.todo;
        return (
            <div style ={this.getStyle()}>
                <p>
                    <input type="checkbox" onChange={this.props.markComplete.bind(this, id)} /> {' '}
                    { title }</p>
            </div>
        )
    }
}


TodoItem.propTypes = {
    todo: propTypes.object.isRequired
}


export default TodoItem


Todos.js:
import React, { Component } from 'react';
import TodoItem from './TodoItem';
import propTypes from 'prop-types';

class Todos extends Component {
  
  render() {
    return this.props.todos.map((todo) => (
      <TodoItem key={todo.id} todo={todo} markComplete={this.props.markComplete} />
    ));
  }
}

Todos.propTypes = {
  todos: propTypes.array.isRequired
}

export default Todos;

App.js: 
import React, { Component } from 'react';
import Todos from './components/Todos';

import './App.css'

class App extends Component {
  state = {
    todos: [
      {
        id: 1,
        title: 'Take out trash',
        completed: false
      },
      {
        id: 2,
        title: 'Dinner with gf',
        completed: false
      },
      {
        id: 3,
        title: 'Meeting with Boss',
        completed: false
      }
    ]
  }
 markComplete = (id) => {
  console.log(id)
 }
 


  render() {
    
    return (
      <div className="App">
        <Todos todos={this.state.todos} markComplete={this.markComplete}/>
      </div>
    )
  }
}

export default App;
Pixel art in CSS
Tags: css, showdev
Published: 2020-03-20 01:08:38

I been learning lately about CSS illustrations and making art in general with CSS. Which i find so cool!

Experimented with pixel art which you can see here: https://codepen.io/cwalle/pen/JjjJddy

Have you dabbled in CSS illustration any good tips for learning?

Thinking of making a tutorial of above codepen, would that be interesting?
How to Use Custom Angular Form Controls in Jest and Storybook
Tags: angular, softwareengineering, ux, programming
Published: 2020-03-23 21:53:43

---
title: How to Use Custom Angular Form Controls in Jest and Storybook
published: true
date: 2020-03-20 00:44:30 UTC
tags: angular,software-engineering,ux,programming
canonical_url: 
---

[![](https://cdn-images-1.medium.com/max/2600/0*5q8PloYuDfH2_diK)](https://medium.com/better-programming/how-to-use-custom-angular-form-controls-in-jest-and-storybook-6479e52b7636?source=rss-3a534b5053e6------2)

Develop highly functional and beautiful custom form controls in Angular

[Continue reading on Better Programming »](https://medium.com/better-programming/how-to-use-custom-angular-form-controls-in-jest-and-storybook-6479e52b7636?source=rss-3a534b5053e6------2)
More App Ideas to Practice Programming with JavaScript
Tags: career, javascript, codenewbie
Published: 2020-03-20 00:33:45

**Subscribe to my email list now at http://jauyeung.net/subscribe/**

**Follow me on Twitter at https://twitter.com/AuMayeung**

**Many more articles at https://medium.com/@hohanga**

**Even more articles at http://thewebdev.info/**

When we're learning how to develop web apps, we need to practice as much as possible. Tutorials are limited in their scope since they can only put so much in a book or blog entry.

Also, we need to be able to solve problems ourselves. Therefore, we need to come up with some project ideas for writing practice apps that'll enhance our knowledge.

Below are some examples of apps that you can build to improve your web development skills.

# Countdown Timer
By writing a countdown timer, we can practice using timers by using the `setInterval` function.

We can also use practice using built-in JavaScript date methods to calculate dates and display them on the screen.

For instance, we can add features like setting the time to count down from, and then display warnings when the time is getting close to 0. Also, we have start buttons to start the count down and a pause button to pause count down if we wish.

If we want more practice, we can save the paused time so we can continue later, so we use things like cookies or local storage.

We can also add more features like multiple countdown timers and things anything else we can think of.

# Playing with Images
We can create an app to let us pan and flip images so that we can practice using the JavaScript canvas and images.

Also, we can add other features for fiddling with images like flipping them, rotating them, add filters and much more.

When a user tries to add an image, we can check if it's actually an image before putting it on the canvas.

# Notes App
A notes app is great practice for writing applications since it lets us practice saving and opening files.

We can also save data to a database and retrieve them from there.

If we want to get fancy, we can also add account management to let people save private notes.

Also, we have to let people edit and delete notes.

When the user closes the browser, it should save the data, and when the user opens the browser, it should show the last edited note.

# Conclusion

These practice app ideas provide plenty of practice for create applications. They involve retrieving, saving, editing and deleting data. Also, we get to manipulate images on the HTML canvas.

Finally, we get to practice using timers and date functions by practicing creating our own countdown timer.