一场春暖

文章 评论 浏览 29

一场春暖 2025-02-20 20:25:25

这是一种通用的多维形式,可以在每个级别上进行逆转和/或映射。

用打字稿编写。对于JavaScript,请查看此 jsfiddle

代码

type itemMap = (n: any) => any;

interface SortConfig<T> {
  key: keyof T;
  reverse?: boolean;
  map?: itemMap;
}

export function byObjectValues<T extends object>(keys: ((keyof T) | SortConfig<T>)[]): (a: T, b: T) => 0 | 1 | -1 {
  return function(a: T, b: T) {
    const firstKey: keyof T | SortConfig<T> = keys[0];
    const isSimple = typeof firstKey === 'string';
    const key: keyof T = isSimple ? (firstKey as keyof T) : (firstKey as SortConfig<T>).key;
    const reverse: boolean = isSimple ? false : !!(firstKey as SortConfig<T>).reverse;
    const map: itemMap | null = isSimple ? null : (firstKey as SortConfig<T>).map || null;

    const valA = map ? map(a[key]) : a[key];
    const valB = map ? map(b[key]) : b[key];
    if (valA === valB) {
      if (keys.length === 1) {
        return 0;
      }
      return byObjectValues<T>(keys.slice(1))(a, b);
    }
    if (reverse) {
      return valA > valB ? -1 : 1;
    }
    return valA > valB ? 1 : -1;
  };
}

用法用

姓氏和姓氏来分类一个人阵列的 代码示例:

interface Person {
  firstName: string;
  lastName: string;
}

people.sort(byObjectValues<Person>(['lastName','firstName']));

按其 name 对语言代码进行排序,而不是其语言代码(请参阅 MAP ),然后通过 discending 版本(请参阅 reververs )。

interface Language {
  code: string;
  version: number;
}

// languageCodeToName(code) is defined elsewhere in code

languageCodes.sort(byObjectValues<Language>([
  {
    key: 'code',
    map(code:string) => languageCodeToName(code),
  },
  {
    key: 'version',
    reverse: true,
  }
]));

Here's a generic multidimensional sort, allowing for reversing and/or mapping on each level.

Written in Typescript. For Javascript, check out this JSFiddle

The Code

type itemMap = (n: any) => any;

interface SortConfig<T> {
  key: keyof T;
  reverse?: boolean;
  map?: itemMap;
}

export function byObjectValues<T extends object>(keys: ((keyof T) | SortConfig<T>)[]): (a: T, b: T) => 0 | 1 | -1 {
  return function(a: T, b: T) {
    const firstKey: keyof T | SortConfig<T> = keys[0];
    const isSimple = typeof firstKey === 'string';
    const key: keyof T = isSimple ? (firstKey as keyof T) : (firstKey as SortConfig<T>).key;
    const reverse: boolean = isSimple ? false : !!(firstKey as SortConfig<T>).reverse;
    const map: itemMap | null = isSimple ? null : (firstKey as SortConfig<T>).map || null;

    const valA = map ? map(a[key]) : a[key];
    const valB = map ? map(b[key]) : b[key];
    if (valA === valB) {
      if (keys.length === 1) {
        return 0;
      }
      return byObjectValues<T>(keys.slice(1))(a, b);
    }
    if (reverse) {
      return valA > valB ? -1 : 1;
    }
    return valA > valB ? 1 : -1;
  };
}

Usage Examples

Sorting a people array by last name, then first name:

interface Person {
  firstName: string;
  lastName: string;
}

people.sort(byObjectValues<Person>(['lastName','firstName']));

Sort language codes by their name, not their language code (see map), then by descending version (see reverse).

interface Language {
  code: string;
  version: number;
}

// languageCodeToName(code) is defined elsewhere in code

languageCodes.sort(byObjectValues<Language>([
  {
    key: 'code',
    map(code:string) => languageCodeToName(code),
  },
  {
    key: 'version',
    reverse: true,
  }
]));

如何通过多个字段对对象进行排序?

一场春暖 2025-02-20 18:45:37

tokenvalidationParameters 您设置 valialateAdience = true 中,这意味着将检查 aud> aud> aud -claim。但是,您永远不会为有效audience 设置值,也不要在令牌中添加 aud> claim。

您可以通过设置

