情未る

文章 评论 浏览 28

情未る 2025-02-21 02:15:03

read_line 将读取来自stdin的字符串,它需要一个缓冲区才能放入它,这应该是您传递的参数。如果您要转换它,那是您的工作:它不会自行执行。因此类型错误。为了实现所需的目标,只需创建一个缓冲区,然后 parse it。

  let mut buffer = String::new();
  io::stdin().read_line(&mut buffer).expect("Failed to read");
  let fahrenheit = buffer.trim().parse::<f64>().expect("Failed to parse as `f64'");

请注意,在您的代码中,分析的通用参数可能是隐式的,因为您的 wahrenheittocelsius 函数可能足以让编译器找出执行转换的类型。

read_line will read a string from stdin, and it needs a buffer to put it in, which is supposed to be argument you pass it. If, then, you want to convert it, it's your job: it won't do that on its own. Thus the type error. To achieve what you want, simply create a buffer, then parse it.

  let mut buffer = String::new();
  io::stdin().read_line(&mut buffer).expect("Failed to read");
  let fahrenheit = buffer.trim().parse::<f64>().expect("Failed to parse as `f64'");

Note that in your code, the generic argument of parse might be left implicit since your fahrenheitToCelsius function might be enough for the compiler to figure out the type to perform the conversion to.

Rust Read_line&#x27;预期结构字符串,找到F64&#x27;

情未る 2025-02-20 22:38:08

问题中的注释正确指示您实例化具有特定大小的字符串,并使用 .data()&amp; [0] 操作员获取所需的东西。

让我建议一个更简单的解决方案,并具有约束。考虑到您的输出字符串具有一定合理的长度,并且您可以使用大量的堆栈内存。因此,请使用固定的长度温度缓冲区来进行printf样式格式。 20K并不是在堆栈上分配的数量不合理的字节。

然后返回一个 std :: String 使用C String构造器的复制版的实例。

std::string Somefunction(const char* formatstring, ...){

   const size_t TEMP_SIZE = 20000;

    va_list vargs = {};

    va_start(vargs, formatstring);

    char buffer[TEMP_SIZE];
    vsnprintf(buffer, TEMP_SIZE, formatstring, vargs);

    va_end(vargs);

    return std::string(buffer);
}

如果需要的话,您总是可以将缓冲区的大小从20000增加到更大。但是我猜你的琴弦永远不会变得那么大。而且,如果他们这样做,您不希望我猜是您的日志文件中的很多字节。

The comments in your question are correctly directing you to instantiate a string with a specific size and use the .data() or &[0] operator to get what you need.

Let me suggest a simpler solution with a constraint. Consider that your output strings have some reasonable length and that you have plenty of stack memory to work with. So use a fixed length temp buffer to do your printf style formatting. 20K is not an unreasonable number of bytes to allocate on the stack.

Then return an instance of a std::string using the copy from C string constructor at the very end.

std::string Somefunction(const char* formatstring, ...){

   const size_t TEMP_SIZE = 20000;

    va_list vargs = {};

    va_start(vargs, formatstring);

    char buffer[TEMP_SIZE];
    vsnprintf(buffer, TEMP_SIZE, formatstring, vargs);

    va_end(vargs);

    return std::string(buffer);
}

You could always increase the buffer size from 20000 to something larger if you needed it. But I'm guessing your strings never get that big. And if they did, you wouldn't want that many bytes in what I'm guessing is your log file.

C&#x2B;&#x2B; 11将堆数组移至std :: string

情未る 2025-02-20 21:04:03

因此,如果您使用的是jetstream,则可能会有一个称为AuthenticatedSessionController.php的文件,该文件应处理登录名,

有一种称为商店的方法,

public function store(LoginRequest $request)
    {
        $request->authenticate();

        $request->session()->regenerate();

        return redirect()->intended(RouteServiceProvider::HOME);
    }

您可以在此处更改逻辑,以便它具有 the Inted(utareserviceProvider :: home)代码>

