teleren/devto huggingface dataset:
SWAP Management - Create, Activate, Swappiness, Deactivate, Remove [EASY GUIDE]
Tags: linux, tutorial
Published: 2022-08-12 08:59:00

#CREATE
---

1. Creating a Swap File
![Calculating Count Value](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k6bdtj70c7mcgfdstxku.png)
```
sudo dd if=/dev/zero of=/swapfile bs=1024 count=<1024*desired_swap-size_in_MB>
```
Keep block size `bs=1024`

2. Set the file permissions to 600 to prevent regular users to write and read the file:
```
sudo chmod 600 /swapfile
```

3. Create a Linux swap area on the file:
```
sudo mkswap /swapfile
```

---
#ACTIVATE
---

4. Activate swap file
```
sudo swapon /swapfile
```

5. To Make the change permanent open the /etc/fstab file:
```
sudo nano /etc/fstab
```

6. Paste following line
```
/swapfile swap swap defaults 0 0 
```
![Make Swap permanent](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x25hq9oxqof5kir8eo1c.png)
 
---
#SWAPPINESS
---

7. Check swappiness value
```
cat /proc/sys/vm/swappiness
```
On Ubuntu, the default swappiness value is set to 60

8. Modify swappiness
```
sudo sysctl vm.swappiness=10
```
While the swappiness value of 60 is OK for most Linux systems, for production servers, you may need to set a lower value.

9. Make swappiness permanent
To make this parameter persistent across reboots, append the following line to the `/etc/sysctl.conf` file:
```
vm.swappiness=10
```

---
#DEACTIVATE
---

10. Deactivate swap file

```
sudo swapoff -v /swapfile
```

---
#REMOVE
---

11. Remove the swap file entry `/swapfile swap swap defaults 0 0` from the `/etc/fstab` file. From Step 5.

12. Finally, remove the actual swapfile from your disk

```
sudo rm /swapfile
```

You can find your swapfile at `root` directory

![swapfile Location](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fl5hqwtr7r1jpfjg38d3.png)

To check the status of swap use `free -h` or `swapon -s`
Why opt for Glitch build?
Tags: glitchbuild, html, theglitchboard, moderndev
Published: 2022-08-12 08:54:23

> Why opt for glitch build

Well, first things first. What is [Glitch Build](https://glitchbuild.pages.dev) used for?

Glitch build is a platform that creates a healthy environment for junior developers to thrive. It offers a platter for developers to buy and sell templates, compile code online, hosts one-time projects and offers a modern way of building web apps.

> Why use Glitch Build

It's quite simple, glitch build is a platform that gives free stock images, free one-time hosting, free communication system, free weekly templates and free tutorials. Glitch Build is completely free and charges $0 while providing the best web development services.

> What is Glitch build one-time project hosting

Glitch Build one-time project hosting is a preview url given when using the Glitch Build code editor, it's a url that can only be accessed when the author shares it but until he/she does, it remains private. The one-time project hosting can never be deleted once the link is out and creates a wider space for an indestructible hosting..... lol.

---

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wwr4lru7hh9pmaxvey14.png)
[Solved] Gitlab: Maximum number of ci instance level variables (25) exceeded
Tags: github, ci, variables
Published: 2022-08-12 08:52:00

1. Start Gitlab Rails Console
```
sudo gitlab-rails console
```

Ref: https://docs.gitlab.com/ee/administration/operations/rails_console.html#starting-a-rails-console-session

2. Run following command to increase instance level variables
```
Plan.default.actual_limits.update!(ci_instance_level_variables: 300)
```

Wait for sometime for the command to run.

Ref: https://docs.gitlab.com/ee/administration/instance_limits.html

3. Exist from Rails Console
```
exit
```
Type `exit` command and press `enter`
Does openGauss support the pgcrypto extension?
Published: 2022-08-12 08:39:34

As the title.

If it is not supported, is there any alternative to hash the string using SHA1, SHA256, SHA384, SHA512, MD5, etc.?
If supported, how should this extension be installed?
I have seen related files in the openGauss source code (openGauss-server-master\contrib\pgcrypto), but there is no contrib folder in the current official docker version and Motianlun online training environment. 
If you execute it directly in the database

create extension pgcrypto;
will report an error

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4vzbck3uffnzqytwl7j2.png)
 If you execute

