teleren/devto huggingface dataset:
GitHub Actions Create: Dockerfile symlinks error
Published: 2021-12-03 22:15:11

---
title: GitHub Actions Create: Dockerfile symlinks error
published: true
date: 2021-04-09 00:00:00 UTC
tags: 
canonical_url: https://devopsjournal.io/blog/2021/04/09/GitHub-Actions-Create-Error-on-Dockerfile
---

I was building a new [GitHub Action](https://docs.github.com/en/actions/creating-actions/about-actions) today with a Dockerfile and got a strange error… `unable to prepare context: path “/action” not found.

![GitHub execution error message](https://devopsjournal.io/images/20210409/20210409_01_ErrorMessage.png)

I was using a Dockerfile in a sub directory, but the [documentation](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-docker-actions) indicates this is supported. So, what gives? Is it a mix-up of the file path? I’m testing it on Windows and can build the Dockerfile itself just fine 🤔. Tested with a backslash instead of a slash, but still an error:  
`unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /path/to/Dockerfile`  
 ![GitHub execution error message with symlinks](https://devopsjournal.io/images/20210409/20210409_02_ErrorMessage.png)

# The fix

On a hunch (this has happened before!), I changed the file ending of the Dockerfile from CRLF into LF (created the file on Windows of-course!) and… 🎉.

![Working result with a successful Docker build](https://devopsjournal.io/images/20210409/20210409_03_Working.png)

# For future reference

1. Check the line endings on your Dockerfile!
2. You can run an image in your GitHub Action in a subdirectory by using the correct path to it. It needs to be relative to the action.yml file!

```
# action.yml
name: 'Octogotchi'
description: 'Octogotchi'
branding:
  icon : alert-circle
  color: blue
runs:
  using: 'docker'
  image: 'action/Dockerfile'

```
DevOps Training in Bangalore
Tags: devops, devopstraining, devopscertification, devopscourse
Published: 2021-04-09 06:57:05

DevOps is one of the trending technology being used by most corporate companies. It is made from the combination of two words Development and Operations which basically means bringing together the software development and IT operations team of the organization. It primarily focuses on the process of continuous integration for a better and faster software development process. There is a huge demand for DevOps engineers in the corporate world and undergoing the [DevOps training in Bangalore](https://www.gamutgurus.com/devops-training) will be beneficial for someone who is willing to make their career in this field.
Should I learn TypeScript Before React
Tags: typescript, react, beginners
Published: 2021-04-09 06:16:43

</h2>Should I learn TypeScript before react?</h2>

No. You don’t need to learn Typescript to use React.

TypeScript is intended for large-scale application development and transcompiles to JavaScript.

Since TypeScript is a superset of JavaScript, any current JavaScript programs are valid TypeScript programs as well.

Neither of these are at all connected. In reality, combining <a href="https://codersera.com/blog/how-to-use-typescript-with-react/">TypeScript with React</a> can be difficult since, unlike Angular and TypeScript or Vue and TypeScript, they were not necessarily designed with each other in mind, since Facebook, and thus React's key proponents, use Flow as their primary "gradual typing" solution. However, there is a nice chunk of community interest, so it should not be impossible.

<b>Why should you learn TypeScript?</b>

Code that is much more predictable and simpler to debug. TypeScript provides the required safeguards for organizing the code and catching errors of all kinds before they are executed.

Static types allow some fantastic tools. Tools for improving the development experience by the code uniformity and quality, as well as saving development time. TSLint, tsserver—which is incorporated into most TS-enabled editors and awesome-typescript-loader are examples of such tools.

The opportunity to use potential features now. TypeScript is capable of automatically closing the feature gap between JavaScript versions (using transpilation). That is, you can concentrate on working with the most recent, cutting-edge features without thinking about whether your code would run on older browsers and computers.

Harmonious teamwork on a growing codebase. Via well-defined interfaces, it combines code and introduces structure.

The key reason to learn TypeScript is code completion and familiarity for Java and C# developers. All of the other touted benefits are either exaggerated or, in my opinion, outweighed by the drawbacks.

Unit tests are more effective than typing at removing errors, and they must also be written while using Typescript.

Big projects require modularity rather than typing. Typescript will make it easier to build large inheritance trees that will land you in hot water. It's a different kind of trouble than with vanilla js, but it's always trouble.
Make Your Own ToDo App with JavaScript!
Tags: html, css, javascript, tutorial
Published: 2021-04-09 06:13:55

Don't forget to Subscribe to my YouTube channel to learn programming fast and free: https://www.youtube.com/channel/UCFzeA3xC-_i4ZT-XwcwsJxQ

Here is the code:
```HTML
<!DOCTYPE html>
<html>
<head>
	<title>To Do List</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://kit.fontawesome.com/007b767ad0.js" crossorigin="anonymous"></script>
<style>
	* {
		margin: 0;
		border: 0;
		font-family: sans-serif;
	}
	h1 {
		margin-top: 10px;
		position: absolute;
		color: blue;
		font-size: 300%;
		width: 100%;
		text-align: center;
	}
	.inp {
		position: absolute;
		top: 13%;
		left: 50%;
		transform: translate(-50%, -13%);
		width: 70%;
		align-items: center;
	}
	input {
		border: none;
		border: 2px solid blue;
		padding: 10px;
		border-radius: 20px 0px 0px 20px;
		outline: none;
		border-right: none;
		color: grey;
		font-size: 20px;
		width: 70%;
	}
	button {
		background: none;
		border: none;
		width: 15%;
		height: 20%;
		border: 2px solid blue;
		border-radius: 0px 20px 20px 0px;
		outline: none;
		padding: 10px;
		font-size: 20px;
		color: blue;
		z-index: 9999px;
		cursor: pointer;
		transition: 0.5s;

	}
	button:hover {
		background: blue;
		color: white;
		transition: 0.5s ease-in-out;
	}
	.to-dos {
		position: absolute;
		top: 26%;
		left: 50%;
		transform: translate(-50%, -50%);
		color: grey;
		font-size: 30px;
		cursor: pointer;
	}
</style>
</head>
<body>
<h1>iDo List</h1>
<div class="inp">
<input id="inputField" type="text" placeholder="I want to do..."><button id="addToDo"><i class="fas fa-plus"></i></button>
</div>
<div class="to-dos" id="toDoContainer">
	
</div>

<script>
	let addToDoButton = document.getElementById('addToDo');
	let toDoContainer = document.getElementById('toDoContainer');
	let inputField = document.getElementById('inputField');

	addToDoButton.addEventListener('click', function(){
		var paragraph = document.createElement('p');
		paragraph.classList.add('paragraph-styling');
		paragraph.innerText = inputField.value;
		toDoContainer.appendChild(paragraph);
		inputField.value = '';
		paragraph.addEventListener('click', function() {
			paragraph.style.textDecoration = 'line-through';
		})
		paragraph.addEventListener('dblclick', function() {
			toDoContainer.removeChild(paragraph);
		})
	})
</script>
</body>
</html>
Bitwise operations in Java
Published: 2021-04-09 06:06:49

### Bitwise complement
Using the symbol ~ you can get the bitwise complement of an integer.
It will reverse each bit of the binary representation including the sign.
```java
int a = 2; // binary 0,00..10 (4 byte signed binary representation)
int b = ~a; // returns -3 -> binary 1,11...01 (sign changed and each bit reversed)
```

### Bitwise AND, OR, XOR
```java
int a = 3; //     011 
int b = 5; //     101
int c = a & b; // 001 -> 1 if both bits are 1
int d = a | b; // 111 -> 1 if either it is 1
int e = a ^ b; // 110 -> 1 if both bits are different
```

### Shifting bytes
1. Signed left shift - "<<" - shift each bit to the left. Add 0s to the empty space on the right.
2. Signed right shift - ">>" - shift each bit to the right. Add 0s/1s (depending on sign, 0 for positive and 1 for negative numbers) to the empty space on the left.
3. Unsigned right shift - ">>>" - shift each bit to the right. Add 0s to the empty space on the left. For negative numbers, this means that they will be converted to positive.

Some examples:
```java
int a = -3; //      1111...11011 
int b = 5; //       0000...00101
int c = a << 1; //  1111...10110
int d = b << 2; //  0000...10100
int e = a >> 2; //  1111...11110
int f = b >> 2; //  0000...00001
int g = a >>> 2; // 0011...11110
```
Day 26 of 100 Days of SwiftUI
Tags: swift, 100daysofcode
Published: 2021-04-09 05:51:59

I just completed day 26 of 100 days of SwiftUI. Today, I started working on the Better Rest app. Better rest app is an app that uses machine learning to determine the right amount of sleep coffee drinks need per day. I was able to learn about two new SwifUI views. The stepper and the date picker view. A stepper is a view with - and + button that can be tapped to select a precise number.
I also created a machine learning model using Create ML.
How to fix dictionary access bugs in Python
Tags: python, programming, dict, debugging
Published: 2021-04-09 05:50:21

In this post I am going to discuss how accessing a value in a `dict` can easily introduce a bug in your code and how to fix it.

# Access
One of the most common scenarios with dictionaries is accessing a value. 

``` python
value = my_dict[key]
```

**Problem**: If `key` doesn't exist in `my_dict`, the code will raise a `KeyError`

**Solution**: To avoid this scenario you have three options:
1. Check if `key` exists before accessing

    ``` python 

        if key in my_dict:
           value = my_dict[key]

    ```

2. Wrap the access in `try-except` block

    ``` python

        try:
            value = my_dict[key]
        except KeyError:
            ...

    ```


3. Use Python's [get](https://docs.python.org/3/library/stdtypes.html#dict.get) function to avoid checking for `key` in `dict` 

    ``` python

        value = my_dict.get(key)

    ```

Since, `get` option (3) looks the neatest, I tend to use that the most. 

Now, suppose for a function I am writing, I am accessing a value from `dict` but I only want to proceed if the given key exists in the `dict`. 

I would write something like this:

``` python
value = my_dict.get(key)
if not value:
    raise MyError('Found bad key')

# continue with code 
```

At first glance, the code looks fine, but I have introduced a bug in it. 

Let me illustrate with an example:

``` python
# Assume my_dict as:
my_dict = {
    'key1': 'value1',
    'key3': [],
}
```

Key | Behavior | Expected?
--- | --- | ---
key1 | Regular code execution | Yes
key2 | raises `MyError` | Yes  
key3 | raises `MyError` | No 

- `key2` raises the exception since `get` function will return `None` by default for non-existing keys. 

- `key3` exists in the `dict` however my code will still throw an error because `if not []` is also `True`, leading to unintentional behavior. 

## Quick Bad Fix 
Reading points about `key2` and `key3` from above, modifying the validation condition seems like the most obvious fix:
``` python
value = my_dict.get(key)
if value is None:
    raise MyError('Found bad key')
```

This, however, only fixes one symptom/effect of the bug that is when the value is an empty data type like `''` or `[]`. If the value in `my_dict` is `None` the above code will still raise the error.

## Fix

Before writing a fix for your code, it is usually a good idea to think about the root cause of the bug, rather than the symptoms that are showing up. In our case, it was not the `if` condition that was causing the bug - it was the `get` function. 

> I only want to proceed if the given key exists in the `dict`

To encode the described behavior the correct code block would look something like this:
``` python 
if key in my_dict:
    value = my_dict[key]
    # rest of code
else:
    raise MyError('Found bad key') 
```

# Learning 
- Capturing intent is critical in writing robust code.
- First step to fixing bugs should be to list assumptions and work from there.
Should you pick C# over JS? Maybe.
Tags: dotnet, blazor, csharp
Published: 2021-04-09 05:48:22

As a new developer people tend to steer you towards Python or to an even greater degree, JavaScript. 

I know this to be the case because I’ve done this myself. But I think I’ve had a change of heart. 

You see the barrier to entry with JavaScript is VERY low. Technically all you need is VSCode and a Web Browser. Both free and bot available on almost every OS. 

Tip: if you setup VSCode in the cloud like I describe here:

- https://youtu.be/zQE13HTocpU

you can literally code on a tablet. 

When I was first exposed to Microsoft and dotnet back in 2004 there was an extremely high barrier to entry. You had to have a MSDN subscription, (which was $3000-5000 per year). 

But today Microsoft has really changed their tune. You can get a free community edition of Visual Studio, you can sign up for the free tier on Azure and even DevOps is free up to a certain number of users. 

Windows 10 is more open than ever, dotnet is cross-platform, etc. So what is the barrier to entry like now? I would say it’s about the same as with JavaScript. You have a choice of free IDEs and free hosting. 

So now this is where people argue that “JavaScript” is easier to learn. But is it though? I’ve spent a lot of time with both and I have to say that the learning curve with C# might be just a little bit steeper but once you learn the basics you can advance at the same rate as someone learning JavaScript.

One thing that I had forgotten about since I hadn’t done a great deal of dotnet development in almost 5 years was how much the IDE assists you. I can create a Model with 20 properties in about 10 minutes. The `prop` snippet is your friend.

I never really feel at home in a JavaScript codebase but I dove into a fairly complex ASP.NET backend project recently without having done much in over 5 years and everything was still accessible to me. I still had the muscle memory.

I think one of the Pros (though it could be considered a con by some), is the fact that the C# language itself doesn’t seem to be evolving as rapidly as JavaScript. It’s more “mature” if you will. Maybe that has more to do with the fact that its highly structured.

One of the things that struck me as funny when I came back to dotnet was the fact that if you search online for how to do something the C# code snippets you find are going to be fairly similar. Whereas, with JavaScript you can find 100 posts with 100 different ways to do things.

I think a lot JavaScript development is, “let’s see how clever I can be” instead of, “let’s see how readable and robust I can make this.”

These are my personal opinions and I’m sure this “hit-piece” is going to cause some controversy but I think if you commit to taking a look at the “new” dotnet you’ll be pleasantly surprised.

Thanks for reading and that's all y'all.
Maintaining Multiple Postgres Version
Tags: postgres, database
Published: 2021-04-09 05:44:59

Sometimes we need to have different Postgres versions in our local machine. We just need to know the port the versions are running and we are good to go.

For this let's install two versions of Postgres 9.6 and 11 via commands

>*Install Postgres 9.6*
```
sudo apt-get install postgresql-9.6 
```

>*Install Postgres 11*
```
sudo apt-get install postgresql-11
```

>*Lists the postgres clusters*
```
pg_lsclusters
```

>*start-stop the clusters*
```
sudo pg_ctlcluster 9.6 main start
sudo pg_ctlcluster 9.6 main stop
sudo pg_ctlcluster 11 main start
sudo pg_ctlcluster 11 main stop
```

>*connects to 9.6*
```
sudo -i -u postgres psql -p 5432
```

>*connects to 11*
```
sudo -i -u postgres psql -p 5433
```

By changing the port only we can restore and dump db according to postgres version
>*dumps and restores 9.6*
```
pg_dump --host localhost --port 5432 --username "postgres" --encoding UTF8 --verbose --file "{{db_backup_path}}" "{{db_name}}"
pg_restore --host 127.0.0.1 --port 5432 --username "postgres" --dbname "{{db_name}}" --verbose "{{db.backup}}"
```

>*dumps and restores 11*
```
pg_dump --host localhost --port 5433 --username "postgres" --encoding UTF8 --verbose --file "{{db_backup_path}}" "{{db_name}}"
pg_restore --host 127.0.0.1 --port 5433 --username "postgres" --dbname "{{db_name}}" --verbose "{{db.backup}}"
```
Why SAP on azure
Tags: azure, sap, question
Published: 2021-04-09 05:40:38

Hey we are Testing successfully to spin up an SAP System in the Azure Cloud.

IT works very well for now. And all tecs are excited 😉.

But the central sales comes up with the question

"Why in Azure?"

I think I cannot come up with the Argument that the Azure Ad Support will be excellent. That is not a Management descission.

So do you know some more arguments that will be Pro for Azure?

I am very excited about your Suggestion. Blogpost are also welcome 😊
49 Days of Ruby: Day 13 - Conditional Statements, Part II
Tags: ruby
Published: 2021-04-09 05:37:50

---
title: 49 Days of Ruby: Day 13 - Conditional Statements, Part II
published: true
description: Join us on a 49 day learning journey through Ruby!
series: 49 Days of Ruby
tags: #ruby
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/9m73qaetuse3nm3y3it8.png
---

**Welcome to day 13 of the 49 Days of Ruby! 🎉**

Yesterday, we dived into building conditional statements with if/else. This type of logic in our code allows us to make branches of possibilities. *If there are green apples, buy them, else, buy the red apples.*

Today, we're going to add another layer to the if/else that will give us the power to introduce even more flexibility to our conditional statements! I'm talking about the `elsif`.

## What Is Elsif?

If we continue our example of buying apples in the grocery store, we can demonstrate the utility of the `elsif`:

*If there are green apples, buy them, `elsif` there are red apples, buy them, else, go to the next store.*

The introduction of the `elsif` brings the possibility of numerous branches to our conditional statements. Whereas, with only a single `else` you are limited to one other option, with the `elsif` you can build multiple ones.

## Elsif in Ruby

How do we use this in Ruby?

Let's take a look at an example!

```ruby
morning_coffee = 'yes'

if morning_coffee == 'no'
  puts 'Drink your coffee!'
elsif morning_coffee == 'not ready yet'
  puts 'Prepare your coffee!'
elsif morning_coffee == 'yes'
  puts 'Enjoy your day!'
else
  puts 'Do you even like coffee?'
end
```

Did you notice in the above example that we used two separate `elsif` clauses? That's because you can use as many as you need. We end the condition with a final `else` that acts as a sort of catch-all in case `morning_coffee` is not equal to any of the possibilities in the `elsif` clauses.

Now that you know about the `elsif` what can you do with it? Tomorrow we continue the journey, and in the meantime, share your own learning with the community!

**Come back tomorrow for the next installment of 49 Days of Ruby! You can join the conversation on Twitter with the hashtag [#49daysofruby](https://twitter.com/hashtag/49daysofruby).**
LeetCode 140. Word Break II
(javascript solution)
Tags: algorithms, javascript
Published: 2021-04-09 04:08:26

###Description:
Given a string s and a dictionary of strings wordDict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences in any order.

Note that the same word in the dictionary may be reused multiple times in the segmentation.

###Solution:
Time Complexity : O(wordDict.length^s.length)
Space Complexity: O(s.length)

```javascript
var wordBreak = function(s, wordDict, memo={}) {
    // Return already solved for sentance
    if(memo[s]!==undefined) return memo[s]
    // Base case of yet unsolved sentance
    if(s.length===0) return ['']
    
    const output = []
    
    for(const word of wordDict) {
        if(s.indexOf(word)===0) {
            const suffix = s.slice(word.length)
            // All different sentances to make the suffix
            const suffixWays = wordBreak(suffix, wordDict, memo)
            // Add the word to all the different sentance combinations
            const targetWays = suffixWays.map(way => word + (way.length ? ' ' : '') + way)
            output.push(...targetWays)
        }
    }
    
    memo[s] = output
    return output
}
```
How to Deploy a VuePress Project in China?
Tags: vuepress, vue, webdev, china
Published: 2021-04-09 03:54:57

---
canonical_url: https://www.21cloudbox.com/solutions/how-to-deploy-vuepress-project-in-production-server.html
---
# What is VuePress?
VuePress is a static site generator based on [Vue.js](https://launch-in-china.21yunbox.com/solutions/how-to-deploy-vuejs-project-in-production-server.html). It can be used to make technical documents, personal blogs, etc.

21YunBox provides a very simple VuePress deployment method. You can deploy on the 21YunBox in a **static site** environment.

# How to Deploy VuePress?
1. Register as a [21YunBox member](https://www.21yunbox.com/u/signup/)
1. In Gitee Fork [VuePress Example](https://gitee.com/eryiyunbox-examples/vuepress-starter)
2. Create a **cloud service** on 21YunBox, and allow 21YunBox to access your code base
3. Create with the following configuration


| Environment           | `Static Site`             |
| --------------------- | :------------------------:|
| **Build Command**     | **`yarn && yarn build`.** |
| **Release Directory** | **`docs/.vuepress/dist`** |

If the description of the above text is not clear, refer to watch this[step by step video](https://www.bilibili.com/video/BV1ja4y1W7Gb):

# Why Choose 21YunBox?

> [21YunBox](https://www.21cloudbox.com/) specializes in helping foreign businesses to host their websites in China. We deliver everything you and your team needs to build, run, and scale websites and apps in China.

To learn about the differences between 21YunBox and these foreign (outside of China) cloud service platforms, please refer to:

* [21YunBox vs Heroku](https://launch-in-china.21yunbox.com/solutions/how-to-speed-up-heroku-in-china.html)
* [21YunBox vs Netlify](https://launch-in-china.21yunbox.com/blog/solutions/alternatives-to-netlify-in-china.html)
* [21YunBox vs Vercel](https://launch-in-china.21yunbox.com/solutions/how-to-speed-up-vercel-in-china.html)
* [21YunBox vs Gatsby Cloud](https://launch-in-china.21yunbox.com/solutions/how-to-speed-up-gatsby-cloud-in-china.html)
* [21YunBox vs Github Pages](https://launch-in-china.21yunbox.com/solutions/how-to-speed-up-github-pages-in-china.html)
* [21YunBox vs Surge.sh](https://launch-in-china.21yunbox.com/solutions/how-to-speed-up-surgesh-in-china.html)
* [Compare in terms of function and price: 21YunBox vs Heroku, Netlify, Vercel](https://www.21yunbox.com/compare-others/)

<br>
*This article's content originated [here](https://launch-in-china.21yunbox.com/solutions/how-to-deploy-vuepress-project-in-production-server.html)*

*For additional detail and future modifications, refer the original post.*