您可以将其更改为:

$route = auth()->user()->isSuperAdmin() ? route('superadmin.index') : route('normaluser.index');

return redirect()->intended($route);

So if you are using Jetstream you would probably have a file called AuthenticatedSessionController.php which should handle the login

There is a method called store

public function store(LoginRequest $request)
    {
        $request->authenticate();

        $request->session()->regenerate();

        return redirect()->intended(RouteServiceProvider::HOME);
    }

You could change the logic here so that where it has intended(RouteServiceProvider::HOME)

You could change it to:

$route = auth()->user()->isSuperAdmin() ? route('superadmin.index') : route('normaluser.index');

return redirect()->intended($route);

如何将基于角色的登录重定向到Laravel 8的NWIDART模块

情未る 2025-02-20 06:08:28

我一直在尝试了解为什么只有第二部分被阴影。最终,我准备了第二个示例,其中我找到了另一个可能的解决方案。但是,我不完全满意,因为我不了解 geom_Rect / facet_wrap ;我只找到了一些解决方法。

这是一个示例:

# constructing the dataframe so all the combinations are present for both even and odd rows
df.tmp = data.frame(nst = rnorm(16*6), 
                    Srs = rep(c("S3", "S4"), each=8, 6), 
                    Cnd = rep(c("DN", "DA", "DV", "DAV"), each=2, 12), 
                    Grp = rep(c(rep(c("close","far"), 8), rev(rep(c("close","far"), 8))),3) )

even_numbers <- seq(2,nrow(df.tmp),2) # so the df.tmp[even_numbers, ] contains all the combinations
ggplot(df.tmp) + 
  geom_rect(data = df.tmp[even_numbers, ],
            xmin = even_numbers - 0.5, xmax = even_numbers + 0.5,
            ymin = -Inf, ymax = Inf, alpha = 0.3, fill = 'grey') +
  geom_boxplot(aes(x = Cnd, y = nst, fill = Srs), position = position_dodge(0.9), outlier.shape = 1) + 
  facet_wrap(vars(Grp), ncol=1)

正如您在此处看到的那样,尽管确保 df.tmp [vest_numbers,] Incluber CLOSE> CLOSE datapoints,但该图仅在第二行中阴影矩形。 : “第一行中的非阴影段”

在这里我更改 ggplot ,因此它包含 geom_Rect 分别用于关闭 far segments:

even_numbers <- seq(2,length(unique(df.tmp$Cnd)),2) # here the df.tmp[even_numbers, ] doesn't need to have all the combinations
ggplot(df.tmp) + 
  geom_rect(data = df.tmp[df.tmp$Grp=="close", ][even_numbers, ],
            xmin = even_numbers - 0.5, xmax = even_numbers + 0.5,
            ymin = -Inf, ymax = Inf, alpha = 0.3, fill = 'grey') + 
  geom_rect(data = df.tmp[df.tmp$Grp=="far", ][even_numbers, ],
            xmin = even_numbers - 0.5, xmax = even_numbers + 0.5,
            ymin = -Inf, ymax = Inf, alpha = 0.3, fill = 'grey') +
  geom_boxplot(aes(x = Cnd, y = nst, fill = Srs), position = position_dodge(0.9), outlier.shape = 1) + 
  facet_wrap(vars(Grp), ncol=1)

如下所示,它现在有效:

正如我之前提到的,我仍然不确定为什么 geom_rect 在第一个 地方。在我的解决方案中,需要为每个段准备一个单独的 geom_Rect ,因此绝对不是其中许多图的解决方案。我试图找到一种更优雅的方式,因此不必打扰宣布多少个部分或其他分组。

I have been trying to understand why only the second segment gets shaded. Eventually I prepared a second example, in which I have found another possible solution. However, I am not fully satisfied as I did not understand the issue with geom_rect / facet_wrap; I only found some workaround.

Here's the example:

# constructing the dataframe so all the combinations are present for both even and odd rows
df.tmp = data.frame(nst = rnorm(16*6), 
                    Srs = rep(c("S3", "S4"), each=8, 6), 
                    Cnd = rep(c("DN", "DA", "DV", "DAV"), each=2, 12), 
                    Grp = rep(c(rep(c("close","far"), 8), rev(rep(c("close","far"), 8))),3) )

even_numbers <- seq(2,nrow(df.tmp),2) # so the df.tmp[even_numbers, ] contains all the combinations
ggplot(df.tmp) + 
  geom_rect(data = df.tmp[even_numbers, ],
            xmin = even_numbers - 0.5, xmax = even_numbers + 0.5,
            ymin = -Inf, ymax = Inf, alpha = 0.3, fill = 'grey') +
  geom_boxplot(aes(x = Cnd, y = nst, fill = Srs), position = position_dodge(0.9), outlier.shape = 1) + 
  facet_wrap(vars(Grp), ncol=1)

As you can see here, the plot has shaded rectangles only in the second row, despite ensuring the df.tmp[even_numbers, ] includes close datapoints as well: non-shaded segments in first line

Here I change the ggplot so it contains geom_rect separately for close and far segments:

even_numbers <- seq(2,length(unique(df.tmp$Cnd)),2) # here the df.tmp[even_numbers, ] doesn't need to have all the combinations
ggplot(df.tmp) + 
  geom_rect(data = df.tmp[df.tmp$Grp=="close", ][even_numbers, ],
            xmin = even_numbers - 0.5, xmax = even_numbers + 0.5,
            ymin = -Inf, ymax = Inf, alpha = 0.3, fill = 'grey') + 
  geom_rect(data = df.tmp[df.tmp$Grp=="far", ][even_numbers, ],
            xmin = even_numbers - 0.5, xmax = even_numbers + 0.5,
            ymin = -Inf, ymax = Inf, alpha = 0.3, fill = 'grey') +
  geom_boxplot(aes(x = Cnd, y = nst, fill = Srs), position = position_dodge(0.9), outlier.shape = 1) + 
  facet_wrap(vars(Grp), ncol=1)

As you can see below, it works now: enter image description here

As I mentioned earlier, I am still not sure why geom_rect did not work in the first place. In my solution, a separate geom_rect needs to be prepared for each segment, so it's definitely not a solution for a plot with many of them. I was trying to find a more elegant way, so one wouldn't have to bother how many segments or other groupings are declared.

为什么Geom_Rect颜色仅facet_wrap的第一行?

情未る 2025-02-20 05:26:34

this kotlinlang slack 包括问题229839039 ,它是关于在 swipeablestate 讨论您应该做什么:

我们目前正在评估我们要为可滑动的API表面,包括可能的基础API。由于可滑动有很多问题,因此我们尚未在M3中公开。

关于上面链接的问题的评论#2如果您需要一些东西来给出潜在客户

This kotlinlang slack includes a link to issue 229839039, which is about making SwipeableState public in the Material3 Compose library and a discussion about what you should be doing:

We are currently evaluating the API surface we want to offer for Swipeable, including a possible Foundation API. As there are quite a few issues with Swipeable, we haven't made it public in M3 yet.

Comment #2 on the issue linked above gives you the full explanation and recommendations if you need something to give to your leads ????

For the time being, we recommend forking Swipeable if you need it in M3!

So you can either also include the Material2 Compose library and use its Swipeable or fork it entirely (i.e., copy/paste the code into your project) and use it directly.

如何在材料上做一个可滑动的构成3

情未る 2025-02-19 21:12:41

我所做的是删除.sln文件,然后使用.csproj文件打开了Visual Studio项目。我还编辑了CSPROJ文件,以具有看起来像这样的行:

<Configuration Condition=" '$(Configuration)' == '' ">Debug_VSTS</Configuration>

另一个看起来像这样的行:

<Configurations>Debug;Release;Debug_VSTS;Release_VSTS</Configurations>

