山色无中

文章 评论 浏览 29

山色无中 2025-02-21 01:15:26

在相对路径中

cd YOUR-TARGET-DIRECTORY

# save the name in cmd
cmd=$(echo myApplication-*.AppImage)

# run it
./$cmd

运行绝对路径

cmd=$(echo /home/myname/Applications/myApplication-*.AppImage)

# WRONG
#./$cmd

# CORRECT
$cmd

以更安全的

#!/bin/bash

filename='/home/myname/Applications/myApplication-*.AppImage';

if [[ -f "$filename" ]]; then
    $filename;
else
    echo "$filename not found";
fi

注意

,如果您的 $ home /home/myname 您需要更新脚本

#!/bin/bash

# wrong
# ./home/myname/Applications/myApplication-*.AppImage

# right
/home/myname/Applications/myApplication-*.AppImage

run in relative path

cd YOUR-TARGET-DIRECTORY

# save the name in cmd
cmd=$(echo myApplication-*.AppImage)

# run it
./$cmd

run in absolute path

cmd=$(echo /home/myname/Applications/myApplication-*.AppImage)

# WRONG
#./$cmd

# CORRECT
$cmd

safer

#!/bin/bash

filename='/home/myname/Applications/myApplication-*.AppImage';

if [[ -f "$filename" ]]; then
    $filename;
else
    echo "$filename not found";
fi

NOTE

if your $HOME is /home/myname you need to update your script

#!/bin/bash

# wrong
# ./home/myname/Applications/myApplication-*.AppImage

# right
/home/myname/Applications/myApplication-*.AppImage

如何使用bash脚本中的正则表达式执行.pappimage文件?

山色无中 2025-02-20 23:28:57

$$。前缀是指执行的上下文对象。它没有作业密钥。也许您的意思是 $$。execution.ID ?如果 job.id 是您自己定义的输入的一部分,请以(单个) $。将其前缀。

The $$. prefix refers to the execution's Context Object. It has no Job key. Perhaps you mean $$.Execution.Id? If Job.Id is part of your own defined input, prefix it with (a single) $..

步骤功能输入问题

山色无中 2025-02-20 21:41:38

您可以在2个步骤中完成此操作,首先您找到嵌套的词典,该字典的值最多:

my_dict = {
    0: {1: 10, 2: 20, 3: 30},
    10: {10: 100, 20: 200, 30: 300},
    20: {100: 1000, 200: 2000, 300: 3000},
}

# step 1
k_outer, v_outer = max(my_dict.items(), key=lambda x: max(x[1]))

# step 2
k_inner, v_inner = max(v_outer.items(), key=lambda x: x[1])

print(k_outer, k_inner, v_inner)

输出:

20 300 3000

我相信上述解决方案将非常有效地工作,但您可以找到您感兴趣的项目,仅在一次迭代中同样:

my_dict = {
    0: {1: 10, 2: 20, 3: 30},
    10: {10: 100, 20: 200, 30: 300},
    20: {100: 1000, 200: 2000, 300: 3000},
}

max_value = float("-inf")
outer_key = None
inner_key = None

for k_outer, v_outer in my_dict.items():
    for k_inner, v_inner in v_outer.items():
        if v_inner > max_value:
            max_value = v_inner
            outer_key = k_outer
            inner_key = k_inner

print(outer_key, inner_key, max_value)

这样,只要您找到一个值( v_inner ),它比您的 max_value 更大,您都会存储这两个键( ofter_keykey innion_key )。迭代完成后,您可以拥有数据。

You can do that in 2 steps, first you find the nested dictionary which has the maximum number in it's values :

my_dict = {
    0: {1: 10, 2: 20, 3: 30},
    10: {10: 100, 20: 200, 30: 300},
    20: {100: 1000, 200: 2000, 300: 3000},
}

# step 1
k_outer, v_outer = max(my_dict.items(), key=lambda x: max(x[1]))

# step 2
k_inner, v_inner = max(v_outer.items(), key=lambda x: x[1])

print(k_outer, k_inner, v_inner)

output:

20 300 3000

I believe the above solution will work quite efficiently but you can find the items you're interested in, in just one iteration as well:

my_dict = {
    0: {1: 10, 2: 20, 3: 30},
    10: {10: 100, 20: 200, 30: 300},
    20: {100: 1000, 200: 2000, 300: 3000},
}

max_value = float("-inf")
outer_key = None
inner_key = None

for k_outer, v_outer in my_dict.items():
    for k_inner, v_inner in v_outer.items():
        if v_inner > max_value:
            max_value = v_inner
            outer_key = k_outer
            inner_key = k_inner

