teleren/devto huggingface dataset:
Linked List in JavaScript
Tags: javascript, programming, beginners, computerscience
Published: 2022-03-21 00:16:00

**What is a Linked List?**
A linked list data structure involves a series of Nodes linked together. Each Node will have a data value and a reference to the next Node in the list. In the last Node, the reference will be set to `null`. Linked lists are not commonly used in front end web development, but they are still very popular for interview coding problems.

**Here is a simple implementation of a Linked List**
```js
class Node {
  constructor(data, next = null) {
    this.data = data;
    this.next = next;
  }
}

class LinkedList {
  constructor() {
    this.head = null;
  }

  // Inserts a Node into the Linked List
  insertFirst(data) {
    this.head = new Node(data, this.head);
  }

  // Returns the number of nodes
  size() {
    let node = this.head;
    let count = 0;

    while (node) {
      count++;
      node = node.next;
    }

    return count;
  }
  
  // Returns the first Node
  getFirst() {
    return this.head;
  }

  // Returns the last Node
  getLast() {
    if (!this.head.next) {
      return null;
    }
    let node = this.head;
    while (node) {
      if (!node.next) {
        return node;
      }
      node = node.next;
    }
  }

  // Removes all Nodes from the Linked List
  clear() {
    this.head = null;
  }

  // Removes the first Node from the Linked List
  removeFirst() {
    if (this.head) {
      this.head = this.head.next;
    }
  }
}
```
Here it is in use:

```js
let list = new LinkedList();
list.insertFirst(1);
list.insertFirst(2);
list.insertFirst(3);
// list = {
//   head: {
//     data: 3,
//     next: {
//       data: 2,
//       next: {
//         data: 1,
//         next: null
//       }
//     }
//   }
// }

list.getFirst() // { data: 3, next:... }
list.getLast() // { data: 1, next: null }
list.size() // 3
list.removeFirst() // { head: { data: 2, next:... }}
list.clear() // { head: null }
```
You will notice that a Linked List in JavaScript is simply a series of nested objects. The list will always start with a head, and the last node reference will be `null`.

**If you are preparing for coding interviews, here are a few coding challenges involving Linked Lists**

- [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/)
- [Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list/)
- [Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list/)
- [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements/)
- [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/)

Leave a comment if you have any questions or feedback.
Learning Rails #2 - Migrations
Tags: ruby, rails, beginners
Published: 2022-03-21 00:14:45

> The role of these series, is to be used as a refresher and a place where beginners can discuss.
If you're also learning (or intend to learn) Rails, I highly recommend that you follow the Getting Started section of the [Rails Guides](https://guides.rubyonrails.org/).

When creating a model, a migration file is also generated. You should see a file like `20130924230504_create_users.rb` in the`db/migrate` folder (this giant number is a timestamp). This is the migration file of your model and if you click it, you see that inside that are all attributes that you made and its types.
After creating a model you have to run the migration, in order to update the database, creating a new table for the model.

## What is a Migration?
A Migration basically is a script that will have all the code needed to change  your database. Basically every change you make to the database should be through a migration.

**For example:** Let's say you created a model for users, and ran its migrations, then you realize you forgot the email attribute, you can solve this problem by creating a new migration file.

```bash 
rails generate migration AddEmailToUsers
```

And in the migration file, you can add any changes, in our case we need to add an email attribute, so we'll do:

```ruby
# In the migration file
class AddEmailToUsers < ActiveRecord::Migration[7.0]

  def change
    add_column :users, :email, :string
  end

end
```

Now:

```bash
rails db:migrate
```

Now all migrations will run, hence the database will be updated.

## How to use Migrate and Rollback
- `rails db:migrate`
As we've seen before, this will run all the migrations.

- `rails db:rollback`
It will run the inverse command for everything a migration did, sometimes you'll need to write it yourself check the [documentation](https://guides.rubyonrails.org/active_record_migrations.html#using-the-up-down-methods) for more information.

By default, the commands above will run all the migrations you have, using the timestamp to track the order of when which script should run. To run only the migrations you want, use the `STEP` parameter. Ex.: `rails db:migrate STEP=2`, this will run only two migrations files.
I've never fired anyone for technical incompetence
Tags: hiring, firing
Published: 2022-09-14 08:18:01

---
title: I've never fired anyone for technical incompetence
published: true
date: 2022-03-21 00:00:00 UTC
tags: hiring,firing
canonical_url: https://jhall.io/archive/2022/03/21/ive-never-fired-anyone-for-technical-incompetence/
---

I’ve hired a number of people over the years. Mostly software developers or operations engineers. A few Scrum Masters.

The candidate selection process has always been geared around detecting technical competence. Reviewing code the candidate wrote, talking about their technical experience, asking them how they would respond in certain technical situations.

