可遇━不可求

文章 评论 浏览 31

可遇━不可求 2025-02-20 20:41:30

您可以如下解决问题:

data[, `:=`(quant=sort(quant, TRUE), val=sort(val, TRUE))]

 head(data)
   quant      val
1:  1.00 181.2349
2:  0.98 161.2233
3:  0.96 156.2067
4:  0.94 155.6911
5:  0.92 154.7337
6:  0.90 147.7275

# or 
cols = c("quant", "val")
data[, (cols) := lapply(.SD, sort, TRUE), .SDcols=cols]

you can solve the problem as follows:

data[, `:=`(quant=sort(quant, TRUE), val=sort(val, TRUE))]

 head(data)
   quant      val
1:  1.00 181.2349
2:  0.98 161.2233
3:  0.96 156.2067
4:  0.94 155.6911
5:  0.92 154.7337
6:  0.90 147.7275

# or 
cols = c("quant", "val")
data[, (cols) := lapply(.SD, sort, TRUE), .SDcols=cols]

如何根据r中的另一列订购一列

可遇━不可求 2025-02-20 18:29:56

要创建具有必需值的新列表,您可以使用列表理解:

given = [[{a: 7}, "1", {x: 0.25}, "2"], [{y: 0.25, x: 1.5}, "4"], [{y: -0.75}, "3"]]
new_data = [[e for e in inner if isinstance(e, str)] for inner in given]

这意味着:“创建新列表,其中内部项目仅是字符串值”。

如果您需要修改给定的列表Inplote,则应执行以下操作:

given = [[{a: 7}, "1", {x: 0.25}, "2"], [{y: 0.25, x: 1.5}, "4"], [{y: -0.75}, "3"]]
for i, inner in enumerate(given):
    given[i] = [e for e in inner if isinstance(e, str)]

在此上下文中使用pop del 不建议使用,因为a)它在迭代期间更改列表长度(和容易发生),b)效率较低。

To create new list with required values, you can use list comprehension:

given = [[{a: 7}, "1", {x: 0.25}, "2"], [{y: 0.25, x: 1.5}, "4"], [{y: -0.75}, "3"]]
new_data = [[e for e in inner if isinstance(e, str)] for inner in given]

This means: "create new list of lists, where inner items are only string values".

If you need to modify given list inplace, the following should do:

given = [[{a: 7}, "1", {x: 0.25}, "2"], [{y: 0.25, x: 1.5}, "4"], [{y: -0.75}, "3"]]
for i, inner in enumerate(given):
    given[i] = [e for e in inner if isinstance(e, str)]

Using pop or del in such context is not advisable, because a) it changes list length during iteration (and is bug prone), and b) it is less efficient.

删除除字符串以外的所有元素

可遇━不可求 2025-02-20 12:53:56

您可以使用以下事实,即排回收索引,因此c(t,f)将从第一行开始其他行,c(f,t)将获得从第二行开始的所有其他行:

data.frame(x = df[c(F,T),], y = trimws(df[c(T,F),]))

输出

                                x                           y
1           2. Nepsalus jezoensis      species, hymenopterans
2      3. Prochas sp. 2 YYH-2022a            species, insects
3      4. Prochas sp. 1 YYH-2022a species, wasps, ants & bees
4  5. Eccoptopterus sp. 1 CP-2022 species, wasps, ants & bees
5     6. Andricus sp. 1 CYS-2022a            species, beetles
6     7. Paralabellula curvicauda species, wasps, ants & bees
7                8. Paralabellula            species, earwigs
8              9. Pristiphora sp.              genus, earwigs
9        10. Phyllotreta flexuosa      species, hymenopterans
10              11. Nematinae sp.            species, beetles
11                  12. Euura sp.      species, hymenopterans
12                13. Dolerus sp.      species, hymenopterans
13     14. Ivieolus inflaticollis      species, hymenopterans
14            15. Germarostes sp.            species, beetles
15       16. Germarostes globosus            species, beetles

You can use the fact that row indices are recycled so c(T,F) will get every other row starting with the first row and c(F,T) will get every other row starting with the second row:

data.frame(x = df[c(F,T),], y = trimws(df[c(T,F),]))

Output

                                x                           y
