teleren/devto huggingface dataset:
LinkedList Questions: Middle Element of Linked List - Naive Approach
Tags: algorithms, cpp, codenewbie, linkedlist
Published: 2021-07-11 03:35:26

In this series of posts, I will discuss coding questions on the `LinkedList` Data structure.
The posts in this series will be organized in the following way,

1. Question Link ❓
2. Possible Explanation 📝
3. Documented C++ Code 🧹
4. Time and Space Complexity Analysis ⌛🌌

## The Question

Given a non-empty, singly linked list with head node `head`, return a middle node of the linked list.

If there are two middle nodes, return the second middle node.

[https://leetcode.com/problems/middle-of-the-linked-list/](https://leetcode.com/problems/middle-of-the-linked-list/)

> 💡 Give yourself at least 15-20 mins to figure out the solution :)

## Explanation

The naive approach is very simple but it is important to understand *what* & *why* we are doing this to fully understand the optimized approach. 

1. Find the length of LinkedList → `L`
2. Find the position (from start) of the node to be deleted: `floor(L/2) + 1` → `K`
    - eg: for `L = 5`, required node is `3 = floor(5/2) + 1`
    - eg: for `L = 6`, required node is `4 = floor(6/2) + 1`
- Reach the `Kth` node in **K-1** iterations and return it.

## C++ Code

### Definition of Linked List

```cpp
//Definition for singly-linked list.
struct ListNode
{
    int val;
    ListNode *next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode *next) : val(x), next(next) {}
};

```

### Solution

```cpp
ListNode *middleNode(ListNode *head)
    {
        ListNode *temp = head;
        int count = 0;

        //- finding length of LL : O(n)
        while (temp)
        {
            count++;
            temp = temp->next;
        }

        //pointing temp to head again
        temp = head;
        int nodeNo = count / 2 + 1; //doesn't matter if count is odd or even

        //-Time: O(k-1)
        //If I want to reach kth node, I need to go k-1 deep
        for (int i = 1; i <= nodeNo - 1; i++)
        {

            temp = temp->next;
        }
        head = temp;
        return head;
    }
```

## Complexity Analysis

### Time Complexity: O(n)

O(n) for finding length of List + O(n/2) for reaching the required node = O(n)

### Space Complexity: O(1)

We didn't use any extra space
How to build a website in markdown
Tags: markdown
Published: 2021-07-11 03:19:50

<table>
<tr>
<td colspan="2">
<h1 id="top">Hey there!</h1>
</td>
</tr>
<tr>
<td valign="top">
<h2>Menu</h2>
<a href="#top">Top</a><br>
<a href="#what">What?</a><br>
<a href="#how">How?</a><br>
<a href="#why">Why?</a><br>
<a href="#when">When?</a><br>
<a href="#where">Where?</a><br>
<a href="#who">Who?</a><br>
This thing is in the middle of the page because of the DEV Markdown parser. Go <a href="https://gist.github.com/SiddharthShyniben/2e33d096f6173ae8688ca046ded151cd">Here</a> for a better one
</td>
<td>
<table>
<tr>
<td valign="top">
<h2 id="what">What?</h2>
I just got bored so I just made a website using a tables like in the old days (Just for fun)<br><br>
Doesn't it look cool? No CSS (except DEV's default stylesheet, no JavaScript, just good 'ol HTML.<br><br>
I mean, I can't believe I built this. I'm so bad at CSS. Not like I used any CSS.
</td>
</tr>
<tr>
<td valign="top">
<h2 id="how">How?</h2>
This is just a bunch of tables. Here's what it looks like in pseudocode:<br> 
<pre class="highlight html"><code>table
    row 
        top menu thingy spanning 2 cols
    row 
        side menu thingy
        content
            another table
                row
                    column with content
                row
                    column with content
                ...
    row
        footer spanning 2 cols
</code></pre>
<br>
<h4>...Wait. So this is HTML, not markdown right?</h4>

Yeah I guess, pretty much HTML. But <strong>limited</strong> HTML.

<h4>You can't put markdown in HTML. S- S- So, Did you t- t- type out all this (gulp) HTML?</h4>

Yes I did. It took some time to figure out how to highlight code blocks and stuff, but I did eventually did it.<br>

<h4>So, how good is this?</h4>

