自由如风

文章 评论 浏览 28

自由如风 2025-02-20 21:11:07

我在类星上遇到了同样的问题(我在Express App的子文件夹中遇到了同样的问题)。 Vercel在打破应用程序的JS文件(甚至更多的行)中添加了相同的行。

对我来说,解决方案是将静态文件(Quasar Spa App)放入/public 文件夹中。

/public 中的文件将被AS-I部署,并且不会修改。它们将以您的URL的根源可用。

示例:

假设您将以下文件结构部署到 https://myapp.vercel.app < /a>:

I had the same issue with a Quasar app (which I had in a sub-folder of an Express app). Vercel was adding the same lines to the js files (and even more lines) which was breaking the app.

The solution for me was to put the static files (Quasar SPA app) into a /public folder.

Files in /public will be deployed as-is and won't be modified. They'll be available at the root of your URL.

Example:

Let's say you deploy the following file structure to https://myapp.vercel.app:

┣ ???? .vercel
┣ ???? api
┃ ┣ ???? index.js
┣ ???? public
┃ ┣ ???? about
┃ ┃ ┣ ???? assets
┃ ┃ ┃ ┣ ???? script.js
┃ ┃ ┣ ????img
┃ ┃ ┃ ┗ ???? logo.jpeg
┃ ┃ ┗ ???? index.html
┣ ???? index.js
┣ ???? package.json
┣ ???? server.js
┗ ???? vercel.json

The index.html page will be available at:

https://myapp.vercel.app/about (or https://myapp.vercel.app/about/index.html )

The script.js file will be available at:

https://myapp.vercel.app/about/assets/script.js

Vercel在部署时正在更改JS文件的内容

自由如风 2025-02-20 17:01:59

实际上,我为此找到了解决方法,并假设为什么我的圆圈没有动画:

for (int i = 0; i < currentState - 1; i++) {
    final double x = size.width * i / (numberOfStates - 1);

    canvas.drawCircle(Offset(x, size.height / 2), 10, filleddotspaint);
}

final double x = size.width * (currentState - 1) / (numberOfStates - 1);

canvas.drawCircle(Offset(x, size.height / 2), 10, filleddotspaint);

我更改了for循环的在外面绘制的最后一个圆圈。这似乎足以让框架检测到它应该动画的东西。也许For循环以某种方式将其混淆了?

I actually found a workaround for this, and have an assumption of why my circles were not animated:

for (int i = 0; i < currentState - 1; i++) {
    final double x = size.width * i / (numberOfStates - 1);

    canvas.drawCircle(Offset(x, size.height / 2), 10, filleddotspaint);
}

final double x = size.width * (currentState - 1) / (numberOfStates - 1);

canvas.drawCircle(Offset(x, size.height / 2), 10, filleddotspaint);

I changed the last circle to be drawn outside of the for loop. This seems to be enough for the framework to detect that this is something that it should animate. Maybe the for loop confused it in some way?

定时动画用自定义画家扑来

自由如风 2025-02-20 15:49:51

您可以使用freetype。 OpENCV可以与Freetype一起编译,这将使您可以从TTF文件加载字体。然后,您可以在线查找免费字体,该字体适合自己制作自己的TTF文件的四个需求。

这是如何与OpenCV一起使用freetype的链接。
< noreferrer“> https://docs.opencv.org/3.4/d9/dfa/classcv_1_1freetype_1_1freetype2.html

You could use freetype. OpenCV can be compiled with FreeType which will allow you to load fonts from ttf files. then you can look up for a free font online which suits four needs of make your own ttf file.

Here is a link on how to use FreeType with opencv.
https://docs.opencv.org/3.4/d9/dfa/classcv_1_1freetype_1_1FreeType2.html

如何使用OpENCV绘制轮廓的轮廓或阴影?

自由如风 2025-02-19 17:10:50

如果要卸载组件,则可以使用有条件渲染,可以在其中声明父组件中的状态,并且基于状态可以安装或卸载组件,为:

这是您想要 oct Unmount

code> codesandbox demo

如果要切换一个组件,则可以执行以下操作,因为只有一种方法可以从 test test 组件更改状态。如果您卸载此组件无法再次进行 Mount 它。因此,您还可以在 app 组件中声明按钮,可以在其中 mount 单击按钮时删除 codesandbox P>

