satoshi-2000/llms-suitable huggingface dataset:
Question: Python: Comparing two lists using a for-loop, how do I print the results correctly?

import random

lst1 = []
lst2 = []
n = int(input('Step a: How many numbers in each list?  '))

for i in range(0, n):
    number1 = random.randint(1, 15)
    number2 = random.randint(1, 15)
    lst1.append(number1)
    lst2.append(number2)
    count = 0
    if lst1[i] > lst2[i]:
        count += 1
        print(f'{number1} : First List')
    else:
        print(f'{number2} : Second List')


print(f'Step b: First List{lst1}')
print(f'Step c: Second List{lst2}')
print('Step d:')
print('Larger number in each comparison:')

Program is supposed to make two lists and compare each element.
Current program prints like this:
Step a: How many numbers in each list?  5
12 : First List
14 : First List
14 : First List
15 : First List
5 : Second List
Step b: First List\[12, 14, 14, 15, 4\]
Step c: Second List\[5, 2, 8, 13, 5\]
Step d:
Larger number in each comparison:

I'm trying to get it to print like this:
Step a: How many numbers in each list?  5
Step b: First List\[12, 14, 14, 15, 4\]
Step c: Second List\[5, 2, 8, 13, 5\]
Step d:
Larger number in each comparison:
12 : First List
14 : First List
14 : First List
15 : First List
5 : Second List

Any suggestions?
I've tried to make functions out of them and kept getting errors. Very new to this and not sure what I should do.


Answer:
Try creating a third list to store the comparison results and then printing the contents only at the end with another loop:
import random

lst1 = []
lst2 = []
comparison_results = []

n = int(input('Step a: How many numbers in each list? '))

for i in range(n):
    number1 = random.randint(1, 15)
    number2 = random.randint(1, 15)
    lst1.append(number1)
    lst2.append(number2)

    if lst1[i] > lst2[i]:
        comparison_results.append(f'{number1} : First List')
    elif lst1[i] < lst2[i]:
        comparison_results.append(f'{number2} : Second List')
    else:
        comparison_results.append(f'{number2} : In Both Lists')

print(f'Step b: First List {lst1}')
print(f'Step c: Second List {lst2}')
print('Step d: Larger number in each comparison:')
for result in comparison_results:
    print(result)


Example Output:
Step a: How many numbers in each list? 5
Step b: First List [5, 11, 9, 3, 4]
Step c: Second List [15, 11, 9, 13, 15]
Step d: Larger number in each comparison:
15 : Second List
11 : In Both Lists
9 : In Both Lists
13 : Second List
15 : Second List
Question: How to upload only updated files in Google Apps Script using clasp?

I'm developing Google Apps Script locally. I used the clasp push --watch command for pushing updated code to the original Apps Script as per the documentation.
https://www.npmjs.com/package/@google/clasp#push
The problem is that when I update the code of any one file, it uploads the whole file. I have attached the screenshot of the file structure and vs code terminal.
You can see there I had updated the code of home.html but still, it's uploaded the whole project. Because of this, we are getting time-consuming issues. It's taking a long time to upload the project. I had also attached the screen shot of clasp.json file.
Is there any way to upload the only updated file ?





Answer:
It seems this behavior is expected based on the documentation:

Warning: Google scripts APIs do not currently support atomic nor per file operations. Thus the push command always replaces the whole content of the online project with the files being pushed.


clasp push replaces code that is on script.google.com and clasp pull
replaces all files locally. For this reason, follow these guidelines:
Do not concurrently edit code locally and on script.google.com. Use a
version control system, like git.

A new feature would be required from the Google Apps Script API to accomplish what you're looking for, it seems there is already a Feature Request here, you can vote for it, add your comments and look for any future updates.
References

Pulling & Pushing Files
Feature request: clasp push -w - add option to push only changed files
Problems when using CLASP to push client-side files from a local editor
Question: How to compile Packages in java

I am new to java , how do I compile packages in Intelij
This is my directory

It is running perfectly in Main.java
To compile , I first ran
javac people/People.java
Then I compile javac Main.java, it returns Main.java:8: error: package com.amigoscode.people does not exist
Main.java
package com.amigoscode;

// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
// then press Enter. You can now see whitespace characters in your code.


import java.util.Scanner;
import com.amigoscode.people.People;


public class Main {

    public static void main(String[] args) {
        People p = new People();
        System.out.println(p.fullName());
    }

}

People.java
package com.amigoscode.people;

public class People {

    public String fname = "John";
    public String lname = "Doe";
    public int age = 24;


    public String fullName() {
        String fullName = fname + " " + lname;
        return fullName;
    }

}

Thank you very much.


Answer:
First, navigate to the src directory using terminal. Then execute the command below to compile the People.java.
javac com/amigoscode/people/People.java

Now, to compile the Main.java execute the command below.
javac com/amigoscode/Main.java

This should work fine.
Question: CMake CMAKE_SOURCE_DIR and CMAKE_CURRENT_SOURCE_DIR to set same path, but only latter 'works'

I'm using CMake in, so far as I can tell, the same way as I always use it.  The problem is that now include_directories($(CMAKE_SOURCE_DIR)/server/include) results in my header files not being found.  When instead I use include_directories($(CMAKE_CURRENT_SOURCE_DIR)/server/include) they are found.
i.e. $(CMAKE_CURRENT_SOURCE_DIR) works, and $(CMAKE_SOURCE_DIR) doesn't.
The bizarre thing is that both of:
message(${CMAKE_SOURCE_DIR}/server/include)
message(${CMAKE_CURRENT_SOURCE_DIR}/server/include)

give:
/home/username/projects/repo/server/include

So why does one work while the other doesn't?


Answer:
$(FOO) is not the correct syntax to refer to the cmake variable FOO. You need to use ${FOO} instead. Neither of the uses of include_directories should work, unless the build system interprets the path $(CMAKE_CURRENT_SOURCE_DIR)/server/include.
Note that you're using the proper syntax for the message commands.
The message command
message($(CMAKE_CURRENT_SOURCE_DIR)/server/include)

prints
$(CMAKE_CURRENT_SOURCE_DIR)/server/include

demonstrating the issue.
I recommend using the CMAKE_CURRENT_SOURCE_DIR instead of CMAKE_SOURCE_DIR btw in all cases except for rare exceptions where you know that the toplevel CMakeLists.txt is located in a directory with specific contents. The former version is easier to recombine when used as part of a larger project via add_subdirectory.
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/server/include)
#                    ^                        ^

Note that the use of target_include_directories usually is preferrable to the use of include_directories, since the former allows restricts the targets the include directories are applied to to the one specifically mentioned. It also would allow you to make the include directories to targets linking a cmake library target, if desired.
Question: why .gitconfig [includIf] override the default config

I have two keys to different github account and there is the config ~/.gitconfig:
[user]
        name = example
        email = example@example.com
[pull]
        rebase = true
[rebase]
        autoStash = true
[filter "lfs"]
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
        process = git-lfs filter-process
        required = true
[includeIf "gitdir/i:/Users/example/Documents/github_2/"]
    [core]
        sshCommand = "ssh -i ~/.ssh/github2_key"

then, I go to a folder that did not at /Users/example/Documents/github_2/, and run git clone github1_private_project, git told me Please make sure you have the correct access rights
It works to git clone the project from account 'github2' in /Users/example/Documents/github_2/

git version:
% git -v
git version 2.39.2 (Apple Git-143)



Answer:
The syntax for includeIf should be (see the docs):
[includeIf "gitdir/i:/Users/example/Documents/github_2/"]
path = </path/to/includeFile>

The syntax
[includeIf "gitdir/i:/Users/example/Documents/github_2/"]
    [core]
        sshCommand = "ssh -i ~/.ssh/github2_key"

actually means
[includeIf "gitdir/i:/Users/example/Documents/github_2/"]
# No `path` hence no include

[core]
    sshCommand = "ssh -i ~/.ssh/github2_key"

where the key core.sshCommand is always (unconditionally) defined.
Question: Am I using NSIS nsexec::ExecToStack Output correctly?

I am calling nsExec::ExecToStack to get the output of a powershell command.  Based on the result, I will either do nothing, or install a windows feature.  I seem to get the result I expect from the powershell command, but the if/then logic is not doing what I expect.
Here's the code:
DetailPrint "======================"
DetailPrint "Checking MSMQ Services"
DetailPrint "======================"

