teleren/devto huggingface dataset:
Weekly Challenge 090
Tags: perl, theweeklychallenge, perlweeklychallenge
Published: 2020-12-13 07:58:40

[Challenge 090](https://perlweeklychallenge.org/blog/perl-weekly-challenge-090/)

# Champion

Mohammad awarded me Team PWC champion for last month. I was totally surprised when reading this weeks challenge to find this out. I feel honoured to have joined the other [champions](https://perlweeklychallenge.org/champions/).

And a big thanks to Randi Comrie and [Perl Careers](https://perl.careers/) team for the reward.

# Task #1 › DNA Sequence

## Task

Write a script to print nucleobase count in the given DNA sequence. Also print the complementary sequence where Thymine (T) on one strand is always facing an adenine (A) and vice versa; guanine (G) is always facing a cytosine (C) and vice versa.

## My solution

I'll admit I know nothing about DNA sequencing, so I took this challenge as a purely programmatic one. The task can be broken down to two parts.

1. To display the count, I use a `foreach` loop to count each character, and another to display the count of each nucleobase.
1. To calculate the complementary sequence I use the [tr function](https://perldoc.perl.org/functions/tr) to reverse the characters in the string, and display it.

## Example

```
» ./ch-1.pl GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG
Nucleobases count
T: 22
A: 14
G: 13
C: 18

Complementary sequence is 'CATTTGGGGAAAAGTAAATCTGTCTAGCTGAGGAATAGGTAAGAGTCTCTACACAACGACCAGCGGC'
```

# Task #2 › Ethiopian Multiplication

## Task

You are given two positive numbers `$A` and `$B`.

Write a script to demonstrate [Ethiopian Multiplication](https://threesixty360.wordpress.com/2009/06/09/ethiopian-multiplication/) using the given numbers.

## My solution

This was a really interesting challenge for two reasons. Firstly, I learnt a new way to multiple numbers and the way that it works. Secondly was the way to show the result without using fonts.

For this task I use a loop to build an array starting with the two numbers, and then divided the first number (dropping the remainder) and multiplying the second. We end that loop when the first number is 1.

I then display each row with the two numbers with `>` symbol to indicate whether the first number is odd. Finally, I add up all the second numbers where the first number is odd, and display the result.

## Examples

```
» ./ch-2.pl 12 14
  12 ×  14
   6 ×  28
>  3 ×  56
>  1 × 112

Result is: 56 + 112 = 168

» ./ch-2.pl 25 31
> 25 ×  31
  12 ×  62
   6 × 124
>  3 × 248
>  1 × 496

Result is: 31 + 248 + 496 = 775
```
I've created the online tools platform
Tags: ocr, macaddress, qr, pdf
Published: 2020-12-13 07:49:34

So, as many other developers, I've many tools to be used daily, such as [JSON Viewer](https://devtools360.com/en/json/viewer) or hashing strings :)

My list of daily used tools is growing with some limitation on some tools online, as a result, I've decided to build my own tool and share it with the community.

After a few days of work, I've launched the initial version of devtools360.com intending to provide more than 100 useful tools for different use cases.

Since then I'm adding tools every week, for instance, the most recent tool was the [OCR Tools](https://devtools360.com/en/ocr/choose), [Mac address Lookup](http://localhost/devtools360/public/en/macaddress/lookup) tool, and [website DNS checker](https://devtools360.com/en/websites/dns) tool.

I thought it would be better to get dev. community feedback on what has been done, and what should be done next to make this platform more convenient and easier to use.

So please let me know your thoughts :)
NULL VS UNDEFINED IN JS
Tags: javascript, null, undefined, jsconcepts
Published: 2020-12-13 06:44:28

![Header Image](https://dev-to-uploads.s3.amazonaws.com/i/pzs64gpjc6ggw9ncq1mc.PNG)


## NULL
### What is null?
> ### null is an assignment value. It can be assigned to a variable as a representation of no value:

There are two features of null you should understand:
- `null `is an empty or non-existent value.
- `null `must be assigned.

In the example below, we are assigning value to null.
```
var x = null
console.log(x);
// null 
```
- null expresses a lack of identification, indicating that variable points to no object
- When you assign null to a variable, you are declaring that this value is explicitly empty.

## UNDEFINED
### What is undefined?
> ### Undefined usually means a variable has been declared, but not defined.
- Another common scenario, where you will encounter an undefined is while trying to access a property of an object that doesn’t exist.
```
var z = {};
console.log(z.value);
// undefined
```
- To summarize,
   - An object is declared but not defined/initialized.
   - Accessing an object property or an array index that does not exist.
   - Calling a function, without it’s required function parameters.

## What is similar?
- Both `null `and `undefined `are primitive values in JavaScript. 
- Another thing to note is that when comparing null and undefined they are equal. 
```
null == undefined
// true
```
- This is because both of them are considered falsy values in JavaScript.

## Differences `null vs. undefined`

### Arithmetic Operations

> ### Another interesting difference to note is when arithmetic operations are performed with null vs. undefined. 
> ### Arithmetic operations with a null value will result in integer value while any arithmetic operation with undefined will result in the value of the variable being changed to `NaN`.
```
var x = 5 + null;
console.log(x);
// 5

var y = 5 + undefined;
console.log(y);
// NaN 
```

## Equality
### Typeof Null and Undefined
- Interestingly enough, when using typeof to test null, it returns an object:
```
console.log(typeof(undefined));  //"undefined"
console.log(typeof(null));       //"object"
```
### Comparison Using Abstract and Strict Equality
- Since these are different data types, if we compare them with strict equality ===, we get false.
- But if we compare them with abstract equality ==, we get true.
```
console.log(null === undefined)    //false
console.log(null == undefined)     //true
console.log(null !== undefined)    //true
```

## Summary
- null is an assigned value. It means nothing.
- undefined typically means a variable has been declared but not defined yet.
- null and undefined are falsy values.
- null and undefined are both primitives. However, an error shows that typeof null = object.
- `null `!== `undefined `but `null` == `undefined`.
Speed up your local WordPress development with Docker on Windows
Tags: docker, wordpress, container
Published: 2020-12-13 07:18:27

If you prefer watching the experiment, here is the video:

https://www.youtube.com/watch?v=SET8P5OeBfo

Most of us when beginning developing with Docker usually mount from a local path to a path inside the containers since it's the simplest solution. However, this simplicity comes with a cost:

Speed!

Especially when you are developing on Windows. 

You see, Docker on Windows, despite all the efforts cannot compare to what it's like on Linux. I have my WP sites on Linux and it loads super fast. 

From what I learn, mounting the local directory to a container on Windows can make app loads very slow, not just WordPress.

So, I decided to give it a try: move codes, database to a volume.

And guess what? Speed improved immensely.

## The old setup

Here is the old setup:

```
version: '3.8'

services:
  wp:
    image: webdevops/php-apache:7.4
    container_name: wp
    restart: always
    volumes:
      - D:\Data\dev\wordpress\main\:/app
    ports:
      - 8888:80
  db:
    image: mariadb:10.5.3
    container_name: db
    restart: always
    volumes:      
      - ./db:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: root

```
You see the problem? Both db and the WordPress code are mounted from a local directory on the host machine. Thus, the site loads super slow.

## The new setup

```
version: '3.8'

services:
  wp:
    image: webdevops/php-apache:7.4
    container_name: wp
    restart: always
    volumes:
      - wordpress:/app

    ports:
      - 8888:80
  db:
    image: mariadb:10.5.3
    container_name: db
    restart: always
    volumes:
      - db:/var/lib/mysql

    environment:
      MYSQL_ROOT_PASSWORD: root

volumes:
  db:
  wordpress:
```
Now, I created two volumes, one for db and one for the WordPress code. Guess what? The site isn't slow anymore.


Give it a try
My idea for the Hackathon
Tags: dohackathon
Published: 2020-12-13 06:55:22

For this Hackathon I'm thinking of creating something for the "Built for Business" category.

## What I'll build
An auto repair shop management system. I know a few local businesses that might make use of something like this.

For the MVP, the app will provide a simple admin interface allowing users to: 
- view various metrics on a dashboard
- manually add staff members / import from csv or excel
- add contacts (who can either be clients or suppliers)
- add vehicles (attached to clients)
- add jobs (attached to clients and assigned to staff members)
- generate invoices for jobs based on the labor and materials required
- add appointments with clients
- send emails to contacts

## Stack
Django + Postgres

## Repo
[auto-repair-saas](https://github.com/wangonya/auto-repair-saas)
Advent of Code 2020: Python Solution Day 13
Tags: adventofcode, challenge, python, algorithms
Published: 2020-12-13 06:48:51

This is a day 13 and again I forgot about the challenge but at last, I did it. First part was easy but for the second part I took a help from Reddit comment <a class="embedly-card" href="https://www.reddit.com/r/adventofcode/comments/kc4njx/2020_day_13_solutions/gfngjda">here.</a>
<script async src="//embed.redditmedia.com/widgets/platform.js" charset="UTF-8"></script> I have uploaded all my 2020 solution on [this repository](https://github.com/q-viper/Adevent-Of-Code-2020).

**Please share your solution too.**

## Part 1
```python
with open("day13.txt", "r") as fp:
    lines = fp.readlines()
timestamp = int(lines[0][:-1])
bus_ids = [int(x) for x in lines[1].split(",") if x.isdigit()]

import numpy as np
timestamps = range(timestamp-50, timestamp+50)
valid = np.inf
diff = np.inf
bus_id = np.inf

for time in timestamps:
    for bus in bus_ids:
        if time%bus==0:
            d = abs(time-timestamp)
            if time>timestamp and d < diff:
                valid = time
                diff = d
                bus_id = bus

bus_id*(valid-timestamp)
    
```

## Second part
```python
LINES=lines
start = int(LINES[0])
busses = ["x" if x == "x" else int(x) for x in LINES[1].split(",")]

def part2():
    mods = {bus: -i % bus for i, bus in enumerate(busses) if bus != "x"}
    print(mods)
    vals = list(reversed(sorted(mods)))
    val = mods[vals[0]]
    r = vals[0]
    for b in vals[1:]:
        while val % b != mods[b]:
            val += r
        r *= b
    return val
part2()
```
Zen Music Player | Javascript Build
Tags: javascript, html, css, codenewbie
Published: 2020-12-13 06:33:03

Hey Everyone, I started with Project based learning. Idea is to build project, at every step of your learning. 
****
>
### I set myself goal:
For every weekend, I try working on new project or write a blog.
>


This weekend I bulit Music Player using Vanilla Javascript. This is how it turns out...

********

![Zen Music PLayer](https://dev-to-uploads.s3.amazonaws.com/i/ifnpgyk97l4980fi5ni0.jpg)

[Live Demo](https://zenbeats.netlify.app) 
[Source Code](https://github.com/vaishnavme/Zen-lofi-beats-player)

***********
Give it try...
If you made your version of Record player do tag me. I love to see your version.
It would really great to hear your Feedback and Suggestions 😃. 

#### Let's Connect 😄

[![Generic badge](https://img.shields.io/badge/Github-black.svg?style=for-the-badge)](https://github.com/vaishnavme)

[![Generic badge](https://img.shields.io/badge/DEV-black.svg?style=for-the-badge)](https://dev.to/vaishnavme)

[![Generic badge](https://img.shields.io/badge/Twitter-blue.svg?style=for-the-badge)](https://twitter.com/vaishnav21_?s=09)
Solving LeetCode - Length of Last Word
Published: 2020-12-13 06:32:22

# Question

Given a string s consists of some words separated by spaces, return the length of the last word in the string. If the last word does not exist, return 0.

A word is a maximal substring consisting of non-space characters only.

Example 1:
```
Input: s = "Hello World"
Output: 5
```
Example 2:
```
Input: s = " "
Output: 0
```

Constraints:

* <= s.length <= 104
* s consists of only English letters and spaces ' '


## Let's Go!

Solve by using [PREP](https://dev.to/phariale/prep-technique-for-algorithms-in-js-5b0g).
* **P** - One parameter. A string _s_
* **R** - Return number that represents length of last word in _s_
* **E** - Examples provided by question. (See Above)
* **P** - See Below

```javascript
var lengthOfLastWord = function(s) {
    // remove whitespace & split s by empty space ' ' 
    // return the length of the last element of the array or 0
};

```

Translate into code...

```javascript
var lengthOfLastWord = function(s) {
    // remove whitespace & split s by empty space ' ' 
    const words = s.trim().split(' ')
    // return the length of the last element of the array or 0
    return words.length > 0 ? words[words.length-1].length : 0
};

```

### Conclusion

& Remember... Happy coding, friends! =)

#### Sources
* https://leetcode.com/problems/length-of-last-word/
While Loop | Shell Scripting 
Tags: linux, bash, tutorial, beginners
Published: 2020-12-13 05:59:27

**This is a multipart blog article series where I am going to explain the concepts of shell scripting and how to write a shell script in Linux, UNIX or Mac based systems. You can also follow this tutorial blog using windows but for that you have to install a bash from.**

_In this article we will learn about while loop. How to use while loop and what are it’s functionalities._

- The syntax of while loop
```shell
while [condition]
do
	command1
	command2
	command3
done
```

- If we want to increment the value of the variable we can do that in this way `n=$(( n+1 ))` or `(( n++ ))` or `(( ++n ))`
- First the condition we be checked in the while loop. If the condition is true than the part written after do will be executed.
- It will execute till the condition becomes false.
- And at last `done` means that while loop has ended.

[Reference code file for this article](https://github.com/rahulMishra05/shell-scripting/blob/main/video15.sh)

_So this was about basic of while loop. Hope you liked it and learned something new form it._

If you have any doubt, question, quires related to this topic or just want to share something with me, than please feel free to contact me.

### 📱 Contact Me

[Twitter](https://twitter.com/r_mishra10)
[LinkedIn](https://www.linkedin.com/in/rahul-mishra-66210b185)
[Telegram](https://t.me/rahul_mishra10)
[Instagram](https://www.instagram.com/rahul_mishra10/?hl=en)

### 📧 Write a mail
<rahulmishra102000@gmail.com>

#### 🚀 Other links

[GitHub](https://github.com/rahulMishra05)
[HackerRank](https://www.hackerrank.com/rahulmishra10201)
fullstacker needed
Published: 2020-12-13 05:58:46

Are you a Passionate Full-Stacker(5 Years Exp. Min.)?

Looking for a technical co-founder to be a part of a small team with an exciting idea and prototype for a unique next-gen social community platform.

We are motivated and looking forward to turning our dream into reality.

If you think you're up to the challenge, please contact us.
please send us an email to shay.lom.tamir@gmail.com

Simplicity is the ultimate sophistication .
the world has changed and so should we.
DOM Blog
Published: 2020-12-13 05:47:37

DOM (Data object model) is a data structure/standard to automatically created by the browser whenever a web page is created which allows JavaScript to dynamically interact and update it. 
[Link]
With DOM any of the webpages elements or properties can be changed dynamically. Methods are actions that can be performed on HTML elements in order to modify them. For example `getElementById` is used to access elements and then perform further actions on them such as `innerHTML` to change its contents. Similarly we can use `attribute` to change the attribute value of an element or "property" to change its style.

With DOM we can also add event handlers which allow certain actions to be done when some element is interacted with.
Array variable | Shell Scripting 
Tags: linux, bash, devops, tutorial
Published: 2020-12-13 05:40:46

**This is a multipart blog article series where I am going to explain the concepts of shell scripting and how to write a shell script in Linux, UNIX or Mac based systems. You can also follow this tutorial blog using windows but for that you have to install a bash from.**

_In this article we will learn about array in shell scripting. And see how to perform different operations on array._

1. We can declare array in this way `<name_of_array_variable>=(“Ubuntu” “Windows” “Kali”)`. By this way we can declare an array and store some value in it.
2. To print all the values of array just write this command `echo ${<name_of_array_variable>[<index_location>]}`. _For example:_ `echo ${os[@]}`
3. If you want to print a specific value of the array than you can use this command `echo ${<name_of_array_variable>[<index_location>]}`. _For example:_ `echo ${os[1]}`
4. If you want to print the index of the array than you can do it like this `echo ${!<name_of_array_variable>[@]}`. _For example:_ `echo ${!os[@]}`
5. If you want to pint the length of an array than you can do it like this `echo ${#<name_of_array_variable>[@]}`. _For example:_ `echo ${#os[@]}`
6. We can add elements to array in this way `<name_of_array_variable>[index_location]=”<value>”`. _For example:_ `os[3]=’mac’`
7. We can update the data of an array in the same way `<name_of_array_variable>[index_locaiton]=”<value>”`. _For example:_ `os[0]=’mac’`
8. If you want to remove an element from an array then you can do it by using `unset` command like this `unset <name_of_array_variable>[index_location]`. _For example:_ `unset os[2]`

[Reference code file for this article](https://github.com/rahulMishra05/shell-scripting/blob/main/video14.sh)

_So this was all about array in shell scripting. Hope you liked it and learned something new from it._

If you have any doubt, question, quires related to this topic or just want to share something with me, than please feel free to contact me. 

### 📱 Contact Me

[Twitter](https://twitter.com/r_mishra10)
[LinkedIn](https://www.linkedin.com/in/rahul-mishra-66210b185)
[Telegram](https://t.me/rahul_mishra10)
[Instagram](https://www.instagram.com/rahul_mishra10/?hl=en)

### 📧 Write a mail
<rahulmishra102000@gmail.com>

#### 🚀 Other links

[GitHub](https://github.com/rahulMishra05)
[HackerRank](https://www.hackerrank.com/rahulmishra10201)
Effective Java! Return Empty Collections or Arrays, Not Nulls
Tags: java, effective, null, architecture
Published: 2020-12-13 05:21:22

---
title: Effective Java! Return Empty Collections or Arrays, Not Nulls
published: true
description: A dive into chapter 54 of Effective Java
tags: java, effective, null, architecture
series: Effective Java Review
canonical_url: https://blog.scaledcode.com/blog/effective-java/return_empty_not_null/
---

It is not uncommon to see code like the following:
```java
private final List<Chesse> cheesesInStock = ...

public List<Cheese> getInStockCheeses() {
  return cheesesInStock.isEmpty() ? null : new ArrayList<>(cheesesInStock);
} 
```

A use of method would looks something like:

```java
List<Cheese> cheeses = getInStockCheeses();

if (cheeses != null && cheeses.contains(Cheese.CHEDDAR)) {
  System.out.println("We have cheese in stock");
}
```

While the above code definitely works it requires more of the consumers than we should be requiring. If a consumer of your class doesn't realize they should be handling null they will have a subtle bug that they may not realize for some time because the function may respond with one or more objects in the list most of the time. A better way of handling this is simply returning an empty collection in cases where the source collection is empty. The change to the above code would look something like:

```java
public List<Cheese> getInStockCheeses() {
  return new ArrayList<>(cheesesInStock);
} 
```

An argument one might have against doing the above is the creation of a new collection on every call, even when it's empty. In extremely performance critical applications this could have a negative effect. In cases like this we can make a slight switch that can keep the improved efficiency. 

```java
public List<Cheese> getInStockCheeses() {
  return cheesesInStock.isEmpty() ? Collections.emptyList() : new ArrayList<>(cheesesInStock);
} 
```

The above will return the same empty list every time that it returns it. This does make the code a little more complex so if you aren't in a performance critical application it may not be worth making the above change.

In cases where we are returning an array we apply the same concept of returning the array, empty or not instead of returning null. Thus the code would look something like:

```java
public Cheese[] getInStockCheeses() {
  return cheesesInStock.toArray(new Cheese[0]);
} 
```

Further optimizations to the above would be to allocate the empty cheese array and reuse that same empty array each time. Something to note is that you shouldn't allocate array to the correct size when making this call. Although it may feel like an optimization it actually hurts performance. 

By making this slight change to our code we can make the job of our function callers easier and safer and even our internal code gets an improvement in readability. This is one of the cases where it does feel like we can have it all.
Kotlin Typealiases
Tags: kotlin, shortpost, tutorial
Published: 2020-12-13 05:20:04

Hi! As a developer on Kotlin, I usually use `typealias` functionality and I wish to share my experience with you :)

## What is it?

Typealiases (like inline classes) are the types which will be erased in runtime, but are available in coding. Compiler will use their type value to put on places in code where this typealias are called.

## Advantages

* Defining of types meaning
* Zero-cost in runtime

## Disadvantages

(Almost) absent typecheck. If you will use opposite by meaning and equal by type typaliases, compiler will not stop you

## Example

```kotlin
typealias XY = Pair<Float, Float>
typealias AbsoluteXY = XY

…

fun draw(xy: AbsoluteXY) { … }
```

In this example we used `AbsoluteXY` typealias to define that function `draw` accept absolute coords instead of relative or something else.
Change Default Web Browser App in Terminal Environment
Tags: linux
Published: 2020-12-13 05:14:32

Open link in terminal, but web browser app of your wish not run. That was annoyed, right?

Be glad cause the command `xdg-settings` is here.

Check default your web browser app.

```bash
xdg-settings get default-web-browser
```

In my case - **result**: `chromium.desktop`

In my mind app want to default is [qutebrowser](https://qutebrowser.org/).

```bash
xdg-settings set default-web-browser org.qutebrowser.qutebrowser.desktop
```

This section `org.qutebrowser.qutebrowser.desktop` i get from `/usr/share/applications/`, in this directory you can find what app of your wish.

To ensure what you set, check again with `xdg-settings get default-web-browser`.
RubyGem to fetch IPs of EC2 instances
Tags: ec2, ruby, rails, rubygem
Published: 2020-12-13 04:38:14

---
title: RubyGem to fetch IPs of EC2 instances
published: true
description: A simple ruby gem to fetch IPs of EC2 instances, developed this to fetch IPs while Capistrano Deployment of Rails application.
tags: EC2, Ruby, Rails, RubyGem
---

I wrote this gem to fetch IPs of EC2 instances during Capistrano deployment. This library fetches IPs based tags. AWS tags are kind of a cool thing available with every resource, rails application an EC2 instance can have tags like name, environment, role, etc. Use this gem to make Capistrano deployment easy.

https://github.com/neymarsabin/aws-dynamic-ip