satoshi-2000/llms-suitable huggingface dataset:
Question: Same height of columns for bootstrap

It's probably simple, but I could not figure out how to fix it.
I use Bootstrap5.
The full code is here :
https://www.codeply.com/p/BywuhLNUXy
Seems codeply has some problems...
So I put it also on jsfiddle
https://jsfiddle.net/paul_z/y7a6dnkf/1/
Mainly it's contact directory page.
The code structure is
<div class="container">
<div class="row gy-5">

    <div class="col-lg-6">
        <div class="card m-b-30">
            <div class="card-body py-5">
                <div class="row">
                    <div class="col-lg-4 text-center">            
                    <img src="/static/logo.png" alt="logo" >            
                    </div>
                <div class="col-lg-8">
                    <h5 class="card-text mb-0"><i class="fa-solid fa-person"></i> user 1</h5>
                    <p class="card-text">CDD IT Informatique</p>
                    <hr class="dropdown-divider">                
                    <p class="card-text"><i class="fa-sharp fa-solid fa-building"></i> ###</p>        
                    <p class="card-text"><i class="fa-solid fa-envelope"></i> mail</p>        
                    <p class="card-text"><i class="fa-solid fa-phone"></i> phone</p>
               </div>
                </div>
              </div>
        </div>
    </div>
    
    ...

On large screens it's shown two cards by column.
The problem is that cards sometimes different height.
For example for user 2 his role change : "Enseignant Chercheur Astrophysique Hautes Energies" instead "CDD IT Informatique" so this line take two lines instead of one line. And so the card for user 2 has height different to others cards.
How could I fix it ?
I don't know the cards size, so I could not fix it implicitly (and in any case it's probably not a good idea).
P.S.: I have also the same problem if logos have different sizes. Despite playing with img-fluid, widht, max-widht, max-height etc some logos change the height of card. But I think at first I have to fix the simple height problem.


Answer:
The col elements already have the same height - Bootstrap v5's grid implementation based on flexbox already sees to that.
All you need to do is make the cards take 100% height of their parent:
.card { height: 100%; }
Question: Why does my Python function return 'None' instead of ('Paul', 29, 1.75)?

