teleren/devto huggingface dataset:
Jquery Append And Prepend Example
Tags: javascript, jquery, append, prepend
Published: 2022-09-21 04:01:59

In this article, We will see examples of the jquery append() and prepend() methods. The append() method inserts the specified content as the last child of each element in the jquery collection. The prepend() method inserts the specified content as the first child of each element in the jquery collection.

Using the append method you can append HTML, append text to div, append HTML in div, append a row to table tbody, append HTML after, or append HTML before.

Using prepend method you can jquery prepend before element, prepend HTML in div, append prepend before after, and prepend text to div using jquery.

> Example: append()

In this example, append some HTML to the <p> tag and append li tag on list. It appends some text to the element on the button click event.

```
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#append_text").click(function(){
    $("p").append(" <b>appended text in p tag</b>.");
  });
  $("#append_item").click(function(){
    $("ol").append("<li><b>Item Nth</b></li>");
  });
});
</script>
</head>
<body>
<h3>Jquery Append And Prepend Example - Techsolutionstuff</h3>
<p>This is a paragraph.</p>

<ol>
  <li>item 1</li>
  <li>item 2</li>
  <li>item 3</li>
</ol>

<button id="append_text">Append Text</button>
<button id="append_item">Append Item</button>

</body>
</html>
```

> Example: prepend()

In this example prepend some HTML to the p tag and prepend li tag on list. It's prepend some text to the element on button click event.

```
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#prepend_text").click(function(){
    $("p").prepend("<b>Prepended text in p tag</b>. ");
  });
  $("#prepend_item").click(function(){
    $("ol").prepend("<li><b>Prepended Item</b></li>");
  });
});
</script>
</head>
<body style="padding:20px;">
<h3>Jquery Append And Prepend Example - Techsolutionstuff</h3>
<p>This is a paragraph.</p>

<ol>
  <li>item 1</li>
  <li>item 2</li>
  <li>item 3</li>
</ol>

<button id="prepend_text">Prepend Text</button>
<button id="prepend_item">Prepend Item</button>

</body>
</html>
```
985. Leetcode Solution in Java
Tags: java
Published: 2022-09-21 04:24:18

```
class Solution {
  public int[] sumEvenAfterQueries(int[] A, int[][] queries) {
    int[] ans = new int[queries.length];
    int sum = 0;

    for (int a : A)
      sum += a % 2 == 0 ? a : 0;

    for (int i = 0; i < queries.length; ++i) {
      if (A[queries[i][1]] % 2 == 0)
        sum -= A[queries[i][1]];
      A[queries[i][1]] += queries[i][0];
      if (A[queries[i][1]] % 2 == 0)
        sum += A[queries[i][1]];
      ans[i] = sum;
    }

    return ans;
  }
}

```

#leetcode
#challenge
Here is the link for the problem:
https://leetcode.com/problems/sum-of-even-numbers-after-queries/
Ways to call a method in Ruby
Tags: ruby, rails, programming, codesummary
Published: 2022-09-21 04:12:34

This is a code summary for https://www.notonlycode.org/12-ways-to-call-a-method-in-ruby/


![Part 1/4 Defining the class](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/di554aoe8j2b2tvmqun8.png)


![Part 2/4: Ways to call a method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x5pdrqs96rd2dinf40i4.png)


![Part 3/4: Other ways to call a method](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3r4672ek3ip93x7q8bdn.png)


![Part 4/4: using bind and binding](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ahleent440wid95ajto.png)


