teleren/devto huggingface dataset:
[Common mistake] Sharing session across multiple Laravel subdomain
Tags: laravel, php
Published: 2021-06-15 06:39:41

To Share session across domain and it's multiple especially when you have large ecosystem were multiple applications communicate with one database So when a user authenticates any of these apps, they will be logged in everywhere.

 For example, when a user **AUTH** into http://mywebsite.com, he or she can easily access the rest of the sub hosted site directly say http://dashboard.mywebsite.com or http://subdomain.mywebsite.com.

Actually it's easy to share session on Laravel by following this steps. Basically you need the exact same sessions configuration in all of your applications, also the same encryption key.
 
1) Open your **.ENV**  and add the following:
**SESSION_DRIVER=database**
**SESSION_DOMAIN=.domain.com**
Example as shown ![session on Laravel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e4tsk3z9v10s6m4wrkz1.PNG)
**(Dont forget Make sure to include a dot(.) before your domain name.)**

2) Store the sessions in the database
This command will create a migration for your sessions:

=> First generate a migration file
**php artisan session:table**

=>Now, migrate generated sessions table
**php artisan migrate**

That’s it. You are done.
Don’t forget to clear the cookies for all of your apps before you start testing. Example below 
![session on Laravel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oda302k80q2l1w6sy0bh.PNG)

**Common mistake and check you should notice whenever you follow the after steps and your session isn't sharing.**

**Make you Update application keys**
Make sure the *“APP_KEY”* variable in your .env file has the same value in all your applications. Just copy one and paste it everywhere.

Don't forget to use same **"APP_NAME"** across you applications, otherwise it will not work, laravel use **APP_NAME** to generate cookies and cookies name should be same to make it work propertly.

DELETE **config.php inside your laravel project bootstrap/cache folder**.

And that's it.. with above checks you are go to go.
Linux zip files
Tags: linux
Published: 2021-06-15 06:37:48

Today we'll be looking at how to zip up one or multiple files on Linux systems.
Zipping files can come in super handy when dealing with multiple files or backups that need to be transferred or moved.

In my case, this situation occurred because I wanted to email attach multiple log files.

## The Linux ZIP command

Let's first look at the command itself.

```bash
zip options zip_name files
```

Where this works as follows:

- `zip`: The Linux command to zip things
- `options`: We can pass in arguments for the end zip results
- `zip_name`: The output name, without the `.zip` part
- `files`: One or more files comma separated

To show you the most simple zip command for one file, we could do this.

```bash
zip archive test.txt
```

This will create an archive.zip in that folder containing the test.txt file.

## Installing `zip` on Ubuntu or Centos

To install the zip command on Ubuntu or Debian systems, you can run the following command.

```bash
sudo apt install zip
```

For CentOS and Fedora systems, you can use Yum.

```bash
sudo yum install zip
```

## Zipping multiple files in Linux systems

To add multiple files, we can specify them with a space between like this.

```bash
zip archive test.txt test2.txt test3.txt
```

However, in most cases, you want to zip a whole folder and its contents, right?

To achieve this, we can pass the `-r` option (Recursive).

```bash
zip -r archive my_directory
```

This will take all the files inside my_directory and zip them into one archive.

As we did above, we can still add separate files in the zip by passing them along.

```bash
zip -r archive my_directory test.txt
```

## Linux zip options

So far, we have seen the `-r` option to add files in a folder recursively.

As you may know, there are multiple compressions levels for zip files. The default one is `deflate`. But we can also zip files using the `bzip2` compression.

To use a different compression method, we can pass the `-Z` option.

```bash
zip -r -Z bzip2 archive my_directory
```

We can also specify the level of compression we want.
This is passed with a number from 0-9.
Where 0 is no compression and 9 the highest.
The default compression is -6.

To use it:

```bash
zip -r -9 archive my_directory test.txt
```

Another cool option is to encrypt the zip. This means we put a password on it.

```bash
zip -r -e archive my_directory
```

This will prompt you for the password twice.

```bash
# Enter password:
# Verify password:
```

### Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on [Facebook](https://www.facebook.com/DailyDevTipsBlog) or [Twitter](https://twitter.com/DailyDevTips1)
6 Beginners Friendly Websites to Learn JavaScript [Free]
Tags: javascript, 100daysofcode
Published: 2021-06-15 06:37:20

