teleren/devto huggingface dataset:
Using custom style loaders with the Neutrino React preset
Tags: javascript, react, neutrino
Published: 2020-05-11 16:38:31

I’m trying out [Neutrino](https://neutrinojs.org/) to build a new React project, using its [React preset](https://neutrinojs.org/packages/react/). 

By default, Neutrino includes everything I need except custom style loaders for tools like Sass. At first, I tried to define my custom loaders according to Neutrino’s [`style-loader` documentation](https://neutrinojs.org/packages/style-loader/#custom-loaders), updating my `.neutrinorc.js` like so:

```javascript
const standard = require('@neutrinojs/standardjs');
const react = require('@neutrinojs/react');
const jest = require('@neutrinojs/jest');
const styles = require('@neutrinojs/style-loader');

module.exports = {
  options: {
    root: __dirname,
  },
  use: [
    standard(),
    react({
      html: {
        title: 'app-title'
      }
    }),
    jest(),
    styles({
      test: /\.(css|sass|scss)$/,
      modulesTest: /\.module\.(css|sass|scss)$/,
      loaders: [
        {
          loader: 'postcss-loader',
          options: {
            plugins: [require('autoprefixer')],
          },
        },
        {
          loader: 'sass-loader',
          useId: 'sass'
        },
      ],
    })
  ],
};

```

Unfortunately, this setup threw an error when I started my dev server:

> DuplicateRuleError: `@neutrinojs/style-loader` has been used twice with the same `ruleId` of `'style'`, which would overwrite the existing configuration. If you are including this preset manually to customise rules configured by another preset, instead use that preset's own options to do so.

It wasn’t immediately obvious to me what was going on here, and Google led me to a couple of people with the same problem, but no solutions.

Soon enough, though, I realized that the React preset was already using `style-loader` under the hood. `style-loader`’s behavior within the React preset is configurable through a property in the preset's options object called `style`. I had missed that option because it's [documented as part of the Web preset](https://neutrinojs.org/packages/web/#preset-options), and not redundantly included in the React preset's docs.

So I adjusted my `module.exports` accordingly:

```javascript
module.exports = {
  options: {
    root: __dirname,
  },
  use: [
    standard(),
    react({
      html: {
        title: 'app-title'
      },
      style: {
        test: /\.(css|sass|scss)$/,
        loaders: [
        {
          loader: 'postcss-loader',
          options: {
            plugins: [require('autoprefixer')],
          },
        },
        {
          loader: 'sass-loader',
          useId: 'sass'
        },
      ]
      }
    }),
    jest()
  ],
};
```

*Et voilà*, it worked.

**TL;DR:** If you’re using Neutrino’s React preset (or presumably any of its web presets), you’ll need to configure your custom style loaders within that preset’s options object, using the `style` property.

I hope this helps someone who’s run into the same issue.
Getting your Windows files and folders to behave as on Linux
Tags: linux, subsystem, windows10, bash
Published: 2020-05-11 16:20:58

---
title: Getting your Windows files and folders to behave as on Linux
published: true
description: Get your Linux subsystem files to behave just like on an actual Linux box.
tags: Linux, subsystem, Windows 10, Bash
---
![Windows,Linux](https://dev-to-uploads.s3.amazonaws.com/i/jl0lr4x7n0wb9f143pqa.jpg)

I will make this brief.

If you write software on a Windows machine but then usually deploy on a Linux server you probably have run into the trouble of your software breaking because of the difference in the way both OS handles file names and the issue with referencing the wrong case of the name in your code.

Basically you can get away with calling on `index.js` as `Index.js` on Windows but not on Linux. 

To get your directories and files to behave on Windows as they would on Linux. 
Open PowerShell navigate into your project directory and run the following script.

```(Get-ChildItem -Recurse -Directory).FullName | ForEach-Object {fsutil.exe file setCaseSensitiveInfo $_ enable}```

This will enable case sensitivity for when you reference a name of a file/folder in your code or if namespacing depends on file and folder names like in PHP. 

This way if you mix up the case of your file you won't be forgiven even on Windows because Linux won't either.
I got this script on Stackoverflow but I am still looking for the source.
I will add that bit when I find it.
I kept the above script in a Gist for when I need it and felt I should share it.
The End...
Why and How I Created Another Console Framework
Tags: dotnet, nuget, console, framwork
Published: 2020-05-11 16:07:09

Console applications are becoming viral tools for developers. After a trend that was going to move each non-visual tool to GUIs for better control, in the last years, we see the success of CLIs. Just remind to Docker and Kubernetes. In the last months, I developed an open-source headless CMS called [RawCMS](https://github.com/arduosoft/RawCMS/), and I put a CLI application on it. I started this tool by using the library in the .Net market, and the final experience wasn’t so good. I completed the task, but the next time I had to develop a client application, I decided to invest some time trying to do something better. I finished developing a straightforward console framework that automates command execution and the interaction with the user.
In this article, I will explain how I did it — focus on the exciting part I learned. The code is available on GitHub, as usual, and I released a Nuget package for testing.

[Read the full article](https://levelup.gitconnected.com/dotnet-cosole-framework-3d5ebce96b8f?source=friends_link&sk=5126fa050d9756d9a3d8d9d60191b366)
Ambianic.ai UI mockup for edge device connectivity, May 2020
Tags: ui, mockup, p2p
Published: 2020-05-11 15:56:21

One of the recent product discussions related to Ambianic.ai UX has been related to enabling remote users to setup initial connection to an edge device that is not on their local network. 

The specific use case that came up was inspired by the COVID19 hackathons we [participated in](https://devpost.com/software/remote-elderly-home-care-via-privacy-preserving-surveillance-tzp2ab).

What if a family member can ship a pre-configured Ambianic Edge system to their isolated elderly or disabled dependents homes so they can better take care of them remotely. Currently the [UI](https://ui.ambianic.ai) can automatically discover and pair up with an Edge device running on the same local network (e.g. home WiFi). But what if family members are not able to physically visit the home where Ambianic Edge will run.

A simple problem statement resulted in an extended UX and p2p connectivity (WebRTC) design discussion. We started with a [high level state machine diagram](https://dev.to/ambianicai/ambianic-ai-p2p-connectivity-state-machine-may-2020-48lm), which helped but wasn't specific enough.

Then Bjorn added a [sequence diagrams](https://drive.google.com/file/d/1Ps-TKQ_WdXS-L6qDeyXqmli9S97mnkFk/view?usp=sharing) to illustrate his proposed implementation in [PR 347](https://github.com/ambianic/ambianic-ui/pull/347).

As the PR discussion went on, new edge cases came up, which forced us to think hard about what's most intuitive to the end user. 

This [UI mockup diagram](https://projects.invisionapp.com/freehand/document/DziiI47LX) illustrates our latest agreement. Its open to community feedback; use the discussion box below.
Learning Golang 107
Tags: go, beginners
Published: 2020-05-10 21:16:32

## Concurrency
Concurrent programming in many environments is made difficult by the subtleties required to implement correct access to shared variables. Go encourages a different approach in which shared values are passed around on channels and, in fact, never actively shared by separate threads of execution. Only one goroutine has access to the value at any given time. Data races cannot occur, by design.  I think this really makes go so shining.

### Goroutines
Prefix a function or method call with the go keyword to run the call in a new goroutine. When the call completes, the goroutine exits, silently.
```
func Announce(message string, delay time.Duration) {
    go func() {
        time.Sleep(delay)
        fmt.Println(message)
    }()  // Note the parentheses - must call the function.
}
```

A channel can allow the launching goroutine to wait for the sort to complete.

```
c := make(chan int)  // Allocate a channel.
// Start the sort in a goroutine; when it completes, signal on the channel.
go func() {
    list.Sort()
    c <- 1  // Send a signal; value does not matter.
}()
doSomethingForAWhile()
<-c   // Wait for sort to finish; discard sent value.
```

**Receivers always block until there is data to receive. If the channel is unbuffered, the sender blocks until the receiver has received the value. If the channel has a buffer, the sender blocks only until the value has been copied to the buffer; if the buffer is full, this means waiting until some receiver has retrieved a value.**


A buffered channel can be used like a semaphore, for instance to limit throughput. In this example, incoming requests are passed to handle, which sends a value into the channel, processes the request, and then receives a value from the channel to ready the “semaphore” for the next consumer. The capacity of the channel buffer limits the number of simultaneous calls to process.

```
var sem = make(chan int, MaxOutstanding)

func handle(r *Request) {
    sem <- 1    // Wait for active queue to drain.
    process(r)  // May take a long time.
    <-sem       // Done; enable next request to run.
}

func Serve(queue chan *Request) {
    for {
        req := <-queue
        go handle(req)  // Don't wait for handle to finish.
    }
}
```

### Channels of channels
One of the most important properties of Go is that a channel is a first-class value that can be allocated and passed around like any other. 
```
type Request struct {
    args        []int
    f           func([]int) int
    resultChan  chan int
}

func sum(a []int) (s int) {
    for _, v := range a {
        s += v
    }
    return
}

request := &Request{[]int{3, 4, 5}, sum, make(chan int)}
// Send request
clientRequests <- request
// Wait for response.
fmt.Printf("answer: %d\n", <-request.resultChan)

```

## Function Literals
As lambda in java, Go supports `Function Literals`. It is a function without a name.
```
c := make(chan int)
func(ch chan int) {
    list.Sort()
    ch <- 1  // Send a signal; value does not matter.
}(c)  // the () means call the function.
```
List: LinkedIn Skills
Tags: codenewbie, watercooler, webdev, beginners
Published: 2020-05-11 15:52:19

When preparing your LinkedIn profile, make sure to include a list of your technical skills, then endorse skills of your connections and/or ask others for endorsements*. 

Here’s a list of some skills you could add to your LinkedIn skills (or, if they are framework-specific, find an equivalent in your language). This is not an exhaustive list — just a stub and written from the perspective of folks with Rails/JS background to give you an idea. Add whatever methodology or language you've used!

## Programming languages and software
List the programming languages and software your program or self-studies covered, for instance:
- Web Development
- Web Applications
- Software Development
- ActiveRecord
- Front-end Development
- Back-end Development
- Full-stack Development
- Ruby
- Ruby on Rails
- PostgreSQL
- SQLite
- SQL
- Sinatra
- JavaScript
- ES6
- React.js
- Redux.js
- Node.js
- Express
- CSS
- HTML
- Git
- Github
*if you deployed your projects:*
- Heroku
- Netlify
- Firebase 
*and if you are interested in accessibility:*
- Web Content Accessibility Guidelines (WCAG)
- Accessibility

## Methodologies
- Test-Driven Development
- Object-Oriented Programming (OOP)
- MVC
- REST API
- Technical Writing
- Debugging

## Soft skills 
*only if you have space — apparently no recruiter would be looking for soft skills*
- Constructive Feedback
- Teamwork
- Project Management
- Public Speaking
- Problem Solving
- Collaborative Problem Solving 

___

*apparently, endorsements are just a vanity thing and do not help with getting noticed by a recruiter; still, not all people who will view your profile are recruiters

Photo by Andrea Piacquadio from [Pexels](pexels.com)
Python multiprocessing VS Numpy vectorization - one example
Tags: python, multiprocessing, numpy, vectorization
Published: 2020-05-11 15:36:55

Today, I came [across a very nice article](https://medium.com/distributed-computing-with-ray/how-to-scale-python-multiprocessing-to-a-cluster-with-one-line-of-code-d19f242f60ff) about parallelization and multiprocessing using Python `Pool` and a [new software named Ray](https://ray.io/) which seamlessly distributes `Pool` over a cluster.

The author used a Monte-Carlo implementation to calculate the pi number as an example of a procedure that can be parallelized using `Pool` and Ray. The author then compares the performance of all the different possibilities: from a single core in a computer to local multicore with `Pool` to, finally, a cluster distributed approach with Ray. The best performance was, obviously, in the cluster with Ray, giving:

```
sample: 10_000_000_000
pi ~= 3.141599
Finished in 131.37s
```

I perfectly understand that the pi calculation example was chosen purely for demonstration porpuses. However, I found it a very nice opportunity to use it as **an example to practice vectorization principles with [Numpy](https://numpy.org/)**. Please go to the [original post]() and read the raw Monte-Carlo sampling implementation using `for` loops.

**How would you convert that example into a vectorized Numpy-based implementation?**

Try it out for yourself first before reading the answer below.

*****************************************************
**SPOILER ALERT!! YOU ARE ABOUT TO READ THE ANSWER!**

This is how I solved it, you are very welcomed to comment and help me improve it further.

```python
def perform(size):
    xxyy = np.random.uniform(-1, size=(size, 2))
    norm = np.linalg.norm(xxyy, axis=1)
    inside = norm <= 1
    return np.sum(inside)


start = time.time()
sample = 10_000_000_000
times = 20
insiders = 0
size = sample // times
print('size: ', size)
for _ in range(times):
    insiders += perform(size)
    
pi = 4 * insiders / sample
print("pi ~= {}".format(pi))
print("Finished in: {:.2f}s".format(time.time()-start))
```

Using a single core in my laptop, I got:

```plain
pi ~= 3.1415858588
Finished in: 236.04s
```

```plain
CPU~Quad core Intel Core i7-8550U (-MT-MCP-)
speed/max~800/4000 MHz
Kernel~4.15.0-99-generic x86_64
Mem~7178.7/32050.2MB
HDD~2250.5GB(56.6% used)
Procs~300
Client~Shell
inxi~2.3.56 
```

Notice that the `sample` function was designed to split the calculation into several parts so that my laptop won't run out of memory when creating so large arrays. However, that does not affect significantly the performance of the calculation.

What do you think?
Cheers,
Ambianic.ai p2p connectivity state machine, May 2020
Tags: p2p, ambianic, statemachine, webrtc
Published: 2020-05-11 15:33:28

As the dev community around Ambianic.ai expands and new ideas are brought in, it feels like a good time to document the current p2p state machine. This should allow more productive discussions on our roadmap and design.

The state machine diagram below complements the recent deep dive WebRTCHacks article [Private Home Surveillance with the WebRTC DataChannel](https://webrtchacks.com/private-home-surveillance-with-the-webrtc-datachannel/). 

![Ambianic.ai high level p2p State Machine](https://dev-to-uploads.s3.amazonaws.com/i/eke8hde6amlgxnda2466.png)

Here is the [source](https://drive.google.com/file/d/1Ps-TKQ_WdXS-L6qDeyXqmli9S97mnkFk/view?usp=sharing) of the diagram to fork and edit. It was created with the excellent diagrams.net (aka draw.io) tool.

Feel free to ask questions or comment in the discussion below.
Throwaway postgres
Tags: postgres, dev, docker, dockercompose
Published: 2020-05-09 08:16:57


I don't like to install too many services on my machine as after a while I end up with lots of services - Postgres, Redis, Mongo, Memcache, Elasticsearch that have lots of data from different POC projects. 

So whenever I need to test something quickly I just prefer to run it in a docker container: 

```
docker run --name postgres -d -p 5432:5432 -e POSTGRES_PASSWORD=kuba -e POSTGRES_DB=db -e POSTGRES_USER=kuba postgres:12
```

Or with docker compose:

```
version: '3'
services:
    postgres:
        image: postgres:12
        environment:
            - POSTGRES_USER=kuba
            - POSTGRES_PASSWORD=kuba
            - POSTGRES_DB=db
        ports:
            - "5432:5432"
```

And we can quickly run the Postgres DB:

```
$ docker-compose up
Starting sql_postgres_1 ... done
Attaching to sql_postgres_1
postgres_1  |
postgres_1  | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres_1  |
postgres_1  | 2020-05-09 08:13:45.246 UTC [1] LOG:  starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres_1  | 2020-05-09 08:13:45.247 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres_1  | 2020-05-09 08:13:45.247 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres_1  | 2020-05-09 08:13:45.249 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1  | 2020-05-09 08:13:45.262 UTC [25] LOG:  database system was shut down at 2020-05-09 08:12:41 UTC
postgres_1  | 2020-05-09 08:13:45.266 UTC [1] LOG:  database system is ready to accept connections
```

And we have a throwaway db running:
```
$ psql postgres://kuba:kuba@localhost:5432/db
Null display is "NULL".
Pager is always used.
Timing is on.
psql (12.2)
Type "help" for help.

kuba@localhost:5432 db#
```
Why Electron, not just fat JAR or executable server, or just a bunch of HTML/CSS/JS?
Tags: discuss, webdev, desktop, electron
Published: 2020-05-11 15:31:19

BTW, how do I convert server fat JAR into \*.exe / \*.app?

I think Neutralino.js falls into the second category as well. It is just superficially windowed.

BTW, using Neutralino.js with Vue CLI necessitates these settings.

```js
// vue.config.js

module.exports = {
  outputDir: 'dist/app',
  assetsDir: 'assets'
}
```

Where `neutralino-*` is at `dist/`, and there are at least

- `dist/app/settings.json`
- `dist/app/assets/neutralino.js`
- `<script src="/neutralino.js"></script>` in `dist/app/index.html`
- `dist/storage/` folder
How to redirect to URL in new tab On window load event🍊
Tags: webdev, html, javascript, tutorial
Published: 2020-05-11 15:22:54

---
title: How to redirect to URL in new tab On window load event🍊
published: true
tags: webdev, HTML, javascript, tutorial
---



{% codepen https://codepen.io/atulcodex/pen/jObKqgZ %}
Solving CWE-606: Unchecked Input for Loop Condition
Tags: discuss, cwe, security
Published: 2020-05-11 15:12:55

The **[CWE-606: Unchecked Input for Loop Condition][1]** is described as:
> The product does not properly check inputs that are used for loop conditions, potentially leading to a _**denial of service because of excessive looping**_. 

with an attached demonstrative example in `C` as:
```c
void iterate(int n){
  int i;
  for (i = 0; i < n; i++){
    foo();
  }
}
void iterateFoo()
{
  unsigned int num;
  scanf("%u",&num);
  iterate(num);
}
```

Recently I came across this issue in my Java application when we scanned the project with [Checkmarx's CxSAST][2]. The code is something like:
```java
List<String> records = ... // The records are read from a received file
for ( int i = 0; i < records.size(); i++){
  // some processing here
}
```
Now in order to solve this issue I identify two approaches:
  1. define a max size of records and compare the size of the records to that value and if it is greater than that then either do not process any record and exit or process the records in chunks by splitting them by the max size.
  2. rewrite this *for-loop* as *for-each* which do not check for the execution condition and process until it has record in there.

In the 1st solution it would be difficult to put a size restriction as we do not know the limit of number of records could be there and we have to process them all. If we go by a chunk processing then we could put some arbitrary value.

In the 2nd solution we may trick the checkmarx that we have not used the user input as loop condition but I am not sure if that will work or not?

What is your opinion on this?

  [1]: https://cwe.mitre.org/data/definitions/606.html
  [2]: https://www.checkmarx.com/products/static-application-security-testing
Wear Headphones when you work from home! - How putting down headphones after a days work can help you unplug at home!
Tags: productivity, career, mentalhealth
Published: 2020-05-11 15:11:12

---
title: Wear Headphones when you work from home! - How putting down headphones after a days work can help you unplug at home!
published: true
description: How putting down headphones after a days work can help you unplug at home!
tags: productivity, career, mentalhealth
cover_image: https://theworkmirror.com/assets/img/post_headphones.png
---

> This was originally released on the [Mirror Blog](https://theworkmirror.com/blog/2020/05/11/Whear-Headphones-when-working-from-home.html). Visit [theworkmirror.com](https://theworkmirror.com) for more resources on how to make time for what matters and stay healthy and productive at work.

I tried not to talk about "how to work better from home" because everyone's an expert now. But apparently a lot of people like my headphone hack so I'll make an exception. Here it comes: **Wear Headphones whenever you work! 🤯🎧**

All those "*go to a desk, don't work from your bed*" home office advice tries to do two things:

1. limit distractions
1. create a boundary between your work and your home so you won't be working 24/7

Especially the last part is very important as for many of us that separation of work and personal spaces was not obvious. It was just something we unconsciously did by going from/to work. These days many people recommend to create a new separation by working from a separate room. But what to do when you do not have that space?

In my experience, Headphones can do the same! Because

1. noise cancellation 😉
1. the important part about separating yourself from work is not the space but to find a clear signal that you are no longer in "work mode". Putting down the headphones does that for me, as I only use them during work.

So if you don't have home office, get yourself a decent pair of headphones to help you unplug after work!