问:
Simplifying a MongoDB aggregate query
I made that aggregate query below to handle a social network main feed that will be able to show the posts and then answer then. Is there a way to simplify that query or the right choice for that case is to lookup, unwind and project?

```<code>`[
      {
        $match: {
          _id: mongoose.Types.ObjectId(myId),
        },
      },
      {
        $addFields: {
          following: {
            $concatArrays: ["$following", [mongoose.Types.ObjectId(myId)]],
          },
        },
      },
      {
        $lookup: {
          from: "users",
          localField: "following",
          foreignField: "_id",
          as: "following",
        },
      },
      {
        $unwind: {
          path: "$following",
          preserveNullAndEmptyArrays: true,
        },
      },
      {
        $project: {
          _id: "$following._id",
          name: "$following.name",
          surname: "$following.surname",
          profilePicPath: "$following.profilePicPath",
        },
      },
      {
        $lookup: {
          from: "posts",
          localField: "_id",
          foreignField: "parentId",
          as: "posts",
        },
      },
      {
        $unwind: {
          path: "$posts",
          preserveNullAndEmptyArrays: true,
        },
      },
      {
        $project: {
          name: true,
          surname: true,
          profilePicPath: true,
          _id: "$posts._id",
          parentId: "$posts.parentId",
          content: "$posts.content",
          date: "$posts.date",
        },
      },
      {
        $lookup: {
          from: "answerposts",
          localField: "_id",
          foreignField: "parentId",
          as: "answerPosts",
        },
      },
      {
        $unwind: {
          path: "$answerPosts",
          preserveNullAndEmptyArrays: true,
        },
      },
      {
        $project: {
          name: true,
          surname: true,
          profilePicPath: true,
          _id: true,
          parentId: true,
          content: true,
          date: true,
          answerPosts_id: "$answerPosts._id",
          answerPostsOwnerId: "$answerPosts.ownerId",
          answerPostsContent: "$answerPosts.content",
          answerPostsDate: "$answerPosts.date",
        },
      },
      {
        $lookup: {
          from: "users",
          localField: "answerPostsOwnerId",
          foreignField: "_id",
          as: "answerPostsOwner",
        },
      },
      {
        $unwind: {
          path: "$answerPostsOwner",
          preserveNullAndEmptyArrays: true,
        },
      },
      {
        $project: {
          name: true,
          surname: true,
          profilePicPath: true,
          _id: true,
          parentId: true,
          content: true,
          date: true,
          answerPosts_id: true,
          answerPostsContent: true,
          answerPostsDate: true,
          answerPostsOwner_name: "$answerPostsOwner.name",
          answerPostsOwner_surname: "$answerPostsOwner.surname",
          answerPostsOwner_profilePicPath: "$answerPostsOwner.profilePicPath",
        },
      },
      {
        $group: {
          _id: "$_id",
          parentId: {
            $first: "$parentId",
          },
          name: {
            $first: "$name",
          },
          surname: {
            $first: "$surname",
          },
          profilePicPath: {
            $first: "$profilePicPath",
          },
          content: {
            $first: "$content",
          },
          date: {
            $first: "$date",
          },
          answerPosts: {
            $push: {
              _id: "$answerPosts_id",
              name: "$answerPostsOwner_name",
              surname: "$answerPostsOwner_surname",
              content: "$answerPostsContent",
              profilePicPath: "$answerPostsOwner_profilePicPath",
              date: "$answerPostsDate",
            },
          },
        },
      },
      {
        $addFields: {
          answerPosts: {
            $cond: [
              {
                $in: [{}, "$answerPosts"],
              },
              [],
              "$answerPosts",
            ],
          },
        },
      },
      {
        $match: {
          _id: {
            $ne: null,
          },
        },
      },
      {
        $sort: {
          date: -1,
          "answerPosts.date": 1,
        },
      },
    ]`
</code>```

It works that way but I want to know if there is a simpler way to make this query.

Title: Simplifying a MongoDB aggregate query

Body:
I made that aggregate query below to handle a social network main feed that will be able to show the posts and then answer then. Is there a way to simplify that query or the right choice for that case is to lookup, unwind and project?

`[
      {
        $match: {
          _id: mongoose.Types.ObjectId(myId),
        },
      },
      {
        $addFields: {
          following: {
            $concatArrays: ["$following", [mongoose.Types.ObjectId(myId)]],
          },
        },
      },
      {
        $lookup: {
          from: "users",
          localField: "following",
          foreignField: "_id",
          as: "following",
        },
      },
      {
        $unwind: {
          path: "$following",
          preserveNullAndEmptyArrays: true,
        },
      },
      {
        $project: {
          _id: "$following._id",
          name: "$following.name",
          surname: "$following.surname",
          profilePicPath: "$following.profilePicPath",
        },
      },
      {
        $lookup: {
          from: "posts",
          localField: "_id",
          foreignField: "parentId",
          as: "posts",
        },
      },
      {
        $unwind: {
          path: "$posts",
          preserveNullAndEmptyArrays: true,
        },
      },
      {
        $project: {
          name: true,
          surname: true,
          profilePicPath: true,
          _id: "$posts._id",
          parentId: "$posts.parentId",
          content: "$posts.content",
          date: "$posts.date",
        },
      },
      {
        $lookup: {
          from: "answerposts",
          localField: "_id",
          foreignField: "parentId",
          as: "answerPosts",
        },
      },
      {
        $unwind: {
          path: "$answerPosts",
          preserveNullAndEmptyArrays: true,
        },
      },
      {
        $project: {
          name: true,
          surname: true,
          profilePicPath: true,
          _id: true,
          parentId: true,
          content: true,
          date: true,
          answerPosts_id: "$answerPosts._id",
          answerPostsOwnerId: "$answerPosts.ownerId",
          answerPostsContent: "$answerPosts.content",
          answerPostsDate: "$answerPosts.date",
        },
      },
      {
        $lookup: {
          from: "users",
          localField: "answerPostsOwnerId",
          foreignField: "_id",
          as: "answerPostsOwner",
        },
      },
      {
        $unwind: {
          path: "$answerPostsOwner",
          preserveNullAndEmptyArrays: true,
        },
      },
      {
        $project: {
          name: true,
          surname: true,
          profilePicPath: true,
          _id: true,
          parentId: true,
          content: true,
          date: true,
          answerPosts_id: true,
          answerPostsContent: true,
          answerPostsDate: true,
          answerPostsOwner_name: "$answerPostsOwner.name",
          answerPostsOwner_surname: "$answerPostsOwner.surname",
          answerPostsOwner_profilePicPath: "$answerPostsOwner.profilePicPath",
        },
      },
      {
        $group: {
          _id: "$_id",
          parentId: {
            $first: "$parentId",
          },
          name: {
            $first: "$name",
          },
          surname: {
            $first: "$surname",
          },
          profilePicPath: {
            $first: "$profilePicPath",
          },
          content: {
            $first: "$content",
          },
          date: {
            $first: "$date",
          },
          answerPosts: {
            $push: {
              _id: "$answerPosts_id",
              name: "$answerPostsOwner_name",
              surname: "$answerPostsOwner_surname",
              content: "$answerPostsContent",
              profilePicPath: "$answerPostsOwner_profilePicPath",
              date: "$answerPostsDate",
            },
          },
        },
      },
      {
        $addFields: {
          answerPosts: {
            $cond: [
              {
                $in: [{}, "$answerPosts"],
              },
              [],
              "$answerPosts",
            ],
          },
        },
      },
      {
        $match: {
          _id: {
            $ne: null,
          },
        },
      },
      {
        $sort: {
          date: -1,
          "answerPosts.date": 1,
        },
      },
    ]`

It works that way but I want to know if there is a simpler way to make this query.


来源: stackexchange

问:
Howto export Helm chart values programmatically and periodically from pod
I thought it to be a simple task but can't find a solution. The goal here is to have the full output of values of an Helm Chart actually installed and used in a k8s cluster. Helm is installed locally so it's easy to do a helm get values but what if I want these values extracted periodically and sent to a third place by a pod running in the same cluster? Like exporting in json and save them in a DB or something.
Can I write a go/python script that run in a pod with Helm installed? Are there some API?

ContentLicense: CC BY-SA 4.0


问:
react native mapbox navigation
Android: Getting the Blank blue screen and when navigate to another screen throwing an error

```<code> "dependencies": {
    "@homee/react-native-mapbox-navigation": "^1.1.0",
    "@types/mapbox__mapbox-gl-geocoder": "^4.7.3",
    "react": "18.1.0",
    "react-native": "0.70.6"
  },
</code>```

Title: react native mapbox navigation

Body:
Android: Getting the Blank blue screen and when navigate to another screen throwing an error

 "dependencies": {
    "@homee/react-native-mapbox-navigation": "^1.1.0",
    "@types/mapbox__mapbox-gl-geocoder": "^4.7.3",
    "react": "18.1.0",
    "react-native": "0.70.6"
  },


问:
DMS is failing sometimes and its not read the data in the next cyle
some time CDC DMS is failing with error 'Failure in resolving stream position by timestamp'

I have a DMS CDC task and it will be run every 4 hours. DMS is able to read transaction log and it place the file in s3 for some runs its failing with error 'Failure in resolving stream position by timestamp'. after that data is not coming in the next cycle. And we have set up polling interval to 24 hours.


问:
How to paste #text from my #clipboard in <textarea> using only <button>?
I have a textarea and I want to create a button.

How do I paste text from my clipboard in this textarea by clicking only in this button?

Look please in the example from Google Translate. ("Coller" means paste)

Google Translate application

Please help me because I do not know how to code.

Thank you.


问:
PrimeNG: How to do copy-paste event on p-chips?
I'm using p-chips for multiple inputs.

I have various input codes like for example IT01 IT02 IT03 IT04

When a user copies these codes and pastes on p-chips input it should separated by space in different tags.
I want to handle space, comma and semicolon if the input is pasted or if a key is pressed while manually typing also. And all those inputs should be pasted in different tags along with manually also adding new tags separated by them.

How can I achieve this using p-chips?

I know separator only accepts comma for now.

This is my code so far

import { COMMA, SEMICOLON, SPACE } from '@angular/cdk/keycodes'; readonly separatorKeysCodes: any = [COMMA, SEMICOLON, SPACE];

I have given any datatype to separatorKeysCodes because it was throwing typeError that number[] or string[] cannot be assigned to type string

paste(event:any):void { this.myForm.patchValue ( { inputCodes: event.value.split(/\s+/g).map((value) => value.trim().toUpperCase()) } ); event.preventDefault(); }

I tried this with (onAdd) event on p-chips calling my paste($event) but it doesn't seem to work.
Currently, I have just handled space,
the problem with this is that when user manually enters another input the previous input is deleted and replaced with the newer one.
Is there any better way to do this?


问:
Kotlin multiplatform can't a find static library, even when I specify an absolute path
Here is my .def file:

```<code>headers = /Users/semyon/Projects/SortedMapKotlinMultiplatform/src/nativeInterop/cinterop/jsw_rbtree.h
staticLibraries = /Users/semyon/Projects/SortedMapKotlinMultiplatform/src/nativeInterop/cinterop/jsw_rbtree.a
package = jsw_rbtree
</code>```

When I copy this /Users/semyon/Projects/SortedMapKotlinMultiplatform/src/nativeInterop/cinterop/jsw_rbtree.a and execute in terminal it outputs Permission denied, what is expected, it indicates, that the file exists.

After trying to rebuild the project it outputs this:

