小编Mar*_*eel的帖子

进行全局状态的正确方法是什么?

我有一个应用程序,我希望应用程序组件保存当前登录的用户。我有以下路线和组件。

基本上,我的应用程序中的每个组件都会使用用户对象。当然,我可以将用户作为 props 传递给每个组件,但这并不优雅。全局共享 user prop 的正确 React 方式是什么?

const App = () => {
    const [user, setUser] = useState(null);

    return (
        <Router>
            <div className="app">
                <Topbar />
                <Switch>
                    <Route path="/login" exact component={Login} />
                    <Route path="/home" exact component={Home} />
                    <Route path="/" exact component={ShopMenu} />
                    <Route path="/orders">
                        <Orders />
                    </Route>
                    <Route path="/wishlist" exact component={Wishlist} />
                    <Route path="/wallet" exact component={Wallet} />
                    <Route path="/cart" exact component={Cart} />
                </Switch>
                <BottomBar />
            </div>
        </Router>
    );
};
Run Code Online (Sandbox Code Playgroud)

reactjs react-router

27
推荐指数
1
解决办法
6万
查看次数

如何以编程方式获取计算机的本地网络IP地址?(C#)

我需要使用C#和.NET 3.5从我的程序中获取计算机的实际本地网络IP地址(例如192.168.0.220).在这种情况下,我不能只使用127.0.0.1.

最好的方法是什么?

.net c# ip-address .net-3.5

26
推荐指数
4
解决办法
6万
查看次数

Python与Matlab

我正在考虑从MATLAB切换到Python.该应用程序是定量交易,成本并不是真正的问题.有一些我喜欢MATLAB的东西,我想知道Python如何堆叠(在我读过的评论中找不到任何答案).

  1. 是否有一个适合Python的IDE与MATLAB(变量编辑器,调试器,分析器)一样好?我读过关于Spyder的好东西,但是它有一个分析器吗?

  2. 在MATLAB中更改路径上的函数时,会自动重新加载.更改库时是否必须手动重新导入库,还是可以自动完成?这是一件小事,但实际上大大提高了我的工作效率.

python ide matlab

26
推荐指数
4
解决办法
4万
查看次数

Excel - 使用 FILTERXML 从字符串中提取子字符串

背景

最近,我一直试图更加熟悉将分隔字符串更改为 XML 以使用 Excel 进行解析FILTERXML并检索那些感兴趣的子字符串的概念。请注意,此功能在 Excel 2013 中可用,但不适用于 Excel for Mac 或 Excel Online。

对于分隔字符串,我的意思是使用空格作为分隔符的普通句子或可用于定义字符串中的子字符串的任何其他字符组合。例如,让我们想象以下内容:

ABC|123|DEF|456|XY-1A|ZY-2F|XY-3F|XY-4f|xyz|123
Run Code Online (Sandbox Code Playgroud)

因此,很多人都知道如何获取第n 个元素(例如:=TRIM(MID(SUBSTITUTE(A1,"|",REPT(" ",LEN(A1))),3*LEN(A1)+1,LEN(A1)))要检索456)。或其他combinationes有LEN()MID()FIND()和所有这些结构,我们如何使用FILTERXML使用更具体的标准来关注的提取子和清理满弦?例如,如何检索:

  • 按位置排列的元素
  • 数字或非数字元素
  • 自身包含子字符串的元素
  • 以子字符串开头或结尾的元素
  • 大写或小写的元素
  • 持有数字的元素
  • 独特的价值
  • ...

xml arrays excel xpath excel-formula

26
推荐指数
2
解决办法
3191
查看次数

SecurityConfiguration 类型的 withDefaults() 方法未定义

我正在使用 Spring Security 构建一个 Spring 应用程序。我在代码中添加了用户名和密码的基本身份验证。我想通过这个基本身份验证通过reactjs Web应用程序访问API。为此,我尝试添加 cors 策略。

在 spring security 的安全配置中,我收到错误: The method withDefaults() is undefined for the type SecurityConfiguration

我已经安装了所有必要的依赖项。可能的解决方案是什么?

下面附上我的代码。

package com.example.demo;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.configurers.CorsConfigurer;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    UserDetailsService userDetailsService;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception { …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security

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

ValueError:安装 DBtypes 才能使用此功能

我是第一次使用 BigQuery。

client.list_rows(table, max_results = 5).to_dataframe();
Run Code Online (Sandbox Code Playgroud)

每当我使用 to_dataframe() 时,它都会引发此错误:

ValueError:请安装“db-dtypes”包才能使用此功能。

我发现了这个类似的问题(几乎完全相同),但我无法理解如何实施他们提出的解决方案。

python google-bigquery valueerror modulenotfounderror

25
推荐指数
2
解决办法
3万
查看次数

“ReadOnlyWorksheet”对象没有属性“define_names”

每当我尝试使用以下命令读取 Excel 时

part=pd.read_excel(path,sheet_name = mto_sheet)
Run Code Online (Sandbox Code Playgroud)

我得到这个例外:

<class 'Exception'> 'ReadOnlyWorksheet' 对象没有属性 'define_names'

这是我使用 Visual Studio Code 和 Python 3.11 的情况。不过我用Anaconda就没有这个问题。有什么理由吗?

python exception

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

使用finally语句

这是一个非常基本的问题.在Java中,我使用finally语句来关闭资源,因为"这是一个很好的做法".我在Javascript中开发,然后在Node.js中开发了几年,我从未使用过该finally语句.我知道在Node.js中我们所有人都遵循第一个参数错误处理模式.无论如何,以下2个片段也是如此:

try{
    throw 123
}catch (e){

}finally{
    console.log(1)
}
Run Code Online (Sandbox Code Playgroud)

.

try{
    throw 123
}catch (e){

}

console.log(1)
Run Code Online (Sandbox Code Playgroud)

两者都打印1.

为什么finally它有没有真正的好处关键字?清理代码可以放在catch中.

javascript node.js

24
推荐指数
3
解决办法
4571
查看次数

方法使用Java 8三元条件和未装箱的原语过载歧义

以下是Java 7中的代码编译,但不是openjdk-1.8.0.45-31.b13.fc21.

static void f(Object o1, int i) {}
static void f(Object o1, Object o2) {}

static void test(boolean b) {
    String s = "string";
    double d = 1.0;
    // The supremum of types 'String' and 'double' is 'Object'
    Object o = b ? s : d;
    Double boxedDouble = d;
    int i = 1;
    f(o,                   i); // fine
    f(b ? s : boxedDouble, i); // fine
    f(b ? s : d,           i); // ERROR!  Ambiguous
}
Run Code Online (Sandbox Code Playgroud)

编译器声称最后一个方法调用不明确.

如果我们改变的第二个参数的类型f …

java overloading java-8

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

将 Gradle 从 7.4.2 升级到 Gradle 8.0.0 在发布应用程序时出现错误 - java.lang.ClassCastException

我最近将 Android Studio 升级到了 Flamingo,并将 Gradle 从 7.4.2 升级到了 8.0.0。7.4.2 版本中一切正常。

当我使用 Gradle 8.0.0 生成签名的 APK 时,它给我一个运行时错误java.lang.ClassCastException

我尝试了很多解决方案,例如为 Retrofit、Okio、OkHttp 等添加 Proguard 规则,但它仍然给我这样的错误。

注意:当我从 8.0.0 降级到 7.4.2 时,它可以工作。

所以任何人都可以帮助我找出 AGP 8.0.0 的问题。

构建.gradle(应用程序)

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
    id 'kotlin-parcelize'
    id 'com.google.dagger.hilt.android'
    id 'com.google.gms.google-services'
    id 'com.google.firebase.crashlytics'
}


android {
    
    compileSdk 33

    defaultConfig {
        
        minSdk 24
        targetSdk 33
        versionCode 22
        versionName "1.0.16"
        multiDexEnabled true

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        /*vectorDrawables {
            useSupportLibrary true
        }*/

        def localPropertiesFile = rootProject.file("local.properties")
        def localProperties …
Run Code Online (Sandbox Code Playgroud)

java gradle kotlin android-gradle-plugin gradle-plugin

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