what i did, was delete the .sln file then opened the visual studio project using the .csproj file. i also edited the csproj file to have a line that looks like this:

<Configuration Condition=" '$(Configuration)' == '' ">Debug_VSTS</Configuration>

and another that looks like this:

<Configurations>Debug;Release;Debug_VSTS;Release_VSTS</Configurations>

当前解决方案包含不正确的配置映射

情未る 2025-02-19 21:01:27

您可以在作业右侧使用表达式。在这里,您需要用当前值分配 studen ,即, studen 加上新值:

cur.execute("UPDATE ueberstunden SET stunden = studen + %s WHERE name ='test'", value)
# Here ----------------------------------------^

You can use expressions on the right side of an assignment. Here, you'd want to assign studen with the current value, i.e., studen plus the new value:

cur.execute("UPDATE ueberstunden SET stunden = studen + %s WHERE name ='test'", value)
# Here ----------------------------------------^

Python Psycopg2 |在数据库中计数加上

情未る 2025-02-19 19:07:42
WHERE tab_Status.ID IN (...)

不能动态。

因此,使用代码:

  1. 浏览 itemsSelected 集合
  2. 构建所选项目的静态列表,例如(1,3)
  3. 修改查询的SQL
WHERE tab_Status.ID IN (...)

cannot be dynamic.

Thus, use code to:

  1. browse the itemsselected collection
  2. build the static list of the selected items, say (1,3)
  3. modify the SQL of the query

访问查询:如何在表单上引用列表框

情未る 2025-02-19 11:59:05

我不确定您想在这里拥有的所有选项,所以这是我的第一次尝试(请注意,我将名称更改为kebab-case):

(def params [{:field-name "salary" :comparator "greater" :input-value "10000" :input-type "number"}
             {:field-name "name" :comparator "include" :input-value "Ros" :input-type "text"}
             {:field-name "start-date" :comparator "between" :input-value "2022-01-01" :max-input-value "2022-06-01" :input-type "date"}])

(defn convert [params]
  (->> (for [{:keys [field-name comparator input-value max-input-value input-type]} params]
         (->> (condp = input-type
                "number" [field-name ({"greater" ">" "less" "<" "equal" "=" "not-equal" "!="} comparator) input-value]
                "text" [field-name ({"include" "LIKE"} comparator) (str "'%" input-value "%'")]
                "date" [field-name ({"between" "BETWEEN"} comparator) (str "'" input-value "'") "AND" (str "'" max-input-value "'")])
              (str/join " ")))
       (str/join " AND ")))

(convert params)
=> "salary > 10000 AND name LIKE '%Ros%' AND start-date BETWEEN '2022-01-01' AND '2022-06-01'"

I'm not sure about all options you want to have here, so this is my first try (note that I changed names to kebab-case):

(def params [{:field-name "salary" :comparator "greater" :input-value "10000" :input-type "number"}
             {:field-name "name" :comparator "include" :input-value "Ros" :input-type "text"}
             {:field-name "start-date" :comparator "between" :input-value "2022-01-01" :max-input-value "2022-06-01" :input-type "date"}])

(defn convert [params]
  (->> (for [{:keys [field-name comparator input-value max-input-value input-type]} params]
         (->> (condp = input-type
                "number" [field-name ({"greater" ">" "less" "<" "equal" "=" "not-equal" "!="} comparator) input-value]
                "text" [field-name ({"include" "LIKE"} comparator) (str "'%" input-value "%'")]
                "date" [field-name ({"between" "BETWEEN"} comparator) (str "'" input-value "'") "AND" (str "'" max-input-value "'")])
              (str/join " ")))
       (str/join " AND ")))

(convert params)
=> "salary > 10000 AND name LIKE '%Ros%' AND start-date BETWEEN '2022-01-01' AND '2022-06-01'"

根据键类型解析地图和过滤的向量

情未る 2025-02-19 05:05:35

如果您的CSS存储在CSS文件夹中:

<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css">

