teleren/devto huggingface dataset:
Learning Slice Notation with Python
Tags: python, beginners
Published: 2020-11-08 01:23:06

Slicing is a shortcut when you have a given array or list, and you want only a part of that. Going through a for loop or what not can take more work and slicing will take less lines.

Let's say we want 2-5 only

example:
```python
array = [1, 2, 3, 4, 5, 6]

array[1:5]
=>
[2, 3, 4, 5]
```

The slicing parameters look like so
[(start here but does not include):(number we end on does include):(optional:how many steps to take)]

The above example does not use the third parameter. If left blank, then the third parameter will default to 1.

We can use it like so

example:
```python
array = [1, 2, 3, 4, 5, 6]

array[2:6:2]
=>
[3, 5]
```
We ignore the 2 and start at 3, then we take 2 steps to include the 5, then we end there because 6 is not 2 steps from 5.

What if we ignored the first parameter?
```python
array = [1, 2, 3, 4, 5, 6]

array[:3]
=>
[1, 2, 3]
```
We would skip the first parameter of where to start so we start from the beginning and the second parameter tells us where to end, so we include everything up to where we stopped at which was 3 here.


Same idea with omitting the first 2 parameters. 
If we skip the first 2 then we would just take those steps from beginning of our input to the end.
```python
array = [1, 2, 3, 4, 5, 6]

array[::2]
=>
[2, 4, 6]
```
What I learnt this week as a web developer| Nov week 1
Tags: productivity, webdev
Published: 2020-11-08 01:07:27

