performance – Terraform / HCL – First element (or any element) from a list of sentences, combined into a list

So I work with Terraform and have the feeling that there has to be a faster or at least nicer way to perform the operation that I have performed.

For some boiler plates I have a data block that looks like this:

data "aws_subnet_ids" "lambda_subnet_ids" {
  count  = length(var.lambda_subnet_tags)
  vpc_id = ...
}

From the results of this data block, I would like to retrieve the first value from each set and combine it in another list. This is how my team went before me. I wrapped it up locals Block to make it easier to see the use case:

locals {
  lambda_subnet_ids = flatten(
    (
      for subnets in data.aws_subnet_ids.lambda_subnet_ids :
        (
          element(tolist(subnets.ids), 1)
        )
    )
  )
}

It works now. It just looks terrible. I feel like there Has to be a nicer way to do the same operation, but I don't know HCL well enough to know what to look for.

By the way, this should really have the tags HCL and Terraform, but I don't have the reputation to create it.

InfoPath – Load the SPList to set the main connector field element, if it exists

I have an infopath web part form on an aspx page. I also use a query string on this page. When the aspx form is opened, I would like to fill the infopath form with the values ​​from the main connection list, if available (if fieldvalue = querystringvalue). Then I would like to update this article when saving. And if there is currently no entry in the main connection list (field value! = Query string value), I would like to create a new entry.

How can I query the list for an existing item and then use these values ​​to set the information on the Infopat form and ensure that I update the item when it is submitted? can set the ID field and then the article will be updated instead of inserted when sending)

8 – Add a class to the field element generated by paragraphs

I have a paragraph type called "Grid Item".

I have created a file called "paragraph – grid-item – default.html.twig" in which I print all the required fields.

Everything works as expected, but I have to add classes (from some list fields) to the element "field – item". I can add classes in other kids to this element, but right after.

This is the current issue that I have:

Enter image description here

This is the code I use in the template:

{% block paragraph %}
    
{{content.field_image.0}} {{content.field_block_title.0}}
{{content.field_body.0}}

{{content. field_read_more_link.0}}

{% endblock paragraph %}

The classes content.field_block_size.0 and content.field_block_style.0 are used as expected, but I need them for the parent element … field – item

php – Is there an advantage in removing an element from both CSS and JS?

I created a website using MediaWiki CMS.

This website contains a ContactPage contact form in which the object The field is firmly integrated into the form wrapper via PHP.
This is strange, since all other fields are not so hard-coded and are actually optional and are inserted into the wrapper from the standard template of the form, which was inserted into the main customization file of the CMS (LocalSettings.php);
By the way, all of these optional fields are HTMLForm template engine fields (while, oddly enough, that object Field is not).

If someone wants to remove that object For whatever reason, it would probably be a logistical effort, as it has to be removed after every automatic upgrade, for example, manually, from the PHP source code relevant for the ContactPage extension (in contrast to all other fields, which are optional) steady file LocalSettings.php).

My problem