```<code>Exception in thread "main" java.lang.IllegalStateException: Could not find '/Users/semyon/Projects/SortedMapKotlinMultiplatform/src/nativeInterop/cinterop/jsw_rbtree.a' binary in neither of []
    at org.jetbrains.kotlin.native.interop.gen.LibraryUtilsKt.resolveLibraries(LibraryUtils.kt:31)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:419)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLibSafe(main.kt:214)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:80)
    at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
    at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:40)
    at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:62)
</code>```

However If I remove staticLibraries line from .def file it compiles with undefined references errors and I's expected, cause I don't include implementations. So it finds jsw_rbtree.h

Here is my folder stracture:

Body:
Here is my .def file:

headers = /Users/semyon/Projects/SortedMapKotlinMultiplatform/src/nativeInterop/cinterop/jsw_rbtree.h
staticLibraries = /Users/semyon/Projects/SortedMapKotlinMultiplatform/src/nativeInterop/cinterop/jsw_rbtree.a
package = jsw_rbtree

When I copy this /Users/semyon/Projects/SortedMapKotlinMultiplatform/src/nativeInterop/cinterop/jsw_rbtree.a and execute in terminal it outputs Permission denied, what is expected, it indicates, that the file exists.

After trying to rebuild the project it outputs this:

Exception in thread "main" java.lang.IllegalStateException: Could not find '/Users/semyon/Projects/SortedMapKotlinMultiplatform/src/nativeInterop/cinterop/jsw_rbtree.a' binary in neither of []
    at org.jetbrains.kotlin.native.interop.gen.LibraryUtilsKt.resolveLibraries(LibraryUtils.kt:31)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:419)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLibSafe(main.kt:214)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:80)
    at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
    at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:40)
    at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:62)

However If I remove staticLibraries line from .def file it compiles with undefined references errors and I's expected, cause I don't include implementations. So it finds jsw_rbtree.h

Here is my folder stracture:


问:
Attaching a PERSISTENT_2 FSX to an AWS Batch Compute instance using Terraform
I have Terraform code that almost successfully builds an AWS Batch Compute Environment with an Fsx file share mount to it.

However, despite passing the aws_fsx_lustre_file_system module a deployment type of PERSISTENT_2:

```<code>resource "aws_fsx_lustre_file_system" "storage" {
  storage_capacity = 1200
  subnet_ids       = [var.subnet_id]
  deployment_type  = "PERSISTENT_2"
  per_unit_storage_throughput = 250
}
</code>```

the Fsx is only spun up at a scratch drive (viewable via AWS management console).

What additional information can I post here to help debug why this Terraform code is not respecting the deployment_type parameter?

Full code:

```<code>// ==========================================================
//   Module input variables
// ----------------------------------------------------------
variable "region" {
  type = string
}

variable "compute_environment_name" {
  type = string
}

variable "job_queue_name" {
  type = string
}

variable "max_vcpus" {
  type = number
}

variable "vpc_id" {
  type = string
}

variable "subnet_id" {
  type = string
}

variable "security_group_id" {
  type = string
}

variable "mounted_storage_bucket" {
  type = string
}

// ==========================================================
//   Components for batch processing for AWS Batch
// ----------------------------------------------------------
resource "aws_iam_role" "batch_role" {
  name = "batch_role"
  assume_role_policy = <<EOF
{
    "Version": "2012-10-17",
    "Statement":
    [
      {
          "Action": "sts:AssumeRole",
          "Effect": "Allow",
          "Principal": {
            "Service": "batch.amazonaws.com"
          }
      },
      {
          "Action": "sts:AssumeRole",
          "Effect": "Allow",
          "Principal": {
            "Service": "ec2.amazonaws.com"
          }
      },
      {
          "Action": "sts:AssumeRole",
          "Effect": "Allow",
          "Principal": {
            "Service": "ecs.amazonaws.com"
          }
      },
      {
          "Action": "sts:AssumeRole",
          "Effect": "Allow",
          "Principal": {
            "Service": "ecs-tasks.amazonaws.com"
          }
      }
    ]
}
EOF
tags = {
    created-by = "Terraform"
  }
}

# Attach the Batch policy to the Batch role
resource "aws_iam_role_policy_attachment" "batch_service_role" {
  role = aws_iam_role.batch_role.name
  policy_arn = "arn:aws:iam::aws:policy/service-role/AWSBatchServiceRole"
}

resource "aws_iam_role_policy_attachment" "elastic_container_service_role" {
  role = aws_iam_role.batch_role.name
  policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
}

# Security Group for batch processing
resource "aws_security_group" "batch_security_group" {
  name = "batch_security_group"
  description = "AWS Batch Security Group for batch jobs"
  vpc_id = var.vpc_id
egress {
    from_port   = 0
    to_port = 65535
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
tags = {
    created-by = "Terraform"
  }
}

# IAM Role for underlying EC2 instances
resource "aws_iam_role" "ec2_role" {
  name = "ec2_role"
assume_role_policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "ec2.amazonaws.com"
      },
      "Effect": "Allow",
      "Sid": ""
    }
  ]
}
EOF
tags = {
    created-by = "Terraform"
  }
}

# Assign the EC2 role to the EC2 profile
resource "aws_iam_instance_profile" "ec2_profile" {
  name = "ec2_profile"
  role = aws_iam_role.ec2_role.name
}

# Attach the EC2 container service policy to the EC2 role
resource "aws_iam_role_policy_attachment" "ec2_policy_attachment" {
  role = aws_iam_role.ec2_role.name
  policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
}

# IAM Role for jobs
resource "aws_iam_role" "job_role" {
  name = "job_role"
  assume_role_policy = <<EOF
{
    "Version": "2012-10-17",
    "Statement":
    [
      {
          "Action": "sts:AssumeRole",
          "Effect": "Allow",
          "Principal": {
            "Service": "ecs-tasks.amazonaws.com"
          }
      }
    ]
}
EOF
tags = {
    created-by = "Terraform"
  }
}

# S3 read/write policy
resource "aws_iam_policy" "s3_policy" {
  name   = "s3_policy"
  policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
        "Effect": "Allow",
        "Action": [
            "s3:Get*",
            "s3:List*",
            "s3:Put*"
        ],
        "Resource": [
          "arn:aws:s3:::${var.mounted_storage_bucket}",
          "arn:aws:s3:::${var.mounted_storage_bucket}/*"
        ]
    }
  ]
}
EOF
}

resource "aws_iam_policy" "ecs_policy" {
  name   = "ecs_policy"
  policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
      {
        "Effect": "Allow",
        "Action": [
          "ecs:*"
        ],
        "Resource": [
          "*"
        ]
      }
  ]
}
EOF
}

# Attach the policy to the job role
resource "aws_iam_role_policy_attachment" "job_policy_attachment_s3" {
  role = aws_iam_role.job_role.name
  policy_arn = aws_iam_policy.s3_policy.arn
}

resource "aws_iam_role_policy_attachment" "job_policy_attachment_ecs" {
  role = aws_iam_role.job_role.name
  policy_arn = aws_iam_policy.ecs_policy.arn
}

resource "aws_fsx_lustre_file_system" "storage" {
  storage_capacity = 1200
  subnet_ids       = [var.subnet_id]
  deployment_type  = "PERSISTENT_2"
  per_unit_storage_throughput = 250
}

resource "aws_fsx_data_repository_association" "storage_association" {
  file_system_id       = aws_fsx_lustre_file_system.storage.id
  data_repository_path = "s3://${var.mounted_storage_bucket}"
  file_system_path     = "/data/fsx"

  s3 {
    auto_export_policy {
      events = ["NEW", "CHANGED", "DELETED"]
    }

    auto_import_policy {
      events = ["NEW", "CHANGED", "DELETED"]
    }
  }
}

resource "aws_launch_template" "launch_template" {
  name = "launch_template"
  update_default_version = true

  user_data = base64encode(<<EOF
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="

--==MYBOUNDARY==
Content-Type: text/cloud-config; charset="us-ascii"

runcmd:
- region=${var.region}
- amazon-linux-extras install -y lustre2.10
- mkdir -p /data/fsx
- mount -t lustre ${aws_fsx_lustre_file_system.storage.dns_name}@tcp:fsx" /data/fsx

--==MYBOUNDARY==--
EOF
)
}

// ==========================================================
//   Batch setup
//    - compute environment
//    - job queue
// ----------------------------------------------------------
resource "aws_iam_role" "ecs_instance_role" {
  name = "ecs_instance_role"

  assume_role_policy = <<EOF
{
    "Version": "2012-10-17",
    "Statement": [
    {
        "Action": "sts:AssumeRole",
        "Effect": "Allow",
        "Principal": {
        "Service": "ec2.amazonaws.com"
        }
    }
    ]
}
EOF
}

resource "aws_iam_role_policy_attachment" "ecs_instance_role" {
  role       = "${aws_iam_role.ecs_instance_role.name}"
  policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
}

resource "aws_iam_instance_profile" "ecs_instance_role" {
  name = "ecs_instance_role"
  role = "${aws_iam_role.ecs_instance_role.name}"
}

resource "aws_iam_role" "aws_batch_service_role" {
  name = "aws_batch_service_role"

  assume_role_policy = <<EOF
{
    "Version": "2012-10-17",
    "Statement": [
    {
        "Action": "sts:AssumeRole",
        "Effect": "Allow",
        "Principal": {
        "Service": "batch.amazonaws.com"
        }
    }
    ]
}
EOF
}

resource "aws_iam_role_policy_attachment" "aws_batch_service_role" {
  role       = "${aws_iam_role.aws_batch_service_role.name}"
  policy_arn = "arn:aws:iam::aws:policy/service-role/AWSBatchServiceRole"
}

resource "aws_batch_compute_environment" "batch_environment" {
  compute_environment_name = var.compute_environment_name

  compute_resources {
    instance_role = "${aws_iam_instance_profile.ecs_instance_role.arn}"

    launch_template {
      launch_template_name = aws_launch_template.launch_template.name
      version = "$Latest"
    }

    instance_type = [
      "c6g.large",
      "c6g.xlarge",
      "c6g.2xlarge",
      "c6g.4xlarge",
      "c6g.8xlarge",
      "c6g.12xlarge"
    ]

    max_vcpus = 16
    min_vcpus = 0

    security_group_ids = [
      aws_security_group.batch_security_group.id,
    ]

    subnets = [
      var.subnet_id
    ]

    type = "EC2"
  }

  service_role = "${aws_iam_role.aws_batch_service_role.arn}"
  type         = "MANAGED"
  depends_on   = [aws_iam_role_policy_attachment.aws_batch_service_role]
  tags = {
    created-by = "Terraform"
  }
}

resource "aws_batch_job_queue" "job_queue" {
  name = "job_queue"
  state = "ENABLED"
  priority = 1
  compute_environments = [
    aws_batch_compute_environment.batch_environment.arn
  ]
  depends_on = [aws_batch_compute_environment.batch_environment]
tags = {
    created-by = "Terraform"
  }
}

output "batch_compute_environment_id" {
    value = aws_batch_compute_environment.batch_environment.id
}

output "batch_job_queue_id" {
    value = aws_batch_job_queue.job_queue.id
}

output "batch_storage_mount_target" {
    value = aws_fsx_lustre_file_system.storage.arn
}

output "batch_storage_mount_target_mount" {
    value = aws_fsx_lustre_file_system.storage.mount_name
}
</code>```

Body:
I have Terraform code that almost successfully builds an AWS Batch Compute Environment with an Fsx file share mount to it.

However, despite passing the aws_fsx_lustre_file_system module a deployment type of PERSISTENT_2:

resource "aws_fsx_lustre_file_system" "storage" {
  storage_capacity = 1200
  subnet_ids       = [var.subnet_id]
  deployment_type  = "PERSISTENT_2"
  per_unit_storage_throughput = 250
}

the Fsx is only spun up at a scratch drive (viewable via AWS management console).

What additional information can I post here to help debug why this Terraform code is not respecting the deployment_type parameter?

Full code:

// ==========================================================
//   Module input variables
// ----------------------------------------------------------
variable "region" {
  type = string
}

variable "compute_environment_name" {
  type = string
}

variable "job_queue_name" {
  type = string
}

variable "max_vcpus" {
  type = number
}

variable "vpc_id" {
  type = string
}

variable "subnet_id" {
  type = string
}

variable "security_group_id" {
  type = string
}

variable "mounted_storage_bucket" {
  type = string
}

// ==========================================================
//   Components for batch processing for AWS Batch
// ----------------------------------------------------------
resource "aws_iam_role" "batch_role" {
  name = "batch_role"
  assume_role_policy = <<EOF
{
    "Version": "2012-10-17",
    "Statement":
    [
      {
          "Action": "sts:AssumeRole",
          "Effect": "Allow",
          "Principal": {
            "Service": "batch.amazonaws.com"
          }
      },
      {
          "Action": "sts:AssumeRole",
          "Effect": "Allow",
          "Principal": {
            "Service": "ec2.amazonaws.com"
          }
      },
      {
          "Action": "sts:AssumeRole",
          "Effect": "Allow",
          "Principal": {
            "Service": "ecs.amazonaws.com"
          }
      },
      {
          "Action": "sts:AssumeRole",
          "Effect": "Allow",
          "Principal": {
            "Service": "ecs-tasks.amazonaws.com"
          }
      }
    ]
}
EOF
tags = {
    created-by = "Terraform"
  }
}

# Attach the Batch policy to the Batch role
resource "aws_iam_role_policy_attachment" "batch_service_role" {
  role = aws_iam_role.batch_role.name
  policy_arn = "arn:aws:iam::aws:policy/service-role/AWSBatchServiceRole"
}

resource "aws_iam_role_policy_attachment" "elastic_container_service_role" {
  role = aws_iam_role.batch_role.name
  policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
}

# Security Group for batch processing
resource "aws_security_group" "batch_security_group" {
  name = "batch_security_group"
  description = "AWS Batch Security Group for batch jobs"
  vpc_id = var.vpc_id
egress {
    from_port   = 0
    to_port = 65535
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
tags = {
    created-by = "Terraform"
  }
}

# IAM Role for underlying EC2 instances
resource "aws_iam_role" "ec2_role" {
  name = "ec2_role"
assume_role_policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "ec2.amazonaws.com"
      },
      "Effect": "Allow",
      "Sid": ""
    }
  ]
}
EOF
tags = {
    created-by = "Terraform"
  }
}

# Assign the EC2 role to the EC2 profile
resource "aws_iam_instance_profile" "ec2_profile" {
  name = "ec2_profile"
  role = aws_iam_role.ec2_role.name
}

# Attach the EC2 container service policy to the EC2 role
resource "aws_iam_role_policy_attachment" "ec2_policy_attachment" {
  role = aws_iam_role.ec2_role.name
  policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
}

# IAM Role for jobs
resource "aws_iam_role" "job_role" {
  name = "job_role"
  assume_role_policy = <<EOF
{
    "Version": "2012-10-17",
    "Statement":
    [
      {
          "Action": "sts:AssumeRole",
          "Effect": "Allow",
          "Principal": {
            "Service": "ecs-tasks.amazonaws.com"
          }
      }
    ]
}
EOF
tags = {
    created-by = "Terraform"
  }
}

# S3 read/write policy
resource "aws_iam_policy" "s3_policy" {
  name   = "s3_policy"
  policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
        "Effect": "Allow",
        "Action": [
            "s3:Get*",
            "s3:List*",
            "s3:Put*"
        ],
        "Resource": [
          "arn:aws:s3:::${var.mounted_storage_bucket}",
          "arn:aws:s3:::${var.mounted_storage_bucket}/*"
        ]
    }
  ]
}
EOF
}

resource "aws_iam_policy" "ecs_policy" {
  name   = "ecs_policy"
  policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
      {
        "Effect": "Allow",
        "Action": [
          "ecs:*"
        ],
        "Resource": [
          "*"
        ]
      }
  ]
}
EOF
}

# Attach the policy to the job role
resource "aws_iam_role_policy_attachment" "job_policy_attachment_s3" {
  role = aws_iam_role.job_role.name
  policy_arn = aws_iam_policy.s3_policy.arn
}

resource "aws_iam_role_policy_attachment" "job_policy_attachment_ecs" {
  role = aws_iam_role.job_role.name
  policy_arn = aws_iam_policy.ecs_policy.arn
}

resource "aws_fsx_lustre_file_system" "storage" {
  storage_capacity = 1200
  subnet_ids       = [var.subnet_id]
  deployment_type  = "PERSISTENT_2"
  per_unit_storage_throughput = 250
}

resource "aws_fsx_data_repository_association" "storage_association" {
  file_system_id       = aws_fsx_lustre_file_system.storage.id
  data_repository_path = "s3://${var.mounted_storage_bucket}"
  file_system_path     = "/data/fsx"

  s3 {
    auto_export_policy {
      events = ["NEW", "CHANGED", "DELETED"]
    }

    auto_import_policy {
      events = ["NEW", "CHANGED", "DELETED"]
    }
  }
}

resource "aws_launch_template" "launch_template" {
  name = "launch_template"
  update_default_version = true

  user_data = base64encode(<<EOF
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="

--==MYBOUNDARY==
Content-Type: text/cloud-config; charset="us-ascii"

runcmd:
- region=${var.region}
- amazon-linux-extras install -y lustre2.10
- mkdir -p /data/fsx
- mount -t lustre ${aws_fsx_lustre_file_system.storage.dns_name}@tcp:fsx" /data/fsx

--==MYBOUNDARY==--
EOF
)
}

// ==========================================================
//   Batch setup
//    - compute environment
//    - job queue
// ----------------------------------------------------------
resource "aws_iam_role" "ecs_instance_role" {
  name = "ecs_instance_role"

  assume_role_policy = <<EOF
{
    "Version": "2012-10-17",
    "Statement": [
    {
        "Action": "sts:AssumeRole",
        "Effect": "Allow",
        "Principal": {
        "Service": "ec2.amazonaws.com"
        }
    }
    ]
}
EOF
}

resource "aws_iam_role_policy_attachment" "ecs_instance_role" {
  role       = "${aws_iam_role.ecs_instance_role.name}"
  policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
}

resource "aws_iam_instance_profile" "ecs_instance_role" {
  name = "ecs_instance_role"
  role = "${aws_iam_role.ecs_instance_role.name}"
}

resource "aws_iam_role" "aws_batch_service_role" {
  name = "aws_batch_service_role"

  assume_role_policy = <<EOF
{
    "Version": "2012-10-17",
    "Statement": [
    {
        "Action": "sts:AssumeRole",
        "Effect": "Allow",
        "Principal": {
        "Service": "batch.amazonaws.com"
        }
    }
    ]
}
EOF
}

resource "aws_iam_role_policy_attachment" "aws_batch_service_role" {
  role       = "${aws_iam_role.aws_batch_service_role.name}"
  policy_arn = "arn:aws:iam::aws:policy/service-role/AWSBatchServiceRole"
}

resource "aws_batch_compute_environment" "batch_environment" {
  compute_environment_name = var.compute_environment_name

  compute_resources {
    instance_role = "${aws_iam_instance_profile.ecs_instance_role.arn}"

    launch_template {
      launch_template_name = aws_launch_template.launch_template.name
      version = "$Latest"
    }

    instance_type = [
      "c6g.large",
      "c6g.xlarge",
      "c6g.2xlarge",
      "c6g.4xlarge",
      "c6g.8xlarge",
      "c6g.12xlarge"
    ]

    max_vcpus = 16
    min_vcpus = 0

    security_group_ids = [
      aws_security_group.batch_security_group.id,
    ]

    subnets = [
      var.subnet_id
    ]

    type = "EC2"
  }

  service_role = "${aws_iam_role.aws_batch_service_role.arn}"
  type         = "MANAGED"
  depends_on   = [aws_iam_role_policy_attachment.aws_batch_service_role]
  tags = {
    created-by = "Terraform"
  }
}

resource "aws_batch_job_queue" "job_queue" {
  name = "job_queue"
  state = "ENABLED"
  priority = 1
  compute_environments = [
    aws_batch_compute_environment.batch_environment.arn
  ]
  depends_on = [aws_batch_compute_environment.batch_environment]
tags = {
    created-by = "Terraform"
  }
}

output "batch_compute_environment_id" {
    value = aws_batch_compute_environment.batch_environment.id
}

output "batch_job_queue_id" {
    value = aws_batch_job_queue.job_queue.id
}

output "batch_storage_mount_target" {
    value = aws_fsx_lustre_file_system.storage.arn
}

output "batch_storage_mount_target_mount" {
    value = aws_fsx_lustre_file_system.storage.mount_name
}


问:
pandas: code works in pycharm but doesn't work in replit
I'm trying to run this code in replit:

```<code>df_cat = pd.melt(df, id_vars='cardio', value_vars=['active', 'alco', 'cholesterol', 'gluc', 'overweight', 'smoke'])

c = df_cat.groupby(['cardio','variable','value'], as_index=False,level=None, sort=True, group_keys=True, observed=False).size()
cardio_0 = c[c['cardio']==0]
cardio_1 = c[c['cardio']==1]
</code>```

the code works perfectly in pycharm, but it doesn't work in replit and I don't know
what else to do. I got this error:

```<code>Traceback (most recent call last):
  File "main.py", line 6, in <module>
    medical_data_visualizer.draw_cat_plot()
  File "/home/runner/boilerplate-medical-data-visualizer/medical_data_visualizer.py", line 33, in draw_cat_plot
    cardio_0 = c(c['cardio']==0)
  File "/home/runner/boilerplate-medical-data-visualizer/venv/lib/python3.8/site-packages/pandas/core/series.py", line 1071, in __getitem__
    result = self.index.get_value(self, key)
  File "/home/runner/boilerplate-medical-data-visualizer/venv/lib/python3.8/site-packages/pandas/core/indexes/multi.py", line 1510, in get_value
    raise e1
  File "/home/runner/boilerplate-medical-data-visualizer/venv/lib/python3.8/site-packages/pandas/core/indexes/multi.py", line 1494, in get_value
    return self._engine.get_value(s, k)
  File "pandas/_libs/index.pyx", line 80, in pandas._libs.index.IndexEngine.get_value
  File "pandas/_libs/index.pyx", line 88, in pandas._libs.index.IndexEngine.get_value
  File "pandas/_libs/index.pyx", line 107, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/index.pyx", line 670, in pandas._libs.index.BaseMultiIndexCodesEngine.get_loc
KeyError: 'cardio'
</code>```

the same code works perfectly in pycharm

Body:
I'm trying to run this code in replit:

df_cat = pd.melt(df, id_vars='cardio', value_vars=['active', 'alco', 'cholesterol', 'gluc', 'overweight', 'smoke'])

c = df_cat.groupby(['cardio','variable','value'], as_index=False,level=None, sort=True, group_keys=True, observed=False).size()
cardio_0 = c[c['cardio']==0]
cardio_1 = c[c['cardio']==1]

the code works perfectly in pycharm, but it doesn't work in replit and I don't know
what else to do. I got this error:

