teleren/devto huggingface dataset:
Daily Challenge #160 - Expression Matters
Tags: challenge
Published: 2020-01-12 14:30:14

---
title: Daily Challenge #160 - Expression Matters
published: true
description: Given three integers a ,b ,c, return the largest number obtained after inserting the following operators and brackets: +, *, ().
tags: challenge
---

##Task

Given three integers `a ,b ,c`, return the largest number obtained after inserting the following operators and brackets: `+, *, ().`

*Consider an Example* :

With the numbers are `1, 2 and 3` , here are some ways of placing signs and brackets:

`1 * (2 + 3) = 5`
`1 * 2 * 3 = 6`
`1 + 2 * 3 = 7`
`(1 + 2) * 3 = 9`

So the maximum value that you can obtain is 9.

##Notes

- The numbers are always positive.
- The numbers are in the range `(1  ≤  a, b, c  ≤  10)`.
- You can use the same operation more than once.
- It's not necessary to place all the signs and brackets.
- Repetition in numbers may occur.
- You cannot swap the operands. For instance, in the given example you cannot get expression `(1 + 3) * 2 = 8`.

*Input >> Output Examples*:
`expressionsMatter(1,2,3)  ==>  return 9`

*Explanation*:
After placing signs and brackets, the maximum value obtained from the expression `(1+2) * 3 = 9`.

`expressionsMatter(1,1,1)`  ==>  return 3

*Explanation*:
After placing signs, the Maximum value obtained from the expression is `1 + 1 + 1 = 3`.

`expressionsMatter(9,1,1)`  ==>  return 18

*Explanation*:
After placing signs and brackets, the maximum value obtained from the expression is `9 * (1+1) = 18`.