print(outer_key, inner_key, max_value)

This way whenever you find a value (v_inner) that is bigger that your max_value, you store those two keys (outer_key, inner_key). After the iteration completes, you have your data.

如何返回最大值以及嵌套词典的关联键

山色无中 2025-02-20 19:29:35

从安装程序中,最后一条消息是:

要启动,运行

exec /bin /zsh
bun -help

From the installer, last message is:

To get started, run

exec /bin/zsh
bun --help

运行安装脚本后找不到的bun

山色无中 2025-02-20 19:22:17

操纵DOM是一个坏主意。您可以使用状态。

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      isStarted: false,
    };
    this.InitialPosition = this.InitialPosition.bind(this);
  }

  InitialPosition() {
    this.setState({ isStarted: true });
  }

  render() {
    return (
      <div>
        {
          this.state.isStarted && (
            <button id="start-button" onClick={this.InitialPostition}>
              Start Game
            </button>
          )
        }
        <div id="a8">
          { this.state.isStarted && <MyComponent /> }
        </div>
      </div>
    );
  }
}

Manipulating DOM is a bad idea in React. You can use states instead.

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      isStarted: false,
    };
    this.InitialPosition = this.InitialPosition.bind(this);
  }

  InitialPosition() {
    this.setState({ isStarted: true });
  }

  render() {
    return (
      <div>
        {
          this.state.isStarted && (
            <button id="start-button" onClick={this.InitialPostition}>
              Start Game
            </button>
          )
        }
        <div id="a8">
          { this.state.isStarted && <MyComponent /> }
        </div>
      </div>
    );
  }
}

如何将组件添加到React中的DIV中?

山色无中 2025-02-20 14:18:56

在这里,stateProvider使用 mycustomObject ,表示每个状态都会 mycustomObject

此行更新单个变量(名称),而不是

ref.read(customObjectProvider.notifier).state.name = 'Reuven';

您可以像

final MyCustomObject oldObj = ref.read(customObjectProvider);
ref.read(customObjectProvider.notifier).state =
    MyCustomObject(name: "newName"); // better will be using copyWith constructor

仅更新单个变量不会刷新,您需要更新状态以强制刷新

更加方便的刷新,就是使用 update

onPressed: () {
  ref
      .read(customObjectProvider.notifier)
      .update((state) => MyCustomObject(name: "newValye"));
},

更多有关 state_provider

Here StateProvider is using MyCustomObject, means every state will a MyCustomObject.

This line update the single variable(name), not the state

ref.read(customObjectProvider.notifier).state.name = 'Reuven';

You can update the state like

final MyCustomObject oldObj = ref.read(customObjectProvider);
ref.read(customObjectProvider.notifier).state =
    MyCustomObject(name: "newName"); // better will be using copyWith constructor

Just updating single variable won't refresh, You need to update the state to force a refresh

More handy is by using update

onPressed: () {
  ref
      .read(customObjectProvider.notifier)
      .update((state) => MyCustomObject(name: "newValye"));
},

More about state_provider.

颤音,riverpod state -provider不上传UI

山色无中 2025-02-20 13:23:58

