teleren/devto huggingface dataset:
Get your nose in your python (starting with `nose2`)
Tags: unittest, nose2, test, python
Published: 2018-05-07 12:16:02

---
title: Get your nose in your python (starting with `nose2`)
published: true
description: Get started with `nose2` more [here][https://nose2.readthedocs.io/en/latest/usage.html]
tags: unittest, nose2, test, python
---

[1]: http://pypi.python.org/pypi/six/1.1.0
[2]: https://docs.python.org/2/library/unittest.html
[3]: https://docs.python.org/3/library/unittest.html
[4]: https://nose2.readthedocs.io/en/latest/usage.html

I need to build some tests with python. This can usually be done coding a
module with many asserts or doing everything manually aka typing some

```sh

python -i totest.py

```

then playing around with the code to see if there are case where the code is
broken.  But you would agree that it's better to design well the tests for your
code in order to automate this process for example.  This process has already
been discussed since very long time ago and there is very few things left
behind this. Moreover, this process has also been extended to things so called
continuous integration,  code coverage or you may have heard of builds that
pass. That's right, you can always put tests in the build process.  Pythonistas
could rather use `nose2`.


# Installation

You could use any environment (virtual, user, global) to install `nose2`

```

pip[3] install [--user] --upgrade nose2

```

> For Python 2.7 and pypy, nose2 requires [six][1] version 1.1.


# How this works ?

> To find tests, `nose2` looks for modules whose names start with `test`. In
> those modules, `nose2` will load tests from all `unittest.TestCase`
> subclasses, as well as functions whose names start with `test`.

Basically you need to write the python tests and execute `nose2` to take care
of your testing jobs.  And

> `nose2` will look in each directory under the starting directory, unless the
> configuration modifies the included paths. Within directories and within any
> Python packages found in the starting directory and any source directories in
> the starting directory, `nose2` will discover test modules and load tests from
> them.

just

```

nose2

```

great right ?


# Naming Tests

`nose2` looks in
- directories that contains `__init__.py`
- direcotries that the lowercased name contains `test`
- directories the name is either `src` or `lib`

and (without configuration)
- `nose2` will run all python files (`.py` extension) that the name starts with
  `test`
- within test modules, `nose2` loads `unittest.TestCase` subclasses


# What's next ?

- go to python `unittest` documentation ([here python3][3], [here python 2][2])
- go to `nose2` ([rtd here][4])
- you will figure it out


Greetings,
Ruby string literals VS Value objects. Overengineering?
Tags: ddd, patterns, ruby, rails
Published: 2018-05-21 20:28:43

---
title: Ruby string literals VS Value objects. Overengineering?
published: true
tags: ddd, patterns, ruby, rails
canonical_url: http://jetrockets.pro/blog/ruby-string-literals-vs-value-objects-overengineering
---

A guide on how to get rid of string literals in Ruby with Rails 5 Attributes API.

[http://jetrockets.pro/blog/ruby-string-literals-vs-value-objects-overengineering](http://jetrockets.pro/blog/ruby-string-literals-vs-value-objects-overengineering)
JavaScript: Reduce the number of conditional operators used in the expression
Tags: javascript, codequality, conditionaloperators
Published: 2018-05-23 16:15:27

---
title: JavaScript: Reduce the number of conditional operators used in the expression
published: true
description: 
tags: JavaScript, CodeQuality, ConditionalOperators
---

We would have all come across a situation where the number of conditional operators to be used in an expression is more like in the below example.
	
~~~~
const firstCondition = true,
      secondCondition = true,
      thirdCondition = true,
      fourthCondition = false,
      fifthCondition = true;

if(firstCondition && secondCondition && thirdCondition && fourthCondition && fifthCondition) {
    console.log("All the conditions met expectation");  
}
else {
    console.log("All the conditions did not meet expectation");
}

if(firstCondition || secondCondition || thirdCondition || fourthCondition || fifthCondition) {
    console.log("Atleast one of the conditions met expectation");  
}
else {
    console.log("None of the conditions met the expectation");
}

//Output:
//All the conditions did not meet the expectation
//At least one of the conditions met expectation
~~~~~~~~

Code quality tools like ESLint, SonarQube, etc will actually suggest us to optimize this code to have fewer conditional operators. So how do we do that? 

There are many ways to solve this. I am going to give a simpler way (Updated). If you have an easier or better solution please feel free to leave it in the comment section.

~~~~
const firstCondition = true,
      secondCondition = true,
      thirdCondition = true,
      fourthCondition = false,
      fifthCondition = true;

const conditionsToCheck = [firstCondition, secondCondition, thirdCondition, fourthCondition, fifthCondition]

if(conditionsToCheck.every(condition => condition)) {
    console.log("All the conditions met expectation");
}
else {
    console.log("All the conditions did not meet expectation");
}

if(conditionsToCheck.some(condition => condition)) {
    console.log("Atleast one of the conditions met expectation");
}
else {
    console.log("None of the conditions met the expectation");
}

//Output:
//All the conditions did not meet the expectation
//At least one of the conditions met expectation
~~~~~~~~

We can also mix in conditions like below and it would work without any problem.

~~~~
const conditionsToCheck = [firstCondition, secondCondition || sixthCondition, thirdCondition, fourthCondition, fifthCondition && seventhCondition];
~~~~~~~~

Unless you are supporting IE8 and below you should fine using Array some and every methods.

I hope this article is helpful.
How To Analyze An Error
Tags: process
Published: 2020-05-07 08:12:02

---
title: How To Analyze An Error
published: true
description: The dimensions of an error as an aid to analyzing it
tags: #process
---

## Dimension Checklist

* Where - In which system, module, function and possibly line of code is the error occurring?
* What - What is the actual error?
* Who - Which actor/user is the error occurring for?
* Why - Why is the error occurring?
* When - When did the error occur?
* Transient - Is the error still occurring?
* Context - What is the surrounding context? Was something happening at the same time elsewhere that could be the cause? (deployment etc.)
* Impact - What is the immediate but also long-term impact of the error?

Do you have other aspects of an error that you feel should be added to the list? Please comment. :)
Thoughts on my JS-Rails project
Tags: codenewbie, ajax, javascript, startrektng
Published: 2018-10-03 23:20:47

---
title: Thoughts on my JS-Rails project
published: true
tags: code-newbie,ajax,javascript,star-trek-tng
canonical_url: 
---

Completing this was kind of a big deal for me. I had been away from the curriculum for a few months. I found the courage to face this project (and the lab/lesson immediately preceding it) by starting from scratch. After completing the JS and jQuery sections in Codecademy, and faithfully following along with Gordon Zhu’s [Watch & Code](https://watchandcode.com/) (which, literally changed my life!) I finally started to feel comfortable enough to start _thinking_ in JS.

For some reason, I decided it would be a good learning experience for me to complete all the requirements for this project without jQuery, and use only vanilla JS. My AJAX functions are a little verbose, as a result, but at this stage, it helps me conceptualize what’s happening at a more granular level to have to manage things like attaching CFRS tokens to a ‘post’ request.

And, since December of 2017 (when I completed the Rails version of this project), my Twitter OmniAuth strategy broke. Their implementation became more complex since I was away, so for now I’m making due with Facebook (I resented a little bit having to sign in and get dragged down that rabbit-hole), but, it was important to get it working again for morale purposes.

Checkout the:

- [Github repo](https://github.com/ddhogan/starfleeter)
- Live version! [starfleeter.herokuapp.com](https://starfleeter.herokuapp.com/)
- [Video tour](https://www.youtube.com/watch?v=6ZASleJcmqE)

_Originally published at_ [_donnacodes.com_](http://donnacodes.com/thoughts_on_my_js-rails_project) _on August 5, 2018._
Install Z-shell (Oh My Zsh) on Ubuntu 18.04 LTS
Tags: ubuntu, zsh, ohmyzsh, zshell
Published: 2018-10-04 14:32:38

---
title: Install Z-shell (Oh My Zsh) on Ubuntu 18.04 LTS
published: true
description: Here are the Steps to Install Oh My Zsh (Z-Shell) on Ubuntu 18.04.
tags: ubuntu,zsh,ohmyzsh,zshell
---

![Z-shell for Ubuntu](https://thepracticaldev.s3.amazonaws.com/i/qmdocrps1ngl6v1ox29n.png)

- Update the packages

```sh
sudo apt-get update
sudo apt upgrade
```

- Install prerequisite packages (ZSH, powerline & powerline fonts)

```sh
sudo apt install zsh
sudo apt-get install powerline fonts-powerline
```

- Clone the Oh My Zsh Respo

```sh
git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
```

-  Create a New ZSH configuration file

```sh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
```

- Set up a Fancy theme for your Terminal  - Open `.zshrc` File using nano editor

```sh
nano .zshrc
```

- Find the line `ZSH_THEME="robbyrussell"` replace `robbyrussell` with `agnoster` theme in `.zshrc` File (CTRL + X & Enter to Save)

```sh
ZSH_THEME="agnoster"
```

- Change your Default Shell 

```sh
chsh -s /bin/zsh
```

- Update & Uninstallation oh-my-zsh Visit - https://github.com/robbyrussell/oh-my-zsh#manual-updates

```sh
cd .oh-my-zsh
upgrade_oh_my_zsh
```

### Want Syntax Highlighting? install ZSH Syntax Highlighting for Oh My Zsh

- Clone the ZSH Syntax Highlighting

```sh
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$HOME/.zsh-syntax-highlighting" --depth 1
```

- Add syntax-highlighting in `.zshrc` Configuration

```sh
echo "source $HOME/.zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> "$HOME/.zshrc"
```

#### Revert Back to Default Shell

```sh
chsh -s /bin/bash
```
PHP Frameworks Discussion (beware lots of opinions)
Tags: discuss, php
Published: 2018-10-04 16:16:23

---
title: PHP Frameworks Discussion (beware lots of opinions)
published: true
description: Discussion of PHP frameworks.
tags: discuss, php
---

I prefer either Phalcon, or modular with independent composer packages that are not coupled to others. I did Laravel development for a while, but I couldn't seem to get the performance I wanted out of it.

What about you?
Convert Microsoft Visio Document to PDF in Java
Tags: visio, pdf, diagram, java
Published: 2018-10-05 14:10:41

---
title: Convert Microsoft Visio Document to PDF in Java
published: true
description: Convert Microsoft Visio Document to PDF in Java
tags: #Visio, #PDF, #Diagram, #Java
---

Developers can convert any Microsoft Visio document to PDF (_Portable Document Format_) in Java using [Aspose.Diagram](https://products.aspose.com/diagram) which is a light-weight, extensible, easy to use API, that helps developers to create, manipulate and convert Microsoft Visio files to various formats on client side and server-side without any need to install Microsoft Visio or using any sort of Microsoft Office automation.

**Supported Platforms**

>Aspose.Diagram supports both Java and .NET platforms. Please see [Aspose.Diagram for Java](https://products.aspose.com/diagram/java) and [Aspose.Diagram for .NET](https://products.aspose.com/diagram/net) for your reference.

# Sample Microsoft Visio Document - VSDX

For demonstration purpose, we will convert the following [sample Microsoft Visio document](https://github.com/shakeel-faiz/Screenshots-and-Sample-Files/blob/master/Convert%20Microsoft%20Visio%20Document%20to%20PDF/sampleConvertMicrosoftVisioDocumentToPDF.vsdx) to PDF in Java using Aspose.Diagram for Java. However, you can use any Microsoft Visio document of your choice inside the sample code and it will also be converted to PDF fine.

![Sample Microsoft Visio Document to be converted to PDF using Aspose.Diagram API.](https://raw.githubusercontent.com/shakeel-faiz/Screenshots-and-Sample-Files/master/Convert%20Microsoft%20Visio%20Document%20to%20PDF/Microsoft-Visio-Document-converted-PDF-Aspose.Diagram.png "Sample Microsoft Visio Document to be converted to PDF using Aspose.Diagram API.")

#Licensing

Please note, if you will execute the code without prior setting the Aspose.Diagram license, you will get _Evaluation Watermark_ in your output documents. For more information, please go through [Licensing](https://docs.aspose.com/display/diagramjava/Licensing).

#Sample Code

The following sample code converts the Microsoft Visio document to PDF by performing these steps.

* Load Microsoft Visio document to _com.aspose.diagram.Diagram_ object.
* Save the _com.aspose.diagram.Diagram_ object into PDF format.

{% gist https://gist.github.com/shakeel-faiz/b78d9c8d447120a6426c6fcc9683ee28 %}

# Output PDF by Aspose.Diagram

The following snapshot shows the [Output PDF generated by Aspose.Diagram](https://github.com/shakeel-faiz/Screenshots-and-Sample-Files/blob/master/Convert%20Microsoft%20Visio%20Document%20to%20PDF/outputConvertMicrosoftVisioDocumentToPDF.pdf) with the code given above. As you can see, the PDF looks exactly same as Microsoft Visio document.

![Output PDF generated by Aspose.Diagram from Microsoft Visio document.](https://raw.githubusercontent.com/shakeel-faiz/Screenshots-and-Sample-Files/master/Convert%20Microsoft%20Visio%20Document%20to%20PDF/Output-PDF-Aspose.Diagram-from-Microsoft-Visio-document.png "Output PDF generated by Aspose.Diagram from Microsoft Visio document.")
Javascript developer from Brazil working in Canada
Tags: introductions
Published: 2018-10-12 15:12:21

---
title: Javascript developer from Brazil working in Canada
published: true
description: I am Daniel and I am happy to be publishing my first 'hello world' post here in *Dev.To* . I am building a web app and I would love to say hi to others working towards their own side projects. Always fun to share the *struggle.*
tags: introductions
---

I am Daniel and I am happy to be publishing my first 'hello world' post here in *Dev.To* . Other than my *day job*, I am building a web app and I would love to say hi to others working towards their own side projects. Always fun to share the *struggle.* Feel free to say hi back to me.
How to package a Polymer 3 app with webpack
Tags: webpack, polymer, javascript, webcomponents
Published: 2018-10-15 12:22:12

---
title: How to package a Polymer 3 app with webpack
published: true
description: We look into how to setup webpack to package our Polymer 3 application.
tags: webpack, polymer, javascript, webcomponent
---

{% youtube R9HDEHdGlHU %}
Avoid Ransack's N+1 Pitfall!
Tags: ransack, rails, beginners
Published: 2018-10-17 10:40:00

---
title: Avoid Ransack's N+1 Pitfall!
published: true
description: Using Ransack to search through related models can cause N+1 problems.  Learn how to deftly avoid them!
tags: Ransack, Rails, Beginner
cover_image: https://images.pexels.com/photos/36763/slip-up-danger-careless-slippery.jpg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260
---



I've written about [Ransack](https://github.com/activerecord-hackery/ransack) before, because it's a handy, little gem for searching quickly through both models and their relationships.  But you may be surprised to know it's deceptively easy to create N+1 queries using Ransack!  The good news is, it's just as easy to fix.

To review basic Ransack use, let's say you have a model `Service`, which has properties for `name` and `description`.  If you wanted to search both of those properties, you'd set up your view with something like this:
```
<%= search_form_for @q do |f| %>
  <%= f.label :name_cont %>
  <%= f.search_field :name_description_cont %>
<% end %>
```
And your controller would be:

```
def index
  @q = Service.ransack(params[:q])
  @services = @q.result(distinct: true)
end
```

Pretty basic stuff, right?  But what if you have another model associated with Services?  For example, let's say you have a `Provider` model with `name` and `address` properties, and each `Provider` has_many `Services`.

Now, you want to search the `name` and `description` properties for `Service`, but you also want to include the `Provider`s `name` property as well.  How do you do that?

Ransack provides an easy approach.  You can change your view to:
```
<%= search_form_for @q do |f| %>
  <%= f.label :name_cont %>
  <%= f.search_field :name_description_provider_name_cont %>
<% end %>
```

Things are working smoothly.  But hold on, let's look at the SQL query that runs when we try to search for something:
![lots of sql queries](https://i.imgur.com/pJUnj0d.png)

Yikes!  That's not what we want at all!

Those familiar with rails will know the dreaded N+1 Problem, but will also likely know we can usually solve it with eager loading and using `includes(:model_name)` . But where do we put it?  Easy, in the Controller of course!

```
def index
  @q = Service.includes(:provider).ransack(params[:q])
  @services = @q.result(distinct: true)
end
```

Running our search again:

![Much better!](https://i.imgur.com/xA9RuMv.png)

(Please note that in my examples, I also have Sub Categories loading for another part of my view)

This isn't a difficult problem to solve, but many may not be aware that using Ransack with associated models can end up creating this N+1 problems.

Good luck, and happy coding!
Most Popular Development Posts Of The Week (17 October 2018)
Tags: webdev, javascript, java, flutter
Published: 2018-10-18 07:31:36

---
title: Most Popular Development Posts Of The Week (17 October 2018)
published: true
tags: webdev,javascript,java,flutter
canonical_url: https://medium.com/daily-now/most-popular-development-posts-of-the-week-17-october-2018-1ef19fe951ea
cover_image: https://cdn-images-1.medium.com/max/1024/1*CR-E7JpaoMbYjz9g-zFB8w.jpeg
---

<figcaption>The way to get started is to quit talking and begin doing</figcaption>

- [The One reason you should learn Python](https://app.dailynow.co/r/248e247acd6293569955d37ae8d2221d)
- [Java is too old, What should you learn in 2018?](https://app.dailynow.co/r/51efd8e766f652f58e9116eeca159920)
- [10 Console tricks, to debug like a Pro.](https://app.dailynow.co/r/265f58d3caaba0c8fc44e035ecb0e80e) by [Amit Solanki](https://medium.com/u/9cd388a0858e)
- [Why is Flutter making people go crazy?](https://app.dailynow.co/r/c9a5cdfc1e9402a31ea3bf6af7fbf7fc)
- [Developers that constantly want to learn new things, here’s a tip!](https://app.dailynow.co/r/b61404ee67973fc1c5cde1bfe167c201) by [Dler Ari](https://medium.com/u/6b4a1cde263)
- [Keeping Axios Where it Belongs](https://app.dailynow.co/r/9d25e927373899fa0021ff57d718f2ea)
- [190 universities just launched 600 free online courses. Here’s the full list.](https://app.dailynow.co/r/2b6c65fa399d0e2e4b45e5967e5c9da6) by [Dhawal Shah](https://medium.com/u/587ae1d1b9ba)
- [What’s a Senior Web Developer](https://app.dailynow.co/r/048f0831d97369d5523ecc42f713353d)
- [The easiest problem you cannot solve.](https://app.dailynow.co/r/8d80d5f625c1badc8fa15ae30462a675) by [Joel Neto](https://medium.com/u/f1e5bf58b039)
- [How to Learn JavaScript in 14 Minutes](https://app.dailynow.co/r/409a5870db78edb959cb47820371b370)

* * *

[_Thanks to Daily_](https://www.dailynow.co/) _developers can focus on code instead of searching for news. Get immediate access to all these posts and much more just by opening a new tab._

![](https://cdn-images-1.medium.com/max/1024/1*m8Uf-6F4Q5AOp_wW6tbKSQ.jpeg)
Go to Objective-C bridge works!
Tags: go, showdev, objc, devlog
Published: 2018-10-19 21:04:36

---
title: Go to Objective-C bridge works!
published: true
description: A working Objective-C bridge for Go
tags: go, showdev, objc, devlog
---
Late last night I made a breakthrough and finally got the Go Objective-C bridge working. This just shows a "Hello world" window so it might seem like that's all there is. But the hard work has been in making the bridge code work at all for any kind of method call. 

![img](https://thepracticaldev.s3.amazonaws.com/i/qyb140ytgq7zpnr27u09.png)

What this means is any Apple API can be used from Go. And since Apple has schemas for every one of their APIs, I can generate wrappers for them so it all feels like native Go.
Who's looking for open source contributors? (October 22nd edition)
Tags: discuss, opensource, hacktoberfest
Published: 2018-10-22 17:33:42

We're towards the end of [#hacktoberfest](/t/hacktoberfest)!

Find something to work on or promote your project here.

Please shamelessly promote your project. Everyone who posted in previous weeks is welcome back this week, as always. 😄

Happy coding!
How to get the most out of DEV
Tags: discuss, meta
Published: 2018-10-25 21:38:12

---
title: How to get the most out of DEV
published: true
description: What content to you gravitate to on DEV and why?
tags: #discuss, meta
---

There was a really interesting discussion that sprang up in the comments on [this post](https://dev.to/devteam/reminder-to-follow-the-code-of-conduct-13i8) about site content. A couple people mentioned that they were getting fatigued with tutorials and whatnot, but they're clearly active and engaged members of the community. So I wondered, what do people like most about DEV? What content do you engage with the most? Are there things that the site could change to make you engage more? Less?

I'm still fairly new here and I'm trying to figure out how to get the most out of this site and find a place in the community. Let me know what's worked for you!
From Idea to Production
Tags: idea, discuss, beginners, production
Published: 2018-11-01 16:03:06

---
title: From Idea to Production
published: true
description: I have a lot of ideas, but none have gone to production. I want to change that with your help
tags: idea, discussion, beginner, production
---

Hey dev.to 👋

I'll jump straight into it. I like many of us have a ton of product ideas every now and then. It a story of programmer gets idea, programmer is excited about idea, programmer tries to build idea, programmer loses interest in idea and locks it in idea purgatory. For me at least, that's the way things usually go, this time I want things to be different. I want to actually ship something into production. Go through the whole experience whatever that might be.

## What I want to build

My friends and I share poetry and prose, a lot. The crazy thing is that it always gets lost in our chats on various platforms. I want to create a platform that my friends an I can log into, post our approx. ~5 line pieces and read each other's pieces too on some sort of timeline. Nothing too fancy. I want this to be as much of a learning experience as possible. I have no idea how to actually achieve this. Going forward, I'd like to know the path if there is one, I want to know the steps one takes, the things one looks out for, the design decisions you make and most importantly, I want to be able to genuinely laugh at the development and production memes :/. I'll use all this help from you all and create the platform. Once I get an idea of everything involved to get this project up and running, I'll give it a deadline and as usual share my progress here. It could probably work with Vue and GraphQL, right? Please share any ideas you have in the comments. I'd love to hear them.