怪我太投入

文章 评论 浏览 31

怪我太投入 2025-02-04 14:28:19

入门 f for Mongoose的页面上> mongoose.model():

  //注意:必须将方法添加到架构中,然后再将其编译为mongoose.model()
kittyschema.methods.speak = function spee(){  
  constring = this.name
    ? “ Meow名称为” + this.name
    :“我没有名字”;
  console.log(问候);
};
const kitten = mongoose.model('kitten',kittyschema); ````````
 

On the Getting Started page for mongoose, it indicates that methods must be declared before calling mongoose.model():

// NOTE: methods must be added to the schema before compiling it with mongoose.model()
kittySchema.methods.speak = function speak() {  
  const greeting = this.name
    ? "Meow name is " + this.name
    : "I don't have a name";
  console.log(greeting);
};
const Kitten = mongoose.model('Kitten', kittySchema); ```

在Mongoose中,我执行了网站中给出的示例程序,但是我得到的错误与以下相同的错误:typeError:fluffy.speak不是一个函数

怪我太投入 2025-02-04 14:15:38

只需将返回产量替换。

def itercolumn(names):
  for i in names:
    result = i[-2:]
    if result == "16":
      yield i

print(list(itercolumn(names)))

或者

def itercolumn(names):
  final = []
  for i in names:
    result = i[-2:]
    if result == "16":
      final.append(i)
  return final

print(itercolumn(names))

您可以使用列表理解

result = [name for name in names if name[-2:] == '16']

Just replace return with yield.

def itercolumn(names):
  for i in names:
    result = i[-2:]
    if result == "16":
      yield i

print(list(itercolumn(names)))

or

def itercolumn(names):
  final = []
  for i in names:
    result = i[-2:]
    if result == "16":
      final.append(i)
  return final

print(itercolumn(names))

or you can use list comprehension

result = [name for name in names if name[-2:] == '16']

python:可以获取变量的子集

怪我太投入 2025-02-04 10:39:19

好吧,您实际上在不仔细观察的情况下回答了自己的问题。
让我向您展示原因:

set command="C:\Program Files\7-Zip\7z.exe" l "FolderName\archive.zip" "file.cmd"
for /F "delims=" %%a in ('"%command%"') do ...

请注意,您的代码将set命令的值转换为:

"C:\Program Files\7-Zip\7z.exe" l "FolderName\archive.zip" "file.cmd"

您在哪里将其传递给循环,以double引号,例如:

"%command%"

最终将是:

""C:\Program Files\7-Zip\7z.exe" l "FolderName\archive.zip" "file.cmd""

它将完全工作在for循环中:

for /f "delims=" %%i in ('""C:\Program Files\7-Zip\7z.exe" l "FolderName\archive.zip" "file.cmd""') do ...

尽管在这种情况下,这将按预期工作,但如果您的引用字符串包含特殊字符,则如&,如本示例所示:

for /f "delims=" %%i in ('""C:\Program Files\7-Zip\7z.exe" l "FolderName\archives & backups.zip" "file.cmd""') do ...

因此,您需要简单地逃脱外部双重引号要克服这一点:

for /f "delims=" %%i in ('^""C:\Program Files\7-Zip\7z.exe" l "FolderName\archives & backups.zip" "file.cmd"^"') do ...

点2。从cmd /?< /code>看似说明了这种行为,根据下面的屏幕截图:

Well, you actually answered your own question without looking closely.
Let me show you why:

set command="C:\Program Files\7-Zip\7z.exe" l "FolderName\archive.zip" "file.cmd"
for /F "delims=" %%a in ('"%command%"') do ...

Note that your code translates the value of the set command to:

"C:\Program Files\7-Zip\7z.exe" l "FolderName\archive.zip" "file.cmd"

where you then pass that to the loop in double quotes again, as:

"%command%"

which ends up being:

""C:\Program Files\7-Zip\7z.exe" l "FolderName\archive.zip" "file.cmd""

Which will work exactly in a for loop:

for /f "delims=" %%i in ('""C:\Program Files\7-Zip\7z.exe" l "FolderName\archive.zip" "file.cmd""') do ...

Though that will work as expected in this case, it will fail if your quoted strings contain special characters like & as shown in this example:

for /f "delims=" %%i in ('""C:\Program Files\7-Zip\7z.exe" l "FolderName\archives & backups.zip" "file.cmd""') do ...

So you need to simply escape the outer double quotes to overcome this:

for /f "delims=" %%i in ('^""C:\Program Files\7-Zip\7z.exe" l "FolderName\archives & backups.zip" "file.cmd"^"') do ...

Point 2. from cmd /? seemingly states this behaviour, as per the below screenshot:
enter image description here

循环中的多个引号(批处理文件)

怪我太投入 2025-02-04 07:25:59

您应该能够使用 dateTime.parseexact.parseexact 获得您需要的东西。

DateTime.ParseExact("203658.000", "HHmmss.fff", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal)

不过,请在午夜左右小心,因为如果日期不匹配,时间可能会近24小时。

You should be able to use DateTime.ParseExact to get what you need.

DateTime.ParseExact("203658.000", "HHmmss.fff", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal)

Be careful around midnight though, as the time could be nearly 24 hours out if the dates don't match.

如何比较字符串“ 203658.000”到C#中的UTC?

怪我太投入 2025-02-04 03:05:23

为了使您获取信息,每个输入必须具有“名称”属性。如下:

<form action="https://formsubmit.co/[email protected]" method="POST">
     <input type="text" name="name" required>
     <input type="email" name="email" required>
     <button type="submit">Send</button>
</form>

另外,将输入从无序列表中取出。

In order for you to get information each input must have a "name" attribute. Like below:

<form action="https://formsubmit.co/[email protected]" method="POST">
     <input type="text" name="name" required>
     <input type="email" name="email" required>
     <button type="submit">Send</button>
</form>

Also, take the inputs out of the unordered list.

&#x27; form submit.co&#x27;发送电子邮件,但没有收到数据

怪我太投入 2025-02-04 01:36:09

使用

mysql -h 127.0.0.1 -D db_name -u username --password=pass --debug-info true shared/local_sql/3.sql

您可能复制字符&lt;&gt;从某个示例中使用这些字符指示文件名的占位符,例如mysql ...&lt ; sql_file&gt;

整个占位符&lt; sql_file&gt;必须用shared/local_sql/3.sql/3.sql在示例中替换为实际文件名。

字符&lt;&gt;被外壳解释为标准输入或标准输出的重定向。

&lt; shared/local_sql/3.SQL指示Shell从指定文件重定向mySQL命令的标准输入。这实际上可能起作用。

&gt;需要一个文件名来指定应将输出重定向到何处。由于没有文件名,但是行的结尾,您会收到错误消息。

Use

mysql -h 127.0.0.1 -D db_name -u username --password=pass --debug-info true shared/local_sql/3.sql

You probably copied the characters < and > from some example where these characters are used to indicate a placeholder for the file name like mysql ... <sql_file>.

The whole placeholder <sql_file> must be replaced with the actual file name which is shared/local_sql/3.sql in your example.

The characters < and > are interpreted by the shell as redirection of standard input or standard output.

<shared/local_sql/3.sql instructs the shell to redirect the standard input of the mysql command from the specified file. This may actually work.

> needs a file name after it to specify where the output should be redirected to. Since there is no file name but the end of the line you get the error message.

php exec | mySQL命令返回SH:-C:第0行:语法错误,近乎意外的令牌`newline&#x27;