ValidateAudience = false

或添加有效audience 之类的

ValidAudience = "audience"

aud> aud -claim with:

var jwt = new JwtSecurityToken(claims: claims, 
                audience: "audience",
                signingCredentials: signingCredentials, 
                expires: DateTime.Now.AddMinutes(30));

您可以阅读 this问/a 要了解有关 aud> aud 索赔的含义的更多信息。

除了受众外,还有发行人( ISS -Claim),可以以相同的方式进行验证。

TokenValidationParameters 添加/更改设置中:

ValidateIssuer = true
ValidIssuer = "issuer"

然后在创建令牌时将发行器传递给构造函数:

var jwt = new JwtSecurityToken(claims: claims, 
                issuer: "issuer"
                audience: "audience",
                signingCredentials: signingCredentials, 
                expires: DateTime.Now.AddMinutes(30));

In the tokenValidationParameters you set ValidateAudience = true, which means that the aud-claim will be checked. But you never set a value for ValidAudience and also don't add an aud-claim to the token.

You can either turn off the check by setting

ValidateAudience = false

or add a ValidAudiencelike e.g:

ValidAudience = "audience"

and add the aud-claim with:

var jwt = new JwtSecurityToken(claims: claims, 
                audience: "audience",
                signingCredentials: signingCredentials, 
                expires: DateTime.Now.AddMinutes(30));

You can read this Q/A to learn more about the meaning of the aud- claim.

Besides the audience, there's also the issuer (iss-claim), which can be validated in the same way.

In the tokenValidationParameters add/change the settings:

ValidateIssuer = true
ValidIssuer = "issuer"

and then pass the issuer to the constructor when you create the token:

var jwt = new JwtSecurityToken(claims: claims, 
                issuer: "issuer"
                audience: "audience",
                signingCredentials: signingCredentials, 
                expires: DateTime.Now.AddMinutes(30));

使用ASP.NET Core使用JWT令牌无效的令牌错误

一场春暖 2025-02-20 18:07:59

只需使用zipoutputstream,然后将其包裹在bytearrayoutputstream上:

ByteArrayOutputStream bStream = new ByteArrayOutputStream();
ZipOutputStream zipStream = new ZipOutputStream(bStream);

ZipEntry myEntry = ZipEntry("my/awesome/folder/file.txt");

zipStream.addEntry(myEntry);
zipStream.write(myAwesomeData);
//add and write more entries
zipStream.close();

byte[] result = bStream.toByteArray();

Just use ZipOutputStream, and wrap it around a ByteArrayOutputStream:

ByteArrayOutputStream bStream = new ByteArrayOutputStream();
ZipOutputStream zipStream = new ZipOutputStream(bStream);

ZipEntry myEntry = ZipEntry("my/awesome/folder/file.txt");

zipStream.addEntry(myEntry);
zipStream.write(myAwesomeData);
//add and write more entries
zipStream.close();

byte[] result = bStream.toByteArray();

在Java中使用文件创建结构化存档

一场春暖 2025-02-19 21:57:18

您将卷映射到/app 路径上。这将图像中该路径中的所有内容都隐藏起来,包括构建Dockerfile时安装的NPM软件包。

另外,您的端口映射与您的应用不符。您的应用在端口3000上听,因此您的应用程序应将端口3000映射到主机端口。

如果您使用此Docker-Compose文件,则可以使用。

version: '2'
services:
  testing:
    container_name: testing
    build:
      context: .
    ports:
      - 3000:3000

然后,您可以访问http:// localhost:3000/,您将获得“ Hello World!”信息。

You have a volume mapping onto the /app path. That hides everything in that path in the image, including the npm packages you install when building your Dockerfile.

Also, your port mappings don't match your app. Your app listens on port 3000, so your should map port 3000 to a host port.

If you use this docker-compose file, it'll work.

version: '2'
services:
  testing:
    container_name: testing
    build:
      context: .
    ports:
      - 3000:3000

Then you can go to http://localhost:3000/ and you'll get your "Hello World!" message.

节点V18.4.0上的Docker-Compose退出代码243

一场春暖 2025-02-19 18:59:31

我很确定您在每个目标上都需要唯一的名称。因此,您的代码应该是:

<target xsi:type="File" name="file" fileName="${basedir}/logs/${shortdate}.log"
        layout="${longdate} ${uppercase:${level}} ${message}" />
<target xsi:type="Database"
    name="database"
    connectionString="Data Source=R5-4500U\SQLEXPRESS;Initial Catalog=BlogDb;Integrated Security=True;"
    commandText="INSERT INTO Logs(CreatedOn,Message,Level,Exception,StackTrace,Logger,Url) VALUES (@datetime,@msg,@level,@exception,@trace,@logger,@url)">
        <parameter name="@datetime" layout="${date}" />
        <parameter name="@msg" layout="${message}" />
        <parameter name="@level" layout="${level}" />
        <parameter name="@exception" layout="${exception}" />
        <parameter name="@trace" layout="${stacktrace}" />
        <parameter name="@logger" layout="${logger}" />
        <parameter name="@url" layout="${aspnet-request-url}" />
</target>

...

<logger name="myAppLoggerRules" minlevel="Debug" writeTo="file" />
<logger name="myAppLoggerRules" minlevel="Debug" writeTo="database" />

I'm pretty sure you will need unique names on each target. So you code should be:

<target xsi:type="File" name="file" fileName="${basedir}/logs/${shortdate}.log"
        layout="${longdate} ${uppercase:${level}} ${message}" />
<target xsi:type="Database"
    name="database"
    connectionString="Data Source=R5-4500U\SQLEXPRESS;Initial Catalog=BlogDb;Integrated Security=True;"
    commandText="INSERT INTO Logs(CreatedOn,Message,Level,Exception,StackTrace,Logger,Url) VALUES (@datetime,@msg,@level,@exception,@trace,@logger,@url)">
        <parameter name="@datetime" layout="${date}" />
        <parameter name="@msg" layout="${message}" />
        <parameter name="@level" layout="${level}" />
        <parameter name="@exception" layout="${exception}" />
        <parameter name="@trace" layout="${stacktrace}" />
        <parameter name="@logger" layout="${logger}" />
        <parameter name="@url" layout="${aspnet-request-url}" />
</target>

...

<logger name="myAppLoggerRules" minlevel="Debug" writeTo="file" />
<logger name="myAppLoggerRules" minlevel="Debug" writeTo="database" />

NLOG正在写入数据库,但没有文件

一场春暖 2025-02-19 15:31:35

您必须在客户端上设置正确的选项 - 不在服务器上。这是一种影响端与SOLR身份验证的客户端的设置。

