satoshi-2000/llms-suitable huggingface dataset:
Question: How can I make an adaptive list to check against another adaptive list?

I apologize from the start as I am not allowed to share the workbook I am working on (it has confidential information from work) but I will do my best to explain what is happening and what my issue is.
I have two sheets, "Tracker" and "Reviewers". In the tracker names are recorded in column L and their submission is recorded in column M. Everything runs on a serial code in column A so there are blank cells between names. Some people have multiple submissions so their names show multiple times in column L. In the reviewers sheet, I have:
=UNIQUE(FILTER(Tracker!L4:L4999,Tracker!L4:L4999<>0))

In cell A2 to pull all the names of people who have a submission. This works flawlessly and adapts to include any new people. Then in cell B2 I have written:
=SUMPRODUCT(IF(ISBLANK(FILTER(Tracker!$L$4:$M$4999,Tracker!$L$4:$L$4999=Reviewers!A2#))=TRUE,1,0))

The idea here was to get a count of how many "submissions" people have without actually writing anything. It is filtering the list of names and submissions by name in the list we just created, checking if their "submission" is a blank cell, then adding them up. Issue is that it works when I filter by cell A2 but not when I filter by the function that spills out of cell A2 (A2#). I need it to be adaptive so if new names are added it can make the list longer, hence why I cannot just pull the cells down the list (A2, A3, A4,...). How would you go about getting a check of how many are blank like this?
As an example, Tracker could have:




Name
Submission




Jim
Idea


Bob
Idea


Pam



Sam
Idea


Jim



Bob
Idea


Jim



Pam
Idea




And Reviewers should return:




Name
#Blank




Jim
2


Bob
0


Pam
1


Sam
0




I hope this makes sense and I hope you can help me edit the equation in cell B2 of the Reviewers sheet to be adaptive and spill the results.


Answer:
=LET(d,DROP(FILTER(A:B,A:A<>""),1),
     n,INDEX(d,,1),
     s,INDEX(d,,2),
     u,UNIQUE(n),
     m,MMULT(--(TOROW(n)=u),--(s="")),
HSTACK(u,m))

Change the filter range (and maybe the lines to drop) and the index numbers to your situation.

I think this would work in your case:
=LET(d,DROP(FILTER(Tracker!$L$4:$M$4999,Tracker!$M$4:$M$4999<>""),1),
     n,INDEX(d,,1),
     s,INDEX(d,,2),
     u,UNIQUE(n),
     m,MMULT(--(TOROW(n)=u),--(s="")),
HSTACK(u,m))
Question: How to set document quality while ingesting document into MarkLogic through PutMarkLogic NiFi processor?

I'm using NiFi 1.21.0 and nifi-marklogic-nar-1.9.1.6.
I have been using PutMarkLogic 1.9.1.6 processor to ingest documents to MarkLogic-db for more than 2 years. Recently witnessed that the processor doesn't support adding document-quality (PFB the processor image).

So I have created a new issue against marklogic/nifi project.


Answer:
This enhancement was fixed as part of https://github.com/marklogic/nifi/pull/121. Therefore use nifi-marklogic-nar-1.15.3.1 or later version to set document-quality. I'm currently using PutMarkLogic 1.16.3.2 and I can now see a provision to add Quality.
Question: Loop through rows of a table on outlook and change (Text To Display) to an ascending number per each row

I have used the below code to Loop through selection on outlook and convert into Hyperlinks and change Text To Display Link.
it works but it adds the the ascending number incrementally to all cells like this picture:

My need is to add the ascending number per each row like this picture:

In advance, great thanks for all your help.
Sub Hyperlink_Outlook()

  Dim wDoc As Word.Document, rngSel As Word.Selection, cel As Cell, i As Long
  
  Set wDoc = Application.ActiveInspector.WordEditor
  Set rngSel = wDoc.Windows(1).Selection
    
  If Not rngSel Is Nothing And rngSel.Information(wdWithInTable) Then
    If rngSel.Range.Cells.Count > 0 Then
       For Each cel In rngSel.Cells
         If Len(cel.Range.Text) > 10 Then
           i = i + 1
            wDoc.Hyperlinks.Add cel.Range, _
             Address:=Left(cel.Range.Text, Len(cel.Range.Text) - 1), _
             TextToDisplay:="Attachment " & i
         End If
       Next
    End If
  End If
  
End Sub



Answer:
Try looping through rows first (the following is not tested):
Sub Hyperlink_Outlook()

  Dim wDoc As Word.Document, rngSel As Word.Selection, cel As Cell, i As Long
  Dim r As Variant
  
  Set wDoc = Application.ActiveInspector.WordEditor
  Set rngSel = wDoc.Windows(1).Selection
    
  If Not rngSel Is Nothing And rngSel.Information(wdWithInTable) Then
    If rngSel.Range.Cells.Count > 0 Then
      For Each r In rngSel.Rows
        i = 0 ' reset i here
        For Each cel In r.Cells
          If Len(cel.Range.Text) > 10 Then
            i = i + 1
             wDoc.Hyperlinks.Add cel.Range, _
              Address:=Left(cel.Range.Text, Len(cel.Range.Text) - 1), _
              TextToDisplay:="Attachment " & i
          End If
        Next cel
      Next r
    End If
  End If
  
End Sub
Question: SwiftUI Toggle how to distinguish changing value by UI action vs changing programatically

If i have a toggle, which updates its state from external async load but also by user intput, how can i differentiate those two? eg. to perform a special action on user action
    Group {
        Toggle(isOn: $on) {
            EmptyView()
        }
    }
    .onChange(of: on) { newValue in
        was "on" changed by user or onAppear async update?
    }
    .onAppear {
        async update on
    }

PS: this is mostly for macOS, and there the tapGesture on Toggle doesn't work


Answer:
If you want a side effect for use the user actions, you can use a custom wrapper Binding:
struct ContentView: View {
    @State private var on: Bool = false
    
    var userManagedOn: Binding<Bool> {
        .init {
            return on
        } set: { newValue in
            print("Side effect")
            on = newValue
        }
    }
    
    var body: some View {
        VStack {
            Group {
                Toggle(isOn: userManagedOn) {
                    EmptyView()
                }
            }
        }
        .padding()
        .onAppear {
            Task { @MainActor in
                try? await Task.sleep(nanoseconds: NSEC_PER_SEC)
                on.toggle()
            }
        }
    }
}
Question: How can I change the color of an icon when a checkbox is checked using Tailwind?

<input type="checkbox" id="darkmode-toggle" class="peer invisible h-0 w-0" />
<label for="darkmode-toggle" class="btn-toggle group">
    <svg class="icon absolute">
        <use href="../../assets/icons/spirit.svg#sun" />
    </svg>
    <svg class="icon absolute  group-[peer-checked]:fill-secondary-dark-300">
        <use href="../../assets/icons/spirit.svg#moon" />
    </svg>
</label>

In the given HTML code (using Tailwind CSS), I want to change the color of the icon when the associated input checkbox is checked.
The attempted selector used is group-[peer-checked]:fill-secondary-dark-300. However, the desired icon color change is not happening.
How can I achieve the desired result of changing the color of the icon when the input checkbox is checked using the provided selector?
This is what I want to achieve with this selector:

group (select the parent "label")

[peer-checked] (when the sibling of the label "input" is checked)

fill-secondary-dark-300: change the icon color.




Answer:
You could consider using group-[.peer:checked+&]::


tailwind.config = {
  theme: {
    extend: {
      colors: {
        'secondary-dark-300': 'red',
      },
    },
  },
};
<script src="https://cdn.tailwindcss.com"></script>

<input type="checkbox" id="darkmode-toggle" class="peer invisible h-0 w-0" />
<label for="darkmode-toggle" class="btn-toggle group">
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6">
    <path d="M12 2.25a.75.75 0 01.75.75v2.25a.75.75 0 01-1.5 0V3a.75.75 0 01.75-.75zM7.5 12a4.5 4.5 0 119 0 4.5 4.5 0 01-9 0zM18.894 6.166a.75.75 0 00-1.06-1.06l-1.591 1.59a.75.75 0 101.06 1.061l1.591-1.59zM21.75 12a.75.75 0 01-.75.75h-2.25a.75.75 0 010-1.5H21a.75.75 0 01.75.75zM17.834 18.894a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 10-1.061 1.06l1.59 1.591zM12 18a.75.75 0 01.75.75V21a.75.75 0 01-1.5 0v-2.25A.75.75 0 0112 18zM7.758 17.303a.75.75 0 00-1.061-1.06l-1.591 1.59a.75.75 0 001.06 1.061l1.591-1.59zM6 12a.75.75 0 01-.75.75H3a.75.75 0 010-1.5h2.25A.75.75 0 016 12zM6.697 7.757a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 00-1.061 1.06l1.59 1.591z" />
  </svg>
 
  <svg class="w-6 h-6 group-[.peer:checked+&]:fill-secondary-dark-300" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
    <path fill-rule="evenodd" d="M9.528 1.718a.75.75 0 01.162.819A8.97 8.97 0 009 6a9 9 0 009 9 8.97 8.97 0 003.463-.69.75.75 0 01.981.98 10.503 10.503 0 01-9.694 6.46c-5.799 0-10.5-4.701-10.5-10.5 0-4.368 2.667-8.112 6.46-9.694a.75.75 0 01.818.162z" clip-rule="evenodd" />
  </svg>
</label>
Question: Javascript - alert problem with onblur and focus-visible Firefox/Chrome

In onblur I need to call alert(), but this doesn't work in Chrome and Firefox. Sess https://jsfiddle.net/mimomade/5sur482w/1/
In Firefox :focus-visible stays after leaving the 2nd and 4th input field and is not removed.
In Chrome I can't leave the 2nd input field. Although the 1st doesn't has any problem.


Answer:
At the very bottom is the code with both bugs fixed. You're initial JavaScript looks like this:
// Has different bugs in Firefox and Chrome.
function blurring(el) {
  console.log(el.id + ' pre  alert');
  alert('blurring ' + el.id);
  console.log(el.id + ' post alert');
}

In Firefox, your apparent bug actually masks a bug similar to what you're encountering in Chrome. When the alert is removed, the code has the intended behavior, so alert and the event are interacting in a weird way. In this specific case, to get around this, we can just wait for the event to finish by wrapping the function in a zero-millisecond timeout.
// Has a similar bug in both browsers.
function blurring(el) {
  console.log(el.id + ' pre  alert');
  setTimeout(function () {
    alert('blurring ' + el.id);
    console.log(el.id + ' post alert');
  }, 0);
}

In Chrome, your bug appears to be caused by the blur event emitting each time the alert box is closed. Luckily, because we wait for the events to finish, the active element should be the element newly selected input instead of whatever the browser set it to. This means checking ensuring el and document.activeElement are different is sufficient to fix this bug.
// addresses both bugs.
function blurring(el) {
  console.log(el.id + ' pre  alert');
  setTimeout(function () {
    if (document.activeElement !== el) {
      alert('blurring ' + el.id);
      console.log(el.id + ' post alert');
    }
  }, 0);
}
Question: Tried to use state variable inside another state variable, but it didn't work as expected it to, Why ? (in ReactJS using function component)

I was trying to use a state variables value inside another state variable, but when the other sub state variable was updated outside, its updated value didn't get reflected in parent state variable, why did this happened? can I not use state variable inside another state variable or is there any specific way to use it?
Can anyone explain this please?
const [noOfPersonstForRoom, setNoOfPersonsForRoom] = useState([2]);

const [ageOfPerson1ForRoom, setAgeOfPerson1ForRoom] = useState([0]);
const [ageOfPerson2ForRoom, setAgeOfPerson2ForRoom] = useState([0]);

    const [rooms, setRooms] = useState([
    {
        roomNo: 1,
        noOfPersons: noOfPersonsForRoom[0], 
                    ageOfPerson1: ageOfPerson1ForRoom[0],
                    ageOfPerson2: ageOfPerson2ForRoom[0]
        

        
    },
]);

This is code of what I tried, with some changes.
To change sub state variable, I used following function, and it was called on onChange() of an input field:
const changeNoOfPersonsForRoom = (e, index) => {
        let newNoOfPersonsForRoom = e.target.value;
        setNoOfPersonsForRoom([
            ...noOfPersonsForRoom.slice(0, index),
            e.target.value,
            ...noOfPersonsForRoom.slice(index + 1),
        ]);



Answer:
Could you add how you update your state(s)?
But in general, states are not bound or connected to each other.
If you change one state, it won't update any other state.
const [rooms, setRooms] = useState([
    {
        roomNo: 1,
        noOfPersons: noOfPersonsForRoom[0], 
        ageOfPerson1: ageOfPerson1ForRoom[0],
        ageOfPerson2: ageOfPerson2ForRoom[0]
    },

Given your example, you just set the initial state of rooms with the values of your previous states. Nothing more. If you need to update several states, you have to update each of them separately.
Question: Spring Boot Wrong date returned

I have an entity Person
@Entity
@Data
public class Person {

  @Temporal(TemporalType.DATE)
  private Calendar dob;
}

And some dao classes
@Data
public class PersonResponse {

  @JsonFormat(pattern = "yyyy-MM-dd")
  private Calendar dob;
}

@Data
public class PersonRequest{
  @DateTimeFormat(pattern = "yyyy-MM-dd")
  private Calendar dob;
}

When storing values it works perfectly. Example if I send "2000-01-01" it's stored as is in the database "2000-01-01". But When I try to return it I get "1999-12-31".
Now it's clear that is a Timezone Problem but I don't know how to fix it.
My explanation for the cause
The user timezone is GMT+1 so it is some how retrieved as "2000-01-01T00:00:00.000 +01:00", then parsed to UTC "1999-12-31T23:00:00.000 +00:00" to finally be returned as "1999-12-31".
But why? And how can I prevent this knowing that users timezones can change (so adding the time offset manually of 1 hour won't work).
I tried also changing type from Calendar to java.util.Date and java.sql.Date... but no result.
Similar questions where asked before like this one but I still couldn't understand how to fix it


Answer:
If Applicable try to switch from class Calendar to LocalDate. LocalDate does not take time zone into consideration. This should resolve your issue (and simplify your code). Also, for formatting the LocalDate with Json see the answer to this question: Spring Data JPA - ZonedDateTime format for json serialization
Question: Python: Fix missing import with a monkey patch

I am trying to monkey patch a missing import. The old_invoke() still does not get the import.
In case it is relevant, MyClass is a gdb.Command.
(gdb) pi
>>> import mymodule
>>> old_invoke = mymodule.MyClass.invoke
>>> def new_invoke(self, *k, **kw):
...   print("New invoke")
...   import getopt
...   old_invoke(self, *k, **kw)
...
>>> mymodule.MyClass.invoke = new_invoke
>>>
(gdb) my_gdb_command
New invoke
Python Exception <class 'NameError'> name 'getopt' is not defined:
Error occurred in Python: name 'getopt' is not defined

Also, in case it is relevant, the initial files and sourcing looks something like this:
mymodule.py:
import gdb
class MyClass(gdb.Command):
   ...

   def invoke(self, arg, from_tty):
      options, remainder = getopt.getopt(args, 'p:s:t:o:')
      ...

MyClass()

myothermodule.py:
import mymodule
...

Sourcing the above
(gdb) source myothermodule.py



Answer:
old_invoke is trying to reference mymodule's getopt, which doesn't exist. You need:
>>> import mymodule
>>> old_invoke = mymodule.MyClass.invoke
>>> def new_invoke(self, *k, **kw):
...   print("New invoke")
...   import getopt
...   
...   # here
...   mymodule.getopt = getopt
...   
...   old_invoke(self, *k, **kw)
...
>>> mymodule.MyClass.invoke = new_invoke

But, realistically, you should just have an import getopt in mymodule:
# mymodule.py
import getopt
...

Then your function is simply:
>>> import mymodule
>>> old_invoke = mymodule.MyClass.invoke
>>> def new_invoke(self, *k, **kw):
...   print("New invoke")
...   old_invoke(self, *k, **kw)
...
>>> mymodule.MyClass.invoke = new_invoke

Addendum
As another note, using import in a function isn't generally recommended. Unless you are only calling this function once (and even then, why?), every time you call the function you are attempting to load a module, which at best will always do a check against sys.modules when you probably don't have to.
Have the import getopt at the top of the script:
import getopt
import mymodule

mymodule.getopt = getopt

Which is where you'd probably expect this to be anyways
Question: Adding a volume in dockerfile

I am trying to create an image of Windows with additional things. My question is whether it is possible to include a specific volume when creating the container. For example, I would like to do:
docker run --name container -v shared:c:\shared -it mcr.microsoft.com/windows/servercore:20H2-amd64 powershell
There I am accessing the shared volume, but I want to do this in the dockerfile as a command.
I want something like this after running the container:

Thank you for the help
I tried to use the VOLUME command but I don't know if I am doing it right or it's not for what I am trying.


Answer:
Using VOLUME in dockerfile does not mount the volume during build, this only specifies a target where a directory can be mounted during container runtime (anonymous volume).
Because image build and container run can happen on different machines, so having VOLUME source defined in dockerfile (buid time) does not make sense.
Question: How to change cursor size in PyQt5?

I want to implement brush cursor like in most image editors when cursor is a circle that change its size according to brush size. I've read the docs and found only setShape method, but no setSize. Is it possible in Qt to change cursor size?


Answer:
pixmap = QPixmap("image.png")  # Replace with the path to your custom cursor image, brush in your case
pixmap = pixmap.scaled(30, 30)  # Set the desired size
cursor = QCursor(pixmap)
self.setCursor(cursor)

you can change the size and the "form" of your cursor in PyQt5 by creating a pixmap and then assigning in to your cursor
Question: Give same width to items vertically positioned

I have two items positioned vertically, and I'd like the narrower one is as wide as the wider one.
My code looks like
<div class="flex flex-col items-end">
  <div>This should take all the space</div>
  <div class="flex flex-row gap-x-4">
    <div> this is the first element</div>
    <div> this is the second element</div>
  </div>
</div>

and produce

However, I would like the result to be

items-end is needed because the items are displayed on the right side of the page.
I have tried to mess with positioning, but I cannot achieve the final result I'm looking for.
Can anyone give me a hand on this?


Answer:
You could shrink-wrap the container and then right align it:


<script src="https://cdn.tailwindcss.com"></script>

<div class="flex flex-col w-max ml-auto">
  <div>This should take all the space</div>
  <div class="flex flex-row gap-x-4">
    <div> this is the first element</div>
    <div> this is the second element</div>
  </div>
</div>



You could also use a grid layout with one grid column track sized to max-content and then align the grid column track to the right:


<script src="https://cdn.tailwindcss.com"></script>

<div class="grid grid-cols-[max-content] justify-end">
  <div>This should take all the space</div>
  <div class="flex flex-row gap-x-4">
    <div> this is the first element</div>
    <div> this is the second element</div>
  </div>
</div>
Question: Is there a better way to publish messages using Pusher Channels' batch event?

I'm trying to send messages to my users from my server using Pusher Channels. My api receives a list of users and the message needs to be sent to all the users in the list. I can't group these users into a single channel and an individual channel has to be used for each user. This makes my api slow as the list of users can have a size of anything between 1 and 10000 (possibly more in the future), and pusher batch events can only accept a Event list of size 10.

I'm using .net 6 for my api

I've tried using batch events to try and improve performance; my code looks something like this,
var events = new List<Event>();
// count can be anything between 1 and 10000
for (int i = 1; i <= count; i++)
{
    // creating a sample list of events
    events.Add(new Event
    {
        Channel = string.Format("batch-channel-{0}", i),
        EventName = "batch-event",
        Data = new
        {
            Channel = string.Format("batch-channel-{0}", i),
            Event = "batch-event",
            Message = string.Format("{0} - sample message", i)
        {
    });
}
var result = new List<HttpStatusCode>();
int chunkSize = 10;
int totalChunks = (int)Math.Ceiling((double)events.Length / chunkSize);
for (int i = 0; i < totalChunks; i++)
{
    var eventsChunk = events.Skip(i * chunkSize).Take(chunkSize).ToArray();
    // publishing event lists of size 10
    var chunkResult = await pusher.TriggerAsync(eventsChunk);
    result.Add(chunkResult.StatusCode);
}

I tested this code with a Event list of size 10000 and it takes around 6 minutes to complete execution. I want to know if there is anything I'm missing and if I can somehow improve performance.
Any help is appreciated. Thank you.


Answer:
If you are sending the same event to multiple channels then you can use the standard trigger endpoint but specify a list of the channels that you are broadcasting to. For example:
using PusherServer;

var options = new PusherOptions();
options.Cluster = "APP_CLUSTER";
var pusher = new Pusher("APP_ID", "APP_KEY", "APP_SECRET", options);

ITriggerResult result = await pusher.TriggerAsync(
  new string[]{"my-channel-1", "my-channel-2", "my-channel-3"},
  "my-event",
  new { message: "hello world" });

This would trigger the event to the three specified channels. You can specify up to 100 channels in a single publish.
If you are sending a different event to each channel then the batch event endpoint you have mentioned would be the way forward. In this case you might look at multi-threading to or similar to be able to handle multiple batch triggers at the same time, rather than sequentially.
Source - https://pusher.com/docs/channels/server_api/http-api/#example-publish-an-event-on-multiple-channels