Traceback (most recent call last):
  File "main.py", line 6, in <module>
    medical_data_visualizer.draw_cat_plot()
  File "/home/runner/boilerplate-medical-data-visualizer/medical_data_visualizer.py", line 33, in draw_cat_plot
    cardio_0 = c(c['cardio']==0)
  File "/home/runner/boilerplate-medical-data-visualizer/venv/lib/python3.8/site-packages/pandas/core/series.py", line 1071, in __getitem__
    result = self.index.get_value(self, key)
  File "/home/runner/boilerplate-medical-data-visualizer/venv/lib/python3.8/site-packages/pandas/core/indexes/multi.py", line 1510, in get_value
    raise e1
  File "/home/runner/boilerplate-medical-data-visualizer/venv/lib/python3.8/site-packages/pandas/core/indexes/multi.py", line 1494, in get_value
    return self._engine.get_value(s, k)
  File "pandas/_libs/index.pyx", line 80, in pandas._libs.index.IndexEngine.get_value
  File "pandas/_libs/index.pyx", line 88, in pandas._libs.index.IndexEngine.get_value
  File "pandas/_libs/index.pyx", line 107, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/index.pyx", line 670, in pandas._libs.index.BaseMultiIndexCodesEngine.get_loc
KeyError: 'cardio'

the same code works perfectly in pycharm


问:
How to configure pollInterval to make SvelteKit detect newly updated file versions?
SvelteKit does a great job to avoid full page reloads where possible. However, this can be an issue when the pages should be reloaded, for example when developers uploaded a new version of files.

SvelteKit addresses exactly this via pollInterval. Documentation is here.

However, I don't see any effect setting pollInterval.

(1) As vite updates my local files during development, I visited my production ready test site with a browser (avoiding the effects of vite).

(2) Then I changed the configuration by setting pollInterval to 3000 ms in svelte.config.js like this:

```<code>const config = {
    preprocess: vitePreprocess(),
    kit: {
        adapter: adapter()
        version: {
            pollInterval: 3000
        }
    }
};

</code>```

(3) Additionally I changed content on some pages.

(4) Finally I uploaded it all (effectively overwriting the old files).

Result:

The client browser did only see the old (previous) content when browsing the routes, not the new content. Reloading the URLs did not help either. Only after restarting nodejs on the production test site the new content was present in the client's browser.

What am I missing? An example is appreciated.

Body:
SvelteKit does a great job to avoid full page reloads where possible. However, this can be an issue when the pages should be reloaded, for example when developers uploaded a new version of files.

SvelteKit addresses exactly this via pollInterval. Documentation is here.

However, I don't see any effect setting pollInterval.

(1) As vite updates my local files during development, I visited my production ready test site with a browser (avoiding the effects of vite).

(2) Then I changed the configuration by setting pollInterval to 3000 ms in svelte.config.js like this:

const config = {
    preprocess: vitePreprocess(),
    kit: {
        adapter: adapter()
        version: {
            pollInterval: 3000
        }
    }
};

(3) Additionally I changed content on some pages.

(4) Finally I uploaded it all (effectively overwriting the old files).

Result:

The client browser did only see the old (previous) content when browsing the routes, not the new content. Reloading the URLs did not help either. Only after restarting nodejs on the production test site the new content was present in the client's browser.

What am I missing? An example is appreciated.


问:
Gatsby server side rendering with getServerData() working locally but not on Netlify
I have an example site built with Gatsby 4.25.0, Node 14.20.1 and React 18.1.0 and served on Netlify. There are two pages- /test.js and a dynamic page /dogs/[breed].js. The test page fetches a list of dog breeds from an API and renders them in a list of links:

```<code>// test.js
          <ul>
            {dogBreeds.map((breed, idx) => (
              <li key={idx}>
                <Link to={`/dogs/${breed}`}>{breed}</Link>
              </li>
            ))}
          </ul>
</code>```

The [breed].js page uses getServerData() to fetch an image of the breed passed to it from params and display it on the page:

```<code>export async function getServerData(context) {
  const { breed } = context.params
  try {
    const res = await fetch(`https://dog.ceo/api/breed/${breed}/images/random`)
    const data = await res.json()

    console.log(`data from the getServerData function: ${data}`)

    if (!res.ok) {
      throw new Error(`Response failed`)
    }

    return {
      props: {
        breed,
        imageUrl: data.message,
      },
    }
  } catch (error) {
    return {
      status: 200,
      headers: {},
      props: {},
    }
  }
}
</code>```

Running locally, this all works fine. I can navigate to the dynamic route from the links and the images show up fine. On Netlify, hovering over the links in test.js causes 404 errors to show up in the console from "loader.js" and "prefetch.js":

And clicking a dog breed link on /test leads me to a 404. We are using gatsby-plugin-netlify and @netlify/plugin-gatsby.

Body:
I have an example site built with Gatsby 4.25.0, Node 14.20.1 and React 18.1.0 and served on Netlify. There are two pages- /test.js and a dynamic page /dogs/[breed].js. The test page fetches a list of dog breeds from an API and renders them in a list of links:

// test.js

            {dogBreeds.map((breed, idx) => (

                <Link to={`/dogs/${breed}`}>{breed}</Link>

            ))}

The [breed].js page uses getServerData() to fetch an image of the breed passed to it from params and display it on the page:

export async function getServerData(context) {
  const { breed } = context.params
  try {
    const res = await fetch(`https://dog.ceo/api/breed/${breed}/images/random`)
    const data = await res.json()

    console.log(`data from the getServerData function: ${data}`)

    if (!res.ok) {
      throw new Error(`Response failed`)
    }

    return {
      props: {
        breed,
        imageUrl: data.message,
      },
    }
  } catch (error) {
    return {
      status: 200,
      headers: {},
      props: {},
    }
  }
}

Running locally, this all works fine. I can navigate to the dynamic route from the links and the images show up fine. On Netlify, hovering over the links in test.js causes 404 errors to show up in the console from "loader.js" and "prefetch.js":

And clicking a dog breed link on /test leads me to a 404. We are using gatsby-plugin-netlify and @netlify/plugin-gatsby.


问:
Discord Py - Appending info to an external file but program can't read the last entry (altho info gets saved)
New to programming. I'm creating a bot for moderators to view and add to a filter trigger word list, which is saved as an external text file. When the command to add a word is evoked, it gets added to the text file. But when I make the command to view the list in the server, the printed list doesn't get updated and the last entry just made is not there.</p>
```<code>
with open('triggers.txt', 'r') as x:
    global triggerlist
    trig = x.read()
    triggerlist = trig.split()

@client.command(aliases = ["viewlist", "viewtriggers"])   #view
@has_permissions(ban_members = True)
async def viewblocklist(ctx):
    channel = client.get_channel(LOG_CHANNEL_ID)
    await ctx.message.add_reaction(emoji_thumbsup)
    printformat = '\n'.join(triggerlist)
    await channel.send(printformat)

@client.command(aliases = ["addlist", "addtrigger"])   #add/append
@has_permissions(ban_members = True)
async def addblocklist(ctx, *, arg):
    with open('triggers.txt', 'a+') as x:
        x.write(arg.strip().lower()+'\n')
        x.flush()
        x.close()
    await ctx.message.add_reaction(emoji_thumbsup)
    return

</code>```

Body:
New to programming. I'm creating a bot for moderators to view and add to a filter trigger word list, which is saved as an external text file. When the command to add a word is evoked, it gets added to the text file. But when I make the command to view the list in the server, the printed list doesn't get updated and the last entry just made is not there.

with open('triggers.txt', 'r') as x:
    global triggerlist
    trig = x.read()
    triggerlist = trig.split()

@client.command(aliases = ["viewlist", "viewtriggers"])   #view
@has_permissions(ban_members = True)
async def viewblocklist(ctx):
    channel = client.get_channel(LOG_CHANNEL_ID)
    await ctx.message.add_reaction(emoji_thumbsup)
    printformat = '\n'.join(triggerlist)
    await channel.send(printformat)

@client.command(aliases = ["addlist", "addtrigger"])   #add/append
@has_permissions(ban_members = True)
async def addblocklist(ctx, *, arg):
    with open('triggers.txt', 'a+') as x:
        x.write(arg.strip().lower()+'\n')
        x.flush()
        x.close()
    await ctx.message.add_reaction(emoji_thumbsup)
    return


问:
How auto update my electron app with electron-forge + electron-release-server?
How i can update my app using electron-forge with electron-release-server?

I deployed the implementation server and uploaded two assemblies .exe and.nupkg to it

and I'm trying to get these updates in the application according to the documentation

```<code>const url = `${server}download/latest`

autoUpdater.setFeedURL({ url })

setInterval(() => {
  autoUpdater.checkForUpdates()
}, 10000)

autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
  const dialogOpts = {
    type: 'info',
    buttons: ['Restart', 'Later'],
    title: 'Application Update',
    message: process.platform === 'win32' ? releaseNotes : releaseName,
    detail:
      'A new version has been downloaded. Restart the application to apply the updates.',
  }

  dialog.showMessageBox(dialogOpts).then((returnValue) => {
    if (returnValue.response === 0) autoUpdater.quitAndInstall()
  })
})
</code>```

but in development i get error:

There was a problem updating the application  Error: Can not find
Squirrel

If I understood correctly I can't use checkForUpdates() in development
but in production build the update doesn't work either

Body:
How i can update my app using electron-forge with electron-release-server?

I deployed the implementation server and uploaded two assemblies .exe and.nupkg to it

and I'm trying to get these updates in the application according to the documentation

const url = `${server}download/latest`

autoUpdater.setFeedURL({ url })

setInterval(() => {
  autoUpdater.checkForUpdates()
}, 10000)

autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
  const dialogOpts = {
    type: 'info',
    buttons: ['Restart', 'Later'],
    title: 'Application Update',
    message: process.platform === 'win32' ? releaseNotes : releaseName,
    detail:
      'A new version has been downloaded. Restart the application to apply the updates.',
  }

  dialog.showMessageBox(dialogOpts).then((returnValue) => {
    if (returnValue.response === 0) autoUpdater.quitAndInstall()
  })
})

but in development i get error:

There was a problem updating the application  Error: Can not find
Squirrel

If I understood correctly I can't use checkForUpdates() in development
but in production build the update doesn't work either


问:
Does parser type conversion happen inside django tests?
I have defined a custom argument parser

```<code>from dateutil.relativedelta import relativedelta

def custom_parser(value):
    # Do some actions with value
    return relativedelta(...)
</code>```

I the use this in a management command as

```<code>parser.add_argument(
            "--tes",
            help=("blablaaa"),
            type=custom_parser,
            required=False,
            default='15s',
        )
</code>```

Inside the handler, tes is correctly converted If I call the management command from the terminal directly.

```<code>def handle(self, *_args, **options):
    tes = options['tes']
</code>```

This is correctly converted to relativedelta when I directly run the command. However, If I run this using call_command('mycommand', tes='20s') options['tes'] is always a string.
Why is it not being converted? Can't seem to find something on the codebase that would explain it.

Body:
I have defined a custom argument parser

from dateutil.relativedelta import relativedelta

def custom_parser(value):
    # Do some actions with value
    return relativedelta(...)

I the use this in a management command as

parser.add_argument(
            "--tes",
            help=("blablaaa"),
            type=custom_parser,
            required=False,
            default='15s',
        )

Inside the handler, tes is correctly converted If I call the management command from the terminal directly.

def handle(self, *_args, **options):
    tes = options['tes']