+ Whole week just completed [[Bootstrap]] beginner module (2.5 hours)
+ This is what happens when you don't plan your week.
+ Posted [this](https://dev.to/deepakpoojary/css-z-index-and-stacking-order-4c32) blog on dev.to
+ Learnt a new thing called 80/20 principle in coding and you can see this [here](https://www.instagram.com/p/CHQRhcDgvLV/?igshid=1w7h2al5r17fx).
+ learnt [[Aim low principle]] (such an important one) and please watch [this](https://youtu.be/8vTiVtf8ce8) video 
+ I would highly recommend you to [[Publicize your days, weeks]] so that you get accountability and you so that you just stay grounded.
Solving LeetCode - Longest Substring Without Repeating Characters
Published: 2020-11-08 00:30:31

# Question

Given a string s, find the length of the longest substring without repeating characters.

Example 1:

```
Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
```

Example 2:
```
Input: s = "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.
```
Example 3:
```
Input: s = "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.
Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
```

Example 4:
```
Input: s = ""
Output: 0
```

Constraints:

* 0 <= s.length <= 5 * 104
* s consists of English letters, digits, symbols and spaces.

## Let's Go!

Solve by using [PREP](https://dev.to/phariale/prep-technique-for-algorithms-in-js-5b0g).
* **P** - A string _s_ of letters, digits, symbols and spaces
* **R** - Return a number which is the length of the _Longest Substring Without Repeating Characters_
* **E** - Examples provided by question. (See Above)
* **P** - See Below

### Attempt 1

```javascript
var lengthOfLongestSubstring = function(s) {
    const arr = s.split('')
    let charMap = {}
    let count = [ 0 ]
    
    for (let i=0; i<arr.length; i++) {
        if (!charMap[arr[i]]) {
            count[count.length - 1] = count[count.length - 1]+1
            charMap[arr[i]] = 1
        } else {
            charMap = {}
            charMap[arr[i]] = 1
            count[count.length] = 1
        }
    }
    return count.reduce((max, current) => current > max ? current : max)
};

```

### Results of Attempt 1
```
console.log(lengthOfLongestSubstring("abcabcbb")) // 3 - PASS
console.log(lengthOfLongestSubstring("aab")) // 2 - PASS
console.log(lengthOfLongestSubstring("dvdf")) // 2  - FAIL (CORRECT is 3) 
```

To Be Continued...

### Attempt 2...
High-availability, Multi-Tiers, Auto Scaling WordPress Site Deployment on AWS
Tags: aws, wordpress, bitnami
Published: 2020-11-08 00:16:50

### Based on Bitnami WordPress Multi-Tier solution for AWS:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/adqrauhptf4nt0keu8en.png)

# Run a stack on AWS:
[Read the official doc on Bitnami](https://docs.bitnami.com/aws-templates/apps/wordpress-production-ready/get-started/launch-production-ready-deployment/)

# Build SSH tunnel over Bastion Host to App Instance
[Reference: Connect To An Application Instance Using An SSH Tunnel](https://docs.bitnami.com/aws-templates/infrastructure/lamp-production-ready/get-started/connect-app-ssh-tunnel/)

I am tired of ssh to Bastion Host and then ssh to App Instance, so, build a ssh tunnel.

1. Get 'Elastic IP 1 for Bastion' in CloudFormation
1. Get 'Private IP' of app instance in EC2
1. `sudo chmod 600 KEYFILE_PATH`
1. `ssh -i ec2-user@BASTION_IP`
1. Do in Bastion Host: 
```bash
sudo sed -i -e 's/AllowTcpForwarding no/AllowTcpForwarding yes/g' /etc/ssh/sshd_config
sudo /etc/init.d/sshd restart
exit
```
6. Do in local:
```bash
cat >> ~/.ssh/config <<'EOF'
Host bastionHost
 Hostname BASTION_IP
 User ec2-user
 ForwardAgent yes
 IdentityFile KEYFILE_PATH

Host YOUR_APP_NAME
 Hostname APP_INSTANCE_PRIVATE_IP
 User bitnami
 ForwardAgent yes
 IdentityFile KEYFILE_PATH
 ProxyCommand ssh -A -W %h:22 bastionHost
EOF
```
7. Connect to App: `ssh YOUR_APP_NAME`
How to repeat strings in JavaScript?
Tags: javascript
Published: 2020-11-08 00:00:00

---
  title: How to repeat strings in JavaScript?
  published: true
  tags: JavaScript
  date: Sun Nov 08 2020 05:30:00 GMT+0530 (India Standard Time)
  canonical_url: https://melvingeorge.me/blog/repeat-strings-javascript
  cover_image: https://melvingeorge.me/_next/static/images/main-568d92f248d77006d70176576f67f359.jpg
  ---
  [Originally posted here!](https://melvingeorge.me/blog/repeat-strings-javascript)
  
To repeat string in JavaScript, you can use the `repeat()` string method.

Consider this string,

```js
// string
const str = "hehe";
```

Let's repeat this string `5` times using the `repeat()` string method.

```js
// string
const str = "hehe";

// repeat string 5 times
const repeatStr = str.repeat(5);

console.log(repeatStr); // "hehehehehehehehehehe"
```

See this example live in [JSBin](https://jsbin.com/budojudisa/1/edit?js,console).

- You can pass a positive integer as the number of times you want the string to be repeated as the first argument to the `repeat()` method.

- The method returns a new string.

### Feel free to share if you found this useful 😃.

---
Using Abbreviations instead of Aliases
Tags: tips, beginners
Published: 2020-11-09 22:19:02

---
title: Using Abbreviations instead of Aliases
published: true
date: 2020-11-08 00:00:00 UTC
tags: tips,beginners
canonical_url: https://allanmacgregor.com/posts/using-abbreviations-instead-of-aliases
---

I recently came across one of [Fish shell](https://github.com/fish-shell/fish-shell) best and likely most underrated features, **abbreviations** ; a great alternative to **aliases** and dare I say a full replacement.

## The Problem with Aliases

> An alias is a (usually short) name that the shell translates into another (usually longer) name or command. Aliases allow you to define new commands by substituting a string for the first token of a simple command.

The main issue is that aliases are expanded behind the scenes, take the following alias:

```
alias rm='rm -Rfi'
```

The way aliases work on most shells the following drawbacks become apparent:

- They hide what is really happening as they are resolved behind the scenes
- Makes copy-pasting a command-line for instructions to others, difficult of not impossible
- Command history will be recorded as the alias, so history loses value
- Aliases become less valuable if you have to edit the options

## The better approach

**Abbreviations** work on the same principle as **aliases** but with the main advantage that an abbreviation will get expanded ‘live’ as is being typed. Let’s look at the following example:

```
abbr --add miex "iex --erl "-kernel shell_history enabled" -S mix"
```

I converted this from an alias that I used on a daily basis for elixir development, here are the advantages so far:

- The `abbr` expands “live”, the git completions work as normal and commandline doesn’t have to lie or do any other hacks like that.
- Clean history. Using abbr means other developers can understand your terminal history.
- Easy to use a shortcut that’s close to what you want and edit it.

## Summary

- `abbr` make for a better and more understandable `alias`
- I’m replacing all my aliases with abbreviations 

### Further Reading

- [Managing abbreviations - Fish](https://fishshell.com/docs/current/cmds/abbr.html)
- [When an alias should actually be an abbr](https://www.sean.sh/log/when-an-alias-should-actually-be-an-abbr/)
Circuit breaker in Java with Hystrix, Resilience4j and Microprofile fault tolerance
Tags: java, microservices, devops, resilience
Published: 2020-11-07 23:35:04

I tried to see implementation of circuit breaker with 3 java libraries : 

* [Hystrix](https://github.com/Netflix/Hystrix) (Deprecated, use Resilience4j)
* [Resilience4j](https://resilience4j.readme.io/)
* [Microprofile fault tolerance](https://download.eclipse.org/microprofile/microprofile-fault-tolerance-2.1/microprofile-fault-tolerance-spec.html)

I implement 3 projects with the same application based on a [Microprofile application](https://microprofile.io/)

All is in this github (with more in the Readme).

{% github jufab/hystrix-resilience4j-microprofile-fault-tolerance %}

I would like to share it in order to help someone to understand how to implement it and how it works.

I hope this could help.
FireLinker + TeleScope
Tags: opensource
Published: 2020-11-07 23:33:33

## What is this Blog About?
This week, I used my Open Source project [FireLinker](https://github.com/zg3d/fireLinker) to interact with [Telescope](https://github.com/Seneca-CDOT/telescope).Last week, I wrote a blog about my first contribution to telescope in that blog I already had setup telescope on my local machine and I also talked about working with it more in the future. So, here we are I am using my FireLinker to check links in the posts API for telescope.

previous blog about telescope with setup: https://dev.to/zg3d/telescope-my-first-contribution-19en

## API How does it work?
The way the posts API works is every time you go to /posts on the backend server you get a JSON of the 10 latest post with a relative URL and post id.

## How did I connect FireLinker and Telescope?
I made a new command for my FireLinker So it can interact with APIs. I tried to generalize it but my goal was to connect with the telescope API. So, I did make some assumptions like I knew it was a relative path, so I found the base URL and added it. I also made an assumption that there was a attribute for URL in the API. But with those assumptions I got it working on my local machine. FireLinker basically uses the given API URL and fetch it with a get request and from there the code parses the JSON and checks on the URL links.
![](https://cdn.discordapp.com/attachments/153626925200441344/774778497331101706/unknown.png)

## What are my Thoughts?
This was a very quick and dirty way of doing things. I still need to add check to see id the API URL is valid and proper error code messaging. This was a simple thing to do as I am comfortable with working with API like rest. And this was a basic API.

## Update
So, I also made it so that FireLinker check all links in the 10 recent posts. Which made my code more modular and now I am happy with the state of my code.
Javascript Regex Part 1 Test/Match Methods
Published: 2020-11-07 22:36:19

**Intro**
Regular expressions are used in Javascript to help you match strings patterns. They can useful to search for key words or patterns in large amounts of text.

**Test Method**
Javascript has multiple ways to use regular expressions. The first method we will look at is the test method. The test method takes the regex and applies it to a string. This will return true or false depending on if your pattern matches or not:

```
const testStr = "My favorite color is blue"
const testRegex = /blue/
testRegex.test(testStr) // Returns true
```
Using the same example as above you can search for multiple patterns using the or operator:

```
const testStr = "My favorite color is blue"
const testRegex = /blue|color/     // searches for blue or color
testRegex.test(testStr) // Returns true
```

**Ignore case while matching**
In our previous example we would only get a match if the letter case was the same. What if you want a match while ignoring the letter case? You can do this by adding an ignore flag at the end of your search:

```
const testStr = "AmazonPrime"
const testRegex = /amazon/i   // the i at the end is the ignore flag
testRegex.test(testStr) // Returns true
```

**Match Method**
So far we have only been checking if a pattern exists within a string and returning a boolean value of true or false. You can also find the actual matches within a string with the match method:

```
let myStr = "Basketball team";
let myRegex = /team/;
myStr.match(myRegex); // Returns ["team"]
```

**Global flag**
What if you want to search for a pattern more than once? This is where you use the global flag:

```
let myStr = "Basketball team team";
let myRegex = /team/g;
myStr.match(myRegex); // Returns ["team","team"]
```
A slightly different way to the color palette
Tags: image, color, palette
Published: 2020-11-07 22:34:21

---
title: A slightly different way to the color palette
published: true
description: Extract color palette from images
tags: "image, color, palette"
canonical_url: null
id: 2020110701
---

I wonder how many hours I have spent on Unsplash or similar sites, looking for images for projects, wallpapers or just to get an overview. But sometimes just for pleasure, the urge to see beautiful, harmonious images. The focus here is rarely on the motive. I am especially enthusiastic about unusual perspectives or messages. The other main factor are contrasts, as they (almost) only occur in nature and can only be captured by very well photographers.

![Unsplash Screenshot](assets/unsplash.jpeg)

Unfortunately I am not such a good photographer, in fact I am not a photographer at all. But that does not mean that I do not recognize and want to use this beauty.
During my work as a frontend developer I try to create color palettes regularly. If you have ever tried to find two or three of the 16,777,216 colors that fit well together, convey the desired message and have the appropriate contrast, you know that this is not an easy task.
So why not use the harmonic compositions of these images and generate color palettes from them? Since I understand very little about the harmony of colors and do not know how they interact in the pictures. I first researched whether there are already projects that can do this. Here, I am referring to this great library [Vibrant.js](https://jariz.github.io/vibrant.js/).

> Vibrant.js is a javascript port of the [awesome Palette class](https://developer.android.com/reference/android/support/v7/graphics/Palette.html) in the Android support library.

In order to use this knowledge as efficiently as possible in everyday life I have written a website where you can copy/pull/upload any image you want. Afterwards the image is analyzed by Vibrant.js and a corresponding color palette is displayed.
Maybe this site can help you find inspiration or even an (almost) finished color concept. Just give it a try [https://image-palette.tomeckardt.com](https://image-palette.tomeckardt.com)

Comment if you are interested in a way to copy to CSS variables or JSON objects.

![Unsplash Screenshot](assets/imagepalette.jpeg)
Bash Transform and Sort commands
Tags: bash
Published: 2020-11-07 22:25:04

The Transform and Sort commands are another useful set of tricks to add to your bash toolbelt. The Transform command is used to replace parts of a string, file, or text with a chosen delimiter. The next section covers how to use this command and gives a few examples.

## Transform
The template for the transform command is as follows:

```
any type of text | tr "replace" "with" 
```

Before the pipe, any type of string or text reading can be used. Then after the transform or 'tr', you can put what you want replaced in the first set of parentheses and what you want it replaced within the second. A few examples are displayed below:

```
echo "Hello" | tr "e" "E"
//=> HEllo

echo "Hello how are you" | tr " " '-'
//=> Hello-how-are-you

echo "Hello how are you 1234" | tr -d [0-9]
//=> Hello how are you 

echo "Hello how Are You" | tr -d [:lower:]
//=> H A Y
```
The third and fourth example implements an alternate template to use with the transform command. Instead of directly replacing a certain character you can instead give a flag, like the delete flag above, and then provide what you want that flag applied to. So the third command above says to delete all numbers in the text and the fourth tells the transform to delete all lowercase letters. The tr command can be used to format text in hundreds of ways, if you want to read some more on tr look [here](https://www.thegeekstuff.com/2012/12/linux-tr-command/). Now on to the sort command.

## Sort
So as its name implies, the sort command will sort input in text or TSV formats in various different ways. A number of flags are often used in addition to sort which changes the sorting method to the following: 

* No Flag: The vanilla sort command simply sorts the lines of the input file in lexicographical order.
* -n Flag: sorts the file on the basis of the numeric fields available if the first word or column in the file is a number.
* -r Flag: option reverses the sorting order to either the reverse of the usual lexicographical ordering or descending order while sorting in numerical mode.
* -k Flag: useful while sorting a table of data (tsv, csv etc.) based on a specified column (or columns).
* -t Flag: used while specifying a delimiter in a particular file where columns are separated by tabs, spaces, pipes etc.

Due to the examples of sort being lengthy, I decided to leave them out and either allow you to try it out yourself or look at the resources. Here are a few links with some great examples of using sort
[Sort Wiki Page](https://en.wikipedia.org/wiki/Sort_%28Unix%29)
[Sort examples](https://www.thegeekstuff.com/2013/04/sort-files/)
[Youtube video](https://youtu.be/h5MpG3QYSSk)
OSD600 - Lab 6 Setting up Telescope and creating a gist
Published: 2020-11-07 22:16:54

This week in OSD600 Lab, we had to set up the [Telescope](https://github.com/Seneca-CDOT/telescope) environment.  Then we had to use the Telescope REST API with our [Release 0.1](https://github.com/Seneca-CDOT/topics-in-open-source-2020/wiki/release-0.1) that we had done previously in the semester.  After following all the instructions, we had to create a gist.

Setting up Telescope was not as difficult as I had thought.  Once [Docker](https://www.docker.com/?utm_source=google&utm_medium=cpc&utm_campaign=dockerhomepage&utm_content=namer&utm_term=dockerhomepage&utm_budget=growth&gclid=EAIaIQobChMI-Z2p3rnx7AIVCbSzCh3QEgIOEAAYASAAEgIKzPD_BwE) was set up I had to open the Power Shell on my laptop and type the command from the [Lab 6](https://github.com/Seneca-CDOT/topics-in-open-source-2020/wiki/lab-6) instructions in the environment set up guide.  I opened Visual studio code and ran Telescope's back end from there. I checked local host 3000 to see if I was getting the right stuff! Then after a few minutes I opened up Bash and typed npm run develop.  I held my breath... surely this can't be that simple.  It started the process and then stalled partway through.  I quit 2 times and restarted before it finally worked.  Opened Local host 8000 to confirm everything was up and running. Thank goodness that's over!

Now I needed to take my existing code from that checks URL's and add code to read Telescope's data to get the last 10 posts indexed.  After much discussion with a few friends and reading up on node.js I decided to make a function to fetch the data and print it to a text file.  After I did that, I tested it.  Then I realized that every time I ran my code, it kept adding to the txt file.  I used truncate and tested that. For some reason I was over thinking this part of the lab. Combination of fatigue and other outside unavoidable distractions.  

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/g5x39a3fgdogt5pqno01.png)

After I had finished, I pushed the changes to the branch and created a [PR](https://github.com/strawberries73/OSD600-Journey-on-rocky-trails/pull/11
), checked if everything was ok.  Copied the changes for creating my gist.  Then I [merged](https://github.com/strawberries73/OSD600-Journey-on-rocky-trails/commit/991ceb268fe788b5aa340ed3cec3a7c9960268f4).  Once I created the [gist](https://gist.github.com/strawberries73/73d0a875ee54506c2309470deb7698e1), I was thinking there should be an option on GitHub to copy the diff to a gist.  Ambitious maybe?

After all this... Wow! This was pretty cool!  I felt pretty proud of myself for the smooth set up and my fiancé said it looked like the matrix on my screen!  HAHAHA!
Can you create "resources" in .jar files in Java?
Tags: java, help, gamedev
Published: 2020-11-07 22:12:46

I know there's a `.getResource(String name)` method in Java, but is there like a `.setResource(String name, File f)`, or something like that, in Java?
I'm asking because I want to create a save file, but I don't want the user to see them (unless the purposefully try to find it).

<div>
<center>
##<b>Thanks!<br/>Cheers!</b>
</center>
</div>
Frequently Asked React and Front-end Interview Questions
Tags: javascript, webdev
Published: 2020-11-07 22:03:47

---
title: 'Frequently Asked React and Front-end Interview Questions'
canonical_url: https://ogzhanolguncu.com/blog/frequently-asked-react-and-frontend-interview-questions
---

> Check my blog post for, frequently asked interview questions that I've encountered recently in my job search.

[Frequently Asked React and Front-end Interview Questions](https://ogzhanolguncu.com/blog/frequently-asked-react-and-frontend-interview-questions)
Functional Programming Terminology
Tags: javascript, functional, programming, terminology
Published: 2020-11-07 21:57:25

One thing I have found to be of vital importance when learning something new, is learning and using the correct terminology. Doing this not only helps you as your learn on your own, but it also makes it easier to communicate with, and ask others for help. With that in mind, I would like to devote this week's blog post to some key functional programming terms that you will definitely encounter.

The first term that you have no doubt already used, but maybe didn't know what it is called are "callbacks." If you have used the .filter() array method you have used a callback. In a nut shell, a callback function is a function that is passed into another function to decide the invocation of that function. In the case of .filter(), the callback function sets the criteria for how we filter an array. 

There are also "first class functions," which are functions that can be assigned to a variable, passed into another function, or returned from another function just like any other normal value. The beauty of JavaScript is that all functions are first class functions.

There are also "higher-order functions," which are the functions that take a function as an argument, or return a function as a return value. Again, you have most likely already been using higher-order functions like .filter(), .map(), and .reduce(). 

The last term I want to touch on are "lamda" functions. Lamda functions are when the functions are passed in to another function or returned from another function, then those functions which gets passed in or returned can be called a lambda.

Functional programming is a vast topic, but I hope that this introduction to some of the key terms aides you in your quest to learn JavaScript.