I want to remove the above object Field and the only one steady Options that I have with the current architecture of MediaWiki are CSS and JS;
However, this is problematic because one user can easily turn both of them off (most users don't, but still).

At the moment I only removed the subject field with CSS, but I'm considering adding an "insurance" removal with JS to prevent end users from disabling CSS for any reason, but forgot to disable JS (e.g. random cognitive bias). stop using that object Field.

My question

In view of the IS literature, is it plausible to have such a "JS insurance" for CSS removals, and if not, which is the better way?

node.js – Only delete an element from the frontend, not from MongoDB

I'm using a simple CRUD app Vue.js as frontend Nodejs as backend and MongoDB as database , I have a delete function, but the problem is that it only deletes customers from the frontend, not from the database when I refresh the page to see All customers After deletion, the customer appears again in the frontend. Below is my delete function

            {
               let uri = 'http://localhost:3000/Customer/delete/'+id;
              this.items.splice(id, 1);
               this.axios.get(uri);
            }```

                 //AND HERE IS MY BACKEND API FOR DELETE Customer

app.post('/delete/:id', async (req, res) => {
    try {
        Customer.findByIdAndRemove(req.params.id, req.body, function (err, doc) {
            if (err) res.json(err);
            else res.json('Successfully removed');
        })
    } catch (error) {
        res.json({
            response: "Invalid ID"
        })
    }
});```

.net – C # Windows Forms app: Add an element to the BindingSource and save these changes in the database

I created a C # Windows Form app that uses the Entity Framework (first DB model). I use an .mdf database file for the data.

The data view of dbo.students:
Enter image description here

GUI:
GUI

The Form1 class:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    StudentsEntities db = new StudentsEntities();

    private void Form1_Load(object sender, EventArgs e)
    {
        bsStudents.DataSource = db.students.ToList();
        dgvStudents.DataSource = bsStudents;

        lstResults.DisplayMember = "FullName";

        DisplayStudent();
    }

    // Displaying student info(name & credits) in lables, & refreshes DataGridView
    private void DisplayStudent()
    {
        if (bsStudents.Current != null)
        {
            lblName.Text = ((student)bsStudents.Current).FullName;
            lblCurrent.Text = ((student)bsStudents.Current).CurrentCredits.ToString();
            lblTotal.Text = ((student)bsStudents.Current).TotalCredits.ToString();

            dgvStudents.Refresh();
        }
    }

    private void bsStudents_CurrentChanged(object sender, EventArgs e)
    {
        DisplayStudent();
    }

    // add 1 credit to selected student's current credits
    private void btnAdd1_Click(object sender, EventArgs e)
    {
        ((student)bsStudents.Current).AddToCurrentCredits(1);
        DisplayStudent();
        lblForm1UserPrompt.Text = "1 credit has been added to the current credits of " + ((student)bsStudents.Current).FullName;
    }

    // add 3 credits to selected student's current credits
    private void btnAdd3_Click(object sender, EventArgs e)
    {
        ((student)bsStudents.Current).AddToCurrentCredits(3);
        DisplayStudent();
        lblForm1UserPrompt.Text = "3 credits has been added to the current credits of " + ((student)bsStudents.Current).FullName;
    }

    // place current credits into total credits of selected student
    private void btnAddCurrentToTotal_Click(object sender, EventArgs e)
    {
        ((student)bsStudents.Current).AddCurrentToTotal();
        DisplayStudent();
        lblForm1UserPrompt.Text = ((student)bsStudents.Current).FullName + "'s" + " current credits were added to their total credits.";
    }

    // change current credits of selected student to user input
    private void btnUpdateCurrentCredits_Click(object sender, EventArgs e)
    {
        string currentCredits = txtUpdateCurrentCredits.Text;
        int currentCreditsNumeric = 0;

        // validate user input
        if (int.TryParse(currentCredits, out currentCreditsNumeric))
        {
            ((student)bsStudents.Current).UpdateCurrentCredits(currentCreditsNumeric);
            DisplayStudent();
            lblForm1UserPrompt.Text = ((student)bsStudents.Current).FullName + "'s" + " current crdits have been set to " + currentCredits;
            txtUpdateCurrentCredits.Clear();
        }
        else
        {
            lblForm1UserPrompt.Text = "Please enter numeric data for current credits.";
            txtUpdateCurrentCredits.Clear();
        } 
    }

    // change total credits of selected student to user input
    private void btnUpdateTotalCredits_Click(object sender, EventArgs e)
    {
        string totalCredits = txtUpdateTotalCredits.Text;
        int totalCreditsNumeric = 0;

        // validate user input
        if (int.TryParse(totalCredits, out totalCreditsNumeric))
        {
            ((student)bsStudents.Current).UpdateTotalCredits(totalCreditsNumeric);
            DisplayStudent();
            lblForm1UserPrompt.Text = ((student)bsStudents.Current).FullName + "'s" + " total crdits have been set to " + totalCredits;
            txtUpdateTotalCredits.Clear();
        }
        else
        {
            lblForm1UserPrompt.Text = "Please enter numeric data for total credits.";
            txtUpdateCurrentCredits.Clear();
        }
    }

    // add 1 credit to all student's current credits
    private void btnAdd1All_Click(object sender, EventArgs e)
    {
        foreach (student s in bsStudents)
        {
            s.AddToCurrentCredits(1);
        }
        DisplayStudent();
        lblForm1UserPrompt.Text = "1 credit has been added to the current credits of all students";
    }

    // add 3 credits to all student's current credits
    private void btnAdd3All_Click(object sender, EventArgs e)
    {
        foreach (student s in bsStudents)
        {
            s.AddToCurrentCredits(3);
        }
        DisplayStudent();
        lblForm1UserPrompt.Text = "3 credits have been added to the current credits of all students";
    }

    // place current credits into total credits of all students
    private void btnAddCurrentToTotalAll_Click(object sender, EventArgs e)
    {
        foreach (student s in bsStudents)
        {
            s.AddCurrentToTotal();
        }
        DisplayStudent();
        lblForm1UserPrompt.Text = "The current credits of all students have been added to their total credits.";
    }

    // set current credits to 0 for all students
    private void btnSetCurrent0All_Click(object sender, EventArgs e)
    {
        foreach (student s in bsStudents)
        {
            s.CurrentCredits = 0;
        }
        DisplayStudent();
        lblForm1UserPrompt.Text = "The current credits of all students have been set to 0.";
    }

    // set total credits to 0 for all students
    private void btnSetTotal0All_Click(object sender, EventArgs e)
    {
        foreach (student s in bsStudents)
        {
            s.TotalCredits = 0;
        }
        DisplayStudent();
        lblForm1UserPrompt.Text = "The total credits of all students have been set to 0.";
    }

    // navigate to first element
    private void btnFirst_Click(object sender, EventArgs e)
    {
        bsStudents.MoveFirst();
        DisplayStudent();
    }

    // navigate to preceding element
    private void btnPrevious_Click(object sender, EventArgs e)
    {
        bsStudents.MovePrevious();
        DisplayStudent();
    }

    // navigate to succeeding element
    private void btnNext_Click(object sender, EventArgs e)
    {
        bsStudents.MoveNext();
        DisplayStudent();
    }

    // navigate to last element
    private void btnLast_Click(object sender, EventArgs e)
    {
        bsStudents.MoveLast();
        DisplayStudent();
    }

    // TODO: Maybe improve search
    private void txtSearchLastName_TextChanged(object sender, EventArgs e)
    {

    }

    // searches BindingSource for names that start with user input
    private void btnSearch_Click(object sender, EventArgs e)
    {
        List students = new List();

        foreach (student s in bsStudents)
        {
            if (s.StudentLastName.ToLower().StartsWith(txtSearchLastName.Text.ToLower()))
            {
                students.Add(s);
            }
        }

        if (students.Any())
        {
            bsStudents.Position = bsStudents.IndexOf(students.First());
            lstResults.DataSource = students;
            DisplayStudent();
        }
        else
        {
            MessageBox.Show("Not found");
        }
    }

    // navigate to name selected in ListBox
    private void lstResults_SelectedIndexChanged(object sender, EventArgs e)
    {
        List students = new List();

        foreach (student s in bsStudents)
        {
            if (s.FullName == lstResults.Text)
            {
                students.Add(s);
            }
        }

        if (students.Any())
        {
            bsStudents.Position = bsStudents.IndexOf(students.First());
        }
        else
        {
            MessageBox.Show("Not found");
        }
    }

    // create new student & add student to BindingSource
    private void btnAddStudent_Click(object sender, EventArgs e)
    {
        Form2 frmNew = new Form2();
        frmNew.ShowDialog();

        if (frmNew.stu != null)
        {
            bsStudents.Insert(0, frmNew.stu);
        }
    }

    // remove student from binding source
    private void btnRemove_Click(object sender, EventArgs e)
    {
        string fullName = ((student)bsStudents.Current).FullName;
        bsStudents.RemoveCurrent();
        lblForm1UserPrompt.Text = fullName + " has been removed.";
    }

    // save BindingSource to DB
    private void btnSaveToDB_Click(object sender, EventArgs e)
    {
        db.SaveChanges();
    }

    // exit app
    private void btnExitForm1_Click(object sender, EventArgs e)
    {
        this.Close();
    }
}

