teleren/devto huggingface dataset:
Multithread queue
Tags: python, queue, threading
Published: 2019-01-08 16:15:49

---
title: Multithread queue
published: true
description: In this example, I detail the implementation of a process queue with its respective parameters.
tags: python, queue, threading
---

This implementation details a queue of functions, it will be executed depending of the number of threads if number of threads is one, it be a queue of executions. 

## Implementation

```python
import queue
import threading

class Process(object):
    def _get_function(self):
        return self.__function

    def _set_function(self, value):
        if not callable(value):
            raise TypeError("function must be callable")
        self.__function = value
    __function = None
    function = property(_get_function, _set_function)

    def _get_params(self):
        return self.__params

    def _set_params(self, value):
        if type(value) is not list:
            raise TypeError("params must be a list of parameters")
        self.__params = value
    __params = None
    params = property(_get_params, _set_params)

    def __repr__(self):
        return str(self.params) + str(self.function)

class MultithreadQueue(object):
    def __init__(self, thread_number=10, callback_insert=None, callback_get=None):
        self._queue = queue.Queue()
        self.threads = []
        self._cb_insert = callback_insert
        self._cb_get = callback_get
        for i in range(thread_number):
            t = threading.Thread(target=self.run)
            t.start()
            self.threads.append(t)

    def append(self, function, params):
        p = Process()
        p.function = function
        p.params = params
        self._queue.put(p)

    def run(self):
        while True:
            element = self._queue.get(block=True)
            element.function(*element.params)
```

## Example
```python
queue = MultithreadQueue()
for i in range(1,10):
    queue.append(print,[1,2])
```
Top 5 DEV Comments from the Past Week
Tags: bestofdev
Published: 2019-01-08 15:57:47

---
title: Top 5 DEV Comments from the Past Week
published: true
description: Highlighting some of the best DEV comments from the past week.
tags: bestofdev
cover_image: https://res.cloudinary.com/practicaldev/image/fetch/s--7VrAA2ln--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://thepracticaldev.s3.amazonaws.com/i/qmb5wkoeywj06pd7p8ku.png
---