This is correctly converted to relativedelta when I directly run the command. However, If I run this using call_command('mycommand', tes='20s') options['tes'] is always a string.
Why is it not being converted? Can't seem to find something on the codebase that would explain it.


问:
How to return a set as function result

What I have

In TurboPascal I have defined an enumerated type TState and a set TStateS of this type.

```<code>type
  TState = (CS_Type1, CS_Type2, CS_Type3, CS_Type4 );
  TStateS = set of TState;
</code>```

Also I have a function doing some calculation that should return a set

```<code>function Calc: TStateS;
begin
  { do calculate here and return }
  Calc := CS_Type1 + CS_Type2;
end;
</code>```

My problem

The TurboPascal compiler complains with Error 34 "Invalid result type of function". The turbo pascal manual states that ordinal types are ok but does not mention sets.

My Question

Is there any other method of returning a set as a function result?

Title: How to return a set as function result

Body:
What I have

In TurboPascal I have defined an enumerated type TState and a set TStateS of this type.

type
  TState = (CS_Type1, CS_Type2, CS_Type3, CS_Type4 );
  TStateS = set of TState;

Also I have a function doing some calculation that should return a set

function Calc: TStateS;
begin
  { do calculate here and return }
  Calc := CS_Type1 + CS_Type2;
end;

My problem

The TurboPascal compiler complains with Error 34 "Invalid result type of function". The turbo pascal manual states that ordinal types are ok but does not mention sets.

My Question

Is there any other method of returning a set as a function result?


问:
EMR status not aligned with Spark job processing status
I have a python script that launches a Spark step on an EMR cluster.
This is the definition of the step:

```<code>Steps=[{
               'Name': f"remove_num_{source['target_table'].upper()}",
               'ActionOnFailure': 'CONTINUE',
               'HadoopJarStep': {
                   'Jar': 'command-runner.jar',
                   'Args': ["spark-submit", \
                           "--deploy-mode", "cluster", \
                           "--master", "yarn", \
                           "--conf", "spark.yarn.submit.waitAppCompletion=false", \
                           "/home/hadoop/remove_row_num.py", \
                           source['target_table'].upper(), \
                           HDFS_PATH, \
                           IMPORT_BUCKET, \
                           S3_KEY]
               }
           }])
</code>```

The script works fine and the step is correctly created and executed.
The problem is that the Spark step execution takes some minutes to complete while the status of the EMR step turns to Completed just after the Spark job is triggered (about 10sec) and not at the end of the Spark step processing.
Is there a way to let the EMR step turn to Completed just when the Spark job is completed?

Thanks,
Luca

Body:
I have a python script that launches a Spark step on an EMR cluster.
This is the definition of the step:

Steps=[{
               'Name': f"remove_num_{source['target_table'].upper()}",
               'ActionOnFailure': 'CONTINUE',
               'HadoopJarStep': {
                   'Jar': 'command-runner.jar',
                   'Args': ["spark-submit", \
                           "--deploy-mode", "cluster", \
                           "--master", "yarn", \
                           "--conf", "spark.yarn.submit.waitAppCompletion=false", \
                           "/home/hadoop/remove_row_num.py", \
                           source['target_table'].upper(), \
                           HDFS_PATH, \
                           IMPORT_BUCKET, \
                           S3_KEY]
               }
           }])

The script works fine and the step is correctly created and executed.
The problem is that the Spark step execution takes some minutes to complete while the status of the EMR step turns to Completed just after the Spark job is triggered (about 10sec) and not at the end of the Spark step processing.
Is there a way to let the EMR step turn to Completed just when the Spark job is completed?

Thanks,
Luca


问:
Padding Is invalid - rijndael encryption method
I've been trying to encrypt the connection string so I don't write it anywhere.
Using ChatGPT I came across the Rijndael method.

Module:

```<code>Imports System.Security.Cryptography
Imports System.Text

Module DB
    ' Encrypt the connection string
    Public Function EncryptConnectionString(connectionString As String, key As Byte(), iv As Byte()) As String
        ' Create a new Rijndael instance
        Dim rijndael As New RijndaelManaged()
        rijndael.Padding = PaddingMode.PKCS7
        rijndael.Key = key
        rijndael.IV = iv

        ' Convert the connection string to a byte array
        Dim data As Byte() = Encoding.UTF8.GetBytes(connectionString)

        ' Encrypt the data using the Rijndael instance
        Dim encryptedData As Byte() = rijndael.CreateEncryptor().TransformFinalBlock(data, 0, data.Length)

        ' Concatenate the key, the initialization vector, and the encrypted data
        Dim encryptedConnectionString As Byte() = New Byte(rijndael.Key.Length + rijndael.IV.Length + encryptedData.Length - 1) {}
        Array.Copy(rijndael.Key, encryptedConnectionString, rijndael.Key.Length)
        Array.Copy(rijndael.IV, 0, encryptedConnectionString, rijndael.Key.Length, rijndael.IV.Length)
        Array.Copy(encryptedData, 0, encryptedConnectionString, rijndael.Key.Length + rijndael.IV.Length, encryptedData.Length)

        ' Convert the encrypted connection string to a base64 string
        Return Convert.ToBase64String(encryptedConnectionString)
    End Function

    ' Decrypt the connection string
    Public Function DecryptConnectionString(encryptedConnectionString As String, key As Byte(), iv As Byte()) As String
        ' Convert the encrypted connection string from a base64 string
        Dim encryptedConnectionBytes As Byte() = Convert.FromBase64String(encryptedConnectionString)

        ' Extract the key and initialization vector from the encrypted connection string
        Dim decryptedKey As Byte() = New Byte(key.Length - 1) {}
        Dim decryptedIV As Byte() = New Byte(iv.Length - 1) {}
        Array.Copy(encryptedConnectionBytes, decryptedKey, key.Length)
        Array.Copy(encryptedConnectionBytes, key.Length, decryptedIV, 0, iv.Length)

        'Create a New Rijndael instance
        Dim rijndael As New RijndaelManaged()
        rijndael.Padding = PaddingMode.PKCS7
        rijndael.Key = decryptedKey
        rijndael.IV = decryptedIV

        ' Extract the encrypted data from the encrypted connection string
        Dim encryptedData As Byte() = New Byte(encryptedConnectionBytes.Length - key.Length - iv.Length - 1) {}
        Array.Copy(encryptedConnectionBytes, key.Length + iv.Length, encryptedData, 0, encryptedData.Length)

        ' Decrypt the data using the Rijndael instance
        Dim decryptedData As Byte() = rijndael.CreateDecryptor().TransformFinalBlock(encryptedData, 0, encryptedData.Length)

        ' Convert the decrypted data to a string and return it
        Return Encoding.UTF8.GetString(decryptedData)
    End Function
End Module`
</code>```

Form to test:

```<code>Imports System.Security.Cryptography
Imports System.Text

Public Class Form1

    Private Sub BtnEncrypt_Click(sender As Object, e As EventArgs) Handles btnEncrypt.Click
        ' Generate a new key and initialization vector
        Dim key As Byte() = New Byte(31) {}
        Dim iv As Byte() = New Byte(15) {}
        Using rng As New RNGCryptoServiceProvider()
            rng.GetBytes(key)
            rng.GetBytes(iv)
        End Using

        ' Encrypt the connection string
        Dim connectionString As String = "Server=" & txtIP.Text & ";Database=" & txtDatabase.Text & ";User ID=" & txtUsername.Text & ";Password=" & txtPassword.Text & ";port=" & txtPort.Text & ";"
        Dim rijndael As New RijndaelManaged()
        rijndael.Padding = PaddingMode.PKCS7
        rijndael.Key = key
        rijndael.IV = iv
        Dim data As Byte() = Encoding.UTF8.GetBytes(connectionString)
        Dim encryptedData As Byte() = rijndael.CreateEncryptor().TransformFinalBlock(data, 0, data.Length)
        Dim encryptedConnectionString As String = Convert.ToBase64String(encryptedData)

        'Save the encrypted connection string And the key And IV to the settings
        My.Settings.EncryptedConnectionString = encryptedConnectionString
        My.Settings.Key = Convert.ToBase64String(key)
        My.Settings.IV = Convert.ToBase64String(iv)
        My.Settings.Save()
        txtconnectionstring.Text = encryptedConnectionString
        txtKey.Text = Convert.ToBase64String(key)
        txtIV.Text = Convert.ToBase64String(iv)
    End Sub

    Private Sub btnDecrypt_Click(sender As Object, e As EventArgs) Handles btnDecrypt.Click

        ' Retrieve the encrypted connection string, key, and IV from your settings or configuration
        Dim encryptedConnectionString As String = My.Settings.EncryptedConnectionString
        Dim key As Byte() = Convert.FromBase64String(txtKey.Text)
        Dim iv As Byte() = Convert.FromBase64String(txtIV.Text)

        ' Decrypt the connection string using the key and IV
        Dim connectionString As String = DecryptConnectionString(encryptedConnectionString, key, iv)
        txtconnectionstring.Clear()
        txtconnectionstring.Text = connectionString
    End Sub
End Class
</code>```

So Encryption is working good but decrypt is giving me hell. Error is: Padding is invalid and cannot be removed.

```<code>System.Security.Cryptography.CryptographicException
  HResult=0x80131430
  Message=Padding is invalid and cannot be removed.
  Source=mscorlib
  StackTrace:
   at System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast)
   at System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)

</code>```

For a little bit more context because i've read that the IV or KEY neeed to be the same. I saved those keys manual on the settings or i've saved it on the text box. I've always got the same error while decrypting.

If anyone could help,

Fábio

Tried to encrypt my connection string and save it to the settings of the app. Now I was trying to decrypt it so it could be used to connection to the mysql server.

Body:
I've been trying to encrypt the connection string so I don't write it anywhere.
Using ChatGPT I came across the Rijndael method.

Module:

Imports System.Security.Cryptography
Imports System.Text

Module DB
    ' Encrypt the connection string
    Public Function EncryptConnectionString(connectionString As String, key As Byte(), iv As Byte()) As String
        ' Create a new Rijndael instance
        Dim rijndael As New RijndaelManaged()
        rijndael.Padding = PaddingMode.PKCS7
        rijndael.Key = key
        rijndael.IV = iv

        ' Convert the connection string to a byte array
        Dim data As Byte() = Encoding.UTF8.GetBytes(connectionString)

        ' Encrypt the data using the Rijndael instance
        Dim encryptedData As Byte() = rijndael.CreateEncryptor().TransformFinalBlock(data, 0, data.Length)

        ' Concatenate the key, the initialization vector, and the encrypted data
        Dim encryptedConnectionString As Byte() = New Byte(rijndael.Key.Length + rijndael.IV.Length + encryptedData.Length - 1) {}
        Array.Copy(rijndael.Key, encryptedConnectionString, rijndael.Key.Length)
        Array.Copy(rijndael.IV, 0, encryptedConnectionString, rijndael.Key.Length, rijndael.IV.Length)
        Array.Copy(encryptedData, 0, encryptedConnectionString, rijndael.Key.Length + rijndael.IV.Length, encryptedData.Length)

        ' Convert the encrypted connection string to a base64 string
        Return Convert.ToBase64String(encryptedConnectionString)
    End Function

    ' Decrypt the connection string
    Public Function DecryptConnectionString(encryptedConnectionString As String, key As Byte(), iv As Byte()) As String
        ' Convert the encrypted connection string from a base64 string
        Dim encryptedConnectionBytes As Byte() = Convert.FromBase64String(encryptedConnectionString)

        ' Extract the key and initialization vector from the encrypted connection string
        Dim decryptedKey As Byte() = New Byte(key.Length - 1) {}
        Dim decryptedIV As Byte() = New Byte(iv.Length - 1) {}
        Array.Copy(encryptedConnectionBytes, decryptedKey, key.Length)
        Array.Copy(encryptedConnectionBytes, key.Length, decryptedIV, 0, iv.Length)

        'Create a New Rijndael instance
        Dim rijndael As New RijndaelManaged()
        rijndael.Padding = PaddingMode.PKCS7
        rijndael.Key = decryptedKey
        rijndael.IV = decryptedIV

        ' Extract the encrypted data from the encrypted connection string
        Dim encryptedData As Byte() = New Byte(encryptedConnectionBytes.Length - key.Length - iv.Length - 1) {}
        Array.Copy(encryptedConnectionBytes, key.Length + iv.Length, encryptedData, 0, encryptedData.Length)

        ' Decrypt the data using the Rijndael instance
        Dim decryptedData As Byte() = rijndael.CreateDecryptor().TransformFinalBlock(encryptedData, 0, encryptedData.Length)

        ' Convert the decrypted data to a string and return it
        Return Encoding.UTF8.GetString(decryptedData)
    End Function
End Module`