1           2. Nepsalus jezoensis      species, hymenopterans
2      3. Prochas sp. 2 YYH-2022a            species, insects
3      4. Prochas sp. 1 YYH-2022a species, wasps, ants & bees
4  5. Eccoptopterus sp. 1 CP-2022 species, wasps, ants & bees
5     6. Andricus sp. 1 CYS-2022a            species, beetles
6     7. Paralabellula curvicauda species, wasps, ants & bees
7                8. Paralabellula            species, earwigs
8              9. Pristiphora sp.              genus, earwigs
9        10. Phyllotreta flexuosa      species, hymenopterans
10              11. Nematinae sp.            species, beetles
11                  12. Euura sp.      species, hymenopterans
12                13. Dolerus sp.      species, hymenopterans
13     14. Ivieolus inflaticollis      species, hymenopterans
14            15. Germarostes sp.            species, beetles
15       16. Germarostes globosus            species, beetles

如何将一列的数据框架分为R中的两个列?

可遇━不可求 2025-02-20 09:29:54

在Ubuntu上,当Mysqli缺失时,执行以下操作,

sudo apt-get install php7.x-mysqli

sudo service apache2 restart

7.x替换为PHP版本。

注意:这可能是7.0及以上,但是例如,Drupal建议在安全方面推荐Php  7.2。

要检查您的PHP版本,请在命令行类型上

php -v

进行:如果您缺少MBSTRING,则完全相同:

apt-get install php7.x-mbstring

service apache2 restart

我最近必须为PHPMyAdmin执行此操作,而

On Ubuntu, when mysqli is missing, execute the following,

sudo apt-get install php7.x-mysqli

sudo service apache2 restart

Replace 7.x with your PHP version.

Note: This could be 7.0 and up, but for example Drupal recommends PHP 7.2 on grounds of security among others.

To check your PHP version, on the command-line type:

php -v

You do exactly the same if you are missing mbstring:

apt-get install php7.x-mbstring

service apache2 restart

I recently had to do this for phpMyAdmin when upgrading PHP from 7.0 to 7.2 on Ubuntu 16.04 (Xenial Xerus).

如何在PHP 7中启用MySQLI扩展名?

可遇━不可求 2025-02-20 02:39:39

显然,当我将身份验证条件添加到此特征时,我无法将特征添加到用户模型中。
如果我这样做,当用户模型启动时,它必须检查auth,则需要启动用户模型。这导致无限循环。

Apparently when I add the auth condition to this trait, I cannot add the trait to user model.
If I do, when the user model is booting, It must check the Auth, wich requires booting the user model. And this cause the infinite loop.

获取无限循环 - 在用户模型上添加特征的范围

可遇━不可求 2025-02-20 02:19:11

如果您使用的是Mamp Pro,那么简单的修复程序,我真的希望我在开始搜索互联网几天之前已经意识到这一点。它确实很简单...

您只需单击“ MAMP MySQL”选项卡中的“允许网络访问MySQL”即可。

真的,那就是这样。

哦,您可能仍然必须将绑定地址更改为上面帖子中概述的0.0.0.0或127.0.0.1,但是如果您是MAMP用户,则单击该框可能会解决您的问题。

If you are using MAMP PRO, the easy fix, which I really wish I had realized before I started searching the internet for days trying to figure this out. Its really this simple...

You just have to click "Allow Network Access to MySQL" from the MAMP MySQL tab.

Really, thats it.

Oh, and you MIGHT have to still change your bind address to either 0.0.0.0 or 127.0.0.1 like outlined in the posts above, but clicking that box alone will probably solve your problems if you are a MAMP user.

求解“通信链接链接失败”与JDBC和MySQL

可遇━不可求 2025-02-19 18:13:04

这可以解决您的要求吗?

private static bool MatchesPattern(string input)
{
    const string fixedString = "ABCDExyz";
    return fixedString.Length == input.Length && fixedString.Substring(0, 5).Equals(input.Substring(0, 5));
}

在C#的最后版本中,您也可以使用范围:

private static bool MatchesPattern(string input)
{
    const string fixedString = "ABCDExyz";
    return fixedString.Length == input.Length && fixedString[..5].Equals(input[..5]);
}

请参阅此 fiddle

顺便说一句:您可能会使用正则表达式实现相同的操作。

Does this solve your requirements?

private static bool MatchesPattern(string input)
{
    const string fixedString = "ABCDExyz";
    return fixedString.Length == input.Length && fixedString.Substring(0, 5).Equals(input.Substring(0, 5));
}

In last versions of C# you can also use ranges:

private static bool MatchesPattern(string input)
{
    const string fixedString = "ABCDExyz";
    return fixedString.Length == input.Length && fixedString[..5].Equals(input[..5]);
}

See this fiddle.

BTW: You could probably achieve the same using regex.

如何在字符串中检查可变字符并与另一个相同长度的字符串匹配?

可遇━不可求 2025-02-19 08:53:35