I am following a tutorial
when he runs the code it gives  ("Paul', 29, 1.75) but when I run it it gives me None
I tried
# -----Part 2------
# name,age,height
persons = [
    ("Alice", 25, 1.6),
    ("Brian", 35, 1.8),
    ("Paul", 29, 1.75),
    ("Martin", 32, 1.7)
]

def get_infos(name, l):
    for i in l:
        if i[0] == name:
            return i
        return None
    
infos = get_infos("Paul", persons)
print(infos)

and got:
None
but when he runed it he got:
('Paul', 29, 1.75)


Answer:
It's an identation problem, always in the first iteration will return None, try by identing the return None one less tab, like:

def get_infos(name, l):
    for i in l:
        if i[0] == name:
            return i
    return None
Question: How to group states into regions when there is no region table

My data set has states as a column but no region column to group the states by. I would like to group the states into standard census bureau regions to get the count of employee IDs by region:

Select COUNT(DISTINCT Empl_ID) AS Employee_Count,
STATE
FROM Employee_Table
GROUP BY STATE

I tried exporting the query and then sorting in Excel but the dataset is too large for Excel.


Answer:
Create a table based on the data provided in the image:
create table region_state (region varchar(30), state varchar(30));
insert into region_state values
('Northen Region', 'New Jersey'),
('Northen Region', 'New York'),
('Midwest Region', 'Illinois')
...;

Now we can use a join query to get the region for each employee state as the following:
Select COUNT(DISTINCT E.Empl_ID) AS Employee_Count,
       R.region
FROM Employee_Table E JOIN region_state R
ON E.state = R.state
GROUP BY R.region

If there are no duplicates in the Empl_ID column (and that is the typical case, i.e. Empl_ID is the primary key of the table) you would use COUNT(E.Empl_ID), with no need for DISTINCT.
Question: how program to join 2 different tables based on which one has the highest number of rows, with tidyverse?

How program to join 2 different tables based on which one has the highest number of rows, with tidyverse? Now, the total_number_views_ndinstict has only 8 but in the future this may have more rows than the second total_number_views_unique_na which currently has 10 rows. I need both columns in the joined table.
Here is the first table:
> total_number_views_ndinstict
    # A tibble: 8 × 2
      app_name                    n_distinct_users
      <chr>                                  <int>
    1 animals_to_groups                          2
    2 cage_randomiser                            5
    3 combo_cor                                  1
    4 crispr_screen_viz                         21
    5 dep_map_bem                                4
    6 growth_rate_explorer                       3
    7 moprospector                               2
    8 translatability_single_gene               17

And the second table is
> total_number_views_unique_na
# A tibble: 10 × 2
   app_name                    users_na
   <chr>                          <int>
 1 animals_to_groups                 21
 2 cage_randomiser                   14
 3 combo_cor                         14
 4 crispr_screen_viz                  1
 5 dep_map_bem                        0
 6 dtp_browser_prod                   6
 7 flat                              81
 8 growth_rate_explorer              48
 9 moprospector                       0
10 translatability_single_gene        2

Can someone help?


Answer:
A full join will keep theh values of both tables
library(dplyr)
full_join(total_number_views_ndinstict, total_number_views_unique_na)
Question: How can I get the primary key of a selected option from a dataframe-based selectInput in Shiny?

I am displaying a selectInput in my shiny app and it is getting its choices from a dataframe (which is coming from a table in the database).
this table (dataframe) has primary key and title in it. I want to show my users the title, but when they choose an option, I want to get the Id of the selected option to use in my code.
I managed to get the selected "value" but I couldn't find how to get the "id" from the selected option.
below is a simple example of how my code is looking with test objects:


library(DT)
library(tidyverse)
library(shiny)




test_id <- c(1, 2, 3)
test_title <- c("a", "b", "c")

test_df <- data.frame(test_id, test_title)
test_df <- column_to_rownames(test_df, var = "test_id")


ui <- fluidPage(
  selectInput("test", "test", choices = test_df),
  
  textOutput("selectedItem")
  
)

server <- function(input, output, session) {
  
  observeEvent(input$test, {
    output$selectedItem <- renderText(input$test)
  })
  
  
    
}

shinyApp(ui, server)


does anyone have a solution to get the "id" of the selected option?
I have tried this
output$selectedItem <- renderText(input$test)

but it is returning the value and not the Id


Answer:
You could pass a named vector or list to the choices argument.
From the docs (?selectInput):

If elements of the list are named, then that name — rather than the value — is displayed to the user.

library(tidyverse)
library(shiny)

test_id <- c(1, 2, 3)
test_title <- c("a", "b", "c")

test_df <- data.frame(test_id, test_title)
choices <- setNames(test_df$test_id, test_df$test_title)

ui <- fluidPage(
  selectInput("test", "test", choices = choices),
  textOutput("selectedItem")
)

server <- function(input, output, session) {
  observeEvent(input$test, {
    output$selectedItem <- renderText(input$test)
  })
}

shinyApp(ui, server)
#> 
#> Listening on http://127.0.0.1:5936
Question: I'm getting an error: Effect callbacks are synchronous to prevent race conditions. I'm having trouble formatting it in the way it wants

I'm getting this error back though this same format seems to work in examples.
    const response = await axios.get('http://localhost:5000/get-tasks')

    const dataObject = response.data
    

    const arrayOfKeys = Object.keys(dataObject)
    const arrayOfData = Object.keys(dataObject).map((key) => dataObject[key])

    console.log(arrayOfKeys)
    console.log(arrayOfData)
  }, [])```



Answer:
The useEffect function arg can't be asynchronous, but you can call an async function inside it.
useEffect(() => {
  async function getTasks() {
    const response = await axios.get('http://localhost:5000/get-tasks')

    const dataObject = response.data

    const arrayOfKeys = Object.keys(dataObject)
    const arrayOfData = Object.keys(dataObject).map((key) => dataObject[key])

    console.log(arrayOfKeys)
    console.log(arrayOfData)
  };

  getTasks();
}, []);
Question: Change this SPARQL query

I have a query "change the number of publications on artificial intelligence over time." Can you help me change this query not only about artificial intelligence, but also about subclasses of artificial intelligence?
SELECT ?year (COUNT(DISTINCT ?item) AS ?count)
WHERE {
  ?item wdt:P31 wd:Q13442814 ;
        wdt:P921 wd:Q11660 ;
        wdt:P577 ?date .
  BIND(YEAR(?date) AS ?year)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
 GROUP BY ?year
 ORDER BY ?year



Answer:
You have just to replace wdt:P921 with wdt:P921/wdt:P279* (see here for the new query).
wdt:P921/wdt:P279* is called property path. Such expressions are used for concatenating more properties in a single path which must comply with a certain structure. In this case, we are saying that the object of wdt:P921 can be the subject of wdt:P279 (* stands for "zero or more times") and the final object of such optional (chain of) wdt:P279 must be wd:Q11660.
Check out SPARQL 1.1 Query Language § 9 Property Paths for deepening this topic.
Question: Group table by month

data = pd.read_csv("MLs_Unit_per_day.csv",index_col='Date')



            X1      X2  X3  X4  X5      X6
Date                        
01/01/2023  13  0   20  5   24  14
02/01/2023  13  0   20  5   24  15
03/01/2023  11  0   20  6   24  15
04/01/2023  12  0   20  6   22  16
05/01/2023  11  0   20  6   22  16
... ... ... ... ... ... ...
29/05/2023  13  1   23  6   22  17
30/05/2023  13  1   23  6   22  18
31/05/2023  13  1   23  7   23  18
01/06/2023  12  1   23  7   24  19
02/06/2023  13  0   23  8   24  19

I'm trying to group by month ans Sum X1, X2, etc for the hole month. how can I do?
thank you
I tried before without making Date as index with this
data.groupby(data['Date'].dt.strftime('%B'))['RO1'].sum().sort_values()

but it show me wrong time format and then wrong months


Answer:
You need to convert the date to datetime, then create a new column for month and finally use groupby
data = pd.read_csv("MLs_Unit_per_day.csv")
data['Date'] = pd.to_datetime(data['Date'], format='%d/%m/%Y')

# Create a separate column for year and month
data['YearMonth'] = data['Date'].dt.to_period('M')

monthly_data = data.groupby('YearMonth').sum()

print(monthly_data)
Question: R data.table lost rows after order

I have a data.table
> dput(data.summary)
structure(list(summary_type = c("0", "1", "2"), count = structure(list(
    62234441L, 5119L, 821770L), .internal.selfref = <pointer: 0x557538f028c0>)), row.names = c(NA, 
-3L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x557538f028c0>)

data.summary
   summary_type    count
1:            0 62234441
2:            1     5119
3:            2   821770

Its a data.table with 3 row, I want to sort it by count
data.summary[order(count)]

But after this, there are only have 1 row in data.table
data.summary[order(count)]
   summary_type    count
1:            0 62234441



Answer:
For some reason, your count column is a list.
library(data.table)
df <- structure(list(summary_type = c("0", "1", "2"), count = structure(list(
  62234441L, 5119L, 821770L))), row.names = c(NA, -3L), class = c("data.table", "data.frame"))

df[count]
#Error in `[.data.table`(df, count, ) : 
#  count is not found in calling scope but it is a column of type list.  

Use unlist:
df[order(unlist(count))]

#    summary_type    count
# 1:            1     5119
# 2:            2   821770
# 3:            0 62234441
Question: Invalid Syntax on community.mysql.mysql_user with Ansible AWX

I am trying to run a playbook through AWX where I want to create a mariadb user with permissions. The playbook works nicely when run from ansible on my local machine. However, when I try to run the job on AWX, I get the following error :

"module_stdout": "Traceback (most recent call last):\r\n  File "/home/ansible/.ansible/tmp/ansible-tmp-1685691063.0199862-220-69171919718447/AnsiballZ_mysql_user.py", line 107, in \r\n    _ansiballz_main()\r\n  File "/home/ansible/.ansible/tmp/ansible-tmp-1685691063.0199862-220-69171919718447/AnsiballZ_mysql_user.py", line 99, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File "/home/ansible/.ansible/tmp/ansible-tmp-1685691063.0199862-220-69171919718447/AnsiballZ_mysql_user.py", line 48, in invoke_module\r\n    run_name='main', alter_sys=True)\r\n  File "/usr/lib/python3.5/runpy.py", line 205, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File "/usr/lib/python3.5/runpy.py", line 96, in _run_module_code\r\n    mod_name, mod_spec, pkg_name, script_name)\r\n  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code\r\n    exec(code, run_globals)\r\n  File "/tmp/ansible_community.mysql.mysql_user_payload_r3e02o87/ansible_community.mysql.mysql_user_payload.zip/ansible_collections/community/mysql/plugins/modules/mysql_user.py", line 352, in \r\n  File "", line 969, in _find_and_load\r\n  File "", line 958, in _find_and_load_unlocked\r\n  File "", line 664, in _load_unlocked\r\n  File "", line 634, in _load_backward_compatible\r\n  File "/tmp/ansible_community.mysql.mysql_user_payload_r3e02o87/ansible_community.mysql.mysql_user_payload.zip/ansible_collections/community/mysql/plugins/module_utils/mysql.py", line 22, in \r\n  File "/usr/local/lib/python3.5/dist-packages/pymysql/init.py", line 59, in \r\n    from . import connections  # noqa: E402\r\n  File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 206\r\n    ):\r\n    ^\r\nSyntaxError: invalid syntax\r\n"

Here's the task for creating the user :
- name : Create mariadb user
  community.mysql.mysql_user:
    login_user: root
    login_password: "{{ root_password }}"
    name: user
    password: "{{ mariadb_user_pw }}"
    priv: "*.*:PROCESS,SELECT,CREATE,CREATE TABLESPACE,INSERT"
    state: present



Answer:
Ensure the hosts have the correct package installed.
Include this in your playbook:
- name: ensure mysql package for the mysql api is installed
  pip:
    name: pymysql
    executable: pip3

--
you should check your awx container.
either by logging in to the container itself, and check stuff manually, or you can do this w ansible as well.
- shell: locate ansible-galaxy
  delegate_to: localhost
  register: check_galaxy

- debug:
    msg: "{{ check_galaxy.stdout }}"
  delegate_to: localhost

Then, once you have the output, simply check the installed roles and it versions
- shell: ansible-galaxy collection list
  delegate_to: localhost
  register: check_collection

- debug:
    msg: "{{ check_collection }}"
  delegate_to: localhost
Question: The difference between UserDetailsService and the class that implements it

Does it make sense to create your own class that implements the UserDetailsService interface? In many examples, I see how the UserDetailsService is embedded in the security configuration class, and not the class that implements it. What's the difference?
And why, when I enter the wrong username and password, I don't get the error message that I registered in PersonDetailsService? "Bad credentials" is coming out. I'm a beginner and just started learning spring security
@Configuration
@EnableWebSecurity
public class SecurityConfig {
    private final PersonDetailsService personDetailsService;

    @Autowired
    public SecurityConfig(PersonDetailsService personDetailsService) {
        this.personDetailsService = personDetailsService;
    }

    @Autowired
    void configure(AuthenticationManagerBuilder builder) throws Exception {
        builder.userDetailsService(personDetailsService);
    }

    @Bean
    public PasswordEncoder getPasswordEncoder() {
        return NoOpPasswordEncoder.getInstance();
    }

}


@Service
public class PersonDetailsService implements UserDetailsService {
    private final PeopleRepository peopleRepository;

    @Autowired
    public PersonDetailsService(PeopleRepository peopleRepository) {
        this.peopleRepository = peopleRepository;
    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Optional<Person> person = peopleRepository.findByUsername(username);

        if (person.isEmpty())
            throw new UsernameNotFoundException("User not found");

        return new PersonDetails(person.get());
    }
}




Answer:
For your first question you spring security can authenticate multiple ways such as in memory and DB . in UserdetailsService and loadUserByUsername method you can customize how to authenticate users . and if you want DB mode you have multiple tables is DB and you can tell spring for finding username and password which table and columns must be check . for your second question put break point on your if statement and check what is person found . I think if it doesn't return username you have to use this if :
if(person.get()==null)
   throw new UsernameNotFoundException("User not found");
Question: User Document ID is the same as User ID in Firestore

I try to store users inside collection in Firestore as documents and want to make every User ID is same as Document ID..
I tried but it still gives me another ID for the user:
Future<void> userSetupDone() async {
CollectionReference users = FirebaseFirestore.instance.collection('Users');

final docUser = FirebaseFirestore.instance.collection('Users').doc();

FirebaseAuth auth = FirebaseAuth.instance;
String? uid = docUser.id;
// String? uid = auth.currentUser?.uid.toString();
String? email = auth.currentUser?.email.toString();
String? phone = auth.currentUser?.phoneNumber.toString();
String? displayName = auth.currentUser?.displayName.toString();

users.add({'Uid': uid, "Email": email, "Phone": phone, "Name": displayName});
return;
}




Answer:
You have to update uid immediately after adding data to the database. Because you can not get id before adding that data from the Firestore Database.
You will get it by following code:
 Future<void> userSetupDone() async {
    CollectionReference users = FirebaseFirestore.instance.collection('Users');
    
    final docUser = FirebaseFirestore.instance.collection('Users').doc();
    
    FirebaseAuth auth = FirebaseAuth.instance;

    String? email = auth.currentUser?.email.toString();
    String? phone = auth.currentUser?.phoneNumber.toString();
    String? displayName = auth.currentUser?.displayName.toString();
    
    DocumentReference reference= await users.add({'Uid': '', "Email": email, "Phone": phone, "Name": displayName});
    await reference.update({"Uid": reference.id});
    return;
}
Question: Is there a way to maintain C++ array formatting when using VScode's default formatter upon saving?

When using the default VScode formatter for c++. I want to keep format on save but I don't want the array to be changed this drastically.
It changes an array from this
    const int level[] =
    {
        0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
        0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0,
        1, 1, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3,
        0, 1, 0, 0, 2, 0, 3, 3, 3, 0, 1, 1, 1, 0, 0, 0,
        0, 1, 1, 0, 3, 3, 3, 0, 0, 0, 1, 1, 1, 2, 0, 0,
        0, 0, 1, 0, 3, 0, 2, 2, 0, 0, 1, 1, 1, 1, 2, 0,
        2, 0, 1, 0, 3, 0, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1,
        0, 0, 1, 0, 3, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1,
    };


to this
    const int level[] = {
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        1,
        0,
        1,
        1,
        1,
        1,
        1,
        1,
        ...

    };

I want to keep format on save but I don't want the array to be changed this drastically.


Answer:
Not sure if you are trying to keep using the default formatting engine for some reason, I can't find an option to change this behavior using the default, but this behavior is not present when setting the option  C_Cpp:Formatting (Extensions > C/C++ > Formatting > C_Cpp: Formatting) to vcFormat. If you just want format on save to not elongate your arrays Id use that engine option.
Question: Repeat a formula in google sheet within a single cell using different values

So to summarize what i want:
Let's say i have
   A         B
1 "Tommy"    "1,2,3"
2 "Berry"    "3,4,5"
3 "Hank"     "1,4,5"
4
5
6 "1"        
7 "5"

I would like B6 to show "Tommy Hank" and B7 to show "Berry Hank"
If have managed to create this formula;
=IF(ISERROR(MATCH($A6,SPLIT(B1, "," , 1,1),0)),"",A1)

This formula will give me back the value "Tommy" but not Hank.
I want to list all corresponding A values for every B cell that contains the value "1".
I tried some things with arrayformula like =IF(ISERROR(MATCH($A6,SPLIT(B1:B3, "," , 1,1),0)),"",A1:A3) but i don't really understand what i'm doing here.


Answer:
I was going to suggest
=ArrayFormula(
   textjoin(" ",,
     query(
       {A$1:A$3,","&B$1:B$3&","},
       "select Col1 
        where Col2 contains'"&","&A6&","&"'"
     )
   )
 )