apt-get install postgresql-contrib
Then it is actually installed into postgresql, not opengauss
B2D Content Marketing Strategy with Ofir Nachmani
Tags: developercontent, b2d, contentstrategy, dexrelxpodcast
Published: 2022-08-12 08:39:05

**Theme of the week**

> _Why do you need a content plan on top of a marketing plan?_

In our latest episode of the DevRelX podcast, we talk about content marketing for developer audiences. We are joined by Ofir Nachmani, the CEO of [IamOnDemand](https://iamondemand.com/?utm_source=DevRelX_podcast&utm_medium=Devto&utm_campaign=OfirNachmani) to talk about:

- Why does a B2D company need a tech content marketing strategy & planning
- Where and how do you start building such a plan?
- How do you create tech content that developers will like and engage with?
- What tips would you offer to a B2D marketer?
- What are some best practices for building a tech content production machine?

Listen to this episode to better understand how to produce and use content to boost your marketing goals.

{% embed https://open.spotify.com/episode/75xAJFlXSXW2ZDGuVfgsfj?si=lZTx6I9hR5aqcZryW6HwDw %}

The graph Ofir chose to talk about: [Experienced developers have a bigger say on things.](https://www.devrelx.com/trends?lightbox=comp-kisqhm6d3__6fb52f74-5717-4aa2-86b8-142c4d300af4_runtime_dataItem-kisqhm6e)

Ofir Nachmani is a business technology advisor, blogger and lecturer. Ofir's extensive experience in the world of business technology has made his critically acclaimed blog, IamOnDemand.com, the go-to guide for modern technology startups and developers in the world of cloud computing. Today he advises organisations, leading them through new IT market modifications, while building and executing a modern go-to-market strategy.


![Ofir Nachmani](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/565cn49gmjqpw1rtz6j9.jpg)
Education Required For Mechanical Engineering
Tags: mechanicalengineering
Published: 2022-08-12 08:29:00

The education required for Mechanical engineering is a bachelor's degree in mechanical engineering or mechanical engineering technology. All states and the District of Columbia require mechanical engineers who sell services to the public to be licensed.For further details visit this site:https://www.aboutmech.com/2022/08/education-needed-for-mechanical-engineering.html
How can use input value in innerHTML in react-js?
Tags: javascript, react, webdev, reactnative
Published: 2022-08-12 07:53:00

I Defined three file..I want input value in innerHTML show threw button.but I getting not work in innerHTML.So please sugesstion answer.thank you!

////////////index.html
` <div id="root"></div>
    <div id="root2"></div>
    <div id="root3"></div>
    <input id="inpt" type="number" />
    <button onclick="MyClick()">Click here</button>`


////////////index.js file
import React from "react";
import ReactDom from "react-dom?client";
import {Stricks_} from "./App"
`export function Strick1_(){
return(
  <>
  <span></span>
 <Stricks_/>
  </>
)
}
const root = ReactDom.createRoot(document.getElementById("root"));
root.render(<Strick1_ />);`


////////////App.js file
`import reactDom from "react-dom";
export function Stricks_() 
  const inputs = document.getElementById("input");
  const roots = document.getElementById("root3");
  function MyClick() {
    const vale = inputs.value;
    roots.innerHTML = vale;
  }

}
const root = reactDom.createRoot(document.getElementById("root"));
root.render(<Stricks_ />);
`
Hello World ! Hello Cillian!
Tags: devops, kubernetes, beginners, python
Published: 2022-08-12 07:09:21

This is my first time writing an article in DEV.

I am a software development engineer.

Mainly using k8s, python, go, vue, java .

learning cloud native technologies,have obtained CKA and CKS certification.

I will share what I have learned here.

Thank you for following.
Dynamic Programming in Python
Tags: algorithms, python
Published: 2022-08-12 07:01:00

## What is dynamic programming?
Dynamic programming is a technique that allows us to solve a class of problems with overlapping subproblems and optimal substructure. 

Dynamic programming is also a technique that trades space for time. With dynamic programming, a problem with exponential number of subproblems can often be solved in polynomial time.

The time complexity of dynamic programming problems is usually O(MN), where M = number of subproblems, N = time complexity of subproblems.

### Characteristics of dynamic programming
**Overlapping subproblem**: the original problem has multiple instances of the same subproblem.

**Optimal substructure**: the solution to the original problem can be constructed from solutions of subproblems.

### Dynamic programming implementations
The two dynamic programming implementations are:
- top down (DFS + memoization)
- bottom up (tabulation

To solve dynamic programming problems, you need:
- the problem defined as relatable subproblems
- recurrence relation to relate the sub-solutions to the original solution
- base cases for the recurrence relation

## Common dynamic programming questions
Here are 6 common dynamic programming questions:
- Knapsack
- Longest increasing subsequence
- Longest common subsequence (edit distance)
- Matrix chain multiplication
- Kadane's algorithm
- Distinct Ways
Job Announcement Website: Route to Login Page
Tags: javascript, webdev, react, opine
Published: 2022-08-12 06:51:00

{% embed https://dev.to/sokhavuth/table-of-contents-2o4e %}
GitHub: [https://github.com/Sokhavuth/opine-job](https://github.com/Sokhavuth/opine-job)
Deno Deploy: [https://khmerweb-job.deno.dev/users](https://khmerweb-job.deno.dev/users)
<br/>
<p>
In Opine as in Express web frameworks, before building any page, we need to define a route leading to that page first by using Router class in the framework. As the route to the backend under the name “users” was already created by Opine CLI, what we need to do is creating a number of sub-routes to be mounted to this predefined “users” route. In fact, we can create a route leading to the login page, and that route could be mounted to the backend “users” route as below:
</p>

```js
// routes/users.ts

import { Router } from "../deps.ts";
const router = Router();


import login from "./users/login.js";
router.use("/", login);


export default router;
```

```js
// routes/users/login.js

import { Router } from "../../deps.ts";
const router = Router();


import login from "../../controllers/users/login.js";

router.get("/", async (req, res, next) => {
    const html = await login.getForm(req);
    res.send(html);
});


export default router;
```

```js
// controllers/users/login.js

import login from "../../views/users/login.jsx";


class Login{
    async getForm(req){
        const config = req.mysetting();
        config.page_title = "Login Page";
        config.route = '/users/login';

        return await login(config);
    }
}


export default new Login();
```
Create a Static Class in Typescript
Tags: tutorial, typescript, beginners
Published: 2022-08-12 06:39:09

You can't have `static` classes in `Typescript` out of the box, but there are several approaches to make a class that cannot be instantiated. This article is about them.

## 1. Make constructor private
```typescript
class JustAClass {
  private constructor() { }
}
```

Intellisense will alert if you try to instantiate it.

## 2. Throw error in class constructor
```typescript
class Static {
  constructor() {
    throw new Error('No, you don\'t!');
  }
}
```

Throwing an error inside the constructor gets the job done, moreover other classes can now inherit this one to become static themselves:
```typescript
class JustAClass extends Static {
  constructor() { super(); }
}
```

Though no intellisense to help unlike in the first way.

## 3. Use abstract instead
```typescript
abstract class JustAClass {}
```

Intellisense is still going to alert you when trying to instantiate it, though it looks like a misuse of the `abstract` keyword.

## 4. Create a decorator to make any class static
This approach combines method 2 with typescript's decorators feature. We create a function that pumps out anonymous class which inherits a given class, and overrides its constructor call with throwing an error. And yes, it breaks all the rules and does not call the super like a bad boi, so we silence the compiler with `@ts-ignore`.
```typescript
function Static<T extends new (...args: any[]) => any>(ctr: T): T {
  return class extends ctr {
    // @ts-ignore
    constructor(...args: any[]) {
      throw new Error('no way dude');
    }
  }
}

@Static
class JustAClass {}
```

While not providing the safety of intellisense, this approach is quite declarative.

That's the four ways I discovered :)
How To Upload Multiple Image In Laravel 8
Tags: laravel, fileupload, imageupload, php
Published: 2022-08-12 05:46:45

In this article, we will see how to upload multiple images in laravel 8. here, we will see a tutorial on multiple image uploads in laravel 8. Also, we will see upload multiple images with validation in laravel 8 or laravel multiple file upload validation.

So, let's see upload multiple images with a preview in laravel 8 or multiple images upload in laravel 8.


```

Step 1: Install Laravel 8 for Upload Multiple Images

Step 2: Add Model and Migration

Step 3: Create Controller

Step 4: Create Route

Step 5: Create Blade File

```
The Start of My Journey
Tags: beginners
Published: 2022-08-12 05:45:51

Hello, DEV community! My name is Lucy and I'll occasionally be making posts about some interesting things that I've learned on my journey to becoming a software engineer. For example, I've recently learned about how to integrate API data using fetch(). It was a bit confusing at first, but the more that I use it in my projects, the more that I become familiar with it's uses! Keep tuning in if you want to see where my journey takes me.
Uploading files in Remix to a S3 compatible service
Tags: remix, webdev, react
Published: 2022-08-12 05:23:00

Remix is a new react-based framework designed to be a full stack application. With many applications, you will need to be able to store files, sometimes in an S3 compatible service. Here is how I was able to accomplish this. I took heavy influence from [this dev.to article](https://dev.to/timvermaercke/uploading-files-to-google-cloud-storage-with-remixrun-3c5c).

Create a file named `uploader-handler.server.ts` with the following contents:

```ts
import { s3Client } from './s3.server';
import type { UploadHandler } from '@remix-run/node';
import type { PutObjectCommandInput } from '@aws-sdk/client-s3';
import { GetObjectCommand } from '@aws-sdk/client-s3';
import { PutObjectCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';

const uploadStreamToS3 = async (data: AsyncIterable<Uint8Array>, key: string, contentType: string) => {
  const BUCKET_NAME = "my_bucket_name";

  const params: PutObjectCommandInput = {
    Bucket: BUCKET_NAME,
    Key: key,
    Body: await convertToBuffer(data),
    ContentType: contentType,
  };

  await s3Client.send(new PutObjectCommand(params));

  let url = await getSignedUrl(s3Client, new GetObjectCommand({
    Bucket: BUCKET_NAME,
    Key: key,
  }), { expiresIn: 15 * 60 });

  console.log(url);

  return key;
}

// The UploadHandler gives us an AsyncIterable<Uint8Array>, so we need to convert that to something the aws-sdk can use. 
// Here, we are going to convert that to a buffer to be consumed by the aws-sdk.
async function convertToBuffer(a: AsyncIterable<Uint8Array>) {
  const result = [];
  for await (const chunk of a) {
    result.push(chunk);
  }
  return Buffer.concat(result);
}

export const s3UploaderHandler: UploadHandler = async ({ filename, data, contentType }) => {
  return await uploadStreamToS3(data, filename!, contentType);
}
```

Next, you will need to create the actual route to be able to upload a file. I have the following file: `~/routes/api/storage/upload.tsx` with the following contents

```ts
import type { ActionFunction } from "@remix-run/node";
import { unstable_parseMultipartFormData } from "@remix-run/node";
import { auth } from "~/server/auth.server";
import { s3UploaderHandler } from "~/server/uploader-handler.server";

export const action: ActionFunction = async ({ request }) => {
  await auth.isAuthenticated(request, { failureRedirect: '/login' });

  const formData = await unstable_parseMultipartFormData(request, s3UploaderHandler);

  const fileName = formData.get('upload');

  return {
    filename: fileName,
  }
}
```
Now that you have the supporting files in place, let's upload a file.

```tsx
<Form method="post" action={'/api/storage/upload'} encType="multipart/form-data">
    <Input type="file" name="upload" />
    <Button type="submit">Upload</Button>
</Form>
```

There you have it! 

Version of sdks used:
- @remix-run/node: 1.6.5
- @remix-run/react: 1.6.5
- @aws-sdk/client-s3: 3.145.0
- @aws-sdk/s3-request-presigner: 3.145.0
Building a Second Brain
Published: 2022-08-12 05:22:05

> Building a Second Brain: A Proven Method to Organize Your Digital Life and Unlock Your Creative Potential, by Tiago Forte

I am personally not a fan of self-improvement books. Their advice sounds nice and sounds motivating, but in reality, it's really difficult to integrate the advice because it's out of context.

This book is different because it teaches you a systematic way (the second brain) to apply that knowledge in your life.

I'm not a note taker; it's harder to concentrate, and I barely ever looked at them. Plus, it takes forever to find the information you need even if you have all the notes in the world.

Despite not liking note-taking, I found some great takeaways from this book that I want to incorporate into my life.

## Takeaways
- Externalizing our thoughts makes them more concrete
- Organize our digital archive by "how actionable", not "what kind of info"
- Discoverability of info decreases as the amount of note-taking increases
- Distillation of notes increases discoverability

The author shares an amazing organization system called PARA, which stands for
- P: Projects (short-term goals you are working on)
- A: Areas (generalized long-term goals)
- R: Resources (future references)
- A: Archives (completed or inactive)

I organized my notes into PRA (without the 'Areas'), something like this:

```
├── Project/
│   ├── Project1/
│   │   ├── somefile
│   ├── Project2/
│   │   ├── somefile
├── Resources/
│   ├── Topic1/
│   │   └── somefile
│   ├── Topic2/
│   │   └── somefile
└── Archives/
    └── archivefile
```

## Conclusion
This book is a great read and contains a lot of information on how you can organize the massive amount of information you consume every single day. With the abundance of information, it has been harder to keep track of what we know and what we need. If you want to hear a solution to that problem, give this book a read!
235. Leetcode solution in python3
Tags: python
Published: 2022-08-12 05:21:37

```

class Solution:
    def lowestCommonAncestor(self, root, p, q):
        """
        :type root: TreeNode
        :type p: TreeNode
        :type q: TreeNode
        :rtype: TreeNode
        """

        # approach: compare current node with p and q, then move
        #           current to it’s left or right child by result

        current = root
        while root:
            if root.val > p.val and root.val > q.val:
                root = root.left
            elif root.val < p.val and root.val < q.val:
                root = root.right
            else: break

        return root
```



#leetcode
#challenge
here is the link for the problem: 
https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree
Binary Search Templates in Python
Tags: algorithms, python
Published: 2022-08-12 05:14:00

## What is Binary Search?
Binary search is a search algorithm that divides the search interval by half every time. That also means that the time complexity of binary search is O(log n)

## Templates
Binary search can:
- find single element in a sorted array
- find first index satisfying a condition

### Find single element in a sorted array
```python
def binary_search(arr, target):
    left, right = 1, len(arr) - 1
    while left <= right:
        mid = (left + right) // 2
        if arr[mid] < target:
            left = mid + 1
        elif arr[mid] > target:
            right = mid - 1
        else:
            return mid
    return -1
```

### Find first index satisfying a condition
Finding the first index satisfying a condition is the same as finding the first true value of a true-false array. 
ex: `[False, ... False, True, ... True]`

Things to note:
- left and right should include and read & write space
- while loop halts when `left == right`
- after the while loop:
    - `left` is the first index satisfying `condition() == True`
    - `left - 1` is the last index satisfying `condition() == False`
```python
def condition():
    pass

def binary_search(arr):
    left, right = 1, len(arr)-1
    while left < right:
        mid = (left + right) // 2
        if condition():
            right = mid
        else:
            left = mid + 1
    return left
```
How to learn snowflake?
Tags: snowflake, datawarehouse, database, bigdata
Published: 2022-08-12 05:09:11

Hello everyone,
I am quiet new to the field of big data, 
1) I would like to start my journey by learning concepts like **data warehousing, data lake.**
I really wanted to know about some of the best resources I could get for the same. 
2) how should I go about **snowflake**?
thanks and regards.
Amazon API Gateway with .NET – AWS Lambda & DynamoDB Integrations
Tags: aws, api
Published: 2022-08-12 05:09:00

What is Amazon API Gateway?
Amazon API Gateway is a fully managed service that lets you create Gateways, which essentially serves as a door into your world of business logic for your application. With this service, you basically expose endpoints that on accessing connect to AWS Lambdas, public endpoints, and various other AWS Services depending on the way you build Amazon API Gateway.

Building & Publishing an AWS Lambda with .NET
First up, let’s open up Visual Studio 2022 and create a blank solution. I named my solution as AWSServerless.Dotnet.Demo. Basically, we will have 2 Lambda projects in this, which we will gradually add.

A dummy Lambda that returns a Hello message. This lambda will be used to introduce Amazon API Gateway integration basics and stuff.
A Student Lambda, to which we will add multiple Function handlers that can possibly perform some basic CRUD operations against DynamoDB. (PS, I have written an article about Getting started with DynamoDB using .NET.

Creating Amazon API Gateway with .NET
Let’s start designing our First Amazon API Gateway. Search for API Gateway in the search bar you see in the AWS Management Console. You will see the default landing page for Amazon API Gateway. Here you will be presented with choices to select an API Type. Since we will be using HTTP API, let’s click on the Build button associated with it.
Building Students Management AWS Lambda with .NET
We will be building a simple API that can get all student details, get student by ID and create a new Student record. Add a new Lambda project to our Solution and name it StudentLambda. And yes, we will be creating multiple Lambdas from a single Lambda Project. You are free to create separate projects for each of the functions. But for the current scope of the application and requirement, it’s not really necessary. We will stuff all the 3 Lambda functions into a single .NET Lambda project and make use of FunctionHandlers to separately deploy all the Lambdas to AWS.