satoshi-2000/llms-suitable huggingface dataset:
Question: vue styling in view does not apply to html

I have set up a new project with vue3. I started working with some package implementations but then I realized my CSS written in component is not applied in HTML. Here is a very simple view example
<template>
  <div>
    <p class="asd">Hello</p>
  </div>
</template>

<style>
.asd {
  color: purple;
}
</style>

In the result, the text is not purple.
I have checked if it is overridden by some other css but no, it does not event show up in the styles screen of dev tools:

What I have tried and checked:

I have tried writing style as "p.asd {..." and adding an !important in the end. No change.
I have checked if I am working on the correct page by changing the text from "Hello" to "Hello World" and it changes, so I am working on the correct page.
I got a production build if it is a dev env issue, but no, got the same result from the built html.
I have tried moving CSS to App.vue instead, and surprisingly styling written there works but not in the views.
I have tried on a new browser for caching issues, no change.
I have tried adding scoped, no change.
I have tried adding script tags, no change. Script tags work fine, console.log script works, but still no styling update.
I have tried inline CSS and it works.

Here is my package.json:
  "name": "new-project",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview",
    "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore",
    "format": "prettier --write src/"
  },
  "dependencies": {
    "express": "^4.18.2",
    "firebase": "^9.22.1",
    "pinia": "^2.0.36",
    "vue": "^3.3.2",
    "vue-router": "^4.2.0",
    "vue-tel-input": "^8.1.1"
  },
  "devDependencies": {
    "@rushstack/eslint-patch": "^1.2.0",
    "@vitejs/plugin-vue": "^4.2.3",
    "@vue/eslint-config-prettier": "^7.1.0",
    "eslint": "^8.39.0",
    "eslint-plugin-vue": "^9.11.0",
    "prettier": "^2.8.8",
    "vite": "^4.3.5",
    "vite-plugin-webfont-dl": "^3.7.4"
  }
}

codesandbox example: https://codesandbox.io/p/sandbox/github/ihsanser/vue-vite-style-bug/tree/master
I don't know if I am missing something very simple, but I could not figure out the reason for hours now.