Form to test:

Imports System.Security.Cryptography
Imports System.Text

Public Class Form1

    Private Sub BtnEncrypt_Click(sender As Object, e As EventArgs) Handles btnEncrypt.Click
        ' Generate a new key and initialization vector
        Dim key As Byte() = New Byte(31) {}
        Dim iv As Byte() = New Byte(15) {}
        Using rng As New RNGCryptoServiceProvider()
            rng.GetBytes(key)
            rng.GetBytes(iv)
        End Using

        ' Encrypt the connection string
        Dim connectionString As String = "Server=" & txtIP.Text & ";Database=" & txtDatabase.Text & ";User ID=" & txtUsername.Text & ";Password=" & txtPassword.Text & ";port=" & txtPort.Text & ";"
        Dim rijndael As New RijndaelManaged()
        rijndael.Padding = PaddingMode.PKCS7
        rijndael.Key = key
        rijndael.IV = iv
        Dim data As Byte() = Encoding.UTF8.GetBytes(connectionString)
        Dim encryptedData As Byte() = rijndael.CreateEncryptor().TransformFinalBlock(data, 0, data.Length)
        Dim encryptedConnectionString As String = Convert.ToBase64String(encryptedData)

        'Save the encrypted connection string And the key And IV to the settings
        My.Settings.EncryptedConnectionString = encryptedConnectionString
        My.Settings.Key = Convert.ToBase64String(key)
        My.Settings.IV = Convert.ToBase64String(iv)
        My.Settings.Save()
        txtconnectionstring.Text = encryptedConnectionString
        txtKey.Text = Convert.ToBase64String(key)
        txtIV.Text = Convert.ToBase64String(iv)
    End Sub

    Private Sub btnDecrypt_Click(sender As Object, e As EventArgs) Handles btnDecrypt.Click

        ' Retrieve the encrypted connection string, key, and IV from your settings or configuration
        Dim encryptedConnectionString As String = My.Settings.EncryptedConnectionString
        Dim key As Byte() = Convert.FromBase64String(txtKey.Text)
        Dim iv As Byte() = Convert.FromBase64String(txtIV.Text)

        ' Decrypt the connection string using the key and IV
        Dim connectionString As String = DecryptConnectionString(encryptedConnectionString, key, iv)
        txtconnectionstring.Clear()
        txtconnectionstring.Text = connectionString
    End Sub
End Class

So Encryption is working good but decrypt is giving me hell. Error is: Padding is invalid and cannot be removed.

System.Security.Cryptography.CryptographicException
  HResult=0x80131430
  Message=Padding is invalid and cannot be removed.
  Source=mscorlib
  StackTrace:
   at System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast)
   at System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)

For a little bit more context because i've read that the IV or KEY neeed to be the same. I saved those keys manual on the settings or i've saved it on the text box. I've always got the same error while decrypting.

If anyone could help,

Fábio

Tried to encrypt my connection string and save it to the settings of the app. Now I was trying to decrypt it so it could be used to connection to the mysql server.


问:
Dockerfile for mulitple stage and npm private registry
i've a question for my Dockerfile.

This is my dockerfile:

```<code># Builder stage
FROM node:18-alpine as builder
WORKDIR /usr/src/app
RUN rm -f .npmrc
COPY package*.json ./
COPY snkrs-url.json ./
COPY .npmrc ./
COPY . .
RUN npm config set @myorg:registry http://packages:8390/npm/p/myorg/npm/
RUN npm config set //packages:8390/npm/p/myorg/npm/:_authToken=etoken
RUN npm install && npm run build
RUN npm prune --production
RUN wget https://gobinaries.com/tj/node-prune --output-document - | /bin/sh && node-prune

# Runner stage
FROM node:18-alpine as runner
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/snkrs-url.json ./
COPY --from=builder /usr/src/app/dist ./dist
COPY --from=builder /usr/src/app/node_modules ./node_modules

EXPOSE 5000
CMD [ "node", "dist/index.js" ]
</code>```

But return an error for connection refused:

FetchError: request to http://localhost:8390/npm/p/myorg/npm/@myorg/node-discord-webhook/-/node-discord-webhook-1.0.0.tgz failed, reason: connect ECONNREFUSED 127.0.0.1:8390

The registry is in my personal docker container for jetbrains space. and if i try to launch npm install it works.

Can anyone help me?

EDIT:

```<code># Builder stage
FROM node:18 as builder
WORKDIR /usr/src/app
COPY package.json ./
COPY snkrs-url.json ./
COPY .npmrc ./
COPY . .
RUN npm config delete proxy
RUN npm config set @sneakers-monitor:registry http://packages:8390/npm/p/sneakers-monitor/npm/
RUN npm config set //packages:8390/npm/p/sneakers-monitor/npm/:_authToken=eyJhbGciOiJSUzUxMiJ9.eyJzdWIiOiIxbjdENmoxc1Y0ZHQiLCJhdWQiOiJjaXJjbGV0LXdlYi11aSIsIm9yZ0RvbWFpbiI6ImpldGJyYWlucyIsIm5hbWUiOiJhZG1pbiIsImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo4MDg0IiwicGVybV90b2tlbiI6IjJuWHFuRDRYRTVCTiIsInByaW5jaXBhbF90eXBlIjoiVVNFUiIsImlhdCI6MTY3MDY3Njk1Mn0.g7sOBo7r7SvNuWq7VvKttdusdMf5Vad2Als24xBuGFDBId1oGa6XG61Y6X98mE_lifvtMxydD5DFspe49lH2TyS2hhNUI2vYxMno9jcA3oWGNjXMuK8cpAEterD70aNl_yCT-bS2hTh0jeVUKtLewGvoiXIPOvrCTMnyYpHA_qmixi1Qtw49O5rnB9SzTx6Go_iHUJB1p4ZFhEvY_mH8AVFSTo00YRE-RQEQ0j3p54me9amlC5xUTRg6c3bI5J9ElqVPgKn2arODsITKtYkD3vS6K3MRUtCnrr2eKxw3LtDYH1GfXq-hCw5TlYxWiBB_z21U7tnpOCKM8GkxrH-E3hdlYwt4ychoFveDclQKCC8PsMVOWOI9oaMqVttWMz9HkgvAEB3y--pV54s_pHm6xrH_CrYL2oEZ6rELjyJDaZYB-EPpLOrRRIXOYlitYUpe8nKcz13I7HEChpT0huXiP6IWqdotvtSdnR89irqoDILH7RZbGGjkFYB6Yz04zPwzn91-CBONuTMRLm39iv880l2tU6-7BlM2Jivyx0I_IKJCqJjymE0zfXJqB9I1F1S4T2GHBALHbTXtXa9dgC-unwJN3L_4TEPxaozzzcH8ikld8GOcd3bXJX1d-iD4GjqX9ek8cidwqmRzR3ZobAVKnb7_NC0vrXxG14BTqrvJNBg
RUN npm install
RUN npm run build
RUN npm prune --production
RUN wget https://gobinaries.com/tj/node-prune --output-document - | /bin/sh && node-prune

# Runner stage
FROM node:18-alpine as runner
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/snkrs-url.json ./
COPY --from=builder /usr/src/app/dist ./dist
COPY --from=builder /usr/src/app/node_modules ./node_modules

EXPOSE 5000
CMD [ "node", "dist/index.js" ]

</code>```

now with this dockerfile i've this error:

```<code>
17 184.6 npm ERR! network request to http://packages:8390/npm/p/sneakers-monitor/npm/@sneakers-monitor%2fdiscord-bot failed, reason: getaddrinfo ENOTFOUND packages
#17 184.6 npm ERR! network This is a problem related to network connectivity.
#17 184.6 npm ERR! network In most cases you are behind a proxy or have bad network settings.
#17 184.6 npm ERR! network
#17 184.6 npm ERR! network If you are behind a proxy, please make sure that the
#17 184.6 npm ERR! network 'proxy' config is set properly.  See: 'npm help config'
#17 184.6
#17 184.6 npm ERR! A complete log of this run can be found in:
#17 184.6 npm ERR!     /root/.npm/_logs/2022-12-19T18_20_53_636Z-debug-0.log
</code>```

EDIT2:

```<code>this is my docker-compose:

version: '3.8'

services:
    init-configs:
        image: "public.registry.jetbrains.space/p/space-on-premises/docker/init-configs:2022.1.0-BETA"
        volumes:
        - config:/home/init-config/config
        environment:
            AUTOMATION_TAG: "2022.1.0-BETA.1596"
    space:
        image: "public.registry.jetbrains.space/p/space-on-premises/docker/space:2022.1.0-BETA"
        volumes:
        - config:/home/space/circlet-server-onprem/config
        environment:
            JAVA_OPTS: "-Dconfig.file=/home/space/circlet-server-onprem/config/space.on-premises.conf"
        depends_on:
            init-configs:
                condition: service_completed_successfully
            vcs:
                condition: service_started
            redis:
                condition: service_started
            postgres:
                condition: service_started
            elasticsearch:
                condition: service_healthy
            minio:
                condition: service_started
        ports:
        - "8084:8084"
        networks:
        - "frontend"
        - "backend-apps"
        - "backend-data"

    vcs:
        image: "public.registry.jetbrains.space/p/space-on-premises/docker/vcs-hosting:2022.1.0-BETA"
        volumes:
        - config:/home/space/git/vcs-hosting/config
        environment:
            JAVA_OPTS: '-Dproperties.file=config/vcs.on-premises.properties'
        depends_on:
            init-configs:
                condition: service_completed_successfully
            redis:
                condition: service_started
            postgres:
                condition: service_started
            elasticsearch:
                condition: service_healthy
            minio:
                condition: service_started
        ports:
        - "2222:2222"
        - "8080:8080"
        networks:
        - "frontend"
        - "backend-apps"
        - "backend-data"

    packages:
        image: "public.registry.jetbrains.space/p/space-on-premises/docker/packages:2022.1.0-BETA"
        volumes:
        - config:/home/space/packages-server/config
        environment:
            JAVA_OPTS: '-Dconfig.file=/home/space/packages-server/config/packages.on-premises.conf'
        depends_on:
            init-configs:
                condition: service_completed_successfully
            redis:
                condition: service_started
            postgres:
                condition: service_started
            elasticsearch:
                condition: service_healthy
            minio:
                condition: service_started
        ports:
        - "8390:8390"
        - "9390:9390"
        networks:
        - "frontend"
        - "backend-apps"
        - "backend-data"

    langservice:
        image: "public.registry.jetbrains.space/p/space-on-premises/docker/langservice:2022.1.0-BETA"
        volumes:
        - config:/home/space/langservice-server/config
        environment:
            JAVA_OPTS: "-Dconfig.file=/home/space/langservice-server/config/langservice.on-premises.conf"
        depends_on:
            init-configs:
                condition: service_completed_successfully
        ports:
        - "8095"
        networks:
        - "backend-apps"

    postgres:
        image: "postgres:12.2"
        volumes:
         - db_data:/var/lib/postgresql/data
        environment:
            POSTGRES_USER: space
            POSTGRES_PASSWORD: spacepassword
            POSTGRES_DB: spacedb
        ports:
        - "5432"
        networks:
        - "backend-data"

    elasticsearch:
        image: "elasticsearch:7.17.4"
        volumes:
        - elasticsearch_data:/usr/share/elasticsearch/data
        environment:
            ES_JAVA_OPTS: -Xms512m -Xmx1024m
            discovery.type: single-node
            xpack.security.enabled: "false"
        ports:
        - "9200"
        - "9300"
        healthcheck:
            test: [ "CMD", "curl", "-f", "http://localhost:9200/_cat/health" ]
            interval: 5s
            timeout: 5s
            retries: 10
            start_period: 20s
        networks:
        - "backend-data"

    redis:
        image: "redis:7.0.2-alpine"
        ports:
        - "6379"
        networks:
        - "backend-data"

    minio:
        image: minio/minio:RELEASE.2022-03-05T06-32-39Z
        volumes:
        - minio_data:/data
        environment:
            MINIO_ROOT_USER: space-access-key
            MINIO_ROOT_PASSWORD: space-secret-key
        command: server --address :9000 --console-address :9001 --compat /data
        ports:
        - "9000:9000"
        - "9001"
        networks:
        - "backend-data"

    jenkins:
        image: jenkins/jenkins:lts
        deploy:
            resources:
                limits:
                    memory: 1G
        ports:
            - 10007:8080
            - 10008:50000
        volumes:
            - jenkins:/var/jenkins_home
        networks:
            - "backend-data"
volumes:
    elasticsearch_data: {}
    db_data: {}
    minio_data: {}
    config: {}
    jenkins: {}

networks:
    frontend: {}
    backend-apps: {}
    backend-data: {}
</code>```

docker compose is the docker-compose for jetbrains space

Body:
i've a question for my Dockerfile.

This is my dockerfile:

# Builder stage
FROM node:18-alpine as builder
WORKDIR /usr/src/app
RUN rm -f .npmrc
COPY package*.json ./
COPY snkrs-url.json ./
COPY .npmrc ./
COPY . .
RUN npm config set @myorg:registry http://packages:8390/npm/p/myorg/npm/
RUN npm config set //packages:8390/npm/p/myorg/npm/:_authToken=etoken
RUN npm install && npm run build
RUN npm prune --production
RUN wget https://gobinaries.com/tj/node-prune --output-document - | /bin/sh && node-prune

# Runner stage
FROM node:18-alpine as runner
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/snkrs-url.json ./
COPY --from=builder /usr/src/app/dist ./dist
COPY --from=builder /usr/src/app/node_modules ./node_modules

EXPOSE 5000
CMD [ "node", "dist/index.js" ]

But return an error for connection refused:

FetchError: request to http://localhost:8390/npm/p/myorg/npm/@myorg/node-discord-webhook/-/node-discord-webhook-1.0.0.tgz failed, reason: connect ECONNREFUSED 127.0.0.1:8390

The registry is in my personal docker container for jetbrains space. and if i try to launch npm install it works.

Can anyone help me?

EDIT:

# Builder stage
FROM node:18 as builder
WORKDIR /usr/src/app
COPY package.json ./
COPY snkrs-url.json ./
COPY .npmrc ./
COPY . .
RUN npm config delete proxy
RUN npm config set @sneakers-monitor:registry http://packages:8390/npm/p/sneakers-monitor/npm/
RUN npm config set //packages:8390/npm/p/sneakers-monitor/npm/:_authToken=eyJhbGciOiJSUzUxMiJ9.eyJzdWIiOiIxbjdENmoxc1Y0ZHQiLCJhdWQiOiJjaXJjbGV0LXdlYi11aSIsIm9yZ0RvbWFpbiI6ImpldGJyYWlucyIsIm5hbWUiOiJhZG1pbiIsImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo4MDg0IiwicGVybV90b2tlbiI6IjJuWHFuRDRYRTVCTiIsInByaW5jaXBhbF90eXBlIjoiVVNFUiIsImlhdCI6MTY3MDY3Njk1Mn0.g7sOBo7r7SvNuWq7VvKttdusdMf5Vad2Als24xBuGFDBId1oGa6XG61Y6X98mE_lifvtMxydD5DFspe49lH2TyS2hhNUI2vYxMno9jcA3oWGNjXMuK8cpAEterD70aNl_yCT-bS2hTh0jeVUKtLewGvoiXIPOvrCTMnyYpHA_qmixi1Qtw49O5rnB9SzTx6Go_iHUJB1p4ZFhEvY_mH8AVFSTo00YRE-RQEQ0j3p54me9amlC5xUTRg6c3bI5J9ElqVPgKn2arODsITKtYkD3vS6K3MRUtCnrr2eKxw3LtDYH1GfXq-hCw5TlYxWiBB_z21U7tnpOCKM8GkxrH-E3hdlYwt4ychoFveDclQKCC8PsMVOWOI9oaMqVttWMz9HkgvAEB3y--pV54s_pHm6xrH_CrYL2oEZ6rELjyJDaZYB-EPpLOrRRIXOYlitYUpe8nKcz13I7HEChpT0huXiP6IWqdotvtSdnR89irqoDILH7RZbGGjkFYB6Yz04zPwzn91-CBONuTMRLm39iv880l2tU6-7BlM2Jivyx0I_IKJCqJjymE0zfXJqB9I1F1S4T2GHBALHbTXtXa9dgC-unwJN3L_4TEPxaozzzcH8ikld8GOcd3bXJX1d-iD4GjqX9ek8cidwqmRzR3ZobAVKnb7_NC0vrXxG14BTqrvJNBg
RUN npm install
RUN npm run build
RUN npm prune --production
RUN wget https://gobinaries.com/tj/node-prune --output-document - | /bin/sh && node-prune

# Runner stage
FROM node:18-alpine as runner
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/snkrs-url.json ./
COPY --from=builder /usr/src/app/dist ./dist
COPY --from=builder /usr/src/app/node_modules ./node_modules

EXPOSE 5000
CMD [ "node", "dist/index.js" ]

now with this dockerfile i've this error:

17 184.6 npm ERR! network request to http://packages:8390/npm/p/sneakers-monitor/npm/@sneakers-monitor%2fdiscord-bot failed, reason: getaddrinfo ENOTFOUND packages
#17 184.6 npm ERR! network This is a problem related to network connectivity.
#17 184.6 npm ERR! network In most cases you are behind a proxy or have bad network settings.
#17 184.6 npm ERR! network
#17 184.6 npm ERR! network If you are behind a proxy, please make sure that the
#17 184.6 npm ERR! network 'proxy' config is set properly.  See: 'npm help config'
#17 184.6
#17 184.6 npm ERR! A complete log of this run can be found in:
#17 184.6 npm ERR!     /root/.npm/_logs/2022-12-19T18_20_53_636Z-debug-0.log

EDIT2:

this is my docker-compose:

version: '3.8'

services:
    init-configs:
        image: "public.registry.jetbrains.space/p/space-on-premises/docker/init-configs:2022.1.0-BETA"
        volumes:
        - config:/home/init-config/config
        environment:
            AUTOMATION_TAG: "2022.1.0-BETA.1596"
    space:
        image: "public.registry.jetbrains.space/p/space-on-premises/docker/space:2022.1.0-BETA"
        volumes:
        - config:/home/space/circlet-server-onprem/config
        environment:
            JAVA_OPTS: "-Dconfig.file=/home/space/circlet-server-onprem/config/space.on-premises.conf"
        depends_on:
            init-configs:
                condition: service_completed_successfully
            vcs:
                condition: service_started
            redis:
                condition: service_started
            postgres:
                condition: service_started
            elasticsearch:
                condition: service_healthy
            minio:
                condition: service_started
        ports:
        - "8084:8084"
        networks:
        - "frontend"
        - "backend-apps"
        - "backend-data"

    vcs:
        image: "public.registry.jetbrains.space/p/space-on-premises/docker/vcs-hosting:2022.1.0-BETA"
        volumes:
        - config:/home/space/git/vcs-hosting/config
        environment:
            JAVA_OPTS: '-Dproperties.file=config/vcs.on-premises.properties'
        depends_on:
            init-configs:
                condition: service_completed_successfully
            redis:
                condition: service_started
            postgres:
                condition: service_started
            elasticsearch:
                condition: service_healthy
            minio:
                condition: service_started
        ports:
        - "2222:2222"
        - "8080:8080"
        networks:
        - "frontend"
        - "backend-apps"
        - "backend-data"

    packages:
        image: "public.registry.jetbrains.space/p/space-on-premises/docker/packages:2022.1.0-BETA"
        volumes:
        - config:/home/space/packages-server/config
        environment:
            JAVA_OPTS: '-Dconfig.file=/home/space/packages-server/config/packages.on-premises.conf'
        depends_on:
            init-configs:
                condition: service_completed_successfully
            redis:
                condition: service_started
            postgres:
                condition: service_started
            elasticsearch:
                condition: service_healthy
            minio:
                condition: service_started
        ports:
        - "8390:8390"
        - "9390:9390"
        networks:
        - "frontend"
        - "backend-apps"
        - "backend-data"

    langservice:
        image: "public.registry.jetbrains.space/p/space-on-premises/docker/langservice:2022.1.0-BETA"
        volumes:
        - config:/home/space/langservice-server/config
        environment:
            JAVA_OPTS: "-Dconfig.file=/home/space/langservice-server/config/langservice.on-premises.conf"
        depends_on:
            init-configs:
                condition: service_completed_successfully
        ports:
        - "8095"
        networks:
        - "backend-apps"

    postgres:
        image: "postgres:12.2"
        volumes:
         - db_data:/var/lib/postgresql/data
        environment:
            POSTGRES_USER: space
            POSTGRES_PASSWORD: spacepassword
            POSTGRES_DB: spacedb
        ports:
        - "5432"
        networks:
        - "backend-data"

    elasticsearch:
        image: "elasticsearch:7.17.4"
        volumes:
        - elasticsearch_data:/usr/share/elasticsearch/data
        environment:
            ES_JAVA_OPTS: -Xms512m -Xmx1024m
            discovery.type: single-node
            xpack.security.enabled: "false"
        ports:
        - "9200"
        - "9300"
        healthcheck:
            test: [ "CMD", "curl", "-f", "http://localhost:9200/_cat/health" ]
            interval: 5s
            timeout: 5s
            retries: 10
            start_period: 20s
        networks:
        - "backend-data"

    redis:
        image: "redis:7.0.2-alpine"
        ports:
        - "6379"
        networks:
        - "backend-data"

    minio:
        image: minio/minio:RELEASE.2022-03-05T06-32-39Z
        volumes:
        - minio_data:/data
        environment:
            MINIO_ROOT_USER: space-access-key
            MINIO_ROOT_PASSWORD: space-secret-key
        command: server --address :9000 --console-address :9001 --compat /data
        ports:
        - "9000:9000"
        - "9001"
        networks:
        - "backend-data"

    jenkins:
        image: jenkins/jenkins:lts
        deploy:
            resources:
                limits:
                    memory: 1G
        ports:
            - 10007:8080
            - 10008:50000
        volumes:
            - jenkins:/var/jenkins_home
        networks:
            - "backend-data"
