小编Kyu*_*u96的帖子

Mono Bug:幻数错误:542

我正在尝试在Linux上的Rider中编译C#Hello World应用程序.当我尝试运行应用程序时,我会遇到以下异常:

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'System.Console' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.ConsoleDriver' threw an exception. ---> System.Exception: Magic number is wrong: 542
at System.TermInfoReader.ReadHeader (System.Byte[] buffer, System.Int32& position) [0x00028] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.TermInfoReader..ctor (System.String term, System.String filename) [0x0005f] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.TermInfoDriver..ctor (System.String term) [0x00055] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.ConsoleDriver.CreateTermInfoDriver (System.String term) [0x00000] in <a84b655e5e6a49ee96b338ec792f5580>:0
at System.ConsoleDriver..cctor () [0x0004d] in <a84b655e5e6a49ee96b338ec792f5580>:0
--- End of inner exception stack trace ---
at System.Console.SetupStreams (System.Text.Encoding inputEncoding, …
Run Code Online (Sandbox Code Playgroud)

c# mono

13
推荐指数
1
解决办法
7562
查看次数

带通配符的 Ansible 复制文件?

在我的文件目录中,我有各种文件,名称结构相似:

data-example.zip
data-precise.zip
data-arbitrary.zip
data-collected.zip
Run Code Online (Sandbox Code Playgroud)

我想使用 Ansible 在远程机器的 /tmp 目录中传输所有这些文件,而无需明确指定每个文件名。换句话说,我想传输每个以“data-”开头的文件。

这样做的正确方法是什么?在一个类似的帖子中,有人建议了with_fileglob关键字,但我无法让它发挥作用。有人可以为我提供一个如何完成上述任务的例子吗?

copy wildcard provisioning ansible

7
推荐指数
2
解决办法
1万
查看次数

组合位标记

我有几个标志:

    None = 0
    HR = 1
    HD = 2,
    DT = 4,
    Fl = 8
..
Run Code Online (Sandbox Code Playgroud)

等等

我想创建一个输入特定标志的函数,可以这样说:6。

返回值应为HDDT,因为2 | 4 =6。也可能会组合3个或更多标志或仅一个标志。例如:7 = 1 | 2 | 4 => HRHDDT。

如何根据标志值返回缩进的字符串?

在我的情况下,枚举还有很多条目,这会使if语句真的很不舒服,因为我必须涵盖数百种情况。

有什么聪明的解决方案吗?

python flags

5
推荐指数
1
解决办法
184
查看次数

Python 使用 sympy 求解三次方程

我在尝试使用 求解方程时遇到问题sympy。\n某些变量已指定特定值。\n我正在尝试求解 、bc的方程d。\n这是我的尝试:

\n\n
from random import randint\nimport sympy\nfrom sympy.abc import b,c,d,B,C,r,x\n\nB=10\nC=20\nr=123\n\n# Equation: x^3+b*x^2+c*x+d=x^3+(B\xe2\x88\x92r)x^2+(C\xe2\x88\x92B*r)x\xe2\x88\x92C*r\nequation = sympy.Eq(x**3+b*x**2+c*x+d,x**3+(B\xe2\x88\x92r)*x**2+(C\xe2\x88\x92B*r)*x\xe2\x88\x92C*r)\n\nprint(sympy.solve(equation,"b"))\nprint(sympy.solve(equation,"c"))    \nprint(sympy.solve(equation,"d"))\n
Run Code Online (Sandbox Code Playgroud)\n\n

Python 打印出以下错误:

\n\n
    [user@user Python Scripts]$ python polygen.py \n  File "polygen.py", line 10\n    equation = sympy.Eq(x**3+b*x**2+c*x+d,x**3+(B\xe2\x88\x92r)*x**2+(C\xe2\x88\x92B*r)*x\xe2\x88\x92C*r)\n                                                  ^\nSyntaxError: invalid character in identifier\n
Run Code Online (Sandbox Code Playgroud)\n\n

我缺少什么?

\n

python math equation sympy

5
推荐指数
1
解决办法
3902
查看次数

使用 SSH 服务器设置 Docker 容器?

我想设置一个非常简约的 alpine linux docker 容器,具有以下功能:

  • 它运行一个 ssh 服务器
  • 它复制我选择的 SSH 公钥,然后我可以对其进行身份验证

我研究了各种选项,最后决定编写自己的小 Dockerfile。但是,我遇到了一些问题。

Dockerfile

FROM alpine:latest

RUN apk update
RUN apk upgrade
RUN apk add openssh-server

RUN mkdir -p /var/run/sshd
RUN mkdir -p /root/.ssh

ADD authorized_keys /root/.ssh/authorized_keys
ADD entrypoint.sh /entrypoint.sh
RUN chmod 755 /entrypoint.sh

EXPOSE 22
CMD ["/entrypoint.sh"]
Run Code Online (Sandbox Code Playgroud)

入口点.sh

#!/bin/sh
/usr/sbin/sshd -D
Run Code Online (Sandbox Code Playgroud)

授权密钥

ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBP8cIHIPgV9QoAaSsYNGHktiP/QnWfKPOeyzjujUXgQMQLBw3jJ1EBe04Lk3FXTMxwrKk3Dxq0VhJ+Od6UwzPDg=
Run Code Online (Sandbox Code Playgroud)

启动容器出现错误:sshd: no hostkeys available -- exiting。如何修复我的 Dockerfile,以确保 ssh 服务器正确运行并且authorized_keys 文件在那里。我缺少什么?

ssh containers sshd docker alpine-linux

5
推荐指数
1
解决办法
8470
查看次数

测量 C 中经过的时间?

所以,我想看看我的代码中的函数需要多长时间才能运行。(实时)。最初,我有这个:

clock_t begin = clock();
my_function();
clock_t end = clock();
double time_spent = (double)(end - begin);
Run Code Online (Sandbox Code Playgroud)

但显然,这种方法存在一些问题。

  1. 它仅测量 CPU 处理我的应用程序所花费的时间。
  2. 从我所看到的来看,它仅在微秒级别上进行测量 - 这对于我的情况来说不够精确。

那么,获取函数运行时间的正确方法是什么?CPU 时间真的是正确的方法吗?我可以测量多精确?我在想纳秒级?

c time benchmarking timing microbenchmark

4
推荐指数
1
解决办法
1683
查看次数

C#尝试从类型列表中强制转换字符串

所以我有两个长度相等的列表,一个字符串列表和一个类型列表。由于要验证字符串是否可以转换为第二个列表中指定的相应类型。如果这不可能,我想抛出一个异常。

因此,想象一下这样的事情:

var strings = new List<string>(){"hi","123","542342342424423","5.1"};
var types = new List<Types>(){typeof(string),typeof(int),typeof(long),typeof(double)};
Run Code Online (Sandbox Code Playgroud)

所以我想检查一下:

hi can be converted to a string
123 can be converted to an int
542342342424423 can be converted to a long
5.1 can be converted to a double
Run Code Online (Sandbox Code Playgroud)

我以为是这样的:

hi can be converted to a string
123 can be converted to an int
542342342424423 can be converted to a long
5.1 can be converted to a double
Run Code Online (Sandbox Code Playgroud)

但是,这@type不是一个常量表达式,因此不起作用。我不一定需要强制转换值,如果它们可以转换或不转换,我只需要验证(是/否)。我该如何解决?

c# types casting

3
推荐指数
1
解决办法
69
查看次数

PreferenceFragments 不在同一个 FragmentManager 中?

我们有一个PreferenceFragmentCompat,然后点击一个首选项,我们想从当前的 切换PreferenceFragmentCompat到新的PreferenceFragmentCompat。(在新屏幕上进行某些设置)。

但是,无论我们尝试过什么,我们都会遇到以下错误:

Fragment 声明的目标片段不属于此 FragmentManager

主活动.kt

class MainActivity : AppCompatActivity(), ActivityCompat.OnRequestPermissionsResultCallback, PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val navView: BottomNavigationView = findViewById(R.id.nav_view)

        val navController = findNavController(R.id.nav_host_fragment)
        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
        val appBarConfiguration = AppBarConfiguration(
            setOf(
                R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_preferences
            )
        )

        setupActionBarWithNavController(navController, appBarConfiguration)
        navView.setupWithNavController(navController)
    }

    override fun onPreferenceStartFragment(caller: PreferenceFragmentCompat, pref: Preference): Boolean {
        val …
Run Code Online (Sandbox Code Playgroud)

mobile android fragment kotlin fragmentmanager

3
推荐指数
1
解决办法
366
查看次数

带有百分比标签的进度栏?

如何在显示百分比的进度条中间放置标签?问题是python不支持标签背景的透明性,所以我不知道该如何解决。

python transparency label tkinter

1
推荐指数
1
解决办法
1939
查看次数

将std :: array &lt;char,10&gt;的最后一个字符转换为int

给定以下数组:std::array<char, 10> stuff我想将最后4个字符转换为相应的int32值。

我尝试对最后一项进行OR操作的链接,但似乎不是正确的方法:

int a = int(stuff[6] | stuff[7] | stuff[8] | stuff[9])

有解决这个问题的优雅方法吗?

c++ memory arrays int char

1
推荐指数
1
解决办法
81
查看次数

调整动态字符串数组的大小

如何std::string**在不使用C方法的情况下在C++中调整动态多维数组的大小malloc/free

c++ arrays string dynamic

-4
推荐指数
1
解决办法
106
查看次数