---
title: 6 Beginners Friendly Websites to Learn JavaScript [Free] 
published: true
description: 
tags: javascript, 100daysofcode
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/enjt491eic396atlrwwp.png
---
JavaScript is one of the most popular modern web technologies! As your JavaScript skills grow, your websites will enter a new dimension of power and creativity. 
I'm gonna list down 6 platforms/websites from where you can learn JavaScript without spending a single penny:

1. w3schools
2. Learn JavaScript
3. JavaScript Info
4. Developer Mozilla
5. FreeCodeCamp
6. JavaScript30

## 1. w3schools
W3Schools is a web developers site, with tutorials and references on web development languages such as HTML, CSS, JavaScript, PHP, SQL, jQuery, Java, C++, C#, React, Node.js, and Bootstrap, covering most aspects of web programming.

Link: https://w3schools.com/js/

## 2. Learn JavaScript

Learn modern JavaScript from scratch, and practice in an intuitive environment. The challenges are inspired by modern real-world projects to make sure that you're learning the best practices, one step at a time.

Link: https://learnjavascript.online/

## 3. JavaScript Info

Here you start with basic and go on to advanced levels like OOP. 

Link: https://javascript.info/

## 4. Developer Mozilla

JavaScript is arguably more difficult to learn than related technologies such as HTML and CSS. Before attempting to learn JavaScript, you are strongly advised to get familiar with at least these two.

Link: https://developer.mozilla.org/en-US/docs/Learn/JavaScript

## 5. FreeCodeCamp

As you can see here you have a different section/certification. And first, you have tutorials then, in the end, you need to finish 5 projects to get that certification. Certification is free

Link: https://www.freecodecamp.org/learn

## 6. JavaScript30

Beginner to Intermediate developers and designers who want to become comfortable with both JavaScript fundamentals and working in the DOM without a library.

Also, you can check  @wesbos Youtube channel

Link: https://javascript30.com/

Initially created on Twitter:

{% twitter 1404550718292430857%} 

If you liked this article, be sure to ❤️ it.
How to select all diagonal cells in table ?
Published: 2021-06-15 06:28:29


    <table border="1" style="width:100%" id="table">
  <tr>
    <td>1.1</td>
    <td>2.1</td>
    <td>3.1</td>
    <td>4.1</td>
    <td>5.1</td>
  </tr>
  <tr>
    <td>1.2</td>
    <td>2.2</td>
    <td>3.2</td>
    <td>4.2</td>
    <td>5.2</td>
  </tr>
  <tr>
    <td>1.3</td>
    <td>2.3</td>
    <td>3.3</td>
    <td>4.3</td>
    <td>5.3</td>
  </tr>
  <tr>
    <td>1.4</td>
    <td>2.4</td>
    <td>3.4</td>
    <td>4.4</td>
    <td>5.4</td>
  </tr>
  <tr>
    <td>1.5</td>
    <td>2.5</td>
    <td>3.5</td>
    <td>4.5</td>
    <td>5.5</td>
  </tr>
  
</table>
    <script type="text/javascript" charset="utf-8">
      let tableEl = document.getElementById("table");
      let tableRows = document.querySelectorAll("table tr");
      
    let ind=0;
    while(tableRows[ind]){
      tableRows[ind].cells[ind].style.backgroundColor = "red";
      ind++;
    }
    </script>
How to Select all diagonal cells in table ?
Published: 2021-06-15 06:25:15

  <body>
    <table border="1" style="width:100%" id="table">
  <tr>
    <td>1.1</td>
    <td>2.1</td>
    <td>3.1</td>
    <td>4.1</td>
    <td>5.1</td>
  </tr>
  <tr>
    <td>1.2</td>
    <td>2.2</td>
    <td>3.2</td>
    <td>4.2</td>
    <td>5.2</td>
  </tr>
  <tr>
    <td>1.3</td>
    <td>2.3</td>
    <td>3.3</td>
    <td>4.3</td>
    <td>5.3</td>
  </tr>
  <tr>
    <td>1.4</td>
    <td>2.4</td>
    <td>3.4</td>
    <td>4.4</td>
    <td>5.4</td>
  </tr>
  <tr>
    <td>1.5</td>
    <td>2.5</td>
    <td>3.5</td>
    <td>4.5</td>
    <td>5.5</td>
  </tr>
  