volumes:
    elasticsearch_data: {}
    db_data: {}
    minio_data: {}
    config: {}
    jenkins: {}

networks:
    frontend: {}
    backend-apps: {}
    backend-data: {}

docker compose is the docker-compose for jetbrains space


问:
Shortening weekdays in user locale pt-PT with the use of the JS native Intl library
We have a piece of code that returns a shortened weekday via the users' language preferences.

These preferences can be accessed in Javascript via navigator.languages.
We use these weekdays in a calendar. So we don't have too much horizontal space to show the text.

We use the Intl.DateTimeFormat to determine how we should shorten these weekdays.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
MDN Also has a great piece of code which you can play around in. For our problem you can try entering:

```<code>console.log(new Intl.DateTimeFormat('nl-NL', { weekday: 'short' }).format(new Date(Date.UTC(2022, 12, 19, 3, 23, 16, 738))));
</code>```

Up until now, everything is pretty default and working.
The problem comes in if a user has a locale of pt-PT.

For pt, and pt-BR the result for 2022-12-19 return: qui.
For pt-PT however, it just returns the full day: quinta

If I look at documentation about this (f.e. https://www.localeplanet.com/icu/pt-PT/index.html) this looks to be correct, and therefore it doesn't seem to be an implementation issue.

My question is how can I fix this without specifying

```<code>const realLocale = locale === 'pt-PT' ? 'pt' : locale;
</code>```

And if this is a bug in the Intl library. Is there somewhere I can appeal or report this bug?

Body:
We have a piece of code that returns a shortened weekday via the users' language preferences.

These preferences can be accessed in Javascript via navigator.languages.
We use these weekdays in a calendar. So we don't have too much horizontal space to show the text.

We use the Intl.DateTimeFormat to determine how we should shorten these weekdays.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
MDN Also has a great piece of code which you can play around in. For our problem you can try entering:

console.log(new Intl.DateTimeFormat('nl-NL', { weekday: 'short' }).format(new Date(Date.UTC(2022, 12, 19, 3, 23, 16, 738))));

Up until now, everything is pretty default and working.
The problem comes in if a user has a locale of pt-PT.

For pt, and pt-BR the result for 2022-12-19 return: qui.
For pt-PT however, it just returns the full day: quinta

If I look at documentation about this (f.e. https://www.localeplanet.com/icu/pt-PT/index.html) this looks to be correct, and therefore it doesn't seem to be an implementation issue.

My question is how can I fix this without specifying

const realLocale = locale === 'pt-PT' ? 'pt' : locale;

And if this is a bug in the Intl library. Is there somewhere I can appeal or report this bug?


问:
Access variables in nested objects in python (without passing the object as input variable)
I have the following example in Python about nested objects. I need to access the property of an outer object (e.g., Parent). All the objects must be nested (i.e., you cannot break the structure given in the example below).

```<code>class Parent:
    def __init__(self):
        self.x = 1
    class Child1:
        def __init__(self):
            pass
        class Child2:
            def __init__(self):
                pass
            class Child3:
                def __init__(self):
                    pass
                class Child4:
                    def __init__(self):
                        pass
                    def __call__(self):
                        a = 'your solution to get x = 1'
                        return a

object = Parent().Child1.Child2.Child3.Child4()
print(object())
</code>```

The goal is that Object() prints 1 (i.e., access the property of Parent). The constraint is that the Parent object should not pass as a variable, for example:

```<code>class Parent:
    def __init__(self):
        self.x = 1
        self.Child1 = self.Child1(self)
    class Child1:
        def __init__(self,parent):
            self.Child2 = self.Child2(parent)

        class Child2:
            def __init__(self,parent):
                self.Child3 = self.Child3(parent)

            class Child3:
                def __init__(self,parent):
                    self.Child4 = self.Child4(parent)

                class Child4:
                    def __init__(self,parent):
                        self.parent = parent

                    def __call__(self):
                        return self.parent.x

object = Parent().Child1.Child2.Child3.Child4()
print(object)
</code>```

Body:
I have the following example in Python about nested objects. I need to access the property of an outer object (e.g., Parent). All the objects must be nested (i.e., you cannot break the structure given in the example below).

class Parent:
    def __init__(self):
        self.x = 1
    class Child1:
        def __init__(self):
            pass
        class Child2:
            def __init__(self):
                pass
            class Child3:
                def __init__(self):
                    pass
                class Child4:
                    def __init__(self):
                        pass
                    def __call__(self):
                        a = 'your solution to get x = 1'
                        return a

object = Parent().Child1.Child2.Child3.Child4()
print(object())

The goal is that Object() prints 1 (i.e., access the property of Parent). The constraint is that the Parent object should not pass as a variable, for example:

class Parent:
    def __init__(self):
        self.x = 1
        self.Child1 = self.Child1(self)
    class Child1:
        def __init__(self,parent):
            self.Child2 = self.Child2(parent)

        class Child2:
            def __init__(self,parent):
                self.Child3 = self.Child3(parent)

            class Child3:
                def __init__(self,parent):
                    self.Child4 = self.Child4(parent)

                class Child4:
                    def __init__(self,parent):
                        self.parent = parent

                    def __call__(self):
                        return self.parent.x

object = Parent().Child1.Child2.Child3.Child4()
print(object)


问:
reticulate R installed but can't import
I'm trying to install reticulate through jupyter notebook, but :

```<code>> install.packages("reticulate")
> library(reticulate)
>
> ERROR :
> also installing the dependency ‘RcppTOML’
>
> Updating HTML index of packages in '.Library'
> Making 'packages.html' ... done
>
> Error in library(reticulate): there is no package called ‘reticulate’
> Traceback:
>
> library(reticulate)
</code>```

I've also tried

conda install -c bioconda r-reticulate

Title: reticulate R installed but can't import

Body:
I'm trying to install reticulate through jupyter notebook, but :

> install.packages("reticulate")
> library(reticulate)
>
> ERROR :
> also installing the dependency ‘RcppTOML’
>
> Updating HTML index of packages in '.Library'
> Making 'packages.html' ... done
>
> Error in library(reticulate): there is no package called ‘reticulate’
> Traceback:
>
> library(reticulate)

I've also tried

conda install -c bioconda r-reticulate


问:
Interact JS hold duration with manual start true and 'down' pointer event
I use the https://interactjs.io/ library for dragging html elements.
My goal is to clone an html element by clicking on it and make the clone draggable. Actually I want to implement the same behavior like in this example:

```<code>interact(".item")
  .draggable({
    // By setting manualStart to true - we control the manualStart.
    // We need to do this so that we can clone the object before we begin dragging it.
    manualStart: true,
    listeners: {
      move(event) {
        position.x += event.dx;
        position.y += event.dy;
        event.target.style.transform = `translate(${position.x}px, ${position.y}px)`;
      }
    }
  })
  // This only gets called when we trigger it below using interact.start(...)
  .on("move", function(event) {
    const { currentTarget, interaction } = event;
    let element = currentTarget;

    // If we are dragging an item from the sidebar, its transform value will be ''
    // We need to clone it, and then start moving the clone
    if (
      interaction.pointerIsDown &&
      !interaction.interacting() &&
      currentTarget.style.transform === ""
    ) {
      element = currentTarget.cloneNode(true);

      // Add absolute positioning so that cloned object lives right on top of the original object
      element.style.position = "absolute";
      element.style.left = 0;
      element.style.top = 0;

      // Add the cloned object to the document
      const container = document.querySelector(".container");
      container && container.appendChild(element);

      const { offsetTop, offsetLeft } = currentTarget;
      position.x = offsetLeft;
      position.y = offsetTop;

      // If we are moving an already existing item, we need to make sure the position object has
      // the correct values before we start dragging it
    } else if (interaction.pointerIsDown && !interaction.interacting()) {
      const regex = /translate\(([\d]+)px, ([\d]+)px\)/i;
      const transform = regex.exec(currentTarget.style.transform);

      if (transform && transform.length > 1) {
        position.x = Number(transform[1]);
        position.y = Number(transform[2]);
      }
    }

    // Start the drag event
    interaction.start({ name: "drag" }, event.interactable, element);
  });
</code>```

https://codepen.io/emgoto/pen/wvamoRG

The only difference is that I do not use the "move" event, but the "down" event. This is because if you move the mouse cursor to one of the inner edges of the pink rectangle, hold the left mouse button and move it outside of the rectangle quickly, nothing happens. The move event is not triggered, unfortunately.

So I tried it with the "down" event and it works better since the event is triggered immediately after a user clicks on the mouse button. But I am not able to set a hold duration. What I want to achieve is that a user really presses the mouse button and not only clicks on it to start the interaction.

I hope I explained the issue clearly enough. In the end what I want to achieve is a "down" event with a custom hold duration. But this seems not to work when using the "down" pointer event.

Body:
I use the https://interactjs.io/ library for dragging html elements.
My goal is to clone an html element by clicking on it and make the clone draggable. Actually I want to implement the same behavior like in this example:

interact(".item")
  .draggable({
    // By setting manualStart to true - we control the manualStart.
    // We need to do this so that we can clone the object before we begin dragging it.
    manualStart: true,
    listeners: {
      move(event) {
        position.x += event.dx;
        position.y += event.dy;
        event.target.style.transform = `translate(${position.x}px, ${position.y}px)`;
      }
    }
  })
  // This only gets called when we trigger it below using interact.start(...)
  .on("move", function(event) {
    const { currentTarget, interaction } = event;
    let element = currentTarget;

    // If we are dragging an item from the sidebar, its transform value will be ''
    // We need to clone it, and then start moving the clone
    if (
      interaction.pointerIsDown &&
      !interaction.interacting() &&
      currentTarget.style.transform === ""
    ) {
      element = currentTarget.cloneNode(true);

      // Add absolute positioning so that cloned object lives right on top of the original object
      element.style.position = "absolute";
      element.style.left = 0;
      element.style.top = 0;

      // Add the cloned object to the document
      const container = document.querySelector(".container");
      container && container.appendChild(element);

      const { offsetTop, offsetLeft } = currentTarget;
      position.x = offsetLeft;
      position.y = offsetTop;

      // If we are moving an already existing item, we need to make sure the position object has
      // the correct values before we start dragging it
    } else if (interaction.pointerIsDown && !interaction.interacting()) {
      const regex = /translate\(([\d]+)px, ([\d]+)px\)/i;
      const transform = regex.exec(currentTarget.style.transform);

      if (transform && transform.length > 1) {
        position.x = Number(transform[1]);
        position.y = Number(transform[2]);
      }
    }

    // Start the drag event
    interaction.start({ name: "drag" }, event.interactable, element);
  });

https://codepen.io/emgoto/pen/wvamoRG

The only difference is that I do not use the "move" event, but the "down" event. This is because if you move the mouse cursor to one of the inner edges of the pink rectangle, hold the left mouse button and move it outside of the rectangle quickly, nothing happens. The move event is not triggered, unfortunately.

So I tried it with the "down" event and it works better since the event is triggered immediately after a user clicks on the mouse button. But I am not able to set a hold duration. What I want to achieve is that a user really presses the mouse button and not only clicks on it to start the interaction.

I hope I explained the issue clearly enough. In the end what I want to achieve is a "down" event with a custom hold duration. But this seems not to work when using the "down" pointer event.