I’ve also been involved in firing a few people over the years.

But you know what’s interesting?

I’ve never once fired someone, or even been _tempted_ to fire someone, for lack of technical competence.

The reasons I’ve fired people have varied. It’s usually been a combination of multiple factors. Here are a few memorable ones:

- Overt racism toward colleagues
- Gross insubordination
- Failure to simply do any work
- Refusal to accept responsibility for their own professional improvement

In other words, looking back, I’ve only ever fired people for having an attitude that was not condusive to work.

Now to be fair, some of the people I have fired _did_ have a technical competence issue. But that was never the reason they were fired. In fact, in every example I’ve been involved in, if they had been able to overcome their attitude problem, we would have given them plenty of more time to develop their technical skills.

This just makes me wonder: During candiate interviews, do we, as an industry, spend too much time focusing on technical skills, and not enough on the more “soft skills” aspects of our candidate pool?

* * *
_If you enjoyed this message, [subscribe](https://jhall.io/daily) to <u>The Daily Commit</u> to get future messages to your inbox._
PowerShell 7 PSReadLine PredictionViewStyle
Tags: cmd, powershell, psreadline
Published: 2022-11-24 09:15:02

---
title: PowerShell 7 PSReadLine PredictionViewStyle
published: true
date: 2022-03-21 00:00:00 UTC
tags: CMD,PowerShell,PSReadLine
canonical_url: https://ahonerd.com/powershell-7-psreadline-predictionviewstyle
---

Cara mengatasi error yang muncul ketika melakukan perintah tag `Set-PSReadLineOption -PredictionViewStyle ListView`.

## Solution

Untuk mengatasinya dapat dilakukan dengan perintah berikut menggunakan cmd sebagai Administrator:

{% gist https://gist.github.com/ahoNerd/f5020794eca07ea019725fea4bf691dc file=fix_psreadline.cmd %}
"Return value of Maatwebsite\\Excel\\Sheet::mapArraybleRow() must be of the type array, int returned"
Published: 2022-03-20 23:33:58

Hello, why i get this error?
what's the solution ?

view (Ajax) :

```
`            $('#export').click(function (e) {
            let rows_selected = tblMassy.column(0).checkboxes.selected();
                        if (rows_selected.length >= 1)  {

                            $.each(rows_selected, function(index, rowId){

                                console.log( "http://localhost:8000/eksportfilter/" + rowId ) ;
                                // location.href= "/eksportfilter/" + rowId;
                                $.ajax({
                                    type:'POST',
                                    url: "http://localhost:8000/eksportfilter/" + rowId,
                                    dataType: "JSON",
                                    success: function (response) {
                                        console.log( response )
                                    }
                                });   
                            });
                                console.log(rows_selected.length);

                                swal("Good job!", "Eksport data successfully!", "success");
                                
                                $('#tblMassy').DataTable().ajax.reload();
                                // location.reload();
                        } else {
                            swal("Failed Export!", "No Data Delected!", "error");
                        }
        });`
```

my controller :

```
` public function eksportfilter($id)
    {
            $data = [
                'id' => $id,

                $m_assy = m_assy::find($id)
            ];
            return Excel::download(new TransactionsExportFilter($m_assy), 'users.xlsx');
    }`
```

Maatwebsite Export :

```
`public function __construct($data)
    {
        $this->data = $data;
    }


    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return collect($this->data);
    }

    public function headings(): array
    {
        return [
            'id',
            'assymainharness',
            'assyab',
            'assyab1',
            'assyab2',
            'assyab3',
            'type',
            'assycode',
            'suffixlevel',
            'desccarline',
            'factory',
            'customer',
        ];`
```

Can anyone help me solve this problem ?
The missing update command for Homebrew
Tags: dx, homebrew, macos, shell
Published: 2022-03-20 23:03:44

---
title: The missing update command for Homebrew
published: true
tags: #dx, #homebrew, #macos, #shell
canonical_url: https://stldo.com/blog/the-missing-update-command-for-homebrew
---

Homebrew is a great tool for managing packages in macOS. It allows to quickly install and update dozens of libraries and apps that otherwise would consume much more time to compile. Whenever I need an open-source package, most likely it'll be available in Homebrew. It's a really useful tool, but I rarely use it to a point that keeps it up-to-date. Every time I need to install something, Homebrew is outdated. So, to keep things simple, I came up with the following shell function:

```shell
brew() {
  if [[ $@ == "update" ]]; then
    command brew update && \
      brew upgrade && \
      brew autoremove && \
      brew cleanup -s
  else
    command brew "$@"
  fi
}
```

Just copy and paste it to your `~/.zshrc` file — or `~/.bashrc`, if you use Bash — and every time you run `brew update`, it'll run the following commands:

- `brew update`: updates the package definitions and Homebrew itself;
- `brew upgrade`: upgrades all the installed packages — `brew install` upgrades any installed dependencies required by a package, but if it finds conflicts with outdated packages requiring the same libraries, you'll need to sort this out;
- `brew autoremove && brew cleanup -s`: I started using this command after discovering a 50 GB Homebrew cache folder in my machine, it only takes a few seconds to run and keeps everything tidy.

If you want to execute this routine every time you call `brew install`, you can use the following shell function:

```shell
brew() {
  if [[ $@ == "install" ]]; then
    command brew update && \
      brew upgrade && \
      brew autoremove && \
      brew cleanup -s && \
      brew "$@"
  else
    command brew "$@"
  fi
}
```

In the past, I used this function with the `brew install` command, but now I prefer to use it with `brew update`. Sometimes my Homebrew is really outdated and it takes some time until the update is done. I prefer to leave it running while I do other things, and then run `brew install package-name` after everything went well. If you have any questions or know a better approach to keep Homebrew packages updated, please let me know, it'll be great to hear from you.
WEB3 vs WEB2
Published: 2022-03-01 19:41:27



## WEB2

funny enough , the web as we all know it has taken a lot of changes since it was first launched to the public in 1991 . The term Web 2.0 became a thing in the year 1999 . upgrades on the web was what marked the differences between them to the recorded.

Static HTML ruled the Web 1.0 period; there was no responsiveness, and files had to be kept on the server’s disc, which prevented the use of relational databases and other advanced features.

The web as we know it now is Web 2.0. The rising of social media websites, which allowed individuals to share and connect on the internet, was a defining feature of the period. Users’ experience is becoming a top consideration for website owners. On the web, complex data may now be analysed and managed.


## THE LATEST UPGRADE(WEB3)
Well, to be honest, there isn’t a straightforward answer to when Web3 started because it’s more of a concept/theory in work than an implemented upgrade. We are all aware of the rise in the adoption of decentralized products by people, the most famous being Cryptocurrency which runs on Blockchain Technology.


## PROMISES OF WEB3

We are well aware of the growing worry about the privacy of all of the data created by individuals on the internet, particularly in the Web2 age. Big tech corporations (as well as small tech companies) have complete control over how consumers’ data is gathered, kept, and used. Web3 gives consumers complete ownership over their data, which is kept on the blockchain protocol rather than in a single database (controlled by IT corporations).

It also eliminates the necessity for a third party when people interact with one another over the internet. Due to the availability of smart contracts on the Blockchain, the system operates with little or no supervision. Typically, these third parties demand a fee for these services and more; however, Web3 provides users with free and more efficient online access.

“Security is an illusion” is a phrase most people in the tech space have heard. Despite this, Web3 promises to be more secure. Users’ data are protected on the blockchain network and they can decide to be anonymous for as long as they want.

## Conclusion
Web2 the  version of the internet most of us know today. An internet dominated by companies that provide services in exchange for your personal data. Web3 refers to decentralized apps that run on the blockchain. These are apps that allow anyone to participate without having to share your personal information

https://blockgames.gg/
https://nestcoin.com/
https://zuri.team/
Why do you need to use headless platform?
Tags: coredna, headlesscms, cms, opensource
Published: 2022-03-20 22:52:49

A headless platform gives you a number of benefits. These include:

_1. Ability to create your own custom content types that can then be used to build further complex content types that are independent of the original database design._

_2. Freedom to develop interfaces based on your own standards without the constraints of your current CMS._

_3. The ability for you to distribute your content to multiple channels. For example desktop, mobile, phone, interactive screen, digital banners._

_4. A central place for all your content, rather than have it distributed across many different systems._

_5. Ability to access content using application programming interfaces (API)._

_6. Ability to create custom publishing environments that are tailored to your admin requirements._

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1a8neuom8vvfaexefcug.jpg)

_7. Remove the dependence of your systems on specific systems. You can use API interfaces to access what you need from systems and replace them easily if your needs change._

_8. Ability to use microservices for speed and flexibility._ 

_9. Make changes quickly without the need to engineer your CMS; making it faster to get changes done._

_10. Developer friendly, no big learning curves for developers to understand new CMS/eCommerce platforms. Easy-to-learn API interface that gives them the ability to create anything using multiple sources of information._

_11. Ability to improve performance: by controlling exactly what you want to deliver to your visitor, without the overheads of a traditional CMS/eCommerce._

_12. Improved security through access to distinct APIs that can be controlled by the admin._


**Read this next: [Headless CMS vs Decoupled CMS: The Ultimate Guide](https://corednacom.corewebdna.com/blogs/headless-cms)**
TypeScript 配列とオブジェクトの継承
Tags: typescript
Published: 2022-03-20 22:45:35


関数で複雑な型を参照する時にハマったのでまとめておく

---

## オブジェクトの配列を関数に継承する

```ts
type InputProp = {
  label: string;
  value: string;
};
```

この型があり

```ts
const forms: InputProp = [
    { label: "id", value: "0001" },
    { label: "name", value: "Tak" },
]
```

```ts
<FormTable rows={forms} />
```

このように受け渡すと失敗する
rows がないと言われる。

```ts
export type middleProp = {
  rows: InputProp[];
};
```

そのため、InputProp を使うためのミドルウェアとして
このような中にはさむ型の　middleProp が必要になる。

https://yutaro-blog.net/2022/03/21/react-search/

この yutaro さんの記事でも

```ts
type member = {
  name: string;
  country: string;
  food: string;
};

type MemberList = Array<member>;
```

member というオブジェクトの型
それを元にした memberList というオブジェクト配列の型を作成して

```ts
  const [memberList, setMemberList] = useState<MemberList>(allMemberList);
```

allMeberList という実際のデータから state を作るときの型に利用している。


---

## オブジェクトのオブジェクトのタイプを使う

```ts
export type ObjectProp = {
  title: string;
  subTitle?: string;
};
```

オブジェクトの型を定義して

```ts
export type MiddleProp = {
  forms: CpFormObjectProp;
};
```

引き渡し用のミドルウェア的な型を定義

```ts
const formObject: MiddleProp["forms"] = {
  title: "BB";
  subTitle?: "Toy Gun Ammo";
};
```

ミドルウェアから form のプロパティに入っている
オブジェクトの型を呼び出し、オブジェクトの中身を入れる

```ts
<FormTable {...formObject} />
```

これは　forms では渡せないため、スプレッドで渡す。
React router page just disappearing
Tags: react, javascript
Published: 2022-03-20 22:42:23

Hey there! I recently tried using react for a website that lists all freelancers, but now when I try to access a specific freelancer's site, it just shows a blank page. My code is here:


App.js
```
import Navbar from './Navbar';
import Home from './Home';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import Create from './Create';
import Freelancerdetails from './FreelancerDetails';

function App() {

  return (
    <Router>
      <div className="App">
        <Navbar />
        <div className="content">
          <Switch>
            <Route exact path="/">
              <Home />
            </Route>
            <Route exact path="/create">
              <Create />
            </Route>
            <Route path="/freelancers/:username" >
              <Freelancerdetails />
            </Route>
          </Switch>
        </div>
      </div>
    </Router>
  );
}

export default App;
```

FreelancerDetails.js
```
import { useParams } from "react-router-dom";

const Freelancerdetails = () => {
    const { username } = useParams();

  return (
    <div className="freelancer-details">
      <h2>Freelancer details - { username }</h2>
    </div>
  );
}
 
export default Freelancerdetails;
```

Home.js
```
import { useState, useEffect } from "react";
import BlogList from "./BlogList";

const Home = () => {
  const [freelancers, setFreelancers] = useState([
    { skills: 'Not loading', name: 'mario', id: 1, homepage: "https://zetax.dev" },
  ])
  const [isPending, setisPending] = useState(true);

  useEffect(() => {
        const fetchData = async () => {
          const response = await fetch("https://149-56-112-99.my.local-ip.co/", {
          });
            const data = await response.json();
            const newFreelancers = data.slice(0, 50);
            setFreelancers(newFreelancers);
            setisPending(false);
        }
        fetchData();
    }, []);

  return (
    <div className="home">
      { isPending && <div>Fetching data...</div> }
      <BlogList freelancers={freelancers} title="All Freelancers" />
      <a href="https://zetax.dev" className="watermark">Made by Zetax</a>
    </div>
  );
}
 
export default Home;
```

BlogList.js
```
import { faTrash } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Link } from 'react-router-dom';

const BlogList = ({ freelancers, title, }) => {

    return (
        <div className="blog-list">
            <h2>{title}</h2>
            {freelancers.map(blog => (
                <div className="blog-preview" key={blog.id} >
                    <h2><Link to={ "/freelancers/" + blog.name}>{blog.name}</Link></h2>
                    <p>Skills: {blog.skills}</p>
                    <a href={blog.homepage}>Visit Homepage</a>
                </div>
            ))}
        </div>
    );
}

export default BlogList;
```

I really hope someone would be willing to help me as it's a really frustrating issue to deal with! Greetings, Finn
How I read Files in Python
Tags: python
Published: 2022-03-20 22:37:37

---
canonical_url: https://waylonwalker.com/til/pathlib-read-text/
published: true
tags:
- python
series: til
title: How I read Files in Python
---

When I need to read contents from a plain text file in python I find the easiest way is to just use `Pathlib`.

``` python
from pathlib import Path

Path('path_to_file').read_text()
```