Really bad, like literally the worst. <br><br>

This is really hard to maintain. Like seriously, I spent half an hour putting together the table (not the content!)<br><br>

There's a lot more stuff to think about, like the fact that <a href="https://stackoverflow.com/questions/83073/why-not-use-tables-for-layout-in-html#:~:text=the%20layout%20algorithm%20for%20tables%20is%20much%20harder%2C%20the%20browser%20often%20has%20to%20wait%20for%20the%20whole%20table%20to%20load%20before%20it%20can%20begin%20to%20layout%20the%20content.">tables load kinda slower</a><br><br>

This thing is literally two nested tables. Lets not start talking about a11y.
</td>
</tr>
<tr>
<td>
<h2 id="why">Why?</h2>

Fun.<br><br>

(I just really felt like something was missing)
</td>
</tr>
<tr>
<td>
<h2 id="when">When?</h2>

Fri Jul 09 2021 21:38:33 GMT+0530 (India Standard Time)
</td>
</tr>
<tr>
<td>
<h2 id="where">Am I missing something?</h2>

I got this feeling that something should be here...
</td>
</tr>
</tr>
<tr>
<td>
<h2 id="who">Who?</h2>

@siddharthshyniben (Finally I don't have to use markdown for this.
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">Footer (probably)<br>Go <a href="https://gist.github.com/SiddharthShyniben/2e33d096f6173ae8688ca046ded151cd">Here</a> for a better one</td>
</tr>
</table>
An Introduction to Webpack
Tags: codenewbie, webpack5, webpack, production
Published: 2021-07-25 23:09:25

---
title: An Introduction to Webpack
published: true
date: 2021-07-11 02:58:18 UTC
tags: codenewbie,webpack5,webpack,production
canonical_url: https://medium.com/codex/an-introduction-to-webpack-1f33475fd07b
---

[![](https://cdn-images-1.medium.com/max/2600/0*_lUrfmO0sERKe9ue)](https://medium.com/codex/an-introduction-to-webpack-1f33475fd07b?source=rss-be00f566a88f------2)

How to optimize our JavaScript code for production using a module bundler

[Continue reading on CodeX »](https://medium.com/codex/an-introduction-to-webpack-1f33475fd07b?source=rss-be00f566a88f------2)
How to Integrate a Rails Backend into a JavaScript Web Application
Published: 2021-07-11 02:24:06

When it came to learning web development, JavaScript gave me the hardest time, despite being less complicated compared to other web frameworks like React.  Learning how to incorporate database information is incredibly important for making a website flow properly, especially if the website requires user data and any other information that is saved to a user or the web application overall.

In contrast to React where the information pulled from an API is manipulated based on the code written directly in React, with a JS application, manipulating database information is determined by the Ruby code written within your controller files.  In React, the controller files in your Ruby-based backend are used for CRUD -that is Create Read Update and Delete - the essential actions for a web application.
convert OS from linux to windows 10 in Dell laptop
Published: 2021-07-11 01:57:15



the Steps to clean window2 10 installation
1. Boot to the system setup interface by keep pushing F2 key. change the configuration for legacy mode. save and exit(F10)
2. restart the computer and keep pushing the F12 key. Select DVD or USB boot option.  
3. When prompted, choose your language (English is default).
4. Choose your region (US Default).
5. Choose the Troubleshoot option.
6. Choose Advanced option.
7. Choose Command Prompt, this will open a Command Prompt Window.
8. Type: diskpart then press the Enter key to open the Disk Partition tool
9. Type: list disk then press the Enter key to show all hard disk/Solid State disks seen by the tool
10. Type: select disk 0 or 1(depend on your situation) then press the Enter key (Disk 0 is the hard drive where Windows is normally installed if you have multiple drives)
11. Type: clean then press the Enterkey
12. Type: convert GPT then press the Enter key
13. Type: exit then press the Enter key to exit the Diskpart tool
14. Type: exit then press the Enter key to exit the Command Prompt window
Rakkas.js 0.2.1 is out
Tags: react, vite, ssr
Published: 2021-07-11 00:29:22

I'm pleased to announce version 0.2.1 of Rakkas, “the dancing web framework” which aims to unite a Next.js-inspired development experience with Vite's blazing speed. Please check it out, all kinds of feedback are most welcome. It's not production-ready yet but many features have been implemented:

- Hassle-free server-side rendering
- File system-based routing with dynamic routes, nested layouts, and thematic layout groups
- SPA-style client-side router
- Simple but effective data fetching system
- API routes to build API endpoints and middleware

This new version brings:

- Project initializer (`npm init rakkas-app`)
- Hot reloading for pages and layouts
- More robust body parser which now supports `application/x-www-form-urlencoded` in addition to plain text and JSON
- New website domain: rakkasjs.org
- Bug fixes
- Performance and package size improvements

And short term goals incude:

- Static site generation
- Optional data caching
- Support for serverless environments
- Localizable and customizable router

Check the github page for more info: https://github.com/rakkasjs/rakkasjs
Should your builds run on autopilot?
Tags: cicd, continuousdeployment, build, automation
Published: 2021-07-13 07:16:18

---
title: Should your builds run on autopilot?
published: true
date: 2021-07-11 00:00:00 UTC
tags: cicd,continuousdeployment,build,automation
canonical_url: https://jhall.io/archive/2021/07/11/should-your-builds-run-on-autopilot/
---

I was recently discussing the benefits of automated build pipelines (sometimes mistakenly called [CI pipelines](http://whatisci.com/)). The question came up: Given the (sometimes very non-trivial) investment in building an automated build pipeline, are automated builds really appropriate for everyone?

I think the answer is no.

If you’re releasing software 100 times per day, you almost by definition need automated builds.

On the other extreme, if you release your software once ever (i.e. some throw-away one-time-use script), automation is almost certainly a huge waste of effort.

So where’s the exact line between these two alternatives?

I don’t know. I bet nobody else does, either. So here’s the approach I would advocate, adapted from [How to automate anything](https://jhall.io/archive/2021/03/23/how-to-automate-anything/):

1. Document your build process, so any (sufficielty trained) human can execute it. Optionally, ask random (trained) humans to follow the instructions to prove their technical and communication correctness.
2. If you discover that one specific element of the build process is especially time consuming, error prone, repetitive, or otherwise painful, automate that step. Random examples: Creating a new SSL certificate, or pinging the server until it responds after the upgrade.
3. Update the documentation.
4. Optional: Repeat from step 2.

If you follow this process, you may eventually end up with a completely automated build process. On the other hand, if you build your software so infrequently, or the process is so simple, that the gains from automation are insufficient, you’ll likely never have an automated build proces, but you won’t care.

 ![](https://jhall.io/archive/images/autopilot.jpg)
* * *
_If you enjoyed this message, [subscribe](https://jhall.io/daily) to <u>The Daily Commit</u> to get future messages to your inbox._
How to create a file in Linux?
Tags: resource
Published: 2021-07-11 00:00:00

---
  title: How to create a file in Linux?
  published: true
  tags: Resource
  date: Sun Jul 11 2021 05:30:00 GMT+0530 (India Standard Time)
  canonical_url: https://melvingeorge.me/blog/create-file-linux
  cover_image: https://melvingeorge.me/_next/static/images/main-cbb3962de796e4d57a95473076a4fec5.jpg
  ---
  [Originally posted here!](https://melvingeorge.me/blog/create-file-linux)
  
To create a file, you can use the `touch` command followed by the name of the file with the extension in Linux.

For example, to create a file with the name `Hello.txt`, you can use the `touch` command like this,

```bash
# Make a file in Linux
touch Hello.txt
```

This will create a file named `Hello.txt`.

See the above code live in [repl.it](https://replit.com/@melvin2016/create-a-file-in-linux#main.sh)

You can also make more than one file in a single command by adding a space and then writing the file name with the extension like this,

```bash
# Make 2 files in a single command in Linux
touch Hello.txt Hello2.txt
```

That's all 😃!

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

---
Alternative to if/else blocks
Tags: javascript
Published: 2021-07-10 23:45:32

## Introduction

We often overuse if/else blocks. We use them throughout our code base every time we want to run optional block of codes or return different outputs based on an input value or a condition.

## Example
Let's say I have a function that takes an input (string) and modifies that string.

To keep things simple, the function receives a week number, `week 1` and should return `week one`

Using an if/else conditionals, we can have code like so

```js
    function CurrentWeekLabel(value) {
     let weekNumber = value[value.length - 1]
     if (weekNumber === '1') {
       weekNumber = 'one'
     }
     if (weekNumber === '2') {
       weekNumber = 'two'
     }
     else if (weekNumber === '3') {
       weekNumber = 'three'
     }
     else if (weekNumber === '4') {
       weekNumber = 'four'
     }
     else if (weekNumber === '5') {
       weekNumber = 'five'
     }
      return value
        .slice(0, -1)
        .concat(weekNumber)
    }
```

This function serves us well. However, there is an alternative that is less cluttered, less repetitive and more readable.

## Alternative

We can use object lookups as an alternative, which is cleaner 

```js
   function CurrentWeekLabel(value) {
      let weekNumber = value[value.length - 1]
      let options = {
        '1': 'one',
        '2': 'two',
        '3': 'three',
        '4': 'four',
        '5': 'five',
      };
      return value
        .slice(0, -1)
        .concat(options[weekNumber] || weekNumber)
    }
```
Hello World! to Golang setup on windows
Tags: go, tutorial, beginners, github
Published: 2021-07-10 23:17:17

**Follow these steps to install and setup your first Go project on windows**
* Download and install Vscode my preffered editor
* Download and install git bash for windows
* Download and install Go executable from this [link](https://golang.org/doc/install).

* Set up your GO path by typing this on git bash terminal ```export GOPATH=$HOME/go```
 This will create a "go" folder in your computers C: directory like so: `C:/Users/ProfileName/go`

* Setup a new project inside the go folder structure like so:`C:/Users/ProfileName/go/src/github.com/githubUserName/projectFolderName`, instead of doing this manually, you can use the windows ```mkdir``` command to create your project file path like so: `mkdir -p $GOPATH/src/github.com/githubProfileName/projectFolderName`.

* Open up your newly created folder on vscode, install the Go extenstion plugin form vscode plugins to enjoy code highlighting and more.
 
* Create your first Go file with a .go extention then install All on the prompt that pops up after yourFile.go is created.

You are pretty ready to build your first golang project. If this article helped, please kindly hit the buttons so others can get help. Thanks for viewing.
Depth First Search (DFS) Algorithm
Tags: algorithms, beginners, codenewbie, computerscience
Published: 2021-07-10 22:31:57

Hi, today, we're going to talk about Depth First Search (**DFS**)

## Definition of Depth First Search

+ Depth First Search: is an algorithm for traversing or searching in tree or graph data structure using recursion and [**Stack**](https://dev.to/ayabouchiha/stack-data-structure-47ma) data structure.

## Time & Space complexity of Depth First Search (DFS)

| Space complexlity 	| O(V) 	|
|-------------------	|------	|
| **Time complexity**   	| **O(V+E)** 	|

## Depth First Search applications

+ Counting connected components
+ Solving Sudoku Puzzles
+ Topological sorting
+ Pathfinding
+ Finding Strongly Connected Components of a graph

## Depth First Search implementation in Python

[more details...](https://www.educative.io/edpresso/how-to-implement-depth-first-search-in-python)

```python
# code from https://www.educative.io/edpresso/how-to-implement-depth-first-search-in-python
graph = {
    'A' : ['B','C'],
    'B' : ['D', 'E'],
    'C' : ['F'],
    'D' : [],
    'E' : ['F'],
    'F' : []
}

visited = set() # Set to keep track of visited nodes.

def dfs(visited, graph, node):
    if node not in visited:
        print(node)
        visited.add(node)
        for neighbour in graph[node]:
            dfs(visited, graph, neighbour)

dfs(visited, graph, 'A')
```

\#day_28

## References & useful Resources

+ [https://www.educative.io/edpresso/how-to-implement-depth-first-search-in-python](https://www.educative.io/edpresso/how-to-implement-depth-first-search-in-python)

+ [https://www.geeksforgeeks.org/depth-first-search-or-dfs-for-a-graph/](https://www.geeksforgeeks.org/depth-first-search-or-dfs-for-a-graph/)

+ [https://www.hackerearth.com/practice/algorithms/graphs/depth-first-search/tutorial/](https://www.hackerearth.com/practice/algorithms/graphs/depth-first-search/tutorial/)
Explained: Definition of done
Tags: productivity, programming, devlive, career
Published: 2021-07-10 22:24:15

As engineers, our responsibilities don't lie only in writing the code but also to develop a solution that meets standards of quality. To guarantee that quality it is recommended to define what we can expect from a ticket that is done, this is called “definition of done”.

Normally, each team has its own definition of done. For sure, it can change between teams and commonly the responsibilities for developers are: 

* Make sure to cover ticket accepts criteria
* Create Unit test to methods created and updated
* Make a pull request and attend requested changes if there is any
* Make sure Pull Request is closed before continues process
* Make smoke testing of ticket on controlled environment

There are sometimes due to any external situation where your work related to code is done but still the ticket does not satisfy what “done” means to the project, so even when it feels like it is done, the ticket is not yet!!! 

It’s very important to know that there exist mechanisms to manage this type of situation. All of them resume on raising your hand, but there are different ways you can raise the hand. 

* Meeting
* Official communication channel
* Ticket comments
* Email

If daily meetings as stand up take place on your project, you must use them to mention the current situation and also, request the actions to remove the blocker. However, there is a phrase that says “words are gone with the wind”, so if you don't see any movement on your blocked ticket, you should use the official communication channel, as Slack for example, to remember the actions needed. If that doesn't solve the issue you can proceed to write a comment on the ticket and also flag it. If after all this, the situation persists, you can use the email to communicate and explain the context.    

# Conclusions:

* Always have present what “done” mean for your team and make sure your tickets meet those standards 
* Is totally normal that a random situation appears and blocks your intention to make your ticket accomplish the definition of done, but raising your hand as soon as possible you can mitigate risks.
Finding Time For Security When Scaling w/ Liran Tal
Tags: security, devops, codereview, culture
Published: 2021-07-10 21:33:55

Imagine a world where we gave developers the ability to find and fix security vulnerabilities before their code is merged.

This week on [Dev Interrupted](https://devinterrupted.com/podcast/finding-time-for-security-when-scaling/) we bring in Liran Tal, a security expert from Snyk.io, to talk about how our community can begin evolving traditional security workflows. We also discuss what good security culture looks like, and how to best track and prioritize our efforts.

#**Listen to the full episode**
{% spotify spotify:episode:5K9FwWHY2EU2rxVwhipCI5 %}

#**Episode Highlights include:**
* The right metrics to track when looking at security
* How to enable developers to find and fix security vulnerabilities
* Which security issues you need to prioritize for ROI and why
* How to start the transition to a more modern security model


#**Join the Dev Interrupted Discord Server**
With over 1200 members, the Dev Interrupted Discord Community is the best place for Engineering Leaders to engage in daily conversation. No sales people allowed. [Join the community >>](https://discord.gg/tpkmwM6c3g)
![Join the Dev Interrupted Discord Community!](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/19j3dzgz4r4kzav3w6z8.png)
CLI for Managing Shopify App Webhooks
Tags: cli, typescript, shopify, graphql
Published: 2021-07-10 21:27:59

[`shopify-webhook-commander`](https://www.npmjs.com/package/shopify-webhook-commander) is a CLI to create, list, and delete Shopify Admin App webhook subscriptions.

Building out a new admin app often requires setting up listeners for Shop events but building out controllers and UI to manage webhook subscriptions isn't always at the top of the to-do list.

This CLI will let developers manage subscriptions from the terminal.

![shopify-webhook-commander demo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r5vicgwjwl83u841g4ui.gif)

## Install

🚫 This package is under active development; installer beware.

```sh-session
$ npm i -g shopify-webhook-commander
```

## Note about auth tokens

This tool uses a single token to authenticate; this is easiest with a Shopify "Private" Admin App. Set the config secret to the private app password. _There is no OAuth flow to help with "Custom" Partner apps._
You could provide an `accessToken` acquired from a Custom app's authentication flow.
shopify-webhook-commander doesn't really help for "Public" apps that typically manage webhooks for each shop install programatically.

## Roadmap

1. tests 😬
1. replace Apollo client with a slimmer GQL lib
1. integrate `@shopify/shopify-api` types -- gotta get rid of those `any` types
1. `webhooks:update` command
1. autocomplete webhook topics
1. auth loop for custom apps

![some cli typescript](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8uy11d6lz2epdf1jx7cz.png)