</table>
    <script type="text/javascript" charset="utf-8">
      let tableEl = document.getElementById("table");
      let tableRows = document.querySelectorAll("table tr");
      
    let ind=0;
    while(tableRows[ind]){
      tableRows[ind].cells[ind].style.backgroundColor = "red";
      ind++;
    }
    </script>
  </body>
VScode zsh command not found
Tags: macosbigsur, vscode, zsh
Published: 2021-06-15 06:06:13

How to fix this error inside VScode? 

Go to your Mac terminal and run the following commands

```javascript
~ % which code
~ % code .  // don't forget the dot after "code"
```
New window open with VSCode prompting if vscode can access all the folder. Select "YES". You are done. Relaunch VSCode again, now try Ctrl + ~ to launch a new zsh terminal.

Note: This is the fix I found after upgrading to MacOS BigSur. VSCode was working before the OS upgrade for me. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jxrtpy7xo0zxwnzzxm0b.png)
🦊 GitLab Cheatsheet - 3 - GitLabCI Rules
Tags: gitlab, tutorial, cheatsheet, devops
Published: 2021-06-15 05:39:16

The third cheatsheet speaks about GitLabCI Rules.

<a href="https://jeanphi-baconnais.gitlab.io//img/cheatsheet/GitLabCheatsheet-3-GitLabCIRules.jpg" alt="3 - GitLab CI Rules" target="blank">

![GitLab Cheatsheet - 3 - GitLabCI Rules](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/buyhpg8ao9v99xs2fphg.jpg)

</a>


I will create others cheatsheet. Tell me if you have comments or suggest about those cheatsheet 😃.
Meteor React Router Page Reload Problem
Tags: meteor, meteorreact, react, javascript
Published: 2021-06-15 05:35:13

Sometimes when you click on a `Link` in Meteor with `react-router-dom`, the page fully reloads to navigate between pages rather than partially or dynamically reloading.

To solve this issue, use this customized `Link` component instead of the original:

```js
import React from "react";
import { useHistory } from "react-router-dom";

export const Link = ({ children, to, className }) => {
    const history = useHistory();

    const handleMouse = (e) => {
        e.target.href = "";
    };

    const handleClick = (e) => {
        e.preventDefault();
        history.push(to);
        e.target.href = to;
    };

    return (
        <a
            className={className}
            href={to}
            onClick={handleClick}
            onMouseDown={handleMouse}
        >
            {children}
        </a>
    );
};
```
Dropdown Sidebar Menu using HTML CSS
Tags: dropdown, sidebar, navigation, htmlcss
Published: 2021-06-15 05:28:02

**Q: How do I add a dropdown to the sidebar?**
A: After reading and watching the given article and videos, you can create the Responsive Dropdown Sidebar that I have shown on the webpage.

Hello readers, today we are going to learn to create a Responsive Dropdown Sidebar Menu using HTML CSS, and JavaScript. If you want this sidebar design without a dropdown menu then you can visit this link - Responsive Sidebar Menu.

**What is the Dropdown Sidebar Menu?**
Sidebar means the section on the website that is located on the right or left side with some important navigation links and the user can open or close it. Dropdown menu means that sub-menu or nav links which are hidden in very first but when user do hover or click on the main nav link then sub-menu appears.

If you want to watch the real virtual demo and tutorial of this sidebar menu with a submenu then I highly recommend you to watch the given video tutorial of the dropdown. After watching the video I sure you will understand how all code works behind this design.

#Dropdown Sidebar Menu | Free Source Code#
You can download all source code from the given link. <a href="https://www.codinglabweb.com/2021/06/dropdown-sidebar-menu-html-css.html">Click Here To Download All Source Code</a>
Does Airtable Work in China?
Tags: airtable, netlify, headlesscms, 21yunbox
Published: 2021-06-15 05:19:01

---
canonical_url: https://www.21cloudbox.com/solutions/does-airtable-cms-work-in-china.html
---
## What is Airtable?
Airtable is an easy-to-use online platform for creating and sharing relational databases.

<p>&nbsp;</p>
## Does Airtable work in China?

The short answer depends on your use cases.

**If Airtable is served as a Content Management System (CMS) that provides read-only information for a website host in China, Airtable should be ok.**

Before we dive in, let’s first take a look at the Airtable tech stack to see if Airtable is accessible in China or not.