怪我太投入 2025-02-04 01:00:28

考虑以下内容。

$(function() {
  $(".getPtsValue").each(function(i, el) {
    var point = parseInt($(el).text().trim());
    if (point == 0) {
      $(el).addClass("red");
    } else if (point > 100) {
      $(el).addClass("blue");
    }
  });
});
.red {
  color: red;
}

.blue {
  color: blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span class="getPtsValue">20</span>
<span class="getPtsValue">0</span>
<span class="getPtsValue">225</span>
<span class="getPtsValue">100</span>
<span class="getPtsValue">0</span>
<span class="getPtsValue">60</span>

这使用.each(),它将迭代每个元素。

https://api.jquery.com/each/

描述:在jQuery对象上迭代,为每个匹配元素执行一个函数。

为了确保我们将数字与数字进行比较。当我们获得.html().text()时,它将是字符串。我们可以使用parseint()将其作为整数施放。

然后,我们使用.addclass()将类名添加到元素中。这可以是您想要的任何值,我只使用red蓝色

Consider the following.

$(function() {
  $(".getPtsValue").each(function(i, el) {
    var point = parseInt($(el).text().trim());
    if (point == 0) {
      $(el).addClass("red");
    } else if (point > 100) {
      $(el).addClass("blue");
    }
  });
});
.red {
  color: red;
}

.blue {
  color: blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span class="getPtsValue">20</span>
<span class="getPtsValue">0</span>
<span class="getPtsValue">225</span>
<span class="getPtsValue">100</span>
<span class="getPtsValue">0</span>
<span class="getPtsValue">60</span>

This makes use of .each() which will iterate each element.

https://api.jquery.com/each/

Description: Iterate over a jQuery object, executing a function for each matched element.

To ensure that we compare a Number to a Number. When we get .html() or .text(), it will be a String. We can use parseInt() to cast it as an Integer.

We then use .addClass() to add a Class name to the element. This can be any value you want, I just used red and blue.

如何根据jQuery根据跨度值更改跨度文本颜色为蓝色或红色

怪我太投入 2025-02-03 14:31:46

否。不可能这样做,否则应用程序将设置用户的密码,并且用户无法解锁其设备,因为第三方应用程序已更改密码。

No. It is not possible to do that otherwise apps would set user's passcode and users would be unable to unlock their device because a 3rd party app has changed passcode.

按程序上的iOS设置密码

怪我太投入 2025-02-03 11:38:20

您的未来功能:

Future<void> func() async {}

添加超时侦听器:

func().timeout(const Duration (seconds:5),onTimeout : () {
  // move to the page with warning message
});

Your future function :

Future<void> func() async {}

Add timeout listener :

func().timeout(const Duration (seconds:5),onTimeout : () {
  // move to the page with warning message
});

弹奏功能超时

怪我太投入 2025-02-03 10:48:56

这是下面的工作片段。我已经做到了,以便它每0.5秒过渡一次,以便您可以更快地看到它。如果您需要5秒钟,请将间隔更改为5000而不是500。

通常,SetInterval在班级中的工作方式与外部没有不同。您只需要注意this绑定(即,如果您做过setInterval(this.transitionslide,5000),这将无法正常工作,因为 this 将失去范围,因此.bind(this)

要注意的关键内容:

  1. 您想跟踪setInterval的返回值,这是一个间隔ID。这将使您停止间隔不断发生。

  2. 我们现在有2个函数 - startlideshow和stopslideshow,当您实例化新的Gallery时,您应在实例变量上使用.startslideshow()开始。

  3. 当您需要使用items.length时,您正在使用list.length,因为这是跟踪各个幻灯片的方法。

const list = document.querySelector('.js-gallery');
const items = document.querySelectorAll('.gallery__item'); // Use this for slide count, not list
Array.from(list); // Doesn't do anything

class Gallery {
  constructor(slideshow) {
    this.slideshow = slideshow;
    this.slideCount = items.length;
    this.items = items[0].getBoundingClientRect().width;
    this.currentSlide = 1;
    this.slideTransitionInterval = null;
  }

  transitionSlide() {
    console.log('invoked');
    if (this.currentSlide < this.slideCount) {
      list.style.transform = `translateX(-${this.currentSlide * this.items}px)`;
      this.currentSlide += 1;
    } else {
      this.stopSlideshow();
      list.style.transform = `translateX(0)`;
      this.currentSlide = 1;
    }
  }

  // Trying to make a method with setInterval() so that the slide runs every 5 seconds.
  startSlideshow() {
    this.stopSlideshow();
    this.slideTransitionInterval = setInterval(this.transitionSlide.bind(this), 500);
  }
  
  stopSlideshow() {
    if (this.slideTransitionInterval) {
      clearInterval(this.slideTransitionInterval);
    }
  }

}

const pics = new Gallery(list);
pics.startSlideshow();
.title {
  width: 100%;
  text-align: center;
}

.gallery {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  padding: 0;
  transition: all 500ms ease;
}


.gallery-container {
  overflow: hidden;
  position: relative;
  width: 1000px;
  margin: 0 auto;
}

.gallery__item {
  list-style: none;
  height: 500px;
  min-width: 1000px;
  background-position: center center;
  background-size: cover;
}
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="style.css">
  <title>Document</title>
</head>
<body>
  <h1 class="title">Gallery of Real Cool JS3 Images</h1>
  <div class="gallery-container">
    <ul class="gallery js-gallery">
      <li class="gallery__item js-gallery-item" style="background-image: url('https://picsum.photos/1000/650/?image=1062')"></li>
      <li class="gallery__item js-gallery-item" style="background-image: url('https://picsum.photos/1000/650/?image=837')"></li>
      <li class="gallery__item js-gallery-item" style="background-image: url('https://picsum.photos/1000/650/?image=1025')"></li>
      <li class="gallery__item js-gallery-item" style="background-image: url('https://picsum.photos/1000/650/?image=237')"></li>
    </ul>
  </div>
  <script src="script.js" defer></script>
</body>
</html>

Here's a working snippet below. I've made it so that it transitions every 0.5 seconds just so that you can see it faster. If you want it at 5 seconds, change the interval to 5000 instead of 500.

In general, setInterval doesn't work any differently in a class than outside it. You just have to be mindful of this binding (i.e. if you did setInterval(this.transitionSlide, 5000), this wouldn't work as this would lose scope, hence the .bind(this))

Key things to note:

  1. You want to track the setInterval's return value, which is an interval ID. This will let you stop the interval from constantly happening.

  2. We now have 2 functions - startSlideshow and stopSlideshow and when you instantiate a new Gallery, you should use .startSlideshow() on the instance variable whenever you want it to start.

  3. You were using list.length for the slideCount when you needed to use items.length since that's what was tracking the individual slides.

const list = document.querySelector('.js-gallery');
const items = document.querySelectorAll('.gallery__item'); // Use this for slide count, not list
Array.from(list); // Doesn't do anything

class Gallery {
  constructor(slideshow) {
    this.slideshow = slideshow;
    this.slideCount = items.length;
    this.items = items[0].getBoundingClientRect().width;
    this.currentSlide = 1;
    this.slideTransitionInterval = null;
  }

  transitionSlide() {
    console.log('invoked');
    if (this.currentSlide < this.slideCount) {
      list.style.transform = `translateX(-${this.currentSlide * this.items}px)`;
      this.currentSlide += 1;
    } else {
      this.stopSlideshow();
      list.style.transform = `translateX(0)`;
      this.currentSlide = 1;
    }
  }

  // Trying to make a method with setInterval() so that the slide runs every 5 seconds.
  startSlideshow() {
    this.stopSlideshow();
    this.slideTransitionInterval = setInterval(this.transitionSlide.bind(this), 500);
  }
  
  stopSlideshow() {
    if (this.slideTransitionInterval) {
      clearInterval(this.slideTransitionInterval);
    }
  }

}

const pics = new Gallery(list);
pics.startSlideshow();
.title {
  width: 100%;
  text-align: center;
}

.gallery {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  padding: 0;
  transition: all 500ms ease;
}


.gallery-container {
  overflow: hidden;
  position: relative;
  width: 1000px;
  margin: 0 auto;
}

.gallery__item {
  list-style: none;
  height: 500px;
  min-width: 1000px;
  background-position: center center;
  background-size: cover;
}
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="style.css">
  <title>Document</title>
</head>
<body>
  <h1 class="title">Gallery of Real Cool JS3 Images</h1>
  <div class="gallery-container">
    <ul class="gallery js-gallery">
      <li class="gallery__item js-gallery-item" style="background-image: url('https://picsum.photos/1000/650/?image=1062')"></li>
      <li class="gallery__item js-gallery-item" style="background-image: url('https://picsum.photos/1000/650/?image=837')"></li>
      <li class="gallery__item js-gallery-item" style="background-image: url('https://picsum.photos/1000/650/?image=1025')"></li>
      <li class="gallery__item js-gallery-item" style="background-image: url('https://picsum.photos/1000/650/?image=237')"></li>
    </ul>
  </div>
  <script src="script.js" defer></script>
</body>
</html>

如何将setInterval()传递到JavaScript类方法中?

怪我太投入 2025-02-02 17:31:18

tl; dr 为了使圣所起作用,服务器和客户端必须在同一顶级域上,不同的端口还可以。对于使用圣所的本地开发,localhost是最简单的解决方案,如 lar noreferrer“> laravel breeze 建议包装。

假设您正在端口8080上运行前端,然后在端口8000上进行后端。

  1. .env
APP_URL=http://localhost:8000
FRONTEND_URL=http://localhost:8080
  1. config/sanctum.php
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf(
        '%s%s%s',
        'localhost,localhost:8080,127.0.0.1,127.0.0.1:8000,::1',
        env('APP_URL') ? ','.parse_url(env('APP_URL'), PHP_URL_HOST) : '',
        env('FRONTEND_URL') ? ','.parse_url(env('FRONTEND_URL'), PHP_URL_HOST) : ''
    ))),

