自由如风

文章 评论 浏览 28

自由如风 2025-02-21 01:44:11

如果我理解正确,那么您可以这样做:

public function associate($user_id, $parentModelInstance)
{
    $user = User::find($user_id); //or how ever you get user in repository
    $reflect = new ReflectionClass($parentModelInstance);
    $relationName = Str::lower($reflect->getShortName()); //magic for getting relation (if class name is relation name)

    return $user->{$relationName}()->associate($parentModelInstance)->save();
}

您可以这样使用:

$distributor = Distributor::find(1);
$user_id = 1;

$this->associate($user_id, $distributor)

If I understand right, then you can do it with:

public function associate($user_id, $parentModelInstance)
{
    $user = User::find($user_id); //or how ever you get user in repository
    $reflect = new ReflectionClass($parentModelInstance);
    $relationName = Str::lower($reflect->getShortName()); //magic for getting relation (if class name is relation name)

    return $user->{$relationName}()->associate($parentModelInstance)->save();
}

And you can use it like this:

$distributor = Distributor::find(1);
$user_id = 1;

$this->associate($user_id, $distributor)

Laravel通过模型实例交往关系

自由如风 2025-02-20 20:06:41

我能够解决我的问题,我将离开我的方法来解决这个问题,也许它将帮助其他朋友

$('#productSize').selectpicker('refresh');

I was able to solve my problem, I will leave my method to solve this problem, maybe it will help other friends

$('#productSize').selectpicker('refresh');

使用AJAX输入产品代码后,更改下拉列表

自由如风 2025-02-20 19:13:45

gitlab 15.7 (2022年12月)提出了一种替代方法,该方法没有每个项目都涉及创建新代理

在个人名称空间中共享CI/CD访问代理

Kubernetes的GitLab代理提供了一种更安全的解决方案,用于使用Gitlab CI/CD管理簇。
您可以通过共享访问权限将单个代理与多个项目和组一起使用
到代理连接。在以前的版本中,您无法与个人共享访问权限
名称空间。此版本为个人名称空间增加了对CI/CD连接共享的支持。
您现在可以使用个人名称空间下任何项目的单个代理。

“

请参阅 evarese 。。

这意味着从单个代理商那里,您应该能够从多个项目(是否个人名称空间)访问代理连接。

GitLab 15.7 (December 2022) suggests an alternative approach, which does not involve creating a new agent per project

Share CI/CD access to the agent within a personal namespace

The GitLab agent for Kubernetes provides a more secure solution for managing your clusters with GitLab CI/CD.
You can use a single agent with multiple projects and groups by sharing access
to the agent connection. In previous releases, you could not share access with personal
namespaces. This release adds support for CI/CD connection sharing to personal namespaces.
You can now use a single agent from any of the projects under your personal namespace.

https://about.gitlab.com/images/15_7/configure-allow-agent-cicd-access-sharing-within-a-personal-namesp.png -- Share CI/CD access to the agent within a personal namespace

See Documentation and Issue.

That means from a single agent, you should be able to access an agent connection from multiple projects (personal namespace or not).

无法为kubernetes配置gitlab代理

自由如风 2025-02-20 17:21:53

您可以使用参数并在Office脚本中返回值以在功率自动流量中传递往返和Excel Workbook的数据。这些样本可能会为您提供帮助:

基本上,您创建的流程应该看起来像这样:

您的流程将运行一个脚本以获取列表Manager/Store列表配对中的配对。对于每个经理,第二个脚本将在文件1上运行,该脚本将接收客户经理负责的商店(从第一个脚本返回并在第二个脚本中作为参数发送)为了寻找匹配行。然后,该脚本将返回匹配文件1中的商店列表参数的行。接下来,将在您所需的位置创建模板文件的副本,另一个脚本将运行以添加从上一个脚本返回的行中的行中文件。

以下是我创建的脚本以自动化此工作流程,但是您可以以多种方式这样做。