KB5014959似乎打破了SSM 18.12.1和SSMS19。我卸载了它,但是它不断恢复,SSM仍然不起作用。 Windows 11和SSMS发生了什么?

似乎以前正在工作,但是愚蠢的更新并不能让我运行SSM,即使我卸载并暂停更新,它仍然会返回,或者也许实际上并没有像它说的那样卸载。

KB5014959 seems to break ssms 18.12.1 and ssms 19. I uninstall it, but it keeps coming back and ssms still does not work. What is going on with Windows 11 and SSMS?

It seemed like it was working before, but the stupid update doesn't let me run SSMS, even if I uninstall it and pause updates, it still comes back, or maybe it doesn't actually uninstall like it says it does.

Microsoft Visual Studio 2017 Shell(隔离) - 找不到一个或多个组件。请重新安装申请

可遇━不可求 2025-02-18 20:50:19

tl; dr “ foldater”读取XML布局文件,该文件定义了要创建的视图对象和放置在何处,并实际上进行了视图创建。

一些有用的术语:

  • view - 从view类继承的任何东西,例如textviewbutton
  • - 屏幕上不同视图对象的安排(这是您看到的应用程序)
  • xml布局文件 - 描述布局的XML文本文件 - 特别是视图中的内容该布局以及如何定位它们(​​例如activity_main.xml)。 XML文件不是布局,而是如何构建布局的描述。
  • foldater - 采用XML布局文件,读取并实际创建布局(视图对象的布置)的例程/对象。呼叫Aptrate在Exprater上返回View对象,其中包含您在XML文件中定义的所有内容。

更多细节

您在Android应用中看到的屏幕是“视图”的集合。这些可能是textViewCondectLayoutdedittextbutton等...-所有不同类型的类型视图(它们都从视图类继承)。

当您建立这些视图的布局时,通常会使用XML文件来定义要创建的视图以及将这些视图定位的位置。 XML文件不是视图本身,而是对应如何构造和定位视图的描述。

布局Afterater将其XML文件供电,实际上是在您在应用程序中的屏幕上看到视图时要构建视图。当您调用Aptrate时,它会从XML文件中读取有关视图的所有数据,创建这些视图的实例,并根据您告诉您在XML文件中使用的操作将其定位在父视图容器中。

在您显示的示例代码中(从recyclerview适配器)中,它引用的XML文件是描述如何在RecyClerview中给定行中排列视图的XML文件。一旦适配器“夸大”该行的视图,则创建了实际的视图对象(例如textView s)并将其定位在该行中。

RecyClerview适配器将多次调用此方法,以“夸大”每个显示的行的新唯一视图实例。 RecyClerview的“回收器”一部分意味着它将尽量不要将其调用超过必要的要求,并将在您滚动时可以重新使用新行的视图。

其他阅读

TL;DR The "inflater" reads the XML layout file, which defined what View objects to create and where to put them, and actually does the View creation.

Some helpful terms:

  • View - Anything that inherits from the View class, e.g. TextView or Button
  • Layout - an arrangement of different View objects on the screen (this is what you see looking at the app)
  • XML Layout File - An XML text file that describes a layout - specifically what Views go in that layout and how to position them (e.g. activity_main.xml). The XML file is not the layout, it is a description of how to build the layout.
  • Inflater - A routine/object that takes an XML layout file, reads it, and actually creates the Layout (arrangement of View objects). Calling inflate on the inflater returns a View object that contains everything you defined in the XML file.

More Details

A screen you see in an Android app is a collection of "Views". These may be things like TextView, ConstraintLayout, EditText, Button, etc... - all different types of views (they all inherit from the View class).

When you build up a layout of those views you typically use an XML file to define what views to create and where to position those views. The XML file is not the view itself, it is just a description of how the views should be constructed and positioned.

The layout inflater takes that XML file and actually goes about building the views as you see them on the screen in the app. When you call inflate it reads all the data about the views from the XML file, creates instances of those views, and positions them in the parent view container based on what you told it to do in the XML file.

In the example code you showed (from a RecyclerView adapter) the XML file it is referring to is the one that describes how to arrange the views in a given row in the RecyclerView. Once the adapter "inflates" the view for that row, then the actual view objects (e.g. TextViews) have been created and positioned within that row.

The RecyclerView adapter will call this method multiple times, to "inflate" a new unique view instance for each displayed row. The "recycler" part of the RecyclerView means that it will try not to call this more than necessary, and will re-use the views on new rows where it can as you scroll.

Additional Reading

很难理解Layoutinflater Android Studio(Kotlin)

可遇━不可求 2025-02-18 16:08:26