The Form2 class:

public partial class Form2 : Form
{
    public student stu;


    public Form2()
    {
        InitializeComponent();
        lblForm2UserPrompt.Text = "Please enter a first name, last name, current and total credits.";
    }

    private void btnSave_Click(object sender, EventArgs e)
    {
        string firstName = txtFirst.Text;
        string lastName = txtLast.Text;
        string currentCredits = txtCurrentCredits.Text;
        int currentCreditsNumeric = 0;
        string totalCredits = txtTotalCredits.Text;
        int totalCreditsNumeric = 0;

        //validate user input
        if (!string.IsNullOrEmpty(firstName) && !string.IsNullOrEmpty(lastName) && int.TryParse(currentCredits, out currentCreditsNumeric) && int.TryParse(totalCredits, out totalCreditsNumeric))
        {
            // instantiate & initialize student
            stu = new student();
            stu.StudentFirstName = char.ToUpper(firstName(0)) + firstName.Substring(1);
            stu.StudentLastName = char.ToUpper(lastName(0)) + lastName.Substring(1);
            stu.CurrentCredits = currentCreditsNumeric;
            stu.TotalCredits = totalCreditsNumeric;

            lblForm2UserPrompt.Text = "Student has been saved.";
        }
        else
        {
            //if user did not entered first or last name
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName))
            {
                lblForm2UserPrompt.Text = "Please enter a first and last name.";
            }
            //if user did not entered a number for current credit
            else if (!int.TryParse(currentCredits, out currentCreditsNumeric))
            {
                lblForm2UserPrompt.Text = "Please enter numeric data for current credits.";
                txtCurrentCredits.Clear();
            }
            //if user did not entered a number for total credit
            else
            {
                lblForm2UserPrompt.Text = "Please enter numeric data for total credits.";
                txtTotalCredits.Clear();
            }
        }
    }

    private void btnExit_Click(object sender, EventArgs e)
    {
        this.Close();
    }
}