获取经理和存储对:

 function main(workbook: ExcelScript.Workbook): AccountManager[]{
    let worksheet = workbook.getWorksheet("Account Manager Data");

    //gets the first table in the worksheet
    let table = worksheet.getTables()[0];


    let numRows = table.getRowCount();
    let tableValues = table.getRangeBetweenHeaderAndTotal().getValues();
    let managerColumn = table.getColumnByName("Account Manager").getIndex();
    let storeColumn = table.getColumnByName("Store").getIndex();
    let managerMap: Map<string, string[]> = new Map();
    let managerArray: AccountManager[] = []

    //iterate through table and add manager/store pair to managerArray
    for (let i=0; i<numRows; i++){
      let managerName = ""+tableValues[i][managerColumn]
      if (!managerMap.has(managerName)){
        managerMap.set(managerName, [""+tableValues[i][storeColumn]])
      }
      else{
        managerMap.get(managerName).push("" + tableValues[i][storeColumn]);
      }
    }

    managerMap.forEach(function (value, key){
      managerArray.push({manager: key, stores: value})
    });

    return managerArray; 
}

interface AccountManager{
  manager: string
  stores: string[]
}

获取商店数据脚本:

function main(workbook: ExcelScript.Workbook, store: string[]): (string|boolean|number)[][] {
    let table = workbook.getWorksheet("Store Data").getTables()[0];
    let numRows = table.getRowCount();
    let tableValues = table.getRangeBetweenHeaderAndTotal().getValues();
    let storeColumn = table.getColumnByName("Store").getIndex();
    let store_Data: (string|boolean|number)[][] = [];
    store_Data.push(table.getHeaderRowRange().getValues()[0])
    for (let j=0; j< store.length; j++){
      for (let i =0; i<numRows; i++){
        if (store[j] === tableValues[i][storeColumn].toString().trim()){
            store_Data.push(tableValues[i]);
        }
      }
    }
    console.log(store_Data)
    
    return store_Data
}

将数据添加到存储特定的工作簿脚本:

function main(workbook: ExcelScript.Workbook, store_Data: string[][]) {
  let selectedSheet = workbook.getWorksheet("Sheet1");

  let table_Range =selectedSheet.getRange("A1").getResizedRange(store_Data.length-1, store_Data[0].length-1)
  table_Range.setValues(store_Data);
  let table = workbook.addTable(table_Range, true);
}

希望这会有所帮助,并让我知道您是否有任何疑问!

You can use parameters and return values in an Office Script to pass data to and from and Excel workbook in a Power Automate Flow. These samples may help you:

Basically, your Flow that you create should look something like this:
Power Automate Flow to create separate workbooks from a table in a master file

Your Flow will run a script to get the list of manager/store list pairings in File 2. For each manager, a second script will run on File 1 that will take the stores that the account manager is responsible for (returned from the first script and sent as a parameter in the second script) in order to look for the matching rows. Then, that script will return the rows matching the store list parameter in File 1. Next, a copy of a template file will be created in your desired location, and another script will run to add the rows returned from the previous script to that new file.

Below are the scripts I created to automate this workflow, but you could do so in a variety of ways.

Get Manager and Store Pairs:

 function main(workbook: ExcelScript.Workbook): AccountManager[]{
    let worksheet = workbook.getWorksheet("Account Manager Data");

    //gets the first table in the worksheet
    let table = worksheet.getTables()[0];


    let numRows = table.getRowCount();
    let tableValues = table.getRangeBetweenHeaderAndTotal().getValues();
    let managerColumn = table.getColumnByName("Account Manager").getIndex();
    let storeColumn = table.getColumnByName("Store").getIndex();
    let managerMap: Map<string, string[]> = new Map();
    let managerArray: AccountManager[] = []

    //iterate through table and add manager/store pair to managerArray
    for (let i=0; i<numRows; i++){
      let managerName = ""+tableValues[i][managerColumn]
      if (!managerMap.has(managerName)){
        managerMap.set(managerName, [""+tableValues[i][storeColumn]])
      }
      else{
        managerMap.get(managerName).push("" + tableValues[i][storeColumn]);
      }
    }

    managerMap.forEach(function (value, key){
      managerArray.push({manager: key, stores: value})
    });

    return managerArray; 
}

interface AccountManager{
  manager: string
  stores: string[]
}

Get Store Data Script:

function main(workbook: ExcelScript.Workbook, store: string[]): (string|boolean|number)[][] {
    let table = workbook.getWorksheet("Store Data").getTables()[0];
    let numRows = table.getRowCount();
    let tableValues = table.getRangeBetweenHeaderAndTotal().getValues();
    let storeColumn = table.getColumnByName("Store").getIndex();
    let store_Data: (string|boolean|number)[][] = [];
    store_Data.push(table.getHeaderRowRange().getValues()[0])
    for (let j=0; j< store.length; j++){
      for (let i =0; i<numRows; i++){
        if (store[j] === tableValues[i][storeColumn].toString().trim()){
            store_Data.push(tableValues[i]);
        }
      }
    }
    console.log(store_Data)
    
    return store_Data
}

Add Data to Store Specific Workbooks Script:

function main(workbook: ExcelScript.Workbook, store_Data: string[][]) {
  let selectedSheet = workbook.getWorksheet("Sheet1");

  let table_Range =selectedSheet.getRange("A1").getResizedRange(store_Data.length-1, store_Data[0].length-1)
  table_Range.setValues(store_Data);
  let table = workbook.addTable(table_Range, true);
}

Hope this helps and let me know if you have any questions!

基于其他文件拆分Excel文件

自由如风 2025-02-20 08:10:47

我们需要将功能作为支撑传递给第二个组件。

FirstComponent

<SecondComponent { ...data } onClick={ () => manageClick() } />

在第二个组件中使用单击时使用OnClick Prop。

第二组件

<button onClick={onClick}>Click</button>

we need to pass the function as a prop to the second component.

FirstComponent

<SecondComponent { ...data } onClick={ () => manageClick() } />

in the second Component use the onClick prop on click.

SecondComponent

<button onClick={onClick}>Click</button>

如何将onclick()事件从react中的父组件中的按钮中传递给子组件?

自由如风 2025-02-20 05:39:52
def home(request):
    # ...
    return render(request,'home.html',{'mydata': mydata, 'product_data':product_data})

def home(request):
    # ...
    return render(request,'home.html',{'mydata': mydata, 'product_data':product_data})

返回多个变量Django的渲染

自由如风 2025-02-20 01:07:50

正如@steveriesenberg在评论中指出的那样,联合的安全示例已经显示了如何使用自定义器来实现和删除索赔,以及将主名正常化。

如何自定义索赔。

如何正常化主名称

谢谢史蒂夫!

As @steveriesenberg pointed out in the comments, the federated security examples already show how adding and removing claims can be accomplished with the customizer as well as normalizing the principal name.

How to customize claims.

How to normalize principal name

Thank you Steve!

将联合身份验证令牌从远程系统转换为使用Spring授权服务器创建的自定义令牌

自由如风 2025-02-19 13:23:06

通过运行它而解决的问题

>browser-sync start --proxy localhost:8000

仍然无法弄清为什么我的webpack.mix.js被忽略了。

Solved by running this instead

>browser-sync start --proxy localhost:8000

Still couldnt figure it out why my webpack.mix.js was ignored.

browsersync不会从webpack加载代理

自由如风 2025-02-19 10:22:46

在更新一些依赖项之后,对我有用。

   <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>7.5.2</version>
        <exclusions>
            <exclusion>
                <groupId>io.netty</groupId>
                <artifactId>netty-all</artifactId>
            </exclusion>
            <exclusion>
                <groupId>io.netty</groupId>
                <artifactId>netty</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
     <dependency>
        <groupId>com.google.cloud.spark</groupId>
        <artifactId>spark-bigquery-with-dependencies_2.12</artifactId>
        <version>0.23.2</version>
    </dependency>

After updating some dependencies as shown below, it worked for me.

   <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>7.5.2</version>
        <exclusions>
            <exclusion>
                <groupId>io.netty</groupId>
                <artifactId>netty-all</artifactId>
            </exclusion>
            <exclusion>
                <groupId>io.netty</groupId>
                <artifactId>netty</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
     <dependency>
        <groupId>com.google.cloud.spark</groupId>
        <artifactId>spark-bigquery-with-dependencies_2.12</artifactId>
        <version>0.23.2</version>
    </dependency>