因此,运行应用程序时,将参数提供给 java 命令(或将其配置为通过ant/maven/gradle/etc的默认参数。

将其设置在docker容器上,将不会做任何有用的事情。

You'll have to set the correct options on the client - not on the server. This is a setting that affects how the client that connects to Solr authenticates.

So when running your application, give the parameter to the java command (or configure it to be the default parameter through ant/maven/gradle/etc.

Setting it on the docker container will not do anything useful.

向SOLR 8.6.1添加基本身份验证

一场春暖 2025-02-19 10:22:57

您可以使用:

  • case 语句提取您的特定键值
  • max contregation以删除 case catest将生成的null值,从而将其分组来自“ user ”表的其他选定列
SELECT u.*,
       MAX(CASE WHEN m.meta_key = 'key_1'
                THEN m.meta_value         END) AS key_1,
       MAX(CASE WHEN m.meta_key = 'key_2'
                THEN m.meta_value         END) AS key_2
FROM       user u
INNER JOIN meta m
        ON u.ID = m.user_id
GROUP BY u.ID,
         u.email,
         u.name

检查demo 在这里

You can use:

  • CASE statements to extract your specific key values
  • MAX aggregation to remove your NULL values that your CASE statement will generate, hence grouping on the other selected column from the "user" table
SELECT u.*,
       MAX(CASE WHEN m.meta_key = 'key_1'
                THEN m.meta_value         END) AS key_1,
       MAX(CASE WHEN m.meta_key = 'key_2'
                THEN m.meta_value         END) AS key_2
FROM       user u
INNER JOIN meta m
        ON u.ID = m.user_id
GROUP BY u.ID,
         u.email,
         u.name

Check the demo here.

从SQL中的行值对创建列

一场春暖 2025-02-19 05:05:41

当您获得旋转时,您会得到x,x,y,z,w)的x组件,在您的情况下,您需要欧拉角,因此请旋转。eulerangles.x

When you get rotation.x you get the x component of Quaternion (x,y,z,w) and in your case you need Euler Angles so get rotation.eulerAngles.x

quaternion.euler(obj.transform.rotation.x,obj.transform.Rotation.y,obj.transform.rotation.z)和obj.transform.rotation.rotation之间是否存在差异?

一场春暖 2025-02-19 01:01:44

处置功能的两种实现都是从呼叫者的角度来看。然后,您的班级将提供两种机制,以消除任何托管和未管理的资源,而呼叫者的应用程序决定选择什么。这也确保了任何无法使用异步模式的消费者不会丢失。

如果您确定或想强制班级的异步消费,则实际上不需要实现同步处置。

因此,根据您对班级使用的愿景,您可以选择如何处置对象。如果您选择保留这两种机制,则可以双向处理所有资源。

Both implementations of dispose feature is from the callers point of view. Your class would then offer both mechanisms to dispose off any managed and unmanaged resources and the caller application decides what to choose. This also ensures that any consumer which is unable to make use of asynchronous patterns are not lost.

You do not really need to implement synchronous dispose if you are sure about or want to force asynchronous consumption of your class.

So depending on your vision of class usage, you can choose how to dispose objects. If you choose to keep both mechanisms, you can dispose all resources both ways.

实施可iDisposable和iasyncdisposable

一场春暖 2025-02-18 17:57:03

有多种方法可以做到这一点。我认为最简单的是为此使用服务。目前,我们在.find上使用的是 https://graffle.io.io

您也可以使用其中一个SDK自己制作。 Kitty-items有一个 https://github.com/onflow/kitty/kitty-iTems/ << /a>在JavaScript中。

如果您喜欢Golang,我将有一些事件提取代码 https:// https:// github.com/bjartek/overflow/blob/main/overflow/event.go 。这是有关如何使用的示例:

There are multiple ways of doing this. The easiest I think is to use a service for this. The one we use at .find at the moment is https://graffle.io.

You could also make your own using one of the SDKs. Kitty-items has an example of this https://github.com/onflow/kitty-items/ in javascript.

If you prefer golang I have some event fetching code in overflow https://github.com/bjartek/overflow/blob/main/overflow/event.go. Here is an example on how it can be used: https://github.com/bjartek/overflow/blob/main/overflow/event_integration_test.go#L13

我该如何从流量区块链上的智能合约中听取活动?

一场春暖 2025-02-18 03:22:04

每当您在Maya中进行操作时,您都会在脚本编辑器中获得MEL命令回声。

在这种情况下,对于“插入edgeloop”操作,我得到了类似的东西: polysplitring -CH在-splittype 1-加权0.420764 -smoothingangle 30 -fixquads 1 -InterTwithEdgeflow 0;

您可以进一步探索MELA MELA'S MELA'S MELA'S MELA'S MELA'S MELAN''命令文档:
并搜索 polysplitring 命令:它列出了此命令的所有参数和一些示例。

Whenever you make an operation in maya, you'll get a MEL command echo in the script editor.

In this case, for 'insert edgeloop' operation I got something like: polySplitRing -ch on -splitType 1 -weight 0.420764 -smoothingAngle 30 -fixQuads 1 -insertWithEdgeFlow 0 ;

You can then look further into maya's MEL command documentation: https://help.autodesk.com/cloudhelp/2018/ENU/Maya-Tech-Docs/CommandsPython/
and search for polySplitRing command: it lists all the arguments for this command and some examples.

通过MEL脚本插入Edgeloop工具

一场春暖 2025-02-18 01:49:28

变量 player 在函数 main 中是本地的,因此在尝试在 game :: draw 中使用它的地方不可见。

一种解决方案可能是使 player 成为全局变量。您需要切换结构的顺序:

struct Player
{
    bool bGameOver = false;
    int x = 0;
    int y = 0;

};

Player player;

struct Game
{
    bool bGameOver = false;
    int iWidth = 20;
    int iHeight = 40;
    void Draw() {
        if (player.x == 5)
        {
            cout << "Hello"
        }
    }

};

但是我更喜欢建模物品,以便 game “具有” player 。因此,制作 player game 的成员:(

struct Player
{
    bool bGameOver = false;
    int x = 0;
    int y = 0;

};

struct Game
{
    Player player;
    bool bGameOver = false;
    int iWidth = 20;
    int iHeight = 40;
    void Draw() {
        if (player.x == 5)
        {
            cout << "Hello"
        }
    }

};

一边:您可能不需要两个不同的值称为 bgameover ,因为将它们保持在同步中将是额外的工作。

The variable player is local in function main, so it's not visible where you tried to use it in Game::Draw.

One solution could be to make player a global variable. You'll need to switch the order of the structs:

struct Player
{
    bool bGameOver = false;
    int x = 0;
    int y = 0;

};

Player player;

struct Game
{
    bool bGameOver = false;
    int iWidth = 20;
    int iHeight = 40;
    void Draw() {
        if (player.x == 5)
        {
            cout << "Hello"
        }
    }

};

But I'd prefer to instead model things so a Game "has a" Player. So make Player a member of the Game:

struct Player
{
    bool bGameOver = false;
    int x = 0;
    int y = 0;

};

struct Game
{
    Player player;
    bool bGameOver = false;
    int iWidth = 20;
    int iHeight = 40;
    void Draw() {
        if (player.x == 5)
        {
            cout << "Hello"
        }
    }

};

(Aside: You probably don't want two different values called bGameOver, since keeping them in sync would be extra work. It sounds more like a game property than a player property to me.)

如何在其他类方法中引用类属性?

一场春暖 2025-02-17 22:23:51

您可以用一组价格过滤。

const
    filterWithSet = s => ({ price }) => !s.has(price) && s.add(price),
    offersStep = [{ a: 1, price: 67.10 }, { a: 3, price: 88.20 }, { a: 5, price: 88.20 },  { a: 7, price: 57.10 }, { a: 13, price: 57.10 }, { a: 15, price: 57.10 }, { a: 29, price: 57.10 }, { a: 30, price: 57.10 }],
    result = offersStep.filter(filterWithSet(new Set));

console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

You could filter with a set of prices.

const
    filterWithSet = s => ({ price }) => !s.has(price) && s.add(price),
    offersStep = [{ a: 1, price: 67.10 }, { a: 3, price: 88.20 }, { a: 5, price: 88.20 },  { a: 7, price: 57.10 }, { a: 13, price: 57.10 }, { a: 15, price: 57.10 }, { a: 29, price: 57.10 }, { a: 30, price: 57.10 }],
    result = offersStep.filter(filterWithSet(new Set));

console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

如何过滤每个匹配的项目仅存储一次的对象数组

一场春暖 2025-02-17 11:28:01

hi,为了拥有 float 值,必须施放2或9个。但是,这必须在执行划分之前发生(2/9)产生类型 int 的结果,然后然后将其施加到 float
您应该做的是用这些选项替换该代码(对不起,我不是空间的粉丝):(

  • float)2 /9 * somme_diagonale(f)
  • 2 /(float)9 * somme_diagonale(f )
  • (float)2 /(float)9 * somme_diagonale(f)

Hi, in order to have a float value, either the 2 or the 9 must be cast. This, though, must happen before the division is performed. (2/9) produces a result of type int, which only then is cast to float.
What you should do is replace that piece of code with of these options (sorry in advance, I'm not a fan of spaces):

  • (float)2 / 9 * somme_diagonale(F)
  • 2 / (float)9 * somme_diagonale(F)
  • (float)2 / (float)9 * somme_diagonale(F)

打印功能返回(INT)和浮点数常数的乘法结果

一场春暖 2025-02-16 09:40:54

您可以使用 >。

df = df2.apply(lambda x:df1.iloc[0].div(x[df1.columns]), axis=1)

打印(DF):

               A     B          C      D
index                                   
0      10.000000   5.0  33.333333  200.0
1       1.428571  10.0  50.000000   10.0

You can use div.

df = df2.apply(lambda x:df1.iloc[0].div(x[df1.columns]), axis=1)

print(df):

               A     B          C      D
index                                   
0      10.000000   5.0  33.333333  200.0
1       1.428571  10.0  50.000000   10.0

python:在另一个数据框中的所有行中的所有行中的所有行中的行

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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