nsExec::ExecToStack 'powershell.exe -command "(get-windowsfeature -name MSMQ-Services).InstallState"'
Pop $0
Pop $InstallState

DetailPrint "MSMQ is: $InstallState"

${If} $Installstate == "Installed"
    DetailPrint "MSMQ is Installed"
${Else}
    DetailPrint "========================"
    DetailPrint "Installing MSMQ Services"
    DetailPrint "========================"

    nsexec::exectolog 'powershell -command "install-windowsfeature -name msmq-services"'
    
${EndIf}

I set ${DisableX64FSRedirection} in the same section, above this code, to ensure powershell is the 64-bit version and can run the command properly.
Here is what I am seeing in the Log:
======================
Checking MSMQ Services
======================
MSMQ is: Installed

========================
Installing MSMQ Services
========================

Success Restart Needed Exit Code      Feature Result                               
------- -------------- ---------      --------------                               
True    Yes            NoChangeNeeded {}                                           


I have been staring at this code, tweaking, trying different logic...
Here is what the powershell command returns:
PS C:\Windows\system32> $tom=(get-windowsfeature -name MSMQ-Services).InstallState
PS C:\Windows\system32> echo $tom
Installed

First thought was that there were leading or trailing spaces, so I did the comparison with "X$InstallStateX".
I tried adding the /OEM flag to ExectoStack.
I tried variations of if/then logic:
${If} $Installstate != "Installed"
    <install command>
${EndIf}

Honestly, I'm not sure if this is a stupid logic flaw (on my part) or some funky output from exectostack that I'm not expecting.


Answer:
It was just a CR/LF at the end of the PowerShell output.
By changing my statement to:
${If} $InstallState == "Installed$\r$\n"

Worked like it should.
It's always something simple in the end.
Question: Is there a way to warn C++ developers when they accidentally include internal implementation headers of std library?

How to let know developers automatically that this "bits/shared_ptr.h" is internal to standard library (gcc and clang).
#include <bits/shared_ptr.h>

// some code using std::shared_ptr


The best would be to also inform <memory> should be used instead.
This <bits/shared_ptr.h> is just an example - I mean - how to warn about any implementation header being included.
By "automatically" I mean - compiler warning or static analysis like clang-tidy.
I have tried "-Wall -Wextra -pedantic" and all clang-tidy checks, without llvm* checks - these llvm* warns for almost every header and it is just for llvm developers, not for us, regular developers.
Any advice?
I prefer existing solution, I know I can write script for that.

Ok, I found one check in clang-tidy that I can use.
It is portability-restrict-system-includes
Just need to specify in config that "bits" things are not allowed:
-config="CheckOptions: {portability-restrict-system-includes.Includes: '*,-bits/*,bitset'}"
See demo.
But, well, it is not perfect solution - one would need to maintain list of "not allowed" headers.


Answer:
It seems like include-what-you-use does what you want.
It has a mapping of what names are supposed to come from what header, and it seems to know which headers are internal.
For example, when including <bits/shared_ptr.h> https://godbolt.org/z/cvq7354K6:
#include <bits/shared_ptr.h>

std::shared_ptr<int> x;

It says to remove <bits/shared_ptr.h> and add <memory>.
Question: How can I fix incorrect flat lines on my PowerBI line chart with a date hierarchy?

I have a PowerBI report with a line chart that shows average costs over a time period. The time period is based on a date that is set to use a date hierarchy for the year and the month.

When I open the report the line chart does not display correctly. The lines are incorrectly flat.

If I change the date from a date hierarchy to just the date and then back to the hierarchy, then it displays correctly.

This also happened when I published the report to the PBI service. What can be done to negate the need to do this?
I have tried resetting the field for the X-axis and restarting the application.


Answer:
Clicking on the double arrow icon to expand the next level by default resolved my issue.
Question: Create Global HTTPS load-balancer with gcloud

I haven't kept up with changes to GCP's load-balancing, and they've introduced a new kind of global L7 load-balancer, and the ones which I am used to are now termed "classic".
I am not able to find ways to create these new style of load-balancers using gcloud CLI. Is there a way to do this?