Answer:
The space character used in .asd { is not an actual space. It is a NBSP 1.
Replace it with an actual space and everything will work as expected. This is not related to Vue, the behavior would be the same in React, Angular, Svelte or vanilla.
See it working.
As a side-note, this shows how important a runnable mcve is. In your question, you posted the code with a space. Not sure if this is due to the NBSP > Space conversion made by the browser when rendering the current page's HTML or if you simply didn't copy/paste the code in question.
I suspect it's the first.

1 - encoding NBSP outputs %C2%A0, whereas encoding a normal space outputs %20
Question: How to control what classes can extend my class in Java

So I was asked this question in interview that if I have a class A how do I restrict which classes will be able to extend A. For example if I want only class C and E to be able to extend A and classes B and D should not be able to do so. I mentioned about bounded wildcards in generics but I think that didn't answer the question. I am not aware about any new feature added in newer versions of Java. Please let me know what is the correct answer to that.


Answer:
Sealed classes seems to be one method to restrict which classes can extend another. This feature is available since Java 17.
Contraints:

All permitted subclasses must belong to the same module as the sealed class.
Every permitted subclass must explicitly extend the sealed class.
Every permitted subclass must define a modifier: final, sealed, or non-sealed.

Example:
public abstract sealed class Vehicle permits Car, Truck {...}

This restricts that only classes Car or Truck can extend Vehicle.
Question: PostgreSQL - Aggregate attributes from different columns recursively





id_start
id_end




1
2


2
3


3
4




I want to collect elements who are "connected" like [1, 2, 3, 4]. (in an array for example)
I tried a recursive query like:
WITH RECURSIVE q_rec AS (
    SELECT id_start,
           id_end
    FROM my_table
    UNION
    SELECT t.id_start
           t.id_end
    FROM       my_table t
    INNER JOIN q_rec r ON r.id_start = t.id_end
) 
SELECT *
FROM q_rec;

But how can I aggregate them in an array despite they are not in the same column ?


Answer:
Another approach gathers all ids in the recursive query, as a table. Then applies aggregation.
WITH RECURSIVE cte AS (
  SELECT id_start AS first_id, 
         id_start AS id
  FROM tab t1
  WHERE NOT EXISTS(SELECT 1 FROM tab t2 WHERE t1.id_start = t2.id_end)

  UNION ALL

  SELECT cte.first_id,
         tab.id_end
  FROM       cte
  INNER JOIN tab
          ON cte.id = tab.id_start
)
SELECT first_id, 
       ARRAY_AGG(id) AS ids
FROM cte
GROUP BY first_id

Output:




first_id
ids




1
[1,2,3,4]




Check the demo here.
Question: Does overloading the new operator in C++ redefine the operator?

When overloading the new operator in a global scope in C++, are we just redefining the original functionality? From what I understand operator and function overloading works when the overloads have different signatures, however when overloading new operator using
void* operator new(size_t n){
    return malloc(n);
}

we change the underlying functionality itself and whenever we call new this new overload is called? Does this not violate the idea of overloads having different and unique signatures?
I tried overloading the new array operator with extra parameters and how that works is consistent with my current understanding of operator/function overloads. However overloading the new operator and new array operator with just one parameter is where I'm confused.


Answer:
operator new is replacable (from cppreference, same link):

The versions (1-4) are implicitly declared in each translation unit even if the  header is not included. Versions (1-8) are replaceable: a user-provided non-member function with the same signature defined anywhere in the program, in any source file, replaces the default version. Its declaration does not need to be visible.

This is not the usual function overloading. You cannot overload a function with same signature. Overloads must be distinguishable by their arguments. Nevertheless, colloquially one often talks about "overloading the new operator" which is ok in the wider sense of "overloading", but in strict c++ terminology not right.
Question: Oracle partition / archive strategy for type 2 dimension table

I have a really wide table in Oracle that's at type 2 dimension.
Records have from_dates and to_dates with the latest 'current' records having a high end date of 31st Dec 9999.  There are currently two partitions on the table, one for the 'current' records and one for 'history' records.
There's a new requirement to only keep the last 12 months of records in the 'history' partition. I interpret this as keeping records that were valid in the last 12 months i.e. where the record's to_date < (this month- 11 months).
Normally if I wanted to get rid of records I'd just drop a partition, but in this case that wouldn't work as I need to retain some of the records in the existing 'history' partition.
Is there any partitioning strategy that could support this or am I barking up the wrong tree?


Answer:
You aren't accomplishing much with merely two partitions, "current" and "history". You need to repartition this by month. Then you can implement a rolling partition drop of partitions older than 12 months, which will require a bit of scripting.
Normally we use interval partitioning INTERVAL(NUMTOYMINTERVAL(1,'MONTH')) so we don't have to maintain partition adds manually or through scripting. However, unfortunately in your case you won't be able to because of your use of the special date 12/31/9999. This is the maximum date allowable in Oracle. Interval partitioning will internally add the interval to date values when determining whether a new partition is needed or not, and that will overflow the maximum date value allowed and raise an error. The use of this special date essentially disables the use of interval partitioning.
You have no choice but to either change your special "eternity" date to something less than one interval away from 12/31/9999 (anything less than 12/01/9999 would permit monthly interval partitioning, or anything less than 12/31/9998 would permit yearly interval partitioning). Or, as usually happens because code would have to be changed to accommodate these solutions, you have to manually build out partitions ahead of time or create a scheduled script that does it for you.
Question: The UI theme state is not updating until I resave the code while using flutter_riverpod stateprovider

I need to change the Theme using stateprovider of flutter riverpod ,I dont understand what i did wrong here
void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const ProviderScope(child: MyApp()));
}

class MyApp extends ConsumerWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final isDarkTheme = ref.watch(isDarkThemeProvider.notifier).state;

    return GestureDetector(
      onTap: () {
        FocusScope.of(context).unfocus();
      },
      child: ScreenUtilInit(
        designSize: const Size(360, 690),
        minTextAdapt: true,
        splitScreenMode: true,
        builder: (context, child) {
          return MaterialApp(
              builder: FToastBuilder(),
              debugShowCheckedModeBanner: false,
              title: 'code',
              theme: isDarkTheme ? Themes().darkTheme : Themes().lightTheme,
              onGenerateRoute: onAppGenerateRoute(),
              routes: appRoutes(),
              initialRoute: SplashPage.route);
        },
      ),
    );
  }
}

this is my theme  class and theme stateprovider
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:tr_qr_code/utils/colors.dart';

class Themes {
  final ThemeData lightTheme = ThemeData(
    scaffoldBackgroundColor: colorWhite,
    splashColor: Colors.transparent,
    highlightColor: Colors.transparent,
    appBarTheme: const AppBarTheme(color: colorWhite),
    fontFamily: 'OpenSans',
    useMaterial3: true,
  );

  final ThemeData darkTheme = ThemeData(
    scaffoldBackgroundColor: colorBlack,
    splashColor: Colors.transparent,
    highlightColor: Colors.transparent,
    appBarTheme: const AppBarTheme(color: colorBlack),
    fontFamily: 'OpenSans',
    useMaterial3: true,
  );
}

final isDarkThemeProvider = StateProvider<bool>((ref) => false);

on the toggle switch inside the onTap the below code is used to update the state
onTap: () {
    
              ref.read(isDarkThemeProvider.notifier).update(
                  (state) => !ref.read(isDarkThemeProvider.notifier).state);
            },

i tried flutter clean, flutter pub upgrade etc ..