This is a weekly roundup of awesome DEV comments that you may have missed.  You are welcome and encouraged to boost posts and comments yourself using the **[#bestofdev](/t/bestofdev)** tag.

In the **[What is your biggest 'red flag' when interviewing?](https://dev.to/david_j_eddy/what-is-your-biggest-red-flag-when-interviewing-4ec8)** discussion thread, @molly_struve points out how arbitrary and rigid "office hours" rules definitely don't work for everyone:
{% devcomment 805k %}

@raviipradhan offered a great write-up in answer to **[What's your coding origin story?](https://dev.to/kelly/whats-your-coding-origin-story-544m)**.  It's always great to see different people's paths to programming:
{% devcomment 8034 %}

@abraham chimed in to talk about a recent editor switch.  **[If you've recently switched code editors— How's it going so far?](https://dev.to/ben/if-youve-recently-switched-code-editors-hows-it-going-so-far-39i)**  Be sure to check out the whole thread, where different commenters discuss their choices and how it relates to their computer specs, use cases, etc:
{% devcomment 7pg5 %}

**[Decoding the Front-end Interview Process](https://dev.to/emmawedekind/decoding-the-front-end-interview-process-14dl)** offered a great look at cultural interviews, coding interviews, take home challenges, and more.  @httpjunkie jumped in with some experience from a few recent interviews at bigger companies:
{% devcomment 7pc2 %}

Asked to **[Describe Your Tetris Effect](https://dev.to/ben/describe-your-tetris-effect-4890)**, [@\_morgan_adams_](/_morgan_adams_) brought up a phenomenon that I'm sure we're all familiar with in some form or another.  The subconscious brain debugger is one powerful machine:
{% devcomment 8160 %}

See you next week for more great comments ✌
Multi-language build tool?
Tags: discuss, programming, productivity
Published: 2019-01-08 15:40:10

---
title: Multi-language build tool? 
published: true
description: looking for language agnostic - build tool
tags: discuss, programming, productivity
---

The beauty of a multi-language build tool is that it abstracts away the language specific build logic. So if a service uses golang and Java for the backend, and javascript for the front-end, developers working on the project, won't need to learn all the different ways to build it. 
It's a standardization which makes development faster.

I have been looking for open-source multi language build tools.
I have tried [Bazel](https://bazel.build/) and [Pants](https://www.pantsbuild.org/index.html), and looked briefly into [Buck](https://buckbuild.com/). 

They all work fine for a mono-repo, but they are cumbersome to use when the code spans different git repos.

Do you use a language agnostic build tool?
Which one do you use? How do you organize the code in this case?

-Nicola
Python dictionary views
Tags: python, tipstricks, dictionary, views
Published: 2019-01-07 21:27:16

---
title: Python dictionary views
published: true
description: Digging into one of the coolest features of the Mighty Dictionary
tags: ["python", "tips&tricks", "dictionary", "views"]
canonical_url: https://www.christianbarra.com/posts/dictionary-views-in-python/
---

{% twitter 1024266442374557696 %}


Dictionary is one of the Python's greatest features and using the `keys()`, `items()` and `values()` methods is really common.

```python
first_dictionary = {"a": 1, "b": 2}
for key, value in first_dictionary.items():
    print(f"Key {key} with value {value}")

# Key a with value 1
# Key b with value 2
```

But do you know which kind of object is returned?

They all return a special object, called [view](https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects).

Why are __views__ useful?

* they provide a dynamic view on the underline object (you change the dictionary and the view will change as well)
* the object returned by `keys()` and `items()` behaves like a set-like object (with `items()` when the pairs are [hashable](https://docs.python.org/3/glossary.html#term-hashable))

And being a set-like object means you can use the [set operations](https://docs.python.org/3.6/library/stdtypes.html#set-types-set-frozenset).

Let's consider an example, where we want to find the common keys between 2 dictionaries.

```python
first_dictionary = {"a": 1, "b": 2}
second_dictionary = {"b": 2, "c": 3}

first_dictionary.keys() & second_dictionary.keys()
# {'b'}
```

`&` is the [intersection operator](https://docs.python.org/3.6/library/stdtypes.html#frozenset.intersection) and returns the common elements between our dictionaries' keys in this case.

What about the elements that are not in common?

```python
first_dictionary = {"a": 1, "b": 2}
second_dictionary = {"b": 2, "c": 3}

first_dictionary.keys() ^ second_dictionary.keys()
# {'a', 'c'}
```

This is called [simmetric difference](https://docs.python.org/3.6/library/stdtypes.html#frozenset.symmetric_difference).

__One thing that you cannot do is change the dictionary while iterating over the view object.__

```python
for key, value in first_dictionary.items():
    del first_dictionary[key]

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: dictionary changed size during iteration
```
React devs to fight plastic waste around the world
Tags: react, opensource, styledcomponents, javascript
Published: 2019-01-08 15:39:37

---
title: React devs to fight plastic waste around the world
published: true
description: 
tags: #react #opensource #styledcomponents #javascript
---
Precious Plastic is a project (technically a Foundation) tackling the plastic problem for over 5 years providing opensource technology (machines) and tools to transform plastic waste into useful things. We're in the process of building a stronger platform for our community (60K) to connect and collaborate. We have a team of 4-5 devs but need more man(or girl)power to manage to pull it off. It's ambitious but the problem ahead of us is huge. UX and UI is getting there and needs to get on coding :) More info at https://next.preciousplastic.com/ or on our contributing guidelines https://github.com/OneArmyWorld/onearmy/blob/master/CONTRIBUTING.md
#discussion Do not we have enough Introductions?
Tags: discuss, rant
Published: 2019-01-08 14:57:14

---
title: #discussion Do not we have enough Introductions?
published: true
description: 
tags: #discussion #rant
---


Hello everyone. 

Not sure if this topic has been discussed before or not But I feel most of the online tutorials/blogs/posts fall into Introductions to XYZ. Just browse tech blogs anywhere, it's all similar. I feel we always invent the wheel. and I understand blogs are sort of personal branding but come on. Isn't the Internet has enough Introductions and probably it's time to collaborate and improve tech tutorials?

I just wanted to hear different opinions. maybe I'm wrong.
Do you unit test private methods?
Tags: discuss, programming, testing, python
Published: 2019-01-08 14:43:16

---
title: Do you unit test private methods?
published: true
description: Discuss - do you unit test private methods?
tags: discuss, programming, testing, python
---

Encountered an interesting issue at work recently when it came to unit testing a new repo that was setup. The repo in question was relatively small and functioned as a basic cronjob, however in order to follow some best practices I decided to opt in for including some basic unit tests.

In doing so I mistakenly wrote a unit test for a private Python class signified with the standard underscore prefix! As I haven't coded in Python in a while I had forgotten about this syntax, but I was a little stunned to hear from a colleague that best practice seems to be to purposefully not test private methods.

I'm curious to hear the thoughts from the Dev community on this one? I get by their very nature you should probably opt to test the Class that the method belongs to end to end rather than opt for a unit test, but what about when you're looking for simple test functionality in a timely manner?

<img src="https://ekiy5aot90-flywheel.netdna-ssl.com/wp-content/uploads/2014/10/segue-blog-benefits-unit-testing.png"/>

Curious to hear from the community on this one! (across different languages/frameworks too - not just Python)
What are your first ever projects that you worked on and what language were they in?
Tags: discuss, programming, career
Published: 2019-01-08 14:04:45

---
title: What are your first ever projects that you worked on and what language were they in?
published: true
tags: discuss, programming, career
---

If you're an experienced developer, it will be an interesting trip down the memory lane and you can give a pat your back as well because of how far you've come! ✨
If you're a beginner, let this be a motivation, that even the most amazing and experienced developers you know today, did someday start from scratch! So all you need to do is keep working towards your goal. 🙂

Also, are you still actively working in the language you started in or do you use it in your side projects?
Applied Machine Learning Conference in Charlottesville, VA -- RFP closes soon!
Tags: machinelearning, nlp, conference, rfp
Published: 2019-01-08 14:03:48

---
title: Applied Machine Learning Conference in Charlottesville, VA -- RFP closes soon!
published: true
description: Apply for the Tom Tom Applied Machine Learning by January 15!
tags: machine learning, nlp, conference, rfp
---

Hello, DEV!

I'm writing to inform the community of an applied machine learning conference that I help organize in Charlottesville, Virginia -- the Tom Tom Applied Machine Learning Conference is entering its third year and is scheduled for April 11, 2019 at the Violet Crown theater in beautiful downtown Charlottesville.

We've grown each year and are excited for our best installment yet - we're seeking high quality RFPs prior to the submission deadline of January 15. Last year, our speakers included Matt Honnibal and Ines Montani of Explosion AI, Dave Luebke of NVIDIA, and Phil Tinn from the MIT Media Lab. 

Check out the general website [here][1] and the RFP portal [here][2]! If you're interested, I hope you consider applying!


  [1]: https://tomtomfest.com/machine-learning/
  [2]: https://tomtomfoundersfestival.typeform.com/to/niyUjw
Namespaces Quickly Explained
Tags: webdev, beginners, programming
Published: 2019-01-08 13:36:00

---
title: Namespaces Quickly Explained
published: true
description: Sometimes you need a quick reminder of what the basic things are. This is your refresher for namespaces.
tags: #webdev, #beginners, #programming
cover_image: https://cdn-images-1.medium.com/max/800/1*_EAr4BZkLwKCzcvQs5ZGuw.jpeg
---

Has anyone ever asked you what a namespace is? I had someone message me about namespaces a little while ago and now seems like a good time to do a quick review. You don't have to have a vague understanding of what that keyword means anymore.

To put it simply, a namespace is just a way to keep names separate from each other. That's why you can use multiple libraries that have the same class names and method names and they don't conflict with each other. All you have to do is specify the namespace you want to use and then you can access the class or method that you need. 

Namespaces are a way to give your code context which will help keep the meaning of your code clearer when you come back to it later. A method called Draw() in a Triangle namespace will be completely different from a method called Draw() in an Octagon namespace and that's what you would expect.

One thing to keep in mind is that all of your namespaces should have unique names. No two namespaces should be the same. Since this is a requirement, sometimes those namespace names can get too long to use in your code. That's ok because you can make aliases for your namespaces if you need to.

You can also have completely anonymous namespaces which means you don't give them a name at all. Most of the time you'll only do this when you want to make variable declarations that are invisible to code in other files. That's not something you'll see or use every day, but it's nice to be aware that it's an option.

You can have nested namespaces too. These are a little interesting because the nested namespace has access to all of the parent namespace methods, but the parent namespace has to specifically use the nested namespace to get access to its methods.

As you can see, namespaces aren't that complicated. It's literally a name that holds other names. Hopefully that gives you a little more confidence when you're reading code because not knowing these little things made me feel like a phony at first. Is there anything you can add on about namespaces?

<hr>

Hey! You should follow me on Twitter because reasons: https://twitter.com/FlippedCoding
A monochromatic palette with HSL and React
Tags: react, colors, hsl
Published: 2019-08-02 11:07:52

---
title: A monochromatic palette with HSL and React
published: true
tags: react, colors, hsl
canonical_url: http://metamn.io/react/a-monochromatic-palette-with-hsl-and-react/
---

Pick two colors … and voila!

<!--more-->

[![A monochromatic palette](http://metamn.io/react/static/2383090986f7876cec8f6a857bc3f792/fb8a0/monochromatic-palette.png)](/react/static/2383090986f7876cec8f6a857bc3f792/ffad7/monochromatic-palette.png)

## Pick a background color

1. Perhaps it should be warm, which is the right half of the HSL scale, like hue starting from 180deg.
2. Perhaps it should be desaturated a bit (100% → 85%), not fully shiny.
3. If you want the text color to be dark add more light (50% → 85%) to the background. This is the default for now.
4. If you want text color to be light reduce light in background color (try 25%) and increase in text color (try 85%).

## Pick a Text color

1. Start form black, which is set the same as the background color but with 0% lightnes.
2. You can increase / decrease lightness up to a level where the text color is still eligible on the background, ie. the color contrast ratio is bigger than 4.5

## Auto generated monochrome palette

1. You’ll get the inverse color scheme.
2. You’ll get all other color schemes as shades of primary colors which are still eligible.

## To do

1. We need real use cases like a blog, a landing page, or a marketing site to better adjust the algorithm.
2. These real use cases must be semantic, themeable. Picking up two colors should be enough to completely style these use cases. For example the hero should be automatically have the inverted color scheme where a call-to-action button is highlighted through the original color scheme. Later, a less important section must have a dominated color scheme. And so on.

## Live example and code

In the [Storybook](https://tinyurl.com/y7mftg53) and on [Github](https://github.com/metamn/mr-ui/tree/master/src/basics/ColorsHSL)
Side Project: MeetMonocle.com
Tags: showdev, webdev, vue, productivity
Published: 2019-01-08 12:31:54

---
title: Side Project: MeetMonocle.com
cover_image: https://res.cloudinary.com/meetmonocle/image/upload/v1546949321/meetmonocle.com/devtoheader.jpg
published: true
description: make it easier on yourself to get client feedback
tags: showdev, webdev, vuejs, productivity
---

Hi devs, 

in order to learn firebase in combination with building something useful, I built [the following small app](https://meetmonocle.com) to let you manage client feedback easier. I'd be delighted if any of you could find the time to try it out and give me your feedback. **I'm especially interested in knowing if this is something you would use or not at all.**

*tech stack*: vuejs + firebase + sass + parcel♥

A friend of mine at a web development agency reached out to me asking if I knew a good tool that would let their clients give feedback on the online stores. I pointed them to the several excellent tools out there that allow you to upload your designs and get feedback on them (like sketch cloud or redpen).

This wasn't what they were looking for because uploading 60+ screenshots for desktop, mobile, ... was just too cumbersome so they asked if it would be possible to build something that used the real web page on a real device as a basis to give feedback on.

I ended up with a small widget that can be added in minutes to any page. Clients can point & click and submit their feedback, while developers can easily see what browser or device a client was using. 

The widget looks like this:

![Monocle Feedback Widget](https://thepracticaldev.s3.amazonaws.com/i/jklk3hlftfg5or7j0s30.png)

Developers or teams receive the feedback instantly: 

![Monocle Inbox](https://res.cloudinary.com/meetmonocle/image/upload/v1546544749/meetmonocle.com/tutorial2.gif)

Check it out at https://meetmonocle.com

The first one to give me some feedback and spot the dev.to reference in the page gets a free pro account! 

Let me know if you're interested in my experience with firebase or if I can help in any other way.
How bad is self-signed cert?
Tags: ssl, https, tls
Published: 2019-01-08 12:27:49

How bad is you when it come to verifying a cert? People use cert from CA because browser already trusted the root cert that being used to sign the cert. So browser can do the verification. Using self-sign cert, you have to do the verification yourself. If it's only you to access the site, it's not that difficult. You have the cert, so you can add it to your browser to be trusted. 

But if Joe, Anna and Foo also need to access the site, you have to "securely" hand over the cert to them. Probably still not much a problem as you can go and meet them in person. But imagine if there's 100 more, or 1000 more people need to access your site and you don't even know them. Now you start seeing a problem with using self-signed cert.
How to Extract Metadata from Presentation Templates using .NET Parsing API
Tags: net, parsing, api, metadata
Published: 2019-01-08 11:54:13

---
title: How to Extract Metadata from Presentation Templates using .NET Parsing API
published: true
description: post
tags: .NET, Parsing, API, Metadata
---

When it comes to manipulating documents within your applications, the development options are endless. Organizations around the globe, regardless of the niche, regularly incorporate multitudes of innovative functionalities into each of their business scenarios for improving productivity. Extracting different types of information from multi-format documents is one such requisite. However, one primary concern is the accuracy or validity of the extracted data, not all software applications provide developers with highly accurate data extraction functionality. 

Therefore, when looking for applications which could provide you with precise extraction of raw and formatted text as well as metadata from many different types of well-known file formats on .NET platform, GroupDocs.Parser for .NET must be considered. Apart from the basic data extraction features this document text extraction API does provide, app developers can use it for extracting text and metadata from various text and presentation templates with the 
help of the latest API version. Another important feature is the ability to programmatically fetch tables from PDF documents within your .NET apps. And while working with this functionality, you can create table bounds manually or let the API identify the layout in automatic mode. 

In addition to this, you have access to the features of detecting media type of your password-protected Office OpenXML documents and batch document processing –
 http://bit.ly/2QuFPsr

Following code samples show how to extract text and metadata from templates:
`// Extracting Text
void ExtractText(string fileName)
{
    // Extract a text from the file
    var text = Extractor.Default.ExtractText(fileName);
    // Print an extracted text
    Console.WriteLine(text);
}
// Extracting Metadata 
void ExtractMetadata(string fileName)
{
    // Extract metadata from the file
    var metadata = Extractor.Default.ExtractMetadata(fileName);
    // Print extracted metadata
    foreach (var m in metadata)
    {
        // Print a metadata key
        Console.Write(m.Key);
        Console.Write(": ");
        // Print a metadata value
        Console.WriteLine(m.Value);
    }
}`

Below code sample shows how to detect media type in password-protected Office OpenXML documents: 

`// Create load options
LoadOptions loadOptions = new LoadOptions();
// Set a password
loadOptions.Password = "password";
// Get a default composite media type detector
var detector = CompositeMediaTypeDetector.Default;
// Create a stream to detect media type by content (not file extension)                
using (var stream = File.OpenRead(Common.GetFilePath(fileName)))
{
    // Detect a media type
    var mediaType = detector.Detect(stream, loadOptions);
    // Print a detected media type
    Console.WriteLine(mediaType);
}`
What is a "Classic" DEV Post?
Tags: meta
Published: 2019-01-08 11:22:54

---
title: What is a "Classic" DEV Post?
published: true
description: What is a "Classic" DEV Post and what makes it different to any other type of DEV Post?
tags: meta
---
![Classic DEV Post](https://i-hate.light-the.me/l8dl56.jpg)

I am curious as to what makes these posts "Classic", as opposed to anything else.

(Also, this is my first post, please don't judge)