<p>&nbsp;</p>
![From https://stackshare.io/airtable/airtable](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z3ecsgk0hxu4hhmdyov0.png)
<p>&nbsp;</p>

So Airtable’s servers are hosted on AWS (noted that it is not hosted on AWS China region) and their CDN is vendor is using MaxCDN.

<p>&nbsp;</p>
![Airtable staff's reply for data security and hosting: https://community.airtable.com/t/question-about-data-security-hosting/34123](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dnjur1qco1h5p6gghxo8.png)
<p>&nbsp;</p>

Just for the readers to be aware, AWS EC2 global is not blocked in China, but it’s relatively slow when compares to AWS China.

So based on their stack, we can tell it should work in theory for China, but it will be a bit slow.

**Even Airtable loads a bit slow in China, but it's not ok, not more specifically, it's not allowed if you use Airtable to collect Chinese users' information. Because it violates Article 37 of the Cybersecurity Law of the People's Republic of China.**

If you are curious, let's take a quick look at what Article 37 states, here is the original version in Chinese: 

> 关键信息基础设施的运营者在中华人民共和国境内运营中收集和产生的个人信息和重要数据应当在境内存储。因业务需要,确需向境外提供的,应当按照国家网信部门会同国务院有关部门制定的办法进行安全评估;法律、行政法规另有规定的,依照其规定。


...


To read the full content of this post, go to: [https://launch-in-china.21cloudbox.com/solutions/does-airtable-cms-work-in-china.html](https://launch-in-china.21cloudbox.com/solutions/does-airtable-cms-work-in-china.html)

<p>&nbsp;</p>
Toy Problems, Tricks, and Progress
Tags: algorithms, datastructures
Published: 2021-06-15 05:13:10

...and regression (or feelings of). Not the code kind. The bad kind.

but first...

##Learning and Applying
I solved a simple search problem the other day and then compared my solution to another that I found online.

Here's how I set up my loop:
` while (some_item !== target)` etc

and here's how they set up theirs:
` while (left_index <= right_index)` etc

The second resulted in cleaner code with fewer if/else checks (although maybe that wasn't the fault of the while statement and instead was just poor code throughout). But what I like about the second while statement is that the condition checks for values that the code changes (the left- and right- indexes are incremented). The condition itself gives us a preview of the code in that it gives us an idea of what to look for in the code block.

More importantly I applied this to a different (related) problem and got a lot of satisfaction about identifying the application and then using it. Sweet!

###Regression you say?
Well, I was given an assignment and thought I did pretty poorly on it, not passing all of the tests on 2/3 problems and not even reaching the third within the allotted time. I thought they were easy problems too! I'll chalk it up to a tired mind after a long day, but I'd like to re-visit them and knock them out soon. Hopefully I can also consider solutions that are more time-efficient too (compared to the solutions I provided in the test suite).

Feels like a step back, but I've got my head up.
LeetCode 53. Maximum Subarray (javascript solution)

Tags: algorithms, javascript
Published: 2021-06-15 05:09:46

###Description:
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

###Solution:
Time Complexity : O(n)
Space Complexity: O(1)

```javascript
var maxSubArray = function(nums) {
  var prev = 0;
  var max = -Infinity;

  for (var i = 0; i < nums.length; i++) {
    // Compare previous contiguous sum with current number
    prev = Math.max(prev + nums[i], nums[i]);
    // Check if the current prev is the greatest sum 
    max = Math.max(max, prev);
  }
  return max;
};
```
I'm switching to vim!
Tags: vim, tmux, terminal, productivity
Published: 2021-06-15 05:07:12

**UPDATE:** There are a lot of Vim tips in the comments. Check them out!

I just took a short look at the (neo)vim docs, and I'm officially moving to (neo)vim (and tmux)! I have just used it for a few days, but I really can feel the power it gives me. Not to mention that it really saves my 6GB ram for other uses.

{% gist https://gist.github.com/SiddharthShyniben/2b6d4c63775712c7331f3117b48cefb3 %}
<figcaption>A snapshot of my coding session</figcaption>

And I encourage all of you to do the same. It really is super faster (I come from vscode, and it is really faster). Vim has everything you need – Syntax highlighting, Split screen, File explorers(!), Autocomplete(!), Tabs, Folding lines(!), Indentation autofixing(!), macros, line bookmarks, integrated terminal like interface and what not (I should make an article on it soon). Vim is basically equivalent to VSCode for me.
Counting Inversion by piggybacking on Merge Sort with Python and C++ 
Tags: cpp, python
Published: 2021-06-15 05:07:01

### Solution to the problem.


* Solution in Python

```
import os


def main():
 array = []
 with open("IntegerArray.txt") as file:
      array = [line.strip() for line in file]
 mergesort(array)


def merge(a,b):
    c = []
    count = 0
    while len(a) != 0 and len(b) != 0:
        if a[0] < b[0]:
            c.append(a[0])
            a.remove(a[0])
            count += 1
        else:
            c.append(b[0])
            b.remove(b[0])
            count += 1
    if len(a) == 0:
        c += b
    else:
        c += a
    # print("\n\n\n\n"+str(count)+"\n\n\n\n")
    return count


def mergesort(x):
    if len(x) == 0 or len(x) == 1:
        return x
    else:
        middle = len(x)/2
        middle = int(middle)
        
        a = mergesort(x[:middle])
        b = mergesort(x[middle:])
        return merge(a,b)


if __name__ == '__main__':
 main()
```


* Solution of the same problem in C++.


```
#include "bits/stdc++.h"
#include "iostream"
#include "fstream"
using namespace std;

long long  _mergeSort(long long arr[], long long temp[], long long left, long long right);
long long merge(long long arr[], long long temp[], long long left, long long mid, long long right);

long long mergeSort(long long arr[], long long array_size)
{
    long long *temp = (long long *)malloc(sizeof(long long)*array_size);
    return _mergeSort(arr, temp, 0, array_size - 1);
}

long long _mergeSort(long long arr[], long long temp[], long long left, long long right)
{
  long long mid, inv_count = 0;
  if (right > left)
  {
    mid = (right + left)/2;

    inv_count  = _mergeSort(arr, temp, left, mid);
    inv_count += _mergeSort(arr, temp, mid+1, right);

    inv_count += merge(arr, temp, left, mid+1, right);
  }
  return inv_count;
}


long long merge(long long arr[], long long temp[], long long left, long long mid, long long right)
{
  long long i, j, k;
  long long inv_count = 0;

  i = left;
  j = mid;
  k = left;
  while ((i <= mid - 1) && (j <= right))
  {
    if (arr[i] <= arr[j])
    {
      temp[k++] = arr[i++];
    }
    else
    {
      temp[k++] = arr[j++];
      inv_count = inv_count + (mid - i);
    }
  }


  while (i <= mid - 1)
    temp[k++] = arr[i++];

  while (j <= right)
    temp[k++] = arr[j++];

  for (i=left; i <= right; i++)
    arr[i] = temp[i];

  return inv_count;
}


int main()
{
    long long arr[100000];
    ifstream file("..PATH_TO_FILE/file.txt");
        if(file.is_open())
        {

            for(long long i = 0; i < 100000; ++i)
            {
                file >> arr[i];
             }
        }

        std::cout << mergeSort(arr, 100000);
  return 0;
}
```
Main Components of a Computer Systems
Tags: computerscience, beginners, systems, programming
Published: 2021-06-15 04:57:14

In this article, I will walk you through the main components of computer systems, that you can understand what is this and how this machine works and you also be able to send an instruction to this machine to work for you.

The computer basically is a combination of Hardware and Software. Hardware working closely with electrical signals and Software is the way to interact with humans to complete the tasks using machine.

- Main 5 Parts of a Computer:
## Central Processing Unit (CPU): Arithmetic & Logical Unit (ALU)
![ALU](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/huj28a4fojmgd3oe8lbp.gif)
source: Wikipedia

### Main Memory: RAM, ROM, Cache Memory
![memory](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9oh77jq31h9pwpgmm2ze.jpg)
source: Tutorialspoint

### Input Devices
![input](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y64v6dcv6x50vgn5jl0c.jpg)
source: digitalworld839.com

### Output Devices
![out](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ubc751wo1ijjx6f24bs.jpg)
source: digitalworld839.com

### Secondary Memory: HDD or SSD
![hdd](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h83qzezvyijtm6mapfj3.jpg)
![ssd](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6aiext94mqf9jl2ozkhx.jpg)
source: Wikipedia

Thanks for now, see you soon :D


Cover image: Photo by <a href="https://unsplash.com/@lorenzoherrera?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Lorenzo Herrera</a> on <a href="https://unsplash.com/s/photos/computers?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>