注意以上示例中的端口8080和8000

php artisan config:cache

。正确,只需检查上面的两个配置,然后将其他配置转换为默认情况。

tl;dr In order to make Sanctum work, the server and client have to be on the same top-level domain, different ports are ok. For local development with Sanctum, localhost is the easiest solution as Laravel Breeze package recommended.

Let's assume you're running frontend on port 8080 and backend on port 8000.

  1. In .env
APP_URL=http://localhost:8000
FRONTEND_URL=http://localhost:8080
  1. In config/sanctum.php
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf(
        '%s%s%s',
        'localhost,localhost:8080,127.0.0.1,127.0.0.1:8000,::1',
        env('APP_URL') ? ','.parse_url(env('APP_URL'), PHP_URL_HOST) : '',
        env('FRONTEND_URL') ? ','.parse_url(env('FRONTEND_URL'), PHP_URL_HOST) : ''
    ))),

notice port 8080 and 8000 in the above example.

  1. Make sure configs are cached properly:
php artisan config:cache

Your frontend seemed right so just check two configs above and reverse others to default.

Laravel Sanctum 401未经授权的响应

怪我太投入 2025-02-02 14:56:51

不,在调用暂停改造和房间的功能时,您无需切换上下文。我不确定他们是否在引擎盖下使用dispatcher.io,也许他们使用由线程池组成的自定义上下文,但可以保证在背景线程中调用。