Answer:
Just to mark the question answered, I will post @John_Hanley's reply here:
Set the flag like this:
gcloud gcloud compute backend-services create --load-balancing-scheme=EXTERNAL_MANAGED
Question: Create unique pair of elements in a list based on some attribute of the class/object

I have a JSON file in the below format
[
  { "name": "John", "team": "NW", "available": true },
  { "name": "Dani", "team": "NW", "available": true },
  { "name": "Lyle", "team": "NW", "available": false },
  { "name": "Dean", "team": "W", "available": true },
  { "name": "Lyle", "team": "W", "available": true },
  { "name": "David", "team": "W", "available": true },
  { "name": "George", "team": "SW", "available": false },
  { "name": "Luke", "team": "SW", "available": false }
]

and the corresponding Java class like below:
public class Agent {
  private String name;
  private String team;
  private Boolean available;
  ...
  ...
}

I need to pair members from the list with other people on the list. The rules are that the pair has to be with a member who is available and is from a different team.
Need to list the pairs of the members along with any members which could not be paired (odd number of 'pairable' members/not enough members in other teams).
I have written the code to read the JSON in a list of 'Agent' objects using Jackson and have tried the following approaches till now

Iterating over the list and getting the first 'available' member and fetching another one from different team (used stream API/filtering to do this)
Create a map of agents (key: team, value: agent list) and iterate the EntrySet to pair the agents with agents from another team.
Naive approach of creating anew list and adding elements from the original list as and when they are mapped)

However, I am getting a lot of agents unmapped. I wanted to write the logic in such a way that it matches/pairs maximum numbers of agents and print the remaining agents in the output alongwith the agents that were paired.
Not looking for a full blown solution - any pointers will be greatly appreciated!


Answer:
To confirm, when running you first,

Check if the agent is available.
Find a matching agent from a different team (From the map of agents)
And if a match is found, add the pair of agents to the list of pairs and mark both agents in the EntrySet, otherwise mark the agent as unmatched.

Correct?
If so, it sounds like you already have a good solution to the problem, and I would double check your code to ensure you are following these steps properly. A limitation within the data (Such as very unbalanced team sizes), could also cause you to get unbalanced results.
If you wanted another approach though, I would suggest using a 'Maximal Matching' Algorithm, like the Hopcroft-Karp algorithm or the Edmonds' Blossom algorithm to find the maximum matching.
In your case, the agents would be represented as nodes in the bipartite graph, Node set 1 representing available agents and Node set 2 representing unavailable agents. Then generate the edges between the two sets, where each node would represent a potential pairing.
An overview of the algorithm can be found here; https://www.geeksforgeeks.org/hopcroft-karp-algorithm-for-maximum-matching-set-1-introduction/
All you would need to do is generate these nodes and edges, as many implementations of the algorithm can be found online :)
Question: How can I temporarily set a folder as the workspace in VS Code to run specific configurations?

I have a tree structure with multiple different projects in Visual Studio Code (VS Code). Each project is in a separate folder within the tree structure.
Is there a way to make one of these folders the current workspace folder ad hoc, so that I can easily run the configuration specific to that folder?
Is there a way to designate a folder as the active workspace folder temporarily, so that I can execute the configurations specific to that folder without modifying the overall workspace settings?
I've come across the concept of multi-root workspaces in VS Code, but I'm not sure if it allows me to achieve what I need.


Answer:

Is there a way to make one of these folders the current workspace folder ad hoc, so that I can easily run the configuration specific to that folder?

As far as I'm aware, the easiest you'll get is using File: Open File... (if you've never opened the folder / workspace) before, or using File: Open Recent... (these are command palette commands and both of which have keybindings, which you can find in the command palette. They're also both available under the "File" menu item)


I've come across the concept of multi-root workspaces in VS Code, but I'm not sure if it allows me to achieve what I need.

Multi-root workspaces allow you to create a flat list of workspace roots that are all open at once. You can set configuration for all workspaces by putting it in the .code-workspace file, or per-workspace-root by putting it in their .vscode/settings.json files.
Question: Is there an equivalent of the /hierarchy API endpoint for DSpace 7.x?