***
_This [challenge](https://www.codewars.com/kata/5ae62fcf252e66d44d00008e) comes from MrZizoScream on CodeWars. Thank you to [CodeWars](<https://codewars.com/>), who has licensed redistribution of this challenge under the [2-Clause BSD License](<https://opensource.org/licenses/BSD-2-Clause>)!_

_Want to propose a challenge idea for a future post?  Email **yo+challenge@dev.to** with your suggestions!_
Interview Prep #1: Does String has Unique Characters
Tags: career, beginners, cpp, interview
Published: 2020-01-12 14:21:26

## Problem

We are given a string and we need to find if the string has unique characters in it.

```
Examples:

input: dev.to
output: true

input: javascript
output: false
```

## Solution

The solution to this problem is very simple. It involves the usage of the [set](https://en.wikipedia.org/wiki/Set_(abstract_data_type)) data structure. We iterate over the string and store the characters of the string in a set. Every time we store a character, we will check if the character already exist in the set. If we find that the character has already been stored in the set, this means that we encountered the character a while back in the string. Thus the string does not have unique characters hands with return false. If we reach till the end of the string and do not find any duplicate occurrences this means that the string is unique and we return true.

```cpp
bool is_string_unique(string s) {
  set<char> store;
  for (auto a : s) {
    if (store.find(a) != store.end()) {
      // charecter already exists
      return false;
    }
    store.insert(a);
  }
  return true;
}
```

> References: Cracking the Coding Interview - Gayle Laakmann McDowell
Have a nice day 😄
Gzip is good, Brotli is better!
Tags: webperf
Published: 2020-01-12 14:20:30

Compressing the data before sending it to the client is almost a fundamental web development aspect. The lesser the number of bytes transferred down the wire, the faster the client would receive it. The most common compression schemes include gzip and Deflate. 
Recently, I bumped into a relatively younger compression algorith, [Brotli](https://tools.ietf.org/html/rfc7932). After reading this [post](https://engineering.linkedin.com/blog/2017/05/boosting-site-speed-using-brotli-compression) by linkedin, I was pretty much excited and thought to see the results for myself. 

I created a [demo project](https://github.com/uzumaki-narut0/brotlivsgzip) and am putting the comparison snapshot below.
![Gzip vs Brotli](https://thepracticaldev.s3.amazonaws.com/i/2812e4oa3mdf8ntb65kc.PNG)

The [Browser Support](https://www.caniuse.com/#search=brotli) for Brotli is quite good but not 100%. You could easily fallback to gzip for the Browsers that does not support Brotli.

Sending lesser number of bytes would surely improve the latency but remember that the Browser will still parse and evaluate the same number of bytes. So, it would be better if you do not rely upon compressing the data very much and ship the user the best version of yourself for a good user experience.
Lazy Load Apollo Link in Apollo Client
Tags: react, javascript, graphql
Published: 2020-01-12 14:18:21

##### 10 lines of code to help

## Introduction

This is a short post about my small library.

[Apollo Client](https://github.com/apollographql/apollo-client) is a library for GraphQL. [Apollo Link](https://github.com/apollographql/apollo-link) is an interface to extend Apollo Client.

Typically, you would initialize apollo client like this.

```js
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';

const cache = new InMemoryCache();
const link = new HttpLink({ uri });

const client = new ApolloClient({
  cache: cache,
  link: link,
});
```

I want to define the link in another file and lazy load it, because it is not an HttpLink but a complicated large link.

## How to use

We use [dynamic imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) for this.

Let's assmume we have `link.js` file that exports an apollo link. It'd be nice to dynamic import it.

```js
import { lazy } from 'apollo-link-lazy';

const link = lazy(() => import('./link'));
```

`import()` returns a promise, but there's no `await`. How is this possible?

## How to implement

Interestingly, Apollo Link is asynchronous by nature. However, it's not promise based. It has observable interface.

So, all you need is to covert a promise into an observable.

Here's the code.

```js
import { ApolloLink, fromPromise, toPromise, Observable } from 'apollo-link';

export const lazy = (factory) => new ApolloLink(
  (operation, forward) => fromPromise(
    factory().then((resolved) => {
      const link = resolved instanceof ApolloLink ? resolved : resolved.default;
      return toPromise(link.request(operation, forward) || Observable.of());
    }),
  ),
);
```

Luckily, apollo-client exports `fromPromise` and `toPromise` utility functions. Hence, it can be implemented so easily.

A little trick here is to support both ApolloLink promises and default exports.

## Demo

I developed this code as a library.

<https://github.com/dai-shi/apollo-link-lazy>

You can install it and use it. It supports TypeScript.

Here's also a demo in codesandbox.

<https://codesandbox.io/s/github/dai-shi/apollo-link-lazy/tree/master/examples/02_typescript>

## Closing notes

As my motivation was code splitting, supporting default exports like [React.lazy](https://reactjs.org/docs/code-splitting.html#reactlazy) was actually enough. Because it also supports direct promises, we can use it for any async initialization like the following.

```js
import { lazy } from 'apollo-link-lazy';

const link = lazy(async () => {
  // await ...
  return new ApolloLink(...);
});
```

I hope this may help other developers who try lazy loading of apollo links.

----

Originally published at [https://blog.axlight.com](https://blog.axlight.com/posts/lazy-load-apollo-link-in-apollo-client/) on January 10, 2020.
Easy Accessibility: Stop Using tabindex= >0
Tags: a11y, webdev, html
Published: 2020-01-12 14:04:35

<p>At work, part of my job has been to research ways to improve accessibility on our websites. I volunteered to do this, as I wanted to learn more about best practices and make the web more friendly to all. I quickly found that web accessibility (or a11y - titled that way since there are 11 characters between the a and y) is something that is not very easy to learn. There are plenty of resources, but often there is no "right way" of doing something. Some resources say one thing, others say something else. Additionally, there is no single accessibility resource, it takes a lot of research and time to go through everything. With this blog series I aim to compile a swath of easy a11y wins that you can start to implement immediately and won't take much time out of your day.</p>

<p>Now, tabindex. I think that any web developer hates this property by default. Digging through a bunch of code to find out what number to throw in here is obnoxious, and sometimes, almost impossible! At work, it was just assumed that tabindex was a necessary evil. Something that we would have to maintain forever so that keyboard users wouldn't be left in the dark.</p>

<p>As it turns out, manually setting tabindex to anything above 0 is bad for a11y, and annoying to do! It can easily result in the cursor jumping to unexpected places, and is so hard to maintain that it really does not make any sense to bother with. <b>The browser does an infinitely better job than we ever could at this!</b></p>

<p>My only question about this piece of information was <b>"then why would you set tabindex on anything?"</b> The answer is that setting a tabindex of 0 will notify browsers that an element that isn't normally given a tabindex should be given a tabindex, allowing keyboard users to focus that element. In other words, use tabindex only when you are creating a component which needs to be able to be used by keyboard users but does not have the ability by default. For example, I used this when I built a custom select dropdown with an unordered list element. </p>

<p>You <b>can</b> use a tabindex of <0, to remove an item from the tab order entirely. Use this sparsely, as you're breaking the intended function of an element, which can quite easily cause confusion and result in bad user experience. Additionally, hiding an element with CSS will remove it by the tab order automatically, so it only applies to visible, unusable elements (which are confusing!). Be careful.</p>

<p>Thanks for reading, I hope that you learned something new!</p>
I Built Daily Developer Jokes and the First Ever DEV Bot
Tags: bots, showdev
Published: 2020-01-12 13:08:21

---
title: "I Built Daily Developer Jokes and the First Ever DEV Bot"
published: true
description: "Today I am proud to release my latest project -- a website and the first ever DEV bot (as far as I know), called Daily Developer Jokes. The Daily Developer Jokes bot will post programmer humor and jokes every day at 8:00 AM (EST)."
cover_image: "https://xtrp.io/api/content/static_files/daily-jokes-bot-release/photo2.png"
tags: #bots, #showdev
---

Today I am proud to release my latest project &mdash; a website and the first ever DEV bot (as far as I know), called Daily Developer Jokes.

The Daily Developer Jokes bot will post programmer humor and jokes every day at 8:00 AM (EST), both on the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/), and on the [Daily Developer Jokes DEV Profile](https://dev.to/dailydeveloperjokes).

Each joke comes with a custom Daily Developer Jokes banner on DEV, and an image with the joke overlayed on the top.

This is our first joke (from today):

[![First Joke from Daily Developer Jokes](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e125927bb96c.png)](https://dailydeveloperjokes.github.io/)

You can check out the official, searchable list of daily developer jokes on the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/).

Daily Developer Jokes runs on a set of Python programs, Node.js server(s), and several PHP servers to generate posts, get jokes, generate images for jokes, and post the final markdown files to the site and DEV profile.

For posting to DEV, the Daily Developer Jokes bot uses the [DEV API](https://docs.dev.to/api/) along with a cronjobs system written in Python, running 24/7 on a Raspberry Pi. As far as I know, **the Daily Developer Jokes DEV account is the first ever DEV bot** to use the DEV API to post daily.

Go check it out!

[![Daily Developer Jokes Website](https://xtrp.io/api/content/static_files/daily-jokes-bot-release/ddj_website.png)](https://dailydeveloperjokes.github.io/)
[![Follow Daily Developer Jokes on DEV](https://xtrp.io/api/content/static_files/daily-jokes-bot-release/follow_ddj_on_dev.png)](https://dev.to/dailydeveloperjokes)

I may elaborate on the way I built this project and bot in the near future (and may open source it), and I hope you enjoyed this post and the project.

Thanks for scrolling.

*&mdash; Gabriel Romualdo, January 12, 2020*
Why I made a React Components library based on the concept of Neumorphism?
Tags: react, javascript, css, design
Published: 2020-01-12 13:00:58

So, If you are a designer or a passionate front end developer, then it's more likely that you have heard about the concept of Neumorphism.

![](https://cdn.dribbble.com/users/1034014/screenshots/9165794/flight_dribbble.png)

If you haven't let us first understand it:

"The neomorphic effect is a combination of the current famous flat UI and the old skeuomorphic principles! The components have a dark box-shadow on the bottom and a light box-shadow on top; the combination of both creates the effect of the elements pushing themselves through your display."

It's also called Soft UI.

## What next ?

When I saw all these designs on Dribble and articles on Medium, I started thinking about it's implementation in ReactJS.

So, I started working on an awesome library called `neumorphic-ui` as I call it. I implemented 6 basic components in it. The components are NeuButton, NeuCard, NeuReaction, NeuHeading, NeuInput and NeuProgressBar.
If you want to see it on GitHub, just go to this [link](https://github.com/dev-saeed/neumorphic-ui).

### How to use `neumorphic-ui`?

I have also published it as an npm package. To use it, you just have to do `npm install --save neumorphic-ui` and you are there. 

### Contributions/Suggestions

Contributions to the library are welcome. Just pull it and make a merge request. I will review the code and then if it's up-to-the-mark, I will merge it. Also, if you can suggest something more better, just drop me a message here. My inbox is open for all of you. Also, you can send me an email on : saeed_dev@yahoo.com.

GitHub link : https://github.com/dev-saeed/neumorphic-ui
NPM Link : https://www.npmjs.com/package/neumorphic-ui
Docs Link : https://neumorphic-ui.netlify.com/

### Thanks for reading this. Let's build a Neumorphic world together!

Credits :
- The definition of neumorphic effect is from an article by S Jagoor on Medium. You can see it here :
https://medium.com/@s.jagoori/design-trends-neumorphism-59a9ba9d9284
- The image in article is from https://dribbble.com/shots/9165794-Flight-Search-UI-Exploration/attachments/1208290?mode=media
Daily Developer Jokes - Sunday, Jan 12, 2020
Tags: jokes, dailydeveloperjokes
Published: 2020-01-12 13:00:17

---
title: "Daily Developer Jokes - Sunday, Jan 12, 2020"
description: "Check out today's daily developer joke! (a project by Fred Adams at xtrp.io)"
series: "Daily Developer Jokes"
cover_image: "https://private.xtrp.io/projects/DailyDeveloperJokes/thumbnail_generator/?date=Sunday%2C%20Jan%2012%2C%202020"
published: true
tags: #jokes, #dailydeveloperjokes
---

Generated by Daily Developer Jokes, a project by [Fred Adams](https://xtrp.io/) ([@xtrp](https://dev.to/xtrp) on DEV)

**Read about Daily Developer Jokes on [this blog post](https://xtrp.io/blog/2020/01/12/daily-jokes-bot-release/), and check out the [Daily Developer Jokes Website](https://dailydeveloperjokes.github.io/).**
### Today's Joke is...
![Joke Image](https://private.xtrp.io/projects/DailyDeveloperJokes/public_image_server/images/5e125927bb96c.png)

---

*Have a joke idea for a future post? Email __[xtrp@xtrp.io](mailto:xtrp@xtrp.io)__ with your suggestions!*

*This joke comes from [Dad-Jokes GitHub Repo by Wes Bos](https://github.com/wesbos/dad-jokes) (thank you!), whose owner has given me permission to use this joke with credit.*

<!-- 
Joke text:
**Q:** Why did the database administrator leave his wife?

**A:** She had one-to-many relationships.
 -->
Reading Snippets [33 => Callback]
Tags: beginners, javascript, oop, functional
Published: 2020-01-12 12:42:09

Callback functions determine the order that different actions occur. This allows empowers a programmer to be more flexible in their approach to the execution of actions.

Instead of being forced to create one long, consecutive string of commands, a programmer can ensure that one action happens after another. 

<kbd>Source:<small><a href="https://blog.codeanalogies.com/2016/04/11/javascript-callbacks-explained-using-minions/">Code Analogies</a></small></kbd>
Round Robin implementation in C#
Tags: beginners, tutorial, productivity, csharp
Published: 2020-01-12 12:12:48

---
title: Round Robin implementation in C#
published: true
description: simple but powerful and thread-safe implementation of Round Robin algorithm in C#
tags: beginner, tutorial, productivity, csharp 
cover_image: https://thepracticaldev.s3.amazonaws.com/i/xuyh6wviwh9geiweuqnc.jpeg
---

[Round Robin](https://en.wikipedia.org/wiki/Round-robin_scheduling) is a very simple but in the same time very useful algorithm,
but there is no native implementation in C# . So here is a simple but powerful and thread-safe implementation of the Round Robin algorithm in C\#.

> [Source Code](https://github.com/alicommit-malp/roundrobin)

> [Nuget](https://www.nuget.org/packages/RoundRobin/)

## Usage

```dotnet
//installation
dotnet add package RoundRobin
Install-Package RoundRobin
```

```c#
var roundRobinList = new RoundRobinList<int>(
    new List<int>{
        1,2,3,4,5
    }
);

for (var i = 0; i < 8; i++)
{
    Write($"{roundRobinList.Next()},");
}

//result
//1,2,3,4,5,1,2,3,

```

Also you can increase/decrease the weights, by doing so you will be able to increase/decrease the priority of an element in the Round Robin list 

```c#
var roundRobinList = new RoundRobinList<int>(
    new List<int>{
        1,2,3,4,5
    }
);

//the weight of the element 1 will be increase by 2 units
roundRobinList.IncreaseWeight(element:1, amount:2);

for (var i = 0; i < 10; i++)
{
    Write($"{roundRobinList.Next()},");
}

//result
//1,1,1,2,3,4,5,1,1,1
```

Enjoy coding :)
lubuntu wifi with wicd-curses
Tags: terminal, ubuntu, network, testing
Published: 2020-01-12 11:08:26

Currently I use Lubuntu on my Acer One laptop. Being a low power, quirky 2 in 1 Windows laptop, I had pain setting up linux on this laptop. Finally I was able to get Lubuntu installed and got it working but wifi connectivity was a big problem on this laptop. The wifi that I configured at install time, ssid only works after installation and any other wifi ssid that I configure it either connects briefly or just stops connecting. I though I was the only one suffering from this problem, but after reading many ununtu forums I get the idea that Ubuntu or even Lubuntu's network manager or the whole stack is not dependable. 

After searching the internet I came across Wicd which was the most promising alternative to the default network manager in Lubuntu. But there was a problem, if I ran Wicd then Lubuntu's network manager stopped working and based on some advice should be stopped before starting wicd.

``sudo service network-manager stop``

Another problem with Wicd was that from its GUI even after setting the password key, using different WPA1/2 formats, it never worked and gave "Bad password" error. Having worked on ncurses based terminal wifi managers earlier I searched for such suitable options. Ubuntus network manager already has nmcli which helps to edit, wired and wifi network settings but given it still depended on Lubuntus network manager I did not explore it further. But wicd-curses was the right tool that I was searching for. With its easy interface I can not only select an ssid but also set the password and connect to all available wifi networks in my vicinity. Unlike wicd gui, wicd-curses worked like a charm from the terminal and even give the strength of the signal.

You can install wicd-curses with the below command
``sudo apt wicd-curses``

You can type the following command to connect.
``wicd-curses``



The final piece of the puzzle was the DNS access, once the wifi is connected through wifi, the DNS server access stops working and FireFox did not connect to most of the sites. As a solution I added google dns servers to /etc/resolv.conf to get the DNS working.

```
$ cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 127.0.0.53
nameserver 8.8.8.8
nameserver 8.8.4.4
```

Thanks to the above setup my wifi is working fine now.
React.Fragment understand with simple words
Tags: react, node, javascript
Published: 2020-01-12 10:41:46

Fragment lets you group a list of children elements without adding an extra node to the DOM.

as you know It works fine.


![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/8ut82n088t45w065w37n.png)


when you see in inspect: 
You have an additional div tag

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/pnlvmd7bjrl43oi4f5e1.png)

That why React.Fragment concept is coming to the picture:
So now it works fine
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/qsnhys3vz7pkggmdwn64.png)

when you see in inspect there is not additional div.
Bitwise Operations: Find If a Number Is a Power of Two
Tags: bitwise, binary, bits
Published: 2020-01-12 10:27:48

In this post, I'll show you how to find if a number is a power of two (2<sup>x</sup>) without using loops or math functions.

"A number is a power of two" means that it can be written as 2<sup>x</sup> where "x" is an integer. For example:

* 8 **is** a power of two = 2<sup>3</sup>
* 12 is **not** a power of two since there is no integer `x` that satisfies 2<sup>x</sup> = 8

A solution using loops will look like:

```java
while ((input != 2 && input % 2 == 0) || input == 1) {
  input /= 2;
}
return input == 2;
```

Compare to:

```java
return (num & -num) == num;
```

We achieved the same thing, with **O(1)** time complexity. Let's go through an example to feel what's going on here. 

Let our input be 8, and let's work on a binary system (assuming 32-bits). The binary representation of the number 8 is:

```
0000 0000 0000 0000 0000 0000 0000 1000
```

While -8 looks:

```
1111 1111 1111 1111 1111 1111 1111 1000
```

How did we calculate that? A good way to remember how to represent negative numbers (two's complement) is to begin from the *rightmost* bit, as long as you have 0s, proceed to the left bit, and stop when you see 1 for the first time. Leave that 1, but from now on flip every bit until you reach the *leftmost* bit (inclusive).

Now let's `&` them:

```
0000 0000 0000 0000 0000 0000 0000 1000     8
1111 1111 1111 1111 1111 1111 1111 1000 &  -8
---------------------------------------------
0000 0000 0000 0000 0000 0000 0000 1000 =   8
```

As you can see, we got input as a result! So `input & -input == input` condition is met.

Now let's consider a non-power of two number, say 7. Again, let's write it and its negative representation in binary:

```
0000 0000 0000 0000 0000 0000 0000 0111     7
1111 1111 1111 1111 1111 1111 1111 1001 &  -7
---------------------------------------------
0000 0000 0000 0000 0000 0000 0000 0001 !=  7
```

Give it a try for more examples and you'll get the general idea - If the number is a power of two, then there must be **only one bit set** in its binary representation. For example:

```
0000 0000 0000 1000 0000 0000 0000 0000 = 2^19
```

This is not the only solution, of course. Another solution using bitwise operations:

```
input & (input - 1) == 0 && input > 0
```

I'll leave it for you to verify this for the examples above, it should be straightforward.
I'm New Here
Published: 2020-01-12 10:09:13

Hi! I'm Adewale 25, I'm a just learning how to code. I'm a newbie, am learning web development. The first website I build is https://movirr.com

I hope to learn more in this wonderful community. Please how do I subscribe for daily tips? I'm new here. I'm just navigating this website pages to know more about it..

I'm Happy to be here
Hope am welcomed