The student class:

 public partial class student
{
    public int Id { get; set; }
    public string StudentLastName { get; set; }
    public string StudentFirstName { get; set; }
    public int CurrentCredits { get; set; }
    public int TotalCredits { get; set; }

    public string FullName
    {
        get
        {
            return $"{StudentFirstName} {StudentLastName}";
            //return StudentFirstName + " " + StudentLastName;
        }
    }

    public void AddToCurrentCredits(int newCurrentCredits)
    {
        CurrentCredits += newCurrentCredits;
    }

    public void AddCurrentToTotal()
    {
        TotalCredits += CurrentCredits;
        CurrentCredits = 0;
    }

    public void UpdateCurrentCredits(int newCurrentCredits)
    {
        CurrentCredits = newCurrentCredits;
    }

    public void UpdateTotalCredits(int newTotalCredits)
    {
        TotalCredits = newTotalCredits;
    }

}

The StudentsEntities class:

public partial class StudentsEntities : DbContext
{
    public StudentsEntities()
        : base("name=StudentsEntities")
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        throw new UnintentionalCodeFirstException();
    }

    public virtual DbSet students { get; set; }
}

The app is running, but not as expected …

These are the parts I'm having trouble with:

  1. I seem to be able to create a new student and add it to the BindingSource. I know that because it shows up in the DataGridView. However, your ID value is always 0. In addition, the ID value must be unique.
  2. When I save the changes made in the BindingSource to the underlying database file, the new students are not saved. When I edit a student's credits, these changes are saved. But the newly created students will not.

The btnAddStudent_Click method:

 private void btnAddStudent_Click(object sender, EventArgs e)
    {
        Form2 frmNew = new Form2();
        frmNew.ShowDialog();

        if (frmNew.stu != null)
        {
            bsStudents.Insert(0, frmNew.stu);
        }
    }

The student object is then created in Form2 and given values.

After adding 2 new students and setting all current credits in the BindingSource to 0:
I have set all current credits in the BindingSource to 0

The data view of dbo.students after saving the changes made to the BindingSource:
Data view of dbo.students after saving

As you can see, the changes in student credits have changed. But the number of students has not.