> parent component

export default function App() {
  const [isShowing, setIsShowing] = useState(true);  // STATE
  return (
    <div className="App">
      {isShowing && <Test setIsShowing={setIsShowing} />}
    </div>
  );
}

儿童组件

function Test({ setIsShowing }) {
  function unmountComponent() {
    setIsShowing(false);
  }
  return (
    <div className="app-component">
      <h2 className="h2">App Component</h2>
      <button onClick={unmountComponent}>Unmount This Component</button>
    </div>
  );
}

If you want to unmount a component then you can use conditional rendering where you can declare state in parent component and based on the state you can mount or unmount component as:

This is the parent component from where you want to mount or unmount

CODESANDBOX DEMO

If you want to toggle component once then you can do the following because there is only one way to change state i.e from Test component. If you unmount this component there is no way to mount it again. So you can also declare button in App component from where you can mount or unmount on click of a button. CODESANDBOX

Parent component

export default function App() {
  const [isShowing, setIsShowing] = useState(true);  // STATE
  return (
    <div className="App">
      {isShowing && <Test setIsShowing={setIsShowing} />}
    </div>
  );
}

Child component

function Test({ setIsShowing }) {
  function unmountComponent() {
    setIsShowing(false);
  }
  return (
    <div className="app-component">
      <h2 className="h2">App Component</h2>
      <button onClick={unmountComponent}>Unmount This Component</button>
    </div>
  );
}

单击按钮,我如何从DOM中卸载功能组件

自由如风 2025-02-19 09:41:40

请参阅此处的Slebetman答案: https://stackoverflow.com/a/65874173/132510 。尝试在 import 语句中将“ .js”附加到文件名上,或者使其成为绝对导入。

See slebetman's answer here: https://stackoverflow.com/a/65874173/132510. Try appending '.js' to the filename in the import statement, or make it an absolute import.

相对导入路径需要eCMAScript导入中的明确文件扩展,当'-moduleReSolution&#x27; IS&#x27; node16&#x27;或Nodenext&#x27;您的意思是。

自由如风 2025-02-18 16:44:57

这是不可能的。当您仅通过某些字段进入协会时,它将创建该实体并分配它。您需要事先解决ID,仅引用ID。

有一个问题,可以使用唯一字段来解决此类问题。但是我想这将在不久的将来无法解决

This is not possible. When you pass in an association just some fields, it will create that entity and assign it. You need to resolve the ID beforehand and reference only the ID.

There is an issue open to allow referencing using unique fields, to solve issues like this. But I guess this will be not solved in near future

在Shopware 6中与国家 /地区的进口实体6

自由如风 2025-02-17 23:35:49

没有针对此问题的一般解决方案,因为并非每个功能都有一个导数。
例如,无法找到函数的导数:

f = lambda x: random()
g = lambda x: str(x)

您可以为某些类型的可区分函数定义类,例如常数函数,多项式函数,其他可区分函数的总和等,例如:

class ConstantFunction:
    def __init__(self, constant):
        self.constant = constant
    
    def __call__(self, x):
        return self.constant
    
    def derivative(self):
        return ConstantFunction(0)

f = ConstantFunction(10)
print(f(3))
f1 = f.derivative()
print(f1(3))

There is no general solution for this problem, because not every function has a derivative.
For example there is no way to find the derivative of functions like:

f = lambda x: random()
g = lambda x: str(x)

You could define classes for some types of differentiable functions, like constant functions, polynomial functions, sums of other differentiable functions, etc., for example:

class ConstantFunction:
    def __init__(self, constant):
        self.constant = constant
    
    def __call__(self, x):
        return self.constant
    
    def derivative(self):
        return ConstantFunction(0)

f = ConstantFunction(10)
print(f(3))
f1 = f.derivative()
print(f1(3))

采用Python中Lambda功能的派生

自由如风 2025-02-17 06:28:36

如果rawdata总是相同的格式,我会说这样的话

const rawData = [
  {
    c: [
      {
        v: "Food Truck: The Vegan"
      },
      {
        v: "06/02/2022 16:00:00"
      },
      {
        v: "06/02/2022 21:00:00"
      },
      {
        v: "06/02/2022"
      }
    ]
  },
  {
    c: [
      {
        v: "Food Truck: Lob Dogs"
      },
      {
        v: "06/03/2022 16:00:00"
      },
      {
        v: "06/03/2022 21:00:00"
      },
      {
        v: "06/03/2022"
      }
    ]
  }
];

const format = ["name", "start_date", "end_date", "date"];

const formattedResult = rawData.map(({ c }) => Object.fromEntries(
  format.map((key, i) => [key, c[i].v])
));

console.log(formattedResult);

If the rawData is always the same format i would say something like this

const rawData = [
  {
    c: [
      {
        v: "Food Truck: The Vegan"
      },
      {
        v: "06/02/2022 16:00:00"
      },
      {
        v: "06/02/2022 21:00:00"
      },
      {
        v: "06/02/2022"
      }
    ]
  },
  {
    c: [
      {
        v: "Food Truck: Lob Dogs"
      },
      {
        v: "06/03/2022 16:00:00"
      },
      {
        v: "06/03/2022 21:00:00"
      },
      {
        v: "06/03/2022"
      }
    ]
  }
];

const format = ["name", "start_date", "end_date", "date"];

const formattedResult = rawData.map(({ c }) => Object.fromEntries(
  format.map((key, i) => [key, c[i].v])
));

console.log(formattedResult);

如何将这些数据转换为给定格式

自由如风 2025-02-16 20:53:05

我注意到有两件事:

1)在某些数据源上方,您有一个评论说将其标记为主要数据库

这是一件好事,但实际上您并没有将其标记为主要。为此,您需要使用 @primary 注释。

2)您不能拥有多个主数据源,

只能有一个主数据源,因此将其中的多个标记为主要数据源是错误的,并且会导致错误。您需要选择一个数据源以将标签标记为主要,而巧合的是,该数据源是您可以从H2控制台进行交互的数据。

There are two things I noticed:

1) Above some datasources you have a comment saying tags it as primary database

This is a fine thing to do, but you don't actually tag those as primary. For that you need to use the @Primary annotation.

2) You can't have multiple Primary datasources

There can be only one primary datasource, so tagging multiple of them as primary is wrong and will result in an error. You need to choose one datasource to tag as primary and coincidentally, that datasource is the one you'll be able to interact with from your H2 Console.

Spring Boot从2.1.3.Release升级到2.5.12:“没有合格的类型bean Javax.sql.datasource&#x27;可用”在Junit Run

自由如风 2025-02-16 09:24:37

urls.py:

urlpatterns = [

    path('get_department_data/', views.get_department_data, name = "get_department_data")
    # ...

]

视图:

def get_department_data(request):
    if request.is_ajax and request.method == "GET":
        q = YourModel.objects.all().values()
        data = []
        for i in q:
            data.append([(i['field1'],i['field2'])])
        return JsonResponse({"data":data}, status = 200)

html:

<input value="{% url 'get_department_data' %}" type="hidden"></input>

JS:

dd_url = $('#department_data_url').val();
$.ajax({
    url: dd_url,
    type: "GET",
    dataType: "json",
    success: function(response) {
        console.log(response.data); 
        $.each(response.data, function (i, obj) {
              console.log( obj[0][0] , obj[0][1] ); 
        });
    }
});

urls.py:

urlpatterns = [

    path('get_department_data/', views.get_department_data, name = "get_department_data")
    # ...

]

views:

def get_department_data(request):
    if request.is_ajax and request.method == "GET":
        q = YourModel.objects.all().values()
        data = []
        for i in q:
            data.append([(i['field1'],i['field2'])])
        return JsonResponse({"data":data}, status = 200)

HTML:

<input value="{% url 'get_department_data' %}" type="hidden"></input>

js:

dd_url = $('#department_data_url').val();
$.ajax({
    url: dd_url,
    type: "GET",
    dataType: "json",
    success: function(response) {
        console.log(response.data); 
        $.each(response.data, function (i, obj) {
              console.log( obj[0][0] , obj[0][1] ); 
        });
    }
});

如何通过JavaScript设置循环的DTL(Django Tamplate语言)和值

自由如风 2025-02-15 11:43:48

使用列表理解:

[[item for item in sublist if item != 0] for sublist in coord]

此输出:

[
 [(1.0, 1.0), (4.0, 2.0), (1.0, 5.0), (3.0, 3.0)],
 [(1.0, 1.0), (4.0, 2.0), (1.0, 5.0), (3.0, 3.0)]
]