The source code if you want to play with this is [here](https://github.com/lucianghinda/shortrubynewsletter/blob/main/code-summaries/week37/ways_to_call_a_method.rb).

---

Follow me on Twitter [@lucianghinda](https://twitter.com/lucianghinda) where I share/retweet mostly Ruby and Rails content.

I also publish a newsletter with Ruby and Rails fresh content at [newsletter.shortruby.com](https://newsletter.shortruby.com) — in case you want to stay up to date with what is happening in Ruby and Rails world.
What is the empty or zero value for a slice in Go or Golang?
Tags: go
Published: 2022-09-21 04:08:03

---
  title: What is the empty or zero value for a slice in Go or Golang?
  published: true
  tags: Go
  date: Wed Sep 21 2022 09:38:03 GMT+0530 (India Standard Time)
  canonical_url: https://melvingeorge.me/blog/empty-or-zero-value-of-slice-go-golang
  cover_image: https://melvingeorge.me/_next/static/images/main-2b001a59e341b8964b2c398169863e57.jpg
  ---
  [Originally posted here!](https://melvingeorge.me/blog/empty-or-zero-value-of-slice-go-golang)
  
The empty or zero value of a slice in go or golang is `nil`. These slices have a capacity and a length of `0`.

### TL;DR

```go
package main

import "fmt"

func main() {
    // declare an int slice
    var mySlice []int

    // check if the mySlice zero value is
    // `nil` using an if conditional statement
    if mySlice == nil {
        fmt.Println("The zero value is nil") // The zero value is nil ✅ This will be printed upon execution.

        // check the capacity and the length of the `mySlice` slice
        fmt.Println(cap(mySlice), len(mySlice)) // 0 0 ✅
    }
}
```

For example, First, let's declare an `int` slice like this,

```go
package main

func main(){
    // declare an int slice
    var mySlice []int
}
```

Now to see if the initial or the zero value of the `mySlice` slice, let's use a simple if conditional check to see if the slice is equal to the value of `nil`.

It can be done like this,

```go
package main

import "fmt"

func main(){
    // declare an int slice
    var mySlice []int

    // check if the mySlice zero value is
    // `nil` using an if conditional statement
    if mySlice == nil {
        fmt.Println("The zero value is nil") // The zero value is nil ✅ This will be printed upon execution.
    }
}
```

As you can see that the if condition has become `true` which, proves that the zero value of the `mySlice` slice is `nil`.

Now let's also print the capacity and the length of the `mySlice` slice using the [`cap()`](https://melvingeorge.me/blog/get-total-number-of-elements-array-can-hold-or-capacity-go-golang) and the [`len()`](https://melvingeorge.me/blog/get-number-of-elements-in-array-or-length-go-golang) method respectively.

It can be done like this,

```go
package main

import "fmt"

func main() {
    // declare an int slice
    var mySlice []int

    // check if the mySlice zero value is
    // `nil` using an if conditional statement
    if mySlice == nil {
        fmt.Println("The zero value is nil") // The zero value is nil ✅ This will be printed upon execution.

        // check the capacity and the length of the `mySlice` slice
        fmt.Println(cap(mySlice), len(mySlice)) // 0 0 ✅
    }
}
```

As you can see that the zero value of the slice is `nil` and the capacity and length of the slice are `0`.

See the above code live in [The Go Playground](https://go.dev/play/p/H3DliRrKfg5).

That's all 😃.

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

---
Redis en Docker Container
Tags: spanish, latam, docker, redis
Published: 2022-09-21 04:01:53

# ¿Que es Redis?

Base de datos NoSQL. No maneja el concepto de documentos como en mongo db o tablas como en postgres o mysql. Trabaja exclusivamente con pares key value y podemos almacenar múltiples pares clave valor. Redis almacena los datos 100% en memoria y no en disco, Permite que tenga una alta performance y la velocidad de acceso a la información sea mucho mayor. La desventaja es que al estar en memoria, su data es volátil. Igualmente tiene un sistema de guardado en disco para data persistente aunque su objetivo principal es guardar la data en cache.

# Casos de uso principales

## Real-time data store

Representa la oportunidad ideal para construir aplicaciones en tiempo real y que requieran baja latencia y alto rendimiento

## Streaming & Messaging

Redis desde su versión 5 ofrece un tipo de dato particular llamado stream que lo hace ideal para aplicaciones del estilo y se usa para colas de mensajería

## Caching & Session Storage

Puede funcionar como sistema de cache para optimizar al máximo el acceso a datos y la performance en general en aplicaciones

# Instalar y correr el contenedor de redis

## Pre requisitos

Previo a irnos a la practica debemos considerar lo siguiente:

- Debes tener instalado Docker desktop [Link oficial](https://www.docker.com/products/docker-desktop/)

## Instalar contenedor

Debemos ejecutar el siguiente comando

```powershell
docker run --name my-redis -p 6379:6379 -d redis
```

- creamos y corremos el contenedor con el nombre my-redis
- ruteamos el puerto 6379 de nuestra computadora con el puerto por defecto de redis en el contenedor con el 6379

Confirmamos que el contenedor este corriendo

```powershell
docker ps
```

Para conectarnos a nuestro redis dentro de consola del contenedor

```powershell
docker exec -it my-redis sh
```

## Como conectarse desde mi equipo como cliente

Para mayor información sobre como conectarse con *redis cli* lo pueden revisar en la documentación oficial del siguiente link: [get redis cli without installing redis server](https://redis.com/blog/get-redis-cli-without-installing-redis-server/)

Debes tener instalado nodejs y ejecutar el siguiente comando

```npm
npm i -g redis-cli
```

conectarse a un servidor redis remoto que en este caso seria nuestro redis container

```npm
rdcli -h localhost -p 6379
```
listo ya estamos conectados a nuestro contenedor con redis

:briefcase: <a href="http://airarrazabal.netlify.app/" target="_blank">Mi Portafolio</a>
Find Duplicate in Array
Tags: javascript, striversdesheetproblem
Published: 2022-09-21 03:56:55

```js
const removeExactlyOneDuplicate = (arr) => {
  let map = new Map();

  for (let i = 0; i < arr.length; i++) {
    if (!map.has(arr[i])) {
      map.set(arr[i], 1);
    } else {
      return arr[i];
    }
  }
};

// console.log(removeExactlyOneDuplicate([1, 3, 4, 2, 2]));
console.log(removeExactlyOneDuplicate([3, 1, 3, 4, 2]));


```
Sort 0, 1, 2
Tags: javascript, striversdesheetproblem
Published: 2022-09-21 03:54:20

Approach 1:
New Array approach

```js
function sort(arr) {
  let zero = [];
  let one = [];
  let two = [];

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] === 0) {
      zero.push(arr[i]);
    } else if (arr[i] === 1) {
      one.push(arr[i]);
    } else if (arr[i] === 2) {
      two.push(arr[i]);
    }
  }

  return zero.concat(one).concat(two);
}

console.log(sort([0, 1, 2, 2, 1, 0]));
```
Approach 2 :
Keeping the same old Array & performing Swaps

```js
function sort_1(a) {
  let lo = 0;
  let hi = a.length - 1;
  let mid = 0;
  let temp = 0;

  while (mid <= hi) {
    if (a[mid] == 0) {
      temp = a[lo];
      a[lo] = a[mid];
      a[mid] = temp;
      lo++;
      mid++;
    } else if (a[mid] == 1) {
      mid++;
    } else {
      temp = a[mid];
      a[mid] = a[hi];
      a[hi] = temp;
      hi--;
    }
  }

  return a;
}
console.log(sort_1([0, 1, 2, 2, 1, 0]));

```
Developer-first observability tool #betatesting 💻🧪🔥
Published: 2022-09-21 03:51:19

Introducing #CaptureAi 

A developer-first observability tool. Keep it open while you develop to stream data, logs, traces, requests, and more—in real-time.

We're looking for #betatesters and feedback as we prepare for beta and public launch! 


Try it! => https://getcapture.ai
Daily Temperatures
Tags: javascript, leetcode
Published: 2022-09-21 03:49:17

```js
var dailyTemperatures = function(temperatures) {
let warmerList = [];
  for (let i = 0; i < temperatures.length; i++) {
    let count = 0;
    for (let j = i; j < temperatures.length; j++) {
      if (temperatures[j] > temperatures[i]) {
        break;
      } else {
        count++;
      }

      if (j === temperatures.length - 1) {
        count = 0;
      }
    }

    warmerList.push(count);
  }

  return warmerList;
};
console.log(dailyTemperatures([73, 74, 75, 71, 69, 72, 76, 73]));
```
Docker Desktop Alternative
Tags: docker
Published: 2022-09-21 03:45:26

What if there is a more straightforward solution to manage your containers with a UI?

---

Okay, we all know that managing containers when you have a lot of them can be challenging, especially if you are a command line fan.
Let's be sincere, a UI to help us deal with that is up in handy.

Most of you might know Docker Desktop, it's the "official" software to help us play with our loved containers. But I must confess, I'm not good with it. A time ago, I had problems with some hardware compatibilities. Some of that was fixed, however, I think Docker Desktop is kinda heavy ☹️

I am a WSL user. I use Docker in it as Docker Engine (just like would be in a Linux system), and it broke my heart when I installed Docker Desktop and my previous containers went missing because Docker Desktop creates a new Context, separating the Docker Engine containers from its.

If you got interested to know how I put in using Docker Engine in WSL without depending on Docker Desktop, I wrote about it right here (it's in Portuguese, but if you don't understand it, give it a try, it's a beautiful language 😏):
[WSL 2](https://medium.com/@leonardord99/ambiente-de-desenvolvimento-com-wsl-2-9f1717073bf3)

---

But let's say I just had a personal bad experience. Regardless of that, whether you are having a bad experience or not I come to show you an alternative, a lighter one. It's a Container!

Portainer.io is a container that works just like a PGAdmin container, you will get a localhost port opened with an interface to manage your containers!

![Dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hnedt0k2w21kqmbbn9ch.png)


![Container command helpers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1aach40dypq6ac04ibw5.png)


![Options](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/px1xdbg91sfafv79te20.png)

You can understand more of it in its official documentation: [Portainer.io](https://docs.portainer.io/start/install?_ga=2.29650623.1228274015.1663163173-1685457721.1663163173)


But if you're impatient or eager to get started fast, here is the command line to pull the image and start the container. (Feel free to change the PORT you want it to run):

```
docker volume create portainer_data
docker run -d -p 7000:7000 -p 9000:9000 -p 9443:9443 --name portainer \
        --restart=always \
        -v /var/run/docker.sock:/var/run/docker.sock \
        -v portainer_data:/data \
        portainer/portainer-ce:latest
```


![Command line](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e447aynnq5ym495dnhzq.png)

---

After that, just access your localhost:9000 (or with the port you chose) and VOILÁ!

That's it for today. Feel free to check some other articles and follow me to read my next friendly (or evil 👀) articles. ☕


![Bye](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gyxetaljvzvu8dmhdre3.gif)
LinkedIn AWS Lambda Skill Assessment Answers
Tags: linkedin, badge, webdev, aws
Published: 2022-09-21 03:37:24


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fz77ka8rx1ajnekj5q9g.png)



AWS Lambda Skill Badge: AWS Lambda LinkedIn Test Answers: In this post you will get all the correct answers of **[LinkedIn AWS Lambda quiz answers](https://www.rbtechtips.com/linkedin-aws-lambda-assessment-answers/)** given by the experts. Get All LinkedIn Assessment Answers.
Open-source Next.js SaaS Starter Kit
Tags: nextjs, saas, javascript, showdev
Published: 2022-09-21 03:25:46

## Enterprise SaaS Starter Kit

Recently we ([BoxyHQ](https://github.com/boxyhq)) launched an open-source Enterprise SaaS Starter Kit on GitHub. This repository is still in an early stage of development.

[Kickstart your enterprise app development with Next.js SaaS Starter Kit](https://github.com/boxyhq/saas-starter-kit)

It is Next.js based project that saves you months of development by starting you off with all the same features in every SaaS app, so you can focus on what makes your app unique.

## Getting Started

Please follow these simple steps to get a local copy up and running.

### Prerequisites

- Node.js (Version: >=15.x <17)
- PostgreSQL
- NPM

#### 1. Setup

Clone or fork this GitHub repository

```bash
git clone https://github.com/boxyhq/saas-starter-kit.git
```

#### 2. Go to the project folder

```bash
cd saas-starter-kit
```

#### 3. Install dependencies

```bash
npm install
```

#### 4. Set up your .env file

Duplicate `.env.example` to `.env`.

```bash
cp .env.example .env
```

#### 5. Set up database schema

```bash
npx prisma db push
```

#### 6. Start the server

In a development environment:

```bash
npm run dev
```

#### 7. Start the Prisma Studio

Prisma Studio is a visual editor for the data in your database.

```bash
npx prisma studio
```

## Features 

The app supports the following features as of now.

- Create account
- Sign in with Email and Password
- Sign in with Magic Link
- Sign in with SAML SSO
- Directory Sync (SCIM)
- Update account
- Create team
- Invite users to the team
- Manage team members
- Update team settings
- Configure SAML SSO

## Coming Soon

- Audit logs
- Unit and integration tests
- Dark mode
- Mobile-first UI
- Billing & subscriptions
- Internationalization
- Roles and Permissions

## Contributing
Contributions make the open-source community a fantastic place to learn, inspire, and create. Any contributions you make are greatly appreciated.

We also invite new supporters to contribute to the repository if you are interested.

Here are some [open issues](https://github.com/boxyhq/saas-starter-kit/issues).

Discover a collection of [SaaS Starter Kits](https://www.kirandev.com/saas-starter-kits) based on [Next.js](https://www.kirandev.com/saas-starter-kits/nextjs), Supabase, React.js, Remix, Ruby on Rails, Laravel, and Go.
Create an Express Server
Tags: beginners, javascript, webdev, node
Published: 2022-09-21 03:20:20


## How to Create an Express Server.
**I recommend this _only_ for beginners since it's so basic.**

Step 1:
Create a folder and name it whatever you like.
Go to your terminal and run (cd folder name like`cd myapp` )and run `npm init -y`


Go to a text editor (like VSC or Caret or Sublime Editor) and open the index.js file

Then write this in your file:
```
const express = require("express");
const app = express();
```
The first line of code imports the express module. 
The second line of code initializes an express app.

But the app isn't really running yet.

Write these lines of code after the code above.

```
app.get('/', (req,res) => {
 res.send("Hello World!")
}
app.listen(3000, (err) => {
if (err) console.log(err)
else console.log("Server Running on port 3000")
}
```
Now, to break this down.

For the first three lines of code, on the homepage (like [https://dev.to] (dev.to)) it will show Hello World!. By the way, read about arrow functions here [https://www.w3schools.com/js/js_es6.asp] (https://www.w3schools.com/js/js_es6.asp). req stands for request and res stands for response. 
As for the rest of the code, the app.listen function makes the app listen on port 3000 and there is an error logger too.

Now go to your terminal and run cd (your folder name) like `cd myapp`. After that run  `npm i express`. Then run `node index.js`. Your app should be up and running !

If this doesn't _express_ much, go to [Free Code Camp back end development](https://www.freecodecamp.org/learn/back-end-development-and-apis/) or go to [Express Js](https://expressjs.com).

Well, that's about it. Comment if you have any suggestions.  Thanks for reading!
Installing GRPC and Protobuf using Laravel Forge
Tags: grpc, protobuf, laravelforge, setup
Published: 2022-09-21 02:49:39

Installing GPRC and Protobuf with Laravel Forge is easy. Just follow these steps.

## Adding the script to recipes
1. Go to Recipes
2. Put any name
3. Keep user as **root**
4. Add the following script to the script input and click **Create** button

```sh
sudo pecl install grpc
sudo pecl install protobuf

echo "Add 'extension=grpc.so' to the php.ini file."
echo "Run 'php -i | grep grpc' in a terminal: it is well installed and configured if it returns something"

echo "Add 'extension=protobuf.so' to the php.ini file."
echo "Run 'php -i | grep protobuf' in a terminal: it is well installed and configured if it returns something"
```

## Running the script after the server has been setup
In the **Your Recipes**, when you scroll down, your GRPC/Protobuf recipe will be shown like below
![Your Recipes Area](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1kgz7rilmm0hfp1yeitu.jpg)

1. Click the green button with the triangle to run the script
2. Choose the server you want to have it run in and have it notify you when it's done
3. Once it's done, go to Laravel Forge, for the server go to **PHP** on the left
4. Edit the **php.ini** for both FPM and CLI
![Editing php.ini](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dmu88fr6p5mf26axmxi4.jpg)
5. Add the following to the bottom of **php.ini** then restart PHP
```ini
extension=grpc.so
extension=protobuf.so
```

## Running the script during server setup
1. Choose the **Post-Provision Recipe** to install GRPC and Protobuf
![Post-Provision Recipe](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pf7o0y4nejmpgkua4qxg.jpg)
2. Wait for the server to finish setting up
3. Edit the **php.ini** for both FPM and CLI
![Editing php.ini](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dmu88fr6p5mf26axmxi4.jpg)
4. Add the following to the bottom of **php.ini** then restart PHP
```ini
extension=grpc.so
extension=protobuf.so
```
SSGo 0.1.1
Tags: opensource, ssg, go, showdev
Published: 2022-09-21 02:47:58

New minor patch for [SSGo](https://github.com/devils2ndself/SSGo) - a Static Site Generator built with Go!

## What's in it?

### For users

- Small fix regarding `dist` content removal. Now `dist` will not be wiped if the specified input is invalid, i.e. if file is not `.txt` or folder contains 0 `.txt` files.

- Also some logging changes, the logging is not so obnoxious anymore.

### Code-wise

Firstly, modular programming not only saves sanity when reading the code, but also provides a good foundation for potential updates! So, I made a `utils` package, where all of the logic is kept at. 

Apart from that, I made the code-style more consistent, and made changes to accommodate standards.

This is my first ever project in Go, so if you have any suggestions or concerns, you can let me know in the `Issues` tab of the repo. Any critics are welcome, as they help me become a better programmer!

## Come see yourself!

You can check out the [release](https://github.com/devils2ndself/SSGo/releases/tag/0.1.1) and [code with docs](https://github.com/devils2ndself/SSGo) on my GitHub.

Contributions are more than welcome, thanks to [Kristories](https://dev.to/kristories) for fixing up the docs!