The DSpace OAI-PMH repository exposes an endpoint /hierarchy for API v6, which provides the logical structure of how communities, sub-communities and collections are related. This is documented at https://wiki.lyrasis.org/pages/viewpage.action?pageId=104566810#RESTAPIv6(deprecated)-Hierarchy
As v6 will be deprecated, is there a direct replacement for this endpoint in v7?
There's no reference to it in the documentation https://wiki.lyrasis.org/display/DSDOC7x/REST+API nor can I see anything equivalent in the live demo: https://api7.dspace.org/server/#/server/api


Answer:
There is no exact replacement in DSpace 7 REST API.  But you can retrieve the same information as follows:

Start from the "Top level Communities" search endpoint here: https://github.com/DSpace/RestContract/blob/main/communities.md#search-methods

This will retrieve all the communities at the top of that hierarchy


Then, for each of those top Communities, it's possible to retrieve their sub-communities and sub-collections via the "linked entities"

Sub-Communities: https://github.com/DSpace/RestContract/blob/main/communities.md#subcommunities
Sub-Collections: https://github.com/DSpace/RestContract/blob/main/communities.md#collections



This is how the hierarchy is achieved in the DSpace 7 User Interface when you visit the "/community-list" page, e.g. https://demo7.dspace.org/community-list
Question: From a list, how to get only the items with dates within a certain time period?

I have a list of items, each item has a date value:
[
  {
    "Date Merged": "6/1/2023 3:46:53 PM",
    "PR ID": "470"
  },
  {
    "Date Merged": "5/30/2023 2:44:25 PM",
    "PR ID": "447"
  }
]

I want to get only the PRs of the items with dates that happened in May. I think I can grab the 'PR ID' values with: map(attribute='PR ID'), but I don't know how to filter within a certain date range.


Answer:
Given the data
  prs:
    - Date Merged: 6/1/2023 3:46:53 PM
      PR ID: '470'
    - Date Merged: 5/30/2023 2:44:25 PM
      PR ID: '447'

Q: "Get the PRs with dates that happened in May."
A: There are more options:

Quick & dirty. The test match "succeeds if it finds the pattern at the beginning of the string"

  result: "{{ prs|selectattr('Date Merged', 'match', '5')|
                  map(attribute='PR ID') }}"

gives
  result:
  - '447'


Use the filter to_datetime to get the date objects and create the list of the hashes

  format: '%m/%d/%Y %I:%M:%S %p'
  months: "{{ prs|map(attribute='Date Merged')|
                  map('to_datetime', format)|
                  map(attribute='month')|
                  map('community.general.dict_kv', 'month') }}"

gives
  months:
  - month: 6
  - month: 5

Update the dictionaries
  prs_months: "{{ prs|zip(months)|map('combine') }}"

gives
  prs_months:
  - Date Merged: 6/1/2023 3:46:53 PM
    PR ID: '470'
    month: 6
  - Date Merged: 5/30/2023 2:44:25 PM
    PR ID: '447'
    month: 5

Select the items and get the ids
  result: "{{ prs_months|selectattr('month', 'eq', 5)|
                         map(attribute='PR ID') }}"

gives the same result
  result:
  - '447'



Example of a complete playbook for testing
- hosts: localhost

  vars:

    prs:
      - Date Merged: 6/1/2023 3:46:53 PM
        PR ID: '470'
      - Date Merged: 5/30/2023 2:44:25 PM
        PR ID: '447'

    result1: "{{ prs|selectattr('Date Merged', 'match', '5')|
                     map(attribute='PR ID') }}"

    format: '%m/%d/%Y %I:%M:%S %p'
    months: "{{ prs|map(attribute='Date Merged')|
                    map('to_datetime', format)|
                    map(attribute='month')|
                    map('community.general.dict_kv', 'month') }}"
    prs_months: "{{ prs|zip(months)|map('combine') }}"
    result2: "{{ prs_months|selectattr('month', 'eq', 5)|
                            map(attribute='PR ID') }}"

  tasks:

    - debug:
        var: result1

    - debug:
        var: months
    - debug:
        var: prs_months
    - debug:
        var: result2