例如,您可以在viewModel类中呼叫susthend dao函数类似:

viewModelScope.launch {
    val user dao.getCurrentUser()
    // Update UI using user
}

假设getCurrentUser() as susth 功能:

suspend fun getCurrentUser(): User

No, you don't need to switch context when calling suspend functions of Retrofit and Room. I'm not sure if they use Dispatcher.IO under the hood, maybe they use their custom context composed of thread pools, but it is guaranteed to be called in background thread.

For example you can call suspend Dao functions in ViewModel class like the following:

viewModelScope.launch {
    val user dao.getCurrentUser()
    // Update UI using user
}

assuming getCurrentUser() is a suspend function:

suspend fun getCurrentUser(): User

在使用改造和房间时,我需要提及Coroutine调度员吗?

怪我太投入 2025-02-02 13:53:26

Typescript具有 enum type -type -type

enum ViewDirection {
  Horizontal = "Horizontal",
  Down = "Vertical",
}

-from typescript文档

在现代打字稿中,当对象具有AS时,您可能不需要枚举
const可能就足够:

因此,您可以做:

const ViewDirection = {
  Horizontal = "Horizontal",
  Down = "Vertical",
} as const;

vs字符串类型

如果字符串的值发生更改,则使用字符串 - 启动器仅表示1个字符串,而使用字符串式式型字符串表示,则意味着更改它们到处使用。