What I'm looking for:

  1. I want the new student objects with unique IDs to be stored in the BindingSource.
  2. When I save the changes made to the BindingSource, I want to see new students (if created) in the data view of the DBO.

What do you think? Thanks in advance for the input.

How to capture an element created with Javascript

    // Cria uma variavel para armazenar o botão
            var novoQuadrado = document.querySelector('#btnClick');
            var tela = document.querySelector('body');
            
            let count = 0;
            novoQuadrado.onclick = function() {
                // Quando ocorrer o evento onclick no botão irá
                // instanciar um novo quadrado e definir as propriedades
                // e os estilos abaixo, depois esse elemento é "linkado ao body"
                // para poder ser exibido.
                var quadrado = document.createElement('div');

                quadrado.className = "box-" + count;
                //quadrado.setAttribute('class', 'quadrado');
                quadrado.style.width = '100px';
                quadrado.style.height = '100px';
                quadrado.style.backgroundColor = '#f00';
         
                tela.appendChild(quadrado);  

                quadrado.onmouseover = function () {
                    // Função para criar um padrão aleatórios no padrão #xxxxxx
                    function getRandomColor() {
                        var letters = "0123456789ABCDEF";
                        var color = "#";
                        for (var i = 0; i < 6; i++) {
                            color += letters(Math.floor(Math.random() * 16));
                        }
                        return color;
                    }
                    quadrado.style.backgroundColor = getRandomColor();
                }
                count++;             
            }

What is the most efficient way to select an element specific to the H1?

Let's say I'm stupid, but I really want to know how to choose this particular item most efficiently:

MySite

Code (surcharge):

I got the following from the internet and it is still not specific to the H1 tag:


a(title) {
    color: red;
}
a(title):hover {
    color: orange;
    text-decoration: none;
}
Code (surcharge):

I want this element to be unique and style it differently.

Thank you for your help,

Finite element method – stability analysis of the parabolic problem

I am taking an exam question for the past exam.

Consider the fully discrete implicit backward Euler scheme: e.g. $ K $ a positive
Integer, set $ k = T / K, $ define $ t_ {n} = n k, 0 leq n leq K, $ and for everyone $ 0 leq n leq K-1, $ knowing
$ u_ {h} ^ {n} in W_ {h} $ Find $ u_ {h} ^ {n + 1} in W_ {h} $ so that

$$
forall v_ {h} in W_ {h}, frac {1} {k} left (u_ {h} ^ {n + 1} -u_ {h} ^ {n}, v_ {h} right ) + a left (u_ {h} ^ {n + 1}, v_ {h} right) = 0, \ n = 0.1, cdots, K, ~~ u_ {h} ^ {0} = Pi_ {h} left (u_ {0} right)
$$

Where $ a left (u_ {h} ^ {n + 1}, v_ {h} right) = int _ { Omega} nabla u_ {h} ^ {n + 1} cdot nabla v_ {h } + c u_ {h} ^ {n + 1} v_ {h} dx $ . $ c> 0 $ is a constant.

Please prove the following stability assessment
$$
sup _ {1 leq n leq K} left | u_ {h} ^ {n} right | _ {L ^ {2} ( Omega)} ^ {2} + k sum_ {n = 1} ^ {K} left | u_ {h} ^ {n} right | _ {H ^ {1} ( Omega)} ^ {2} leq left | u_ {h} ^ {0} right | _ {L ^ {2} ( Omega)} ^ {2}
$$

I tried to leave $ v_h = u_h ^ {n + 1} $ but could not get this concrete estimate.

How do I find all positions of the first element and get the elements from the nested list at once?

I have two questions.
Let's think of the following expression.

expr = {plus, {minus, 2, 3}, {times, 1, 2}}

Q1
I want to get something like that at once
ENTRANCE:

AllHeadPositions(expr)

OUTPUT:

expr->{{1}}
minus->{{2,1}}
times->{{3,1}}

and
Q2(MAIN)
I want to put items on a list like

ENTRANCE

expr(({something to specifiy minus}))

OUTPUT

{minus,2,3}

I found the way for the first question

If(Not(NumberQ(#)), {#, Position(expr, #)}, Nothing) & /@ 
 Flatten(expr)

but what to do for the second one?