您发布的内容看起来正确,那么这是正确的语法,因此假设所有文件都在哪里,则问题可能来自Spring Security,

如果您将Spring Security添加为依赖项,则需要告诉春季安全性不需要静态文件的身份验证。

您可以通过创建一个扩展WebsecurityConfigurerAdapter的WebsEcurityConfig类来做到这一点,并实现以下内容:

protected void configure(HttpSecurity http) throws Exception {
        String [] staticResources = {
                "/css/**",
                "/js/**"
        };
        http
                .authorizeRequests()
                .antMatchers(staticResources).permitAll()
    }

Spring会自动在静态文件夹中查看staticResources阵列应包含staticResource阵列,嗯...所有静态资源。如果添加了图像文件夹,则还应将其添加到staticresources数组中,例如:/images/** 如果您想能够在所有页面中使用

剩余代码中的所有页面:

Hey http, I need you to authorizeRequests matching the contents of staticResources. 
I also would like to permitAll users to access the content of staticResources.

This is the correct syntax if your css is stored in a css folder:

<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css">

What you posted looks right so assuming all your files are where they should be, the issue is probably coming from spring security

If you added spring security as a dependency, you need to tell spring security to not require authentication for your static files.

You can do that by creating a WebSecurityConfig class that extends WebSecurityConfigurerAdapter, and implement the following:

protected void configure(HttpSecurity http) throws Exception {
        String [] staticResources = {
                "/css/**",
                "/js/**"
        };
        http
                .authorizeRequests()
                .antMatchers(staticResources).permitAll()
    }

Spring automatically looks in the static folder the staticResources array should contain, well... all your static resources. If you add an images folder, you should also add it to the staticResources array like: /images/** if you want to be able to use the images in all your pages

The remaining code:

Hey http, I need you to authorizeRequests matching the contents of staticResources. 
I also would like to permitAll users to access the content of staticResources.

如何将CSS连接到Spring Boot?

情未る 2025-02-17 18:01:11

您可以使用多阶段构建,因为您可以声明a。 EXE/B.EXE以及所需的运行时是所需的人工制品。

但是我同意,如果您从软件包中安装运行时,只需复制应用程序即可。

You could use a multistage build, since you could declare a.exe/b.exe together with the required runtime to be the required artefacts.

But I agree it could be easier if you install the runtime from packages and just copy the application.

从单独的Docker图像中组合可执行文件?

情未る 2025-02-17 02:22:05

我设法通过重组代码来解决index.js文件中的所有路由功能来解决问题。

var root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
  <React.StrictMode>
     <BrowserRouter>
        <Routes>
            <Route path="/" element={<TodoContainer />}/>
            <Route path="about*" element={<About/>}/>
            <Route path="*" element={<NotMatch/>}/>
        </Routes>
      </BrowserRouter>
   </React.StrictMode>
);

I managed to solve the problem by restructuring my code to make all the routing functionalities in the index.js file as such.

var root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
  <React.StrictMode>
     <BrowserRouter>
        <Routes>
            <Route path="/" element={<TodoContainer />}/>
            <Route path="about*" element={<About/>}/>
            <Route path="*" element={<NotMatch/>}/>
        </Routes>
      </BrowserRouter>
   </React.StrictMode>
);

React browserrouter不渲染组件

情未る 2025-02-17 01:02:31

似乎没有一种方法可以在 onModeLcreating 中更改错误消息。如果您接受,则可以在控制器中进行验证并自定义错误消息。

您可以参考以下代码:

[HttpPost]
public async Task<IActionResult> Test(UserTest userTest)
{
    if (ModelState.IsValid)
    {
         try
         {
              _context.UserTest.Add(userTest);
              _context.SaveChanges();
              return RedirectToAction("Index");
         }
         catch (Exception ex)
         {
              var sqlException = GetInnerException<SqlException>(ex);

              if (sqlException != null
                        && (sqlException.Number == 2627 || sqlException.Number == 2601))
              {
                   ViewData["Message"] = "Username already exists";
                   return View();
              }
         }
    }
    return View();
}

public TException GetInnerException<TException>(Exception exception)
where TException : Exception
{
     Exception innerException = exception;
     while (innerException != null)
     {
         if (innerException is TException result)
         {
             return result;
         }
         innerException = innerException.InnerException;
     }
     return null;
}

测试结果:

”在此处输入图像说明”

There doesn't seem to be a way to change the error message in OnModelCreating. If you accept, you can do the validation in the controller and customize the error message.

You can refer to the following code:

[HttpPost]
public async Task<IActionResult> Test(UserTest userTest)
{
    if (ModelState.IsValid)
    {
         try
         {
              _context.UserTest.Add(userTest);
              _context.SaveChanges();
              return RedirectToAction("Index");
         }
         catch (Exception ex)
         {
              var sqlException = GetInnerException<SqlException>(ex);

              if (sqlException != null
                        && (sqlException.Number == 2627 || sqlException.Number == 2601))
              {
                   ViewData["Message"] = "Username already exists";
                   return View();
              }
         }
    }
    return View();
}

public TException GetInnerException<TException>(Exception exception)
where TException : Exception
{
     Exception innerException = exception;
     while (innerException != null)
     {
         if (innerException is TException result)
         {
             return result;
         }
         innerException = innerException.InnerException;
     }
     return null;
}

Test Result:

enter image description here

如何在EF Core onModeLcreating(modelbuilder modelbuilder)中生成错误消息

情未る 2025-02-17 00:43:38

这将完成这项工作。

        onSubmit={(values) => {
      if(values.radio === 2){
        delete values['input2'];
      }
      console.log(values);
    }}

this will do the job.

        onSubmit={(values) => {
      if(values.radio === 2){
        delete values['input2'];
      }
      console.log(values);
    }}

提交后,从最终JSON中删除隐藏的字段

情未る 2025-02-16 15:56:55

Envoy没有可用的日志旋转(请参见 evary#1109 )。

但是,您可以使用一个工具,例如 logrotate 您的访问日志文件旋转。以下配置可用于每天旋转日志并保留7天的日志:

/var/log/envoy/access.log {
    daily
    rotate 7
    missingok
    compress
    notifempty
    nocreate
    sharedscripts
    copytruncate
}

只需将该配置放入名为 /etc/logrottate.d/envoy 的文件中,然后检查 logrotate 每天运行( /etc/cron.daily/logrotate )。

您可以使用容器进行测试:

FROM    envoyproxy/envoy:v1.22.2

RUN     apt update && apt install -y logrotate

RUN     install -d -m 0755 -o envoy -g envoy /var/log/envoy

# logrotate_envoy.conf is logrotate config file
COPY    logrotate_envoy.conf /etc/logrotate.d/envoy

并使用此Envoy Config:

access_log:
- name: envoy.access_loggers.file
  typed_config:
    "@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
    path: /var/log/envoy/access.log

There is no log rotation available out-of-the-box with Envoy (see issue #1109).

However, you can use a tool like logrotate to handle your access logs file rotation. The following config can be used to rotate logs daily and keep 7 days of logs:

/var/log/envoy/access.log {
    daily
    rotate 7
    missingok
    compress
    notifempty
    nocreate
    sharedscripts
    copytruncate
}

Just put that config in a file named /etc/logrotate.d/envoy, and check that logrotate is run daily (/etc/cron.daily/logrotate).

You can test this using a container:

FROM    envoyproxy/envoy:v1.22.2

RUN     apt update && apt install -y logrotate

RUN     install -d -m 0755 -o envoy -g envoy /var/log/envoy

# logrotate_envoy.conf is logrotate config file
COPY    logrotate_envoy.conf /etc/logrotate.d/envoy

And use this envoy config:

access_log:
- name: envoy.access_loggers.file
  typed_config:
    "@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
    path: /var/log/envoy/access.log

如何在基于Engoy文件的日志记录中启用日志旋转?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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