用外行术语,您可以将Horizo​​ntal =“ Horizo​​ntal”更改为horizo​​ntal =“ H”,而无需在使用字符串枚举时到处更改它。

此处的更多深入:

TS 类型

Typescript has an Enum type -

enum ViewDirection {
  Horizontal = "Horizontal",
  Down = "Vertical",
}

From TypeScript Docs:

In modern TypeScript, you may not need an enum when an object with as
const could suffice:

So you can do:

const ViewDirection = {
  Horizontal = "Horizontal",
  Down = "Vertical",
} as const;

VS String Type

If the values of the strings are subject to change then using a string-enum means only changing 1 string literal, whereas using a string-type means changing them everywhere they're used.

In layman terms you can change Horizontal = "Horizontal" to Horizontal = "H" without the need to change it everywhere when using a string enum.

More in depth here:

Difference between string enums and string literal types in TS

JS:定义功能参数的选项

怪我太投入 2025-02-02 11:57:48

我发现,没有任何方法可以与近孔一起使用:isempty()keyset()始终不会返回连接,因为这些方法不是proxy-object方法。因此,我可以在此处使用getall() get()方法。

I found that not any method can be used with NearCache: isEmpty() or keySet() will always return no connection because these methods are not proxy-object methods. So I may use getAll() or get() methods here.

