池木

文章 评论 浏览 28

池木 2025-02-21 00:17:30

我相信,您不需要子查询。
您的按声明订单略有关闭:它首先按城市分类,然后是酒店,然后才选择约会。
因此,如果您修改订单按City.Name,日期desc,然后是Hotel_id,则应进行工作。
找到以下代码:

SELECT distinct on (city.name) 
  city.name, 
  booking.booking_date as last_booking_date, 
  hotel.id as hotel_id, 
  hotel.photos ->> 0 as hotel_photo
FROM city 
INNER JOIN hotel
    ON city.id = hotel.city_id 
INNER JOIN booking 
    ON booking.hotel_id = hotel.id
ORDER BY city.name, booking.booking_date DESC, hotel.id ASC;

I believe, you do not need the WHEN subquery.
Your ORDER BY statement is slightly off: it first sorts by city, then by hotel and only then choses a date.
So, if you modify ORDER BY to be by city.name, date DESC and then hotel_id it should make the work.
Find the code below:

SELECT distinct on (city.name) 
  city.name, 
  booking.booking_date as last_booking_date, 
  hotel.id as hotel_id, 
  hotel.photos ->> 0 as hotel_photo
FROM city 
INNER JOIN hotel
    ON city.id = hotel.city_id 
INNER JOIN booking 
    ON booking.hotel_id = hotel.id
ORDER BY city.name, booking.booking_date DESC, hotel.id ASC;

如何在Postgresql的不同城市获得最新约会

池木 2025-02-20 16:53:31

这个问题与 jQuery 无关


这是解决方案

var storage = [];
var players = [];


function createplayers(arr) {
  for (let i = 0; i < 8; i++) {
    let a = true,
      n;
    while (a) {
      n = Math.floor(Math.random() * 100) + 1;
      a = arr.includes(n);
    }
    arr.push(n);
  }
}

var x = 3;
var interval = 1000;
for (var i = 0; i < x; i++) {
  setTimeout(function() {
    createplayers(players);
    storage.push(players)
    console.log(players)

    //Notice this line
    players=[];
    console.log(storage)
  }, i * interval)
}

This Question has nothing to do with jQuery

You have to clear the players array everytime you add to storage.
Here is the solution

var storage = [];
var players = [];


function createplayers(arr) {
  for (let i = 0; i < 8; i++) {
    let a = true,
      n;
    while (a) {
      n = Math.floor(Math.random() * 100) + 1;
      a = arr.includes(n);
    }
    arr.push(n);
  }
}

var x = 3;
var interval = 1000;
for (var i = 0; i < x; i++) {
  setTimeout(function() {
    createplayers(players);
    storage.push(players)
    console.log(players)

    //Notice this line
    players=[];
    console.log(storage)
  }, i * interval)
}

在将数组推入二维数组时有问题

池木 2025-02-20 16:34:31

仅通过围绕这些 eval parse 编写包装器函数,

eval2 <- function(txt) {
  eval(parse(text = txt))
}

eval2('5 + 5')
#> [1] 10

eval(parse(text = '5 + 5'))
#> [1] 10

该功能是由 reprex软件包(v2.0.1)

Just by writing a wrapper function around these eval and parse

eval2 <- function(txt) {
  eval(parse(text = txt))
}

eval2('5 + 5')
#> [1] 10

eval(parse(text = '5 + 5'))
#> [1] 10

Created on 2022-07-07 by the reprex package (v2.0.1)

如何将评估解析文本压缩到一个函数中?

池木 2025-02-20 14:51:47

您已经提到的两种方式别无选择。可读性是主观的,但是 exporterget() enforter.get()都是常见的不错选择。如果您明确想在 import 语句本身中列出所有使用的功能,则必须给他们单个别名。树木摇动工具将能够处理两种格式。

There are no alternatives to the two ways you already mentioned. Readability is subjective, but both exporterGet() and exporter.get() are good choices that are common. If you explicitly want to list all the used function in the import statement itself, you will have to give them individual aliases. Tree shaking tools will be able to handle both formats.

ES6模块:导入特定功能作为ANAME

池木 2025-02-20 04:47:26