Answer:
Inside of MyApp class it should be
final isDarkTheme = ref.watch(isDarkThemeProvider);
And alternatively, inside your onTap you can toggle value like this:
onTap: () {
                ref
                    .read(isDarkThemeProvider.notifier)
                    .update((state) => !state);
          },
Question: Why does initializing a negatively-sized array cause an overflow exception?

I was unit testing in C#, and I found the following code gives an overflow exception:
using System;
                    
public class Program
{
    public static void Main()
    {
        int i = 0;
        Console.WriteLine(new float[i - 1]);
        // System.OverflowException: Arithmetic operation resulted in an overflow.
    }
}

https://dotnetfiddle.net/clbgZ3
However, if you explicitly attempt to initialize a negative array, you get the following error:
Console.WriteLine(new float[-1]);
// Compilation error: Cannot create an array with a negative size

Why does initializing a negatively-sized array cause an overflow exception, and not a different type of error?


Answer:
This behaviour is explicitly specified in C# language specification, section 12.8.16.5

The result of evaluating an array creation expression is classified as
a value, namely a reference to the newly allocated array instance. The
run-time processing of an array creation expression consists of the
following steps:
(...)

The computed values for the dimension lengths are validated, as follows: If one or more of the values are less than zero, a
System.OverflowException is thrown and no further steps are executed.


(emphasis mine)
Question: how to use min-height, aspect-ratio, ... with container queries?

I am currently struggling with container queries. As long as I just use min-width and max-width everything is fine and works well. As soon as I try to use logic operators like and/or it doesn´t work anymore.


.wrapper {
  width: 300px;
  container-name: wrapper;
  container-type: inline-size;
}