GCP DataProc上的SparkJob失败而失败-Java.lang.nosuchmethoderror:io.netty.buffer.pooledbydybytebufallocator。

自由如风 2025-02-18 11:31:51

目前不是。如果您找到一种用最少的开销添加此方法的方法,则非常欢迎PR。

Update

这将在Alpha Preview目前的Redux Toolkit 1.9中提供。

Not at the moment. If you find a way to add this with minimal overhead, a PR is very welcome.

update

This will be available in Redux Toolkit 1.9, which is currently in alpha preview.

是否可以将``serializequeryargs''与注入的端点一起定位?

自由如风 2025-02-17 09:05:44

您的传递回调函数的语法不正确。 end()具有一个回调函数,因此您需要更改 .end(((err,res),()=&gt; { to .end(((err,res)=&gt; {)

Your syntax for passing callback function is incorrect. end() takes one callback function so you need to change .end((err,res), () =>{ to .end((err,res) =>{

获取参考:未定义ERR

自由如风 2025-02-17 09:03:42

我也有一个类似的问题,发现尽管{enabled:false}选项是fetchNextPage(),但还是触发了提取。

每当您使用fetchnextpage()时,您可以添加条件,例如,

if ( !!currentCity && typeof selectedPoint !== 'undefined' ) {
    fetchNextPage()
}

尽管我在文档中没有完全找到这种情况,但似乎可以依靠

I had a similar issue and have found that it was fetchNextPage() that triggered fetching despite {enabled: false} option.

You can add a condition whenever you use fetchNextPage(), e. g.

if ( !!currentCity && typeof selectedPoint !== 'undefined' ) {
    fetchNextPage()
}

Although I didn't find exactly this case in the documentation, it seems that one could rely on the description of "refetch" behavior. Anyway, I made a codesandbox example to test how this stuff works.

useInfinitequery在React Query中的启用选项不工作

自由如风 2025-02-17 08:25:38

哎呀,那是因为我的 app.component.ts 在其中有一个,并且在应用程序初始化应用程序(首先浏览到)时都会被

ngOnInit() {
  this.router.navigate(['/login']);
}

ngOnInit() { }

调用 如果您查看<<> logincomponent > >,则添加了一个没有映射的URL路由将转到登录页面,如果您查看<<<< login 页面代码>路由在这里:

const routes: Routes = [
  { path: "login", component: LoginComponent },
  { path: "create-account", component: CreateAccountComponent },
  { path: "password-reset", component: PasswordResetComponent },
  { path: "**", component: LoginComponent }
];

Whoops, it was because my app.component.ts had this in it, and it gets called for every route when the application is initialized (first browsed to):

ngOnInit() {
  this.router.navigate(['/login']);
}

I have refactored this to:

ngOnInit() { }

I have also added a wildcard route resolver to the LoginComponent instead, so that URL routes that have no mapping will go to the login page, if you look at the last element added in the Routes here:

const routes: Routes = [
  { path: "login", component: LoginComponent },
  { path: "create-account", component: CreateAccountComponent },
  { path: "password-reset", component: PasswordResetComponent },
  { path: "**", component: LoginComponent }
];

当手动导航到浏览器时,Angular应用程序没有加载我的组件路径

自由如风 2025-02-17 01:35:03

首先,选择您感兴趣的属性(例如:文件名)。
然后,您可以使用 split -path -leaf 获取没有文件夹的文件名。

由于您的 Get-HardDisk 命令可以返回多个磁盘,因此我在最后一部分中包含了 foreach ,以确保其与单个磁盘和多个磁盘一起使用。

(Get-VM -Name alex-deploy2-000638 | Get-Harddisk).FileName  | % {$_ | Split-Path -Leaf}

First, select the property you are interested in (eg: FileName).
Then, you can use Split-Path -Leaf to get the filename without the folder.

Since your Get-HardDisk command can return multiple disks, I included a Foreach for the last part, to make sure it work with a single disk and multiple disks.

(Get-VM -Name alex-deploy2-000638 | Get-Harddisk).FileName  | % {$_ | Split-Path -Leaf}

过滤powerCli命令的输出仅具有其中的一部分

自由如风 2025-02-16 08:34:16

您可以编写函数用于计算自定义损失 tp -fp -fp 如下:

import tensorflow_addons as tfa
import tensorflow as tf
import numpy as np

x_train = np.random.rand(1000,10)
y_train = np.random.randint(0, 2, 1000)
y_train = tf.keras.utils.to_categorical(y_train, 2)


tp = tf.keras.metrics.TruePositives()
fp = tf.keras.metrics.FalsePositives()
def diff(y_true, y_pred): 
    a = tp(y_true, y_pred) 
    b = fp(y_true, y_pred)
    return a - b

model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(units=64,input_shape=(10,), activation='relu'))
model.add(tf.keras.layers.Dense(32, activation='relu'))
model.add(tf.keras.layers.Dense(16, activation='relu'))
model.add(tf.keras.layers.Dense(2, activation='softmax'))
model.compile(optimizer='adam',
              loss = 'categorical_crossentropy',
              metrics=[diff, tf.keras.metrics.TruePositives(), 
                       tf.keras.metrics.FalsePositives(), tfa.metrics.F1Score(num_classes=2)])

model.fit(x_train,y_train,epochs=2, batch_size=64, validation_split=0.2)

输出:输出:

Epoch 1/2
13/13 [==============================] - 3s 85ms/step - loss: 0.6942 - diff: 8.4615 - true_positives_24: 401.0000 - false_positives_24: 399.0000 - f1_score: 0.5001 - val_loss: 0.6979 - val_diff: -10.0000 - val_true_positives_24: 89.0000 - val_false_positives_24: 111.0000 - val_f1_score: 0.4433
Epoch 2/2
13/13 [==============================] - 0s 10ms/step - loss: 0.6916 - diff: -8.4615 - true_positives_24: 399.0000 - false_positives_24: 401.0000 - f1_score: 0.4807 - val_loss: 0.6990 - val_diff: -34.0000 - val_true_positives_24: 95.0000 - val_false_positives_24: 105.0000 - val_f1_score: 0.4385

You can write a function for computing custom loss of TP - FP like below:

import tensorflow_addons as tfa
import tensorflow as tf
import numpy as np

x_train = np.random.rand(1000,10)
y_train = np.random.randint(0, 2, 1000)
y_train = tf.keras.utils.to_categorical(y_train, 2)


tp = tf.keras.metrics.TruePositives()
fp = tf.keras.metrics.FalsePositives()
def diff(y_true, y_pred): 
    a = tp(y_true, y_pred) 
    b = fp(y_true, y_pred)
    return a - b

model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(units=64,input_shape=(10,), activation='relu'))
model.add(tf.keras.layers.Dense(32, activation='relu'))
model.add(tf.keras.layers.Dense(16, activation='relu'))
model.add(tf.keras.layers.Dense(2, activation='softmax'))
model.compile(optimizer='adam',
              loss = 'categorical_crossentropy',
              metrics=[diff, tf.keras.metrics.TruePositives(), 
                       tf.keras.metrics.FalsePositives(), tfa.metrics.F1Score(num_classes=2)])

model.fit(x_train,y_train,epochs=2, batch_size=64, validation_split=0.2)

Output:

Epoch 1/2
13/13 [==============================] - 3s 85ms/step - loss: 0.6942 - diff: 8.4615 - true_positives_24: 401.0000 - false_positives_24: 399.0000 - f1_score: 0.5001 - val_loss: 0.6979 - val_diff: -10.0000 - val_true_positives_24: 89.0000 - val_false_positives_24: 111.0000 - val_f1_score: 0.4433
Epoch 2/2
13/13 [==============================] - 0s 10ms/step - loss: 0.6916 - diff: -8.4615 - true_positives_24: 399.0000 - false_positives_24: 401.0000 - f1_score: 0.4807 - val_loss: 0.6990 - val_diff: -34.0000 - val_true_positives_24: 95.0000 - val_false_positives_24: 105.0000 - val_f1_score: 0.4385

在Keras/Tensorflow中,如何制作truepostitives的自定义指标减去假阳性(TP-FP)?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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