React-Google-Login未更新为最新的React V18。
要么等待更新,要么降级对v17反应,要么使用 - force标志。

npm i react-google-login --force

请注意,通过使用 - 力量,不能保证此软件包将与React的V18一起使用

react-google-login is not updated to the latest react v18.
Either wait for an update, downgrade react to v17, or use --force flag.

npm i react-google-login --force

Note that by using --force, there is no guarantee that this package will work with v18 of react

我是否解析package.jason文件错误?

可遇━不可求 2025-02-18 15:28:31

使用Flutter_SVG软件包。

文档位于 https://pub.dev/packages/flutter_svg

Use flutter_svg package.

Documentation is at https://pub.dev/packages/flutter_svg.

如何与SVG图像在颤动中的相互作用?

可遇━不可求 2025-02-18 05:49:47

您可以每天从08:00 am到11:00 pm每天运行它。

0 08-23 * * *

您可以在在这里

You can use this to run it everyday at every hour from 08:00 am to 11:00 pm.

0 08-23 * * *

You can check the validation in here.

如何修复node.js中cron的设计模式错误?

可遇━不可求 2025-02-17 16:41:04

是否可以使用案例2进行链接列表?还插入,删除可能吗?

可能,这不是很有用。列表的最大尺寸仅限于您声明的变量数量,我怀疑您是否希望声明超过十几个单独的变量。

您可以做的事情是将数组用作备份商店 - 而不是声明单独的变量ab您可以声明10、100或1000个元素的数组,然后做类似的事情:

a[i].next = &a[j];

但是您仍然有限 - 您的列表永远不会比数组更大。使用动态内存的优点是,列表大小不限(至少不是固定的编译时限制);但是,这意味着要弄乱指针。

指针是C中编程的基本组成部分 - 如果没有以某种方式使用指针的情况下,您就无法编写有用的C代码。

edit :链接列表的更现实的实现将使用insert函数

/**
 * Inserts items into the list in ascending order.
 *
 * If the list is empty (head is NULL) or if the value
 * of the new node is less than the value of the current
 * head, then the new node becomes the new head of the
 * list.
 *
 * Returns the pointer to the new node.  If the allocation
 * was unsuccessful, it returns NULL.
 */
struct linknode *insert( struct linknode **head, int val )
{
  struct linknode *newnode = calloc( 1, sizeof *newnode );

  if ( !newnode )
    return NULL;

  newnode->data = val;
    
  if ( !*head )    
  {
    /**
     * list is empty, newnode becomes the head of the list.
     */
    *head = newnode;
  }
  else if ( newnode->data < (*head)->data )
  {
    /**
     * Value stored in newnode is less than the
     * value stored at the list head, newnode
     * becomes the new list head.
     */
    newnode->next = *head;
    *head = newnode;
  }
  else
  {
    /**
     * Iterate through the list and insert the 
     * newnode in the correct location. 
     */
    struct linknode *cur = *head;
    while ( cur->next && cur->next->data < newnode->data )
      cur = cur->next;
    newnode->next = cur->next;
    cur->next = newnode;
  }
  return newnode;
} 

,它将被类似地使用:

int main( void )
{
  struct linknode *list = NULL;
  int val;

  while ( scanf( "%d", &val ) == 1 )
  {
    if ( !insert( &list, val ) )
    { 
      fprintf( stderr, "Could not add %d to list, not taking any more input...\n", val );
      break;
    }
  }
  ...
}

因此,列表的元素被分配并动态添加,并且您只受到可用内存量的限制。

Isn't it possible to make linked list with case 2? also insert, delete being possible?

It is possible, it just isn’t very useful. The maximum size of your list is limited to the number of variables you declare, and I doubt you’re going to want to declare more than a dozen separate variables.

Something you can do is use an array as your backing store - instead of declaring separate variables a and b you can declare an array of 10, 100, or 1000 elements, then do something like:

a[i].next = &a[j];

But you’re still limited - your list can never be bigger than the array. The advantage of using dynamic memory is that the list size isn’t limited (at least, not some fixed compile-time limit); however, it means messing with pointers.

Pointers are a fundamental part of programming in C - you cannot write useful C code without using pointers in some fashion.

Edit: A more realistic implementation of a linked list would use an insert function like

/**
 * Inserts items into the list in ascending order.
 *
 * If the list is empty (head is NULL) or if the value
 * of the new node is less than the value of the current
 * head, then the new node becomes the new head of the
 * list.
 *
 * Returns the pointer to the new node.  If the allocation
 * was unsuccessful, it returns NULL.
 */
struct linknode *insert( struct linknode **head, int val )
{
  struct linknode *newnode = calloc( 1, sizeof *newnode );