.box {
  background-color: #0000ff;
  color: #ffffff;
  width: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@container wrapper (min-width: 300px) {
  .box {
    background-color: #00ff00;
  }
}

@container wrapper (min-width: 300px) and (min-height: 0px) {
  .box {
    background-color: #ff0000;
  }
}
<div class="wrapper">
  <div class="box">
    <span>test</span>
  </div>
</div>



See the codepen here: https://codepen.io/Resolver1412/pen/dygxWKY
I would expect that the box would become red instead of green. Since the last container query would overwrite the previous one.
Anyone knows whats wrong or what might have happened? I currently use this chrome version: Version 112.0.5615.121


Answer:
According to the docs:

The inline-size CSS property defines the horizontal or vertical size
of an element's block, depending on its writing mode. It corresponds
to either the width or the height property, depending on the value of
writing-mode.
– inline-size | MDN Web Docs

In your example, since writing-mode has the default value of horizontal-tb, only width is usable in @container queries.
You can switch to container-type: size to use both inline and block size in queries:
.wrapper {
  width: 300px;
  height: 60px;
  container-name: wrapper;
  container-type: size;
}

@container wrapper (width >= 300px) and (height >= 0px) {
  .box {
    background-color: #ff0000;
  }
}

Try it:


.wrapper {
  width: 300px;
  height: 60px;
  container-name: wrapper;
  container-type: size;
}

.box {
  background-color: #0000ff;
  color: #ffffff;
  width: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@container wrapper (width >= 300px) {
  .box {
    background-color: #00ff00;
  }
}

@container wrapper (width >= 300px) and (height >= 0px) {
  .box {
    background-color: #ff0000;
  }
}
<div class="wrapper">
  <div class="box">
    <span>test</span>
  </div>
</div>



Or, you can use aspect-ratio instead of width and height:
@container wrapper (aspect-ratio > 1 / 2) {
  .box {
    background-color: #ff0000;
  }
}

Try it:


.wrapper {
  container-name: wrapper;
  container-type: size;
}

.box {
  background-color: #0000ff;
  color: #ffffff;
  width: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@container wrapper (width >= 300px) {
  .box {
    background-color: #00ff00;
  }
}

@container wrapper (aspect-ratio > 1 / 2) {
  .box {
    background-color: #ff0000;
  }
}
<div class="wrapper">
  <div class="box">
    <span>test</span>
  </div>
</div>
Question: Does it make a difference to pass a pointer to a pointer as an argument or simply pass the first pointer?

I'm sorry if this sounds vague or idiotic, but consider the following:
if I have a main function like so:
int main(void)
{
   int red_wins = 0;
  game_loop(&red_wins); 
  // code 
  printf("red has %d wins\n", red_wins); 
} 

then have a a game_loop function which calls another function that uses red_wins:
void game_loop(int *red_wins)
{
  // code 
  particle_move(red_wins);
}

and then another function called particle_move which uses this red_wins variable:
void particle_move(int *red_wins) 
{
  // code 
  if (such and such)
  {
    *red_wins+= 10; 
  } 
}

where red_wins is only modified in the particle_move function and particle_move is only called from the game_loop function, would it be better to do it as shown above or by passing a pointer to a pointer in the particle_move function? Or, but I've been told it's bad practice, by using a global variable red_wins? Or is there another, better, way that I've overlooked?


Answer:
You only need to pass a pointer to pointer in the following situations:

Where the called function is updating the pointer value, not the thing being pointed to:void update( T **p )
{
  *p = new_TStar_value();
}
int main( void )
{
  T *var;
  update( &var ); // updates var
}

Where the pointer is pointing to the first in a sequence of pointers:void foo( int **p )
{
  // do something interesting
}
int main( void )
{
  int **p = malloc( sizeof *p * ROWS );
  if ( p )
  {
    for ( size_t i = 0; i < ROWS; i++ )
      p[i] = malloc( sizeof *p[i] * COLS )
  }
  foo( p );
  return 0;
}

In your case, particle_move is updating the same thing that game_loop is updating, so you don't need to add another layer of indirection.  You're doing it right, here.
Question: Connect 2 Docker images for label-studio

I'm on Windows, I try to run label-studio on a docker-img and enable automatic annotations with a tesseract machine learning model provided from label-studio-ml-backend on another docker-img. (I'm discovering docker these days...)
Set up:
So far I was able to launch a docker with label-studio, and a docker with tesseract:
# Run the label-studio
docker run --name lbl-studio -it -p 8080:8080 -v label-studio-data:/label-studio/data/ heartexlabs/label-studio:latest label-studio

# DL and run tesseract image
git clone https://github.com/heartexlabs/label-studio-ml-backend
cd label-studio-ml-backend/label_studio_ml/examples/tesseract/
docker-compose up

At this point I have 2 images running on docker (or 3/4, I don't really know how to interpret the 'tesseract' image)

Network:
Here are some network info I could gather, I don't know how bas is the fact that lbl-studio is on 172.17 and the two others on 172.18...

# Get ips of images 
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' server # 172.18.0.3
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' redis  # 172.18.0.2
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' lbl-studio  # 172.17.0.2
# server: 172.18.0.3
# redis: 172.18.0.2
# lbl-studio: 172.17.0.2

so far redis can ping server but can't ping lbl-studio
Problem:
But, when I go to http://127.0.0.1:8080/, create a project, and try to link the machine learning wizard (http://127.0.0.1:8080/projects/1/settings/ml > add model), I'm not able to connect the tesseract server to the lbl-studio.
The urls I tried to connect are:

http://127.0.0.1:9090/
http://172.18.0.3:9090/

Going Further:
I tried to dig deepper and ping the server from lbl-studio, but nothing happened
docker exec -it --user root lbl-studio /bin/bash
apt update
apt install iputils-ping
ping 127.18.0.3  # Nothing happening: 100% packet loss ;)

Question:
How can I connect lbl-studio to the server ?
Thank you for your help :)


Answer:
Add lbl-studio to tesseract's docker-compose file as third service. For connect from computer to services use http://127.0.0.1:9090 and http://127.0.0.1:9090. To connect between tesseract and lbl-studio use services name:  http://lbl-studio:8080 and http://server:9090. Example:
version: "3.8"

services:
  redis:
    image: redis:alpine
    container_name: redis
    hostname: redis
    volumes:
      - "./data/redis:/data"
    expose:
      - 6379
  server:
    container_name: server
    build: .
    environment:
      - MODEL_DIR=/data/models
      - RQ_QUEUE_NAME=default
      - REDIS_HOST=redis
      - REDIS_PORT=6379
    ports:
      - 9090:9090
    depends_on:
      - redis
    links:
      - redis
    volumes:
      - "./data/server:/data"
      - "./logs:/tmp"

  lbl-studio:
   image: heartexlabs/label-studio:latest
   ports:
    - 8080:8080
   volumes: 
    - label-studio-data:/label-studio/data/

volumes:
  label-studio-data:
Question: How to start from example diverging REST interface?

In the uvicorn exmaple, one writes uvicorn filename:attributename and by that start the server. However, the interface I have generated has no such method attributename in filename. Therefore, I am unsure what to pass as attributename.
Generated code in main.py
"""
    Somename

    Specification for REST-API of somename.

    The version of the OpenAPI document: 1.0.0
    Generated by: https://openapi-generator.tech
"""
from fastapi import FastAPI
from openapi_server.apis.some_api import router as SomeApiRouter

app = FastAPI(
    title="SomeName",
    description="Specification for REST-API of somename",
    version="1.0.0",
)

app.include_router(SomeApiRouter)



Answer:
The attribute name that you should specify is the name of the variable that holds your FastAPI instance. As they say in the docs:

The ASGI application should be specified in the form path.to.module:instance.path.

In this case for you, it would be uvicorn main:app where main.py is the file your code is in and app is the name of the variable in that file that holds your FastAPI instance.