而不是 $ data ['mm_name'] [$ item] 必须使用$ value,而不是 $ data ['company'] [$ company'] 必须使用$ value。

更改

if (is_countable($data) && count($data) > 0){
.
.
.

if (is_countable($data) && count($data) > 0 && isset($data['company'])){
.
.
.
.

instead of $data['mm_name'][$item] must use $value and instead of $data['company'][$company] must use $value.

and

change

if (is_countable($data) && count($data) > 0){
.
.
.

to

if (is_countable($data) && count($data) > 0 && isset($data['company'])){
.
.
.
.

使用foreach循环将数据插入2个数据库

山色无中 2025-02-20 12:27:19

涂上简单的布尔面具怎么样?

import numpy as np

np.random.seed(42)
arr = np.round(np.random.random(10), 3)
tol = 0.1

print(arr)
# [0.375 0.951 0.732 0.599 0.156 0.156 0.058 0.866 0.601 0.708]

# set to 0 values below `tol`
arr[np.abs(arr) < tol] = 0.0

print(arr)
# [0.375 0.951 0.732 0.599 0.156 0.156 0.    0.866 0.601 0.708]

How about a applying a simple boolean mask:

import numpy as np

np.random.seed(42)
arr = np.round(np.random.random(10), 3)
tol = 0.1

print(arr)
# [0.375 0.951 0.732 0.599 0.156 0.156 0.058 0.866 0.601 0.708]

# set to 0 values below `tol`
arr[np.abs(arr) < tol] = 0.0

print(arr)
# [0.375 0.951 0.732 0.599 0.156 0.156 0.    0.866 0.601 0.708]

基于Python中的公差值再生阵列

山色无中 2025-02-20 12:06:00

除了通常在其他环境变量 github_via 最接近的是 gl_protocol ,它可以告诉您一些信息,例如使用HTTP/SSH或Web UI进行推动。该变量的值将 http ssh Web 相应地。

因此,在您的情况下,您可能会做类似的事情:

if [[ "$GL_PROTOCOL" != "web" ]]; then
  echo "Changes to the default branch must be made by Pull Request. Direct pushes, edits, or merges are not allowed."
  exit 1
fi   

值得一提/project/protected_branches.html“ rel =“ nofollow noreferrer”>受保护的分支。例如,您可以创建一个受保护的分支规则,该规则禁止将其推入分支,并且只允许通过MR进行更改。因此,您应该能够在GitLab中实现相同的效果,而无需预先接管钩子。

Besides the information that is normally exposed in git pre-receive hooks, GitLab does provide some additional environment variables. The closest thing to GITHUB_VIA would be GL_PROTOCOL, which can tell you some information like if a push was made using http/ssh or the web UI. The value of this variable will be either http ssh or web accordingly.

So, in your case you might do something like:

if [[ "$GL_PROTOCOL" != "web" ]]; then
  echo "Changes to the default branch must be made by Pull Request. Direct pushes, edits, or merges are not allowed."
  exit 1
fi   

It is worth mentioning, however, that GitLab has controls for this use case directly in the project settings in protected branches. For example, you can create a protected branch rule that prohibits pushes to the branch and only allows changes via an MR. So you should be able to achieve the same effect in GitLab without a pre-receive hook.

我如何确定源自GitLab中提交的行动?

山色无中 2025-02-20 06:31:07

实际上,您的问题中显示的代码除了将类型传递到 json.unmarshal 和格式化错误之外,您可以做任何其他

func LoadConfiguration(data []byte) (*Type1, error) {
    config := &Type1{}
    if err := loadConf(data, config); err != nil {
        return nil, err
    }
    // ...
}

// "magically" accepts any type
// you could actually get rid of the intermediate function altogether
func loadConf(bytes []byte, config any) error {
    if err := json.Unmarshal(bytes, config); err != nil {
        return fmt.Errorf("cannot load config: %v", err)
    }
    return nil
}

事情不仅将指针传递到 json.unmarshal 的东西还可以从类型参数中受益。

type Configurations interface {
    Type1 | Type2
}

func loadConf[T Configurations](bytes []byte) (*T, error) {
    config := new(T)
    if err := json.Unmarshal(bytes, config); err != nil {
        return nil, fmt.Errorf("cannot load config: %v", err)
    }
    return config, nil
}

func loadConfOther[T Configurations]() (*T, error) {
    flatconfig := new(T)
    // ... code
    return flatconfig, nil
}

在这些情况下,您可以使用 new(t)创建新的指针它 - 只要JSON实际上可以将其分解为任何一个结构。

顶级函数中的特定于类型的代码仍应不同,尤其是因为您想用显式混凝土类型实例化通用功能。因此,我建议保留 loadConfiguration1 loadConfiguration2

func LoadConfiguration1(data []byte) (*Type1, error) {
    config, err := loadConf[Type1](data)
    if err != nil {
        return nil, err
    }
    confOther, err := loadConfOther[Type1]()
    if err != nil {
        return nil, err
    }

    // ... type specific code

    return config, nil
}

但是,如果特定于类型的代码是其中的一小部分,则可以使用特定零件的类型开关逃脱,尽管在您的情况下似乎并不是可行的选择。我看起来像:

func LoadConfiguration[T Configuration](data []byte) (*T, error) {
    config, err := loadConf[T](data)
    if err != nil {
        return nil, err
    }
    // let's pretend there's only one value of type parameter type
    // type-specific code
    switch t := config.(type) {
        case *Type1:
            // ... some *Type1 specific code
        case *Type2:
            // ... some *Type2 specific code
        default:
            // can't really happen because T is restricted to Configuration but helps catch errors if you extend the union and forget to add a corresponding case
            panic("invalid type")
    }

    return config, nil
}

最小示例游乐场: https://go.dev/play/play/p/p/p/-rhigoxintz

Actually the code shown in your question doesn't do anything more than passing a type into json.Unmarshal and format an error so you can rewrite your function to behave just like it:

func LoadConfiguration(data []byte) (*Type1, error) {
    config := &Type1{}
    if err := loadConf(data, config); err != nil {
        return nil, err
    }
    // ...
}

// "magically" accepts any type
// you could actually get rid of the intermediate function altogether
func loadConf(bytes []byte, config any) error {
    if err := json.Unmarshal(bytes, config); err != nil {
        return fmt.Errorf("cannot load config: %v", err)
    }
    return nil
}

In case the code actually does something more than just passing a pointer into json.Unmarshal, it can benefit from type parameters.

type Configurations interface {
    Type1 | Type2
}

func loadConf[T Configurations](bytes []byte) (*T, error) {
    config := new(T)
    if err := json.Unmarshal(bytes, config); err != nil {
        return nil, fmt.Errorf("cannot load config: %v", err)
    }
    return config, nil
}

func loadConfOther[T Configurations]() (*T, error) {
    flatconfig := new(T)
    // ... code
    return flatconfig, nil
}

In these cases you can create a new pointer of either type with new(T) and then json.Unmarshal will take care of deserializing the content of the byte slice or file into it — provided the JSON can be actually unmarshalled into either struct.

The type-specific code in the top-level function should still be different, especially because you want to instantiate the generic functions with an explicit concrete type. So I advise to keep LoadConfiguration1 and LoadConfiguration2.

func LoadConfiguration1(data []byte) (*Type1, error) {
    config, err := loadConf[Type1](data)
    if err != nil {
        return nil, err
    }
    confOther, err := loadConfOther[Type1]()
    if err != nil {
        return nil, err
    }

    // ... type specific code

    return config, nil
}

However if the type-specific code is a small part of it, you can probably get away with a type-switch for the specific part, though it doesn't seem a viable option in your case. I would look like:

func LoadConfiguration[T Configuration](data []byte) (*T, error) {
    config, err := loadConf[T](data)
    if err != nil {
        return nil, err
    }
    // let's pretend there's only one value of type parameter type
    // type-specific code
    switch t := config.(type) {
        case *Type1:
            // ... some *Type1 specific code
        case *Type2:
            // ... some *Type2 specific code
        default:
            // can't really happen because T is restricted to Configuration but helps catch errors if you extend the union and forget to add a corresponding case
            panic("invalid type")
    }

    return config, nil
}

Minimal example playground: https://go.dev/play/p/-rhIgoxINTZ

如何从GO 1.18中的一种方法中返回两种不同的混凝土类型?

山色无中 2025-02-20 04:13:51

带有“结果”键的数组元素的搜索索引,并使用array_slice():

$array = array(
  'zero'  => '0',
  'one'   => '1',
  'result'   => '2',
  'three' => '3',
);
$index=array_search("result",array_keys($array));
$res = array_slice($array, 0, $index, true) +
    array("my_key" => "my_value") +
    array_slice($array, $index, count($array) - 1, true) ;
print_r($res);

结果:

Array
(
    [zero] => 0
    [one] => 1
    [result] => 2
    [my_key] => my_value
    [three] => 3
)

Search index of array element with "result" key and use array_slice():

$array = array(
  'zero'  => '0',
  'one'   => '1',
  'result'   => '2',
  'three' => '3',
);
$index=array_search("result",array_keys($array));
$res = array_slice($array, 0, $index, true) +
    array("my_key" => "my_value") +
    array_slice($array, $index, count($array) - 1, true) ;
print_r($res);

result:

Array
(
    [zero] => 0
    [one] => 1
    [result] => 2
    [my_key] => my_value
    [three] => 3
)

如何将数组推向JSON元素

山色无中 2025-02-19 03:54:14

txt 不是 boolean ,因此永远不会是 false 。它可以是不确定的

var txt ="\n\t\r";
if(txt !== undefined) { //or just: if (txt)
    console.log("Variable is declared.");
} else {
    console.log("Variable is not declared.");
}
//=> will log: 'Variable is declared.'

顺便说一句,声明变量可以是 undefined (例如 var txt; )。

如果您进行更严格的比较(使用 === ),您会看到

var txt = '\n'; txt === 0; //=> false
var txt = '\r'; txt === 0; //=> false
var txt = '\t'; txt === 0; //=> false

另请参见

txt is not a Boolean, so it will never be false. It can be undefined though.

var txt ="\n\t\r";
if(txt !== undefined) { //or just: if (txt)
    console.log("Variable is declared.");
} else {
    console.log("Variable is not declared.");
}
//=> will log: 'Variable is declared.'

By the way, a declared variable may be undefined (e.g. var txt;).

If you do a stricter comparison (without type coercion, using ===), you'll see that

var txt = '\n'; txt === 0; //=> false
var txt = '\r'; txt === 0; //=> false
var txt = '\t'; txt === 0; //=> false

See also

&#x27; \ n \ t \ r&#x27; == 0是真的吗?

山色无中 2025-02-18 21:56:03

我建议使用工厂方法,例如:

public class BaseObjectFactory {
    public static BaseObject create(boolean isGood) {
         return isGood ? new GoodObject(...) : new BadObject(...);
    }
}

如果您想要设计模式方法。在我的实际代码中,我可能会在某个地方有一个IF语句,并且不太关心这一点。

I'd recommend going with the Factory approach, such as:

public class BaseObjectFactory {
    public static BaseObject create(boolean isGood) {
         return isGood ? new GoodObject(...) : new BadObject(...);
    }
}

If you want a Design Pattern approach. In my actual code, I'd probably have an if statement somewhere, and not be too concerned with this.

选择不同的儿童课以创建基于布尔的新实例的最佳方法

山色无中 2025-02-18 06:59:56

您的Xname和Yname Prop的值必须与您的数据对象属性名称相同
例如

,如果您的数据对象是

const dummyData = [{
    { xvalue: 1, yvalue: 6 },
    { xvalue: 2, yvalue: 7 },
    { xvalue: 3, yvalue: 4 },
    { xvalue: 4, yvalue: 8 },
    { xvalue: 5, yvalue: 10 },
  }]

Xname,并且Yname Props值将是

    xName='xvalue'
    yName='yvalue'

这样:

 <SparklineComponent
    id={"line-sparkline"}
    height={"80px"}
    width={"250px"}
    lineWidth={1}
    valueType="Numeric"
    fill={"blue"}
    border={{ color:"blue", width: 2 }}
    dataSource={SparklineAreaData}
    xName='xvalue'
    yName='yvalue'
    type={"Line"}
    >

The value of your xName and yName props must be the same as your data Object property name
For example

if your data object is

const dummyData = [{
    { xvalue: 1, yvalue: 6 },
    { xvalue: 2, yvalue: 7 },
    { xvalue: 3, yvalue: 4 },
    { xvalue: 4, yvalue: 8 },
    { xvalue: 5, yvalue: 10 },
  }]

the xName and yName props value will be

    xName='xvalue'
    yName='yvalue'

like this:

 <SparklineComponent
    id={"line-sparkline"}
    height={"80px"}
    width={"250px"}
    lineWidth={1}
    valueType="Numeric"
    fill={"blue"}
    border={{ color:"blue", width: 2 }}
    dataSource={SparklineAreaData}
    xName='xvalue'
    yName='yvalue'
    type={"Line"}
    >

EJ2 Syncfusion Sparkline组件什么都没有显示

山色无中 2025-02-17 22:39:35

简短的答案

使用:

-target x86_64-apple-macos10.15.7

长时间回答

Xcode的作用,如@Willeke所建议的那样,我走上了正确的道路。 Xcode中的一个新的命令行项目通过:

-target x86_64-apple-macos10.15

汇编时的Swift后端,由于 @Available 约束,该项目仍然失败,但将其修改为:

-target x86_64-apple-macos10.15.7

按预期工作。

令人讨厌的是,在三个中使用相应的 darwin 版本不会引起与使用 macos 版本相同的行为,但是我想这是由于只有一个基于达尔文的操作系统来自苹果的时代的遗产。现在,给定的Darwin版本可以表示MACOS,iOS,TVOS等不同版本,每个版本都具有不同的可用API集。 ✌️

Short answer

Use:

-target x86_64-apple-macos10.15.7

Long answer

Looking at what Xcode does, as suggested by @Willeke has put me on the right path. A new command-line project in Xcode passes:

-target x86_64-apple-macos10.15

to the Swift backend at compilation, which still fails due to the @available constraint, but modifying this to:

-target x86_64-apple-macos10.15.7

works as expected.

It is annoying that the use of corresponding darwin versions in the triple doesn't cause the same behaviour as the use of macos versions, but I imagine that this is due to the legacy of a time when there was only one Darwin based operating system coming out of Apple. Now, a given Darwin version can mean different versions of macOS, iOS, tvOS etc., each with different available API sets. ✌️

`@@opair`属性在macos版本上限制了错误的约束

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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