  if ( !newnode )
    return NULL;

  newnode->data = val;
    
  if ( !*head )    
  {
    /**
     * list is empty, newnode becomes the head of the list.
     */
    *head = newnode;
  }
  else if ( newnode->data < (*head)->data )
  {
    /**
     * Value stored in newnode is less than the
     * value stored at the list head, newnode
     * becomes the new list head.
     */
    newnode->next = *head;
    *head = newnode;
  }
  else
  {
    /**
     * Iterate through the list and insert the 
     * newnode in the correct location. 
     */
    struct linknode *cur = *head;
    while ( cur->next && cur->next->data < newnode->data )
      cur = cur->next;
    newnode->next = cur->next;
    cur->next = newnode;
  }
  return newnode;
} 

and it would be used something like this:

int main( void )
{
  struct linknode *list = NULL;
  int val;

  while ( scanf( "%d", &val ) == 1 )
  {
    if ( !insert( &list, val ) )
    { 
      fprintf( stderr, "Could not add %d to list, not taking any more input...\n", val );
      break;
    }
  }
  ...
}

So the elements of the list are allocated and added dynamically, and you're only limited by the amount of memory you have available.

为什么在链接列表中声明指针?

可遇━不可求 2025-02-17 13:06:43

您的代码片段都是正确的,但是保存用户密码的方法在从Via Save方法中,保存密码的方式不正确,如果您想检查密码,它将密码的原始文本形式保存到数据库中。 ,只需打开您的数据库并检查密码字段,它们以原始文本格式存储(Exapmle:testing123),其中Django保存,检索,使用密码的SHA256的密码,直到和除非您没有指定它,否则PBKDF2_SHA256 ...这种格式。

不要这样的用户:

user = User(username = username , password = password , email = email)
user.save()

像这样

user = User(username = username , email = email)
user.set_password(password)
user.save()

更新您的代码段:

from django import forms
from django.contrib.auth import get_user_model, authenticate, login
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm

class UserRegisterForm(UserCreationForm):
    email = forms.EmailField()

    class Meta:
        model = get_user_model()
        fields = ['username', 'email', 'first_name']


    def save(self):
        self.clean()
        user = self.Meta.model(
            username = self.cleaned_data['username'], 
            email = self.cleaned_data['email'], 
        )
        user.set_password(self.cleaned_data['password2'])
        user.save()
        return user

这将完成所需的工作。

Your code snippets are all correct , but the way of saving the user's password is incorrect in the from via save method , the way you are saving the password , it saves the raw text form of the password to the database , if you want to check , just open your database and check the password fields , they are stored in raw text format ( exapmle : testing123) where as the django saves , retrieves , password using password hashing alogrithm of sha256 until and unless you have not specified it and its hashes to pbkdf2_sha256... this format .

dont save user like this :

user = User(username = username , password = password , email = email)
user.save()

save like this

user = User(username = username , email = email)
user.set_password(password)
user.save()

Update your code snippet :

from django import forms
from django.contrib.auth import get_user_model, authenticate, login
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm

class UserRegisterForm(UserCreationForm):
    email = forms.EmailField()

    class Meta:
        model = get_user_model()
        fields = ['username', 'email', 'first_name']


    def save(self):
        self.clean()
        user = self.Meta.model(
            username = self.cleaned_data['username'], 
            email = self.cleaned_data['email'], 
        )
        user.set_password(self.cleaned_data['password2'])
        user.save()
        return user

This will do the required work.

在我的django authenticationform中,用户名和密码总是不正确

可遇━不可求 2025-02-17 07:45:43

看起来还不错。但是,只需要一个循环:

public function dataValidator($data)
{
    foreach($data as $key => $value) {
        $valid = current(array_filter($formDefinition, function($form) use($key) { return $form->key === $key; }));
        if(!$valid) {
            return 'invalid';
        }
    }
}

下次短提示:尝试一下即可。这可能避免了不必要的问题,因为您可能已经从结果中获得了答案。如果没有,您至少有足够的调试信息与我们分享;-)

Doesn't look that bad. However, only one loop is required:

public function dataValidator($data)
{
    foreach($data as $key => $value) {
        $valid = current(array_filter($formDefinition, function($form) use($key) { return $form->key === $key; }));
        if(!$valid) {
            return 'invalid';
        }
    }
}

Short tip for next time: Just try it out. That might avoid unnecessary questions since you might already get the answers from the result. And if not, you at least have sufficient debugging information to share with us ;-)

是否在PHP中使用另一个JSON来验证JSON对象

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

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