Use a list comprehension:

[[item for item in sublist if item != 0] for sublist in coord]

This outputs:

[
 [(1.0, 1.0), (4.0, 2.0), (1.0, 5.0), (3.0, 3.0)],
 [(1.0, 1.0), (4.0, 2.0), (1.0, 5.0), (3.0, 3.0)]
]

删除列表python列表中的0个值

自由如风 2025-02-15 07:35:19

鉴于上面的文本,您可以使用简单的正则表达式提取所需的内容:

String txt = '''
change <change-id>
  project: <project-name>
  id: <change-id>
  lastUpdated: 2022-06-17 10:07:40 CEST
  currentPatchSet:
    number: 14
    revision: <commit-id> <--- What I want to extract
    parents:
 '''

String revision = ( txt =~ /revision: (.+)/ ).findAll().first().last()

assert revision == '<commit-id> <--- What I want to extract'

如果您需要更复杂的搜索,则应使用jsonslurper来避免重新发明轮子。

Given the text above, you could use a simple regex to extract what you want:

String txt = '''
change <change-id>
  project: <project-name>
  id: <change-id>
  lastUpdated: 2022-06-17 10:07:40 CEST
  currentPatchSet:
    number: 14
    revision: <commit-id> <--- What I want to extract
    parents:
 '''

String revision = ( txt =~ /revision: (.+)/ ).findAll().first().last()

assert revision == '<commit-id> <--- What I want to extract'

If you need a more complex search, you should be using JsonSlurper to avoid reinventing the wheel.

Gerrit SSH查询 - 从结果中提取提交ID

自由如风 2025-02-15 03:24:25

request.getID() null处理并避免陷入例外情况如何?

使用以下一项,假设 applyeeerepository#findbyid 返回可选&lt;雇员&gt; ::

Employee employee = Optional.ofNullable(request.getId())
                            .flatMap(id -> employeeRepository.findById(id))
                            .orElse(new Employee());
Employee employee = Optional.ofNullable(request.getId())
                            .flatMap(EmployeeRepository::findById)
                            .ofElse(new Employee());

How about null-handling of the request.getId() and avoiding falling into the exception?

Use one of the following, assuming employeeRepository#findById returns Optional<Employee>:

Employee employee = Optional.ofNullable(request.getId())
                            .flatMap(id -> employeeRepository.findById(id))
                            .orElse(new Employee());
Employee employee = Optional.ofNullable(request.getId())
                            .flatMap(EmployeeRepository::findById)
                            .ofElse(new Employee());

当异常发生时,可选的ORELSE()无法返回替代值

自由如风 2025-02-14 20:34:08

给定数据格式的名称/计数在单独的数组中,您可以使用循环的基本来获取每个灾难的索引,以根据该索引获得相应的名称/

    data.disasterName[i] + " : " + data.disasterCount[i] 

计数假定灾难名称数量与计数相同,并且关联的值按相同的顺序 - 例如,计数[0]用于森林火灾。

var data = {
  "disasterName": [
    "Fire Forest",
    "Earthquake"
  ],
  "disasterCount": [
    "60",
    "50"
  ]
};

var count = data.disasterName.length;

var html = '';
for (let i = 0; i < count; ++i) {
  html += "<h3>" + data.disasterName[i] + " : " + data.disasterCount[i] + "</h3>";
}
$("#output").append(html);
h3 { font-size: 1em; font-weight: normal; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id='output'></div>


由于您可以更改格式,因此您可以使其更像对象,例如:

    {
      "name": "Forest Fire",
      "count": 60
    },

JS将更接近您的初始尝试,因为您不需要循环索引,并且可以使用.foreach()或。地图()

var data = {
  "disasters": [
    {
      "name": "Forest Fire",
      "count": 60
    },
    {
      "name": "Earthquake",
      "count": 50
    }
  ]
};


// forEach
//var html = '';
//data.disasters.forEach(disaster => {
//  html += "<h3>" + disaster.name + " : " + disaster.count + "</h3>";
//});
// or map

var html = data.disasters.map(disaster =>
  "<h3>" + disaster.name + " : " + disaster.count + "</h3>"
);


$("#output").append(html);
h3 { font-size: 1em; font-weight: normal; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id='output'></div>

Given the format of your data where the name/count are in separate arrays, you can use a basic for loop to get the index for each disaster, to get the corresponding name/count based on that index

    data.disasterName[i] + " : " + data.disasterCount[i] 

This assumes there's the same number of disaster names as counts and that the associated values are in the same order - eg count[0] is for forest fires.

var data = {
  "disasterName": [
    "Fire Forest",
    "Earthquake"
  ],
  "disasterCount": [
    "60",
    "50"
  ]
};

var count = data.disasterName.length;

var html = '';
for (let i = 0; i < count; ++i) {
  html += "<h3>" + data.disasterName[i] + " : " + data.disasterCount[i] + "</h3>";
}
$("#output").append(html);
h3 { font-size: 1em; font-weight: normal; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id='output'></div>


As you can change the format, you could make it more object-like, eg an array of:

    {
      "name": "Forest Fire",
      "count": 60
    },

then the js will be closer to your initial attempt as you don't need to loop the index and can use a .forEach() or .map()

var data = {
  "disasters": [
    {
      "name": "Forest Fire",
      "count": 60
    },
    {
      "name": "Earthquake",
      "count": 50
    }
  ]
};


// forEach
//var html = '';
//data.disasters.forEach(disaster => {
//  html += "<h3>" + disaster.name + " : " + disaster.count + "</h3>";
//});
// or map

var html = data.disasters.map(disaster =>
  "<h3>" + disaster.name + " : " + disaster.count + "</h3>"
);


$("#output").append(html);
h3 { font-size: 1em; font-weight: normal; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id='output'></div>

数组Getjson by Index

自由如风 2025-02-14 20:15:29

编辑:添加Michael Szczesny的想法

import numpy as np

shape = (10, 48, 271, 397)
root = np.arange(shape[0])

您可以使用 /code> (仅在创建时间内获取视图):

arr1 = np.broadcast_to(root, shape[::-1]).T
arr2 = np.full(shape[::-1], fill_value=root).T

%timeit np.broadcast_to(root, shape[::-1]).T
%timeit np.full(shape[::-1], fill_value=root).T

# 3.56 µs ± 18.2 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
# 75.6 ms ± 243 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

您可以使用singleton dimension,而不是再次向后倒退,但似乎不太可以概括:

root = root[:, None, None, None]

arr3 = np.broadcast_to(root, shape)
arr4 = np.full(shape, fill_value=root)

root = np.arange(shape[0])
%timeit root_ = root[:, None, None, None]; np.broadcast_to(root_, shape)
%timeit root_ = root[:, None, None, None]; np.full(shape, fill_value=root_)

# 3.61 µs ± 6.36 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
# 57.5 ms ± 114 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

检查一切都是平等的,实际上是什么我们想要:

assert arr1.shape == shape

for i in range(shape[0]):
    sub = arr1[i]
    assert np.all(sub == i)

assert np.all(arr1 == arr2)
assert np.all(arr1 == arr3)
assert np.all(arr1 == arr4)

Edit: adding ideas from Michael Szczesny

import numpy as np

shape = (10, 48, 271, 397)
root = np.arange(shape[0])

You can use np.full or np.broadcast_to (only get a view at creation time):

arr1 = np.broadcast_to(root, shape[::-1]).T
arr2 = np.full(shape[::-1], fill_value=root).T

%timeit np.broadcast_to(root, shape[::-1]).T
%timeit np.full(shape[::-1], fill_value=root).T

# 3.56 µs ± 18.2 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
# 75.6 ms ± 243 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

And instead of getting the shape backwards and the array backwards again, you can use singleton dimension, but it seems less generalizable:

root = root[:, None, None, None]

arr3 = np.broadcast_to(root, shape)
arr4 = np.full(shape, fill_value=root)

root = np.arange(shape[0])
%timeit root_ = root[:, None, None, None]; np.broadcast_to(root_, shape)
%timeit root_ = root[:, None, None, None]; np.full(shape, fill_value=root_)

# 3.61 µs ± 6.36 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
# 57.5 ms ± 114 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

Checks that everything is equal and actually what we want:

assert arr1.shape == shape

for i in range(shape[0]):
    sub = arr1[i]
    assert np.all(sub == i)

assert np.all(arr1 == arr2)
assert np.all(arr1 == arr3)
assert np.all(arr1 == arr4)

如何沿指定轴创建具有值的数组?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文