正如@slebetman在他的评论中提到的那样,正确答案是将服务器从服务器发送为 utf-8 ,这是在我的情况下通过发送数据,通过发送<<<代码> content-type 作为 text/event-stream; charset = utf-8

我在Golang服务器中的代码变成:

w.Header().Set("Content-Type", "text/event-stream; charset=utf-8")

As mentioned by @slebetman in his comments, the correct answer is to send the data from the server as utf-8 which is done in my case as I'm sending data as streaming, by sending the Content-Type as text/event-stream; charset=utf-8

My code in the GoLang server became:

w.Header().Set("Content-Type", "text/event-stream; charset=utf-8")

UTF-8阿拉伯语在JavaScript中

池木 2025-02-19 19:17:25

(我还考虑过使默认值废话,例如NAN或INF,然后检查哪些值是用户指定的...

通常这是您处理此操作的方式。在简单的情况下,您将使用 none使用作为您的哨兵值:

def func(a=None, b=None, c=None):
  if a is None:
      print('using default value')
      a = 1
  else:
      print('user specified a value')

但是,如果是有效的值,则可以使用其他对象
例子:

NOT_SET_BY_CALLER = object()


def func(a=NOT_SET_BY_CALLER, b=NOT_SET_BY_CALLER, c=NOT_SET_BY_CALLER):
  if a is NOT_SET_BY_CALLER:
      print('using default value')
      a = 1
  else:
      print('user specified a value')

(I've also considered making the defaults values nonsense, like NaN or Inf, then checking which values were user-specified ...

That is typically exactly how you would handle this. In the simple case, you would use None as your sentinel value:

def func(a=None, b=None, c=None):
  if a is None:
      print('using default value')
      a = 1
  else:
      print('user specified a value')

But if None is a valid value, you can use some other object. For
example:

NOT_SET_BY_CALLER = object()


def func(a=NOT_SET_BY_CALLER, b=NOT_SET_BY_CALLER, c=NOT_SET_BY_CALLER):
  if a is NOT_SET_BY_CALLER:
      print('using default value')
      a = 1
  else:
      print('user specified a value')

如何找出默认情况下剩下哪些参数?

池木 2025-02-19 07:04:29

在这种情况下,您可能需要先将日期时间转换为当地时间:

转换为Localtime:

func utcToLocal(dateStr: String) -> String? {
  let dateFormatter = DateFormatter()
  dateFormatter.dateFormat = "HH:mm"
  dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
  if let date = dateFormatter.date(from: dateStr) {
    dateFormatter.timeZone = TimeZone.current
    dateFormatter.dateFormat = "HH:mm"

    return dateFormatter.string(from: date)
  }
  return nil
}

,然后:

let utcTime = formatTime(string: "2022-06-30T02:15:00.000+07:00")
let localTime = utcToLocal(dateStr: utcTime)
print(localTime)

结果:

09:15

希望这有助于您解决问题。

In this case you might want to convert the DateTime to your local time first:

Convert To LocalTime:

func utcToLocal(dateStr: String) -> String? {
  let dateFormatter = DateFormatter()
  dateFormatter.dateFormat = "HH:mm"
  dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
  if let date = dateFormatter.date(from: dateStr) {
    dateFormatter.timeZone = TimeZone.current
    dateFormatter.dateFormat = "HH:mm"

    return dateFormatter.string(from: date)
  }
  return nil
}

And then:

let utcTime = formatTime(string: "2022-06-30T02:15:00.000+07:00")
let localTime = utcToLocal(dateStr: utcTime)
print(localTime)

The Result:

09:15

I hope this help you solve your problem.

如何将日期字符串转换为时间字符串?

池木 2025-02-19 03:30:45

另一个 dplyr 选项:

df <- read.table(text="Player Goals
A        10
A        10  
B        10
C        9
B        8
C        7
A        7
D        6
E        6
F        5", header = TRUE)
library(dplyr)
df %>% 
  arrange(desc(Goals)) %>%
  distinct() %>%
  filter(row_number() <= 5L)
#>   Player Goals
#> 1      A    10
#> 2      B    10
#> 3      C     9
#> 4      B     8
#> 5      C     7

在2022-07-01创建的(v2.0.1)

Another dplyr option:

df <- read.table(text="Player Goals
A        10
A        10  
B        10
C        9
B        8
C        7
A        7
D        6
E        6
F        5", header = TRUE)
library(dplyr)
df %>% 
  arrange(desc(Goals)) %>%
  distinct() %>%
  filter(row_number() <= 5L)
#>   Player Goals
#> 1      A    10
#> 2      B    10
#> 3      C     9
#> 4      B     8
#> 5      C     7

Created on 2022-07-01 by the reprex package (v2.0.1)

根据另一列中的值在一个列中分类特定级别

池木 2025-02-18 13:04:55

如果您不能使用帧,则可以三层矩形彼此之间,两者之间的边缘是您所需的边界厚度。前矩形将是您的背景,背面将是您的边界。

在此处阅读有关形状的信息: android.graphics.drawables.shapetrawable

另外,您可能可以调整所使用的任何容器的填充或边缘,以允许允许边框效果。

If you can't use a frame, you can layer two rectangles on top of each other, where the margin between the two would be your desired border thickness. The front rectangle would be your background, the back would be your border.

Read about the shapes here: android.graphics.drawables.shapedrawable

Alternatively, you could probably adjust the padding or margins of whatever container you are using to allow for a border like effect as well.

如何仅绘制矩形的边界?

池木 2025-02-18 03:40:33

通过创建一个新的 simplescriptContext ,将其传递到 eval() compiredscript 的方法中,然后调用 setContext setContext setContext ,将其修复了修复。 /代码>在调用 InvokeFunction()

疯狂的东西之前,使用新创建的上下文使用新创建的上下文!

Fixed it by creating a new SimpleScriptContext, passing it into the eval() method of CompiledScript, and then calling ScriptEngine#setContext with the newly created context before calling invokeFunction()

Crazy stuff!

ScriptEngine重复使用论点?

池木 2025-02-17 17:06:54

Prolog的出色评论指出了 两个问题的一个。如果您的控制台应用是基于&lt; c#7.1的构建)作为最后一行。这将旋转消息循环,直到击中钥匙为止。 这不是主要问题,我想提供一些调试技巧。

大问题是:

  • 如果我运行您的代码,您的HTTP请求将失败,并且正在抛出 system.formatexception
  • 通常这种例外IS 不是设置为时断裂。 (您可以通过在异常设置窗口中查看这一点来验证这一点。)不幸的是,在这种情况下,这为您提供了无声故障,因此您必须将事情掌握在自己的手中才能观察它。

提出调试代码的建议

  1. 使用 try-catch 阻止任何有可能失败的代码。

  2. 使用 system。 diagnostics.debug.assert 如果任何条件表达式评估为 false (但是仅当您以<<<<代码> debug 模式不是版本模式)。

  3. 将输出语句添加到跟踪执行。使用 debug.writeline 将将消息发送到 output window(但再次,仅在 debug 模式下)。另外,由于我们在此处有一个控制台应用程序,所以我正在使用主应用程序窗口来输出跟踪语句。

使用1-3:

public async Task Put() // must be async
{
    Console.WriteLine("Begin Put()");
    try
    {
        using (var request = new HttpRequestMessage(HttpMethod.Put, "https://api.minecraftservices.com/minecraft/profile/name/egg"))
        {
            request.Headers.Add("Authorization", "Bearer token");
            request.Content = new StringContent("body", Encoding.UTF8, "content-type");

            using (var response = await _client.SendAsync(request))
            {
                var data = await response.Content.ReadAsStringAsync();
                var code = response.StatusCode;
                Console.WriteLine(Convert.ToString(code));

                // do something with data
            }
        }
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.Assert(condition: false, message: ex.Message);
    }
    Console.WriteLine("End Put()");
}

现在,如果我运行代码,它将破坏并显示问题是什么。

  1. 使用异常设置窗口打开所有异常(如果有疑问)。现在,代码将破坏问题的确切行。

  1. 验证您是设置httpclient的授权标头正确,因为这可能是根本原因的一部分例外。

最后,如果您在 debug.assert 之后继续进行,则将在控制台中看到以下文本,这将确认您的 put 方法是否有机会完成。

希望这些建议可以帮助您解决这个问题和未来问题!


// This workaround for C# versions below 7.1 attempts to 
// mimic an `async Main` method. 
static void Main(string[] args)
{
    RunAsync();
    Console.ReadKey();
}

private static async void RunAsync()
{
    YourClient client = new YourClient();
    // Put() should be awaited inside an async method
    await client.Put();
}

The excellent comment by Prolog points out one of two issues. If your Console app is built on < C# 7.1 you will need a workaround to prevent the app from exiting (before the request has time to process) so in this case add Console.ReadKey() as the very last line. This will spin the message loop until you hit a key. But this is not the main issue and I would like to offer a couple of debugging tips.

The big issue is this:

  • If I run your code, your http request is failing and is throwing a System.FormatException
  • Usually this type of exception is not set to Break when Thrown. (You can verify this by looking in the Exception Settings window.) Unfortunately, this is giving you a silent failure in this case, so you must take matters into your own hands to observe it.

Suggestions for debugging your code

  1. Use a try-catch block around any code that has any likelihood of failing.

  2. Use System.Diagnostics.Debug.Assert which will cause your program to break on a line if any condition expression evaluates to false (but only when you're running in Debug mode not Release mode).

  3. Add output statements to trace execution. Using Debug.WriteLine will send messages to the Output window (but again, only in Debug mode). Alternatively, since we have a Console app here, I'm using the main app window to output trace statements.

Example using 1-3:

public async Task Put() // must be async
{
    Console.WriteLine("Begin Put()");
    try
    {
        using (var request = new HttpRequestMessage(HttpMethod.Put, "https://api.minecraftservices.com/minecraft/profile/name/egg"))
        {
            request.Headers.Add("Authorization", "Bearer token");
            request.Content = new StringContent("body", Encoding.UTF8, "content-type");

            using (var response = await _client.SendAsync(request))
            {
                var data = await response.Content.ReadAsStringAsync();
                var code = response.StatusCode;
                Console.WriteLine(Convert.ToString(code));

                // do something with data
            }
        }
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.Assert(condition: false, message: ex.Message);
    }
    Console.WriteLine("End Put()");
}

Now, if I run the code it will break and show what the problem is.

Exception and Assert

  1. Use the Exception Settings window to turn on all exceptions (if in doubt). Now the code will break on the exact line that is the problem.

Break when Thrown

  1. Verify that you are Setting Authorization Header of HttpClient correctly as this may be part of the root cause of the exception.

Finally, if you continue after the Debug.Assert you will see the following text in your console which will confirm whether your Put method has had a chance to complete or not.

console output

Hope these suggestions help you solve this problem and future ones!


// This workaround for C# versions below 7.1 attempts to 
// mimic an `async Main` method. 
static void Main(string[] args)
{
    RunAsync();
    Console.ReadKey();
}

private static async void RunAsync()
{
    YourClient client = new YourClient();
    // Put() should be awaited inside an async method
    await client.Put();
}

我没有任何输出,我不知道为什么

池木 2025-02-17 15:11:46
const theme = extendTheme({
  styles: {
    global: {
      "*": {
        borderColor: "red"
      }
    }
  }
});

这将覆盖所有元素的 bordercolor 属性。唯一要关注的是,如果您为组件定义 border 属性,它将不会继承全局 bordercolor

示例:

const theme = extendTheme({
  styles: {
    global: {
      "*": {
        borderColor: "red"
      }
    }
  }
});

This will override the borderColor property of all elements. The only thing to keep an eye on is that if you define the border property for a component, it won't inherit the global borderColor.

Example: https://codesandbox.io/s/global-bordercolor-style-hzofpv?file=/src/index.tsx

脉轮:可以覆盖全球边界风格

池木 2025-02-17 13:16:36

感谢您的所有答案。
在阅读附录和附录的文档文档后,使用这些方法似乎无法将元素保存到变量中。

我只需要返回附录 li 元素。

   const todoItems = todos.map((todo, i) => {
      let newSpan = document.createElement('span');
      let newLi = document.createElement('li');
      newLi.setAttribute('data-index', i);
      const todoTextNode = document.createTextNode(todo.text);
      newSpan.appendChild(todoTextNode);
      newLi.appendChild(newSpan);
      return newLi;
    });

Thanks for all the answers.
Upon reading on the documentation of append and appendChild, it seems elements cannot be saved into a variable upon using these methods.

I just need to return the append li element.

   const todoItems = todos.map((todo, i) => {
      let newSpan = document.createElement('span');
      let newLi = document.createElement('li');
      newLi.setAttribute('data-index', i);
      const todoTextNode = document.createTextNode(todo.text);
      newSpan.appendChild(todoTextNode);
      newLi.appendChild(newSpan);
      return newLi;
    });

输出.appendchild on&lt; li&gt; &&lt; span&gt;地图功能中的元素

池木 2025-02-17 05:39:49

您使用的API取决于Node.js。他们将不在浏览器中运行。

(您遇到的具体错误是因为 require 是Node.js实现的CommonJS模块规范的一部分,但浏览器不支持这一点)。

如果恶意开发人员可以告诉访客的浏览器以任意方式与计算机上的Gipo引脚进行互动,那将是非常危险的!

如果您想通过浏览器与它们互动,则需要使用Web服务进行操作。

可以使用在Node.js上运行的JavaScript编写此类服务,但是由于您的服务器端上已经有烧瓶,因此使用 python等效

The APIs you are using depend on Node.js. They will not run in the browser.

(The specific error you are encountering is because require is part of the CommonJS module specification as implemented by Node.js but browsers don't support that).

It would be very dangerous if a malicious developer could tells any of their visitors' browsers to interact in arbitrary ways with the GIPO pins on their computers!

If you want to interact with them from a browser, then you need to do so using a web service.

You could write such a service using JavaScript running on Node.js, but since you already have Flask on the server side, it would make more sense to use the Python equivalent.

p5.j​​s“未接收参考:未定义”。在烧瓶应用Raspberry pi中

池木 2025-02-17 00:41:44

浏览器将按照其找到的顺序执行脚本。如果您调用外部脚本,它将阻止页面,直到脚本已加载和执行为止。

为了测试这一事实:

// file: test.php
sleep(10);
die("alert('Done!');");

// HTML file:
<script type="text/javascript" src="test.php"></script>

将脚本添加到文档中后立即执行动态添加的脚本。

要测试这一事实:

<!DOCTYPE HTML>
<html>
<head>
    <title>Test</title>
</head>
<body>
    <script type="text/javascript">
        var s = document.createElement('script');
        s.type = "text/javascript";
        s.src = "link.js"; // file contains alert("hello!");
        document.body.appendChild(s);
        alert("appended");
    </script>
    <script type="text/javascript">
        alert("final");
    </script>
</body>
</html>

警报的顺序被“附加” - &gt; “你好!” - &gt; “最终”

如果在脚本中您尝试访问尚未达到的元素(例如:&lt; script&gt;用#blah&lt;/script&gt;&gt;&lt; div id =“ blah”&gt;&lt ;/div&gt; )然后,您将获得错误。

总体而言,是的,您可以包含外部脚本,然后访问其功能和变量,但前提是您退出当前&lt; script&gt; 标记并启动新的函数。

The browser will execute the scripts in the order it finds them. If you call an external script, it will block the page until the script has been loaded and executed.

To test this fact:

// file: test.php
sleep(10);
die("alert('Done!');");

// HTML file:
<script type="text/javascript" src="test.php"></script>

Dynamically added scripts are executed as soon as they are appended to the document.

To test this fact:

<!DOCTYPE HTML>
<html>
<head>
    <title>Test</title>
</head>
<body>
    <script type="text/javascript">
        var s = document.createElement('script');
        s.type = "text/javascript";
        s.src = "link.js"; // file contains alert("hello!");
        document.body.appendChild(s);
        alert("appended");
    </script>
    <script type="text/javascript">
        alert("final");
    </script>
</body>
</html>

Order of alerts is "appended" -> "hello!" -> "final"

If in a script you attempt to access an element that hasn't been reached yet (example: <script>do something with #blah</script><div id="blah"></div>) then you will get an error.

Overall, yes you can include external scripts and then access their functions and variables, but only if you exit the current <script> tag and start a new one.

网页中JavaScript脚本的加载和执行顺序是什么?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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