Hazelcast 5.1近距离服务器 - 客户端(找不到连接)

怪我太投入 2025-02-02 07:56:04

通常,浏览器将阻止您编辑硬盘驱动器上的任何文件的内容,或者从另一个域/基本URL提供的任何页面。但是,如果两个文件都在与下面所示的同一项目中,则可以从另一个文件进行临时编辑;

/http
|-index.html
|-template.html
|-hello.png

index.html可以包含a &lt; script&gt;标记以下标签,

// first we open a popup showing the other page
let window_template = open("template.html","_blank")

// now we can do whatever we want in the popup window from the original index.html:
let new_img = window_template.document.createElement("img")
new_img.src = "hello.png"
window_template.document.body.appendChild(new_img)

这不会(也不能)将任何更改保存到“ Template.html”。

要实际更改文件,您需要运行自己的服务器。然后,index.html可以将请求发送到服务器,并且服务器将有能力代表基于浏览器的应用程序进行编辑。查看Node.js和Express Server库...我发现随着服务器框架的发展,它足够接近。

In general the browser will prevent you from editing the content of any file on your hard drive, or any page served from another domain/base url. However, if both files are in the same project as shown below, you can make temporary edits to one file from the other;

/http
|-index.html
|-template.html
|-hello.png

index.html can contain a <script> tag with the following

// first we open a popup showing the other page
let window_template = open("template.html","_blank")

// now we can do whatever we want in the popup window from the original index.html:
let new_img = window_template.document.createElement("img")
new_img.src = "hello.png"
window_template.document.body.appendChild(new_img)

This does not (and cannot) save any changes to "template.html".

To actually make changes to files, you need to run your own server. Then index.html can send a request to the server, and the server will have the ability to make edits on behalf of your browser-based app. Check out Node.js and the Express server library... I found it approachable enough as server frameworks go.

如何通过单击另一个HTML文件的元素来更改HTML文件的内容(例如更改图像)

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

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