如何删除给定子字符串的第一个出现?
我有:
phrase = "foobarfoo"
Run Code Online (Sandbox Code Playgroud)
而且,当我打电话:
phrase.some_method_i_dont_know_yet ("foo")
Run Code Online (Sandbox Code Playgroud)
我希望这句话看起来像barfoo
.
我尝试过delete
,slice
但第一次删除所有出现但第二次只返回切片.
我正在为我的一个Identity Server 3客户端使用授权代码流,它配置如下:
ClientId = "tripgalleryauthcode",
ClientName = "Trip Gallery",
Flow = Flows.AuthorizationCode,
AllowAccessToAllScopes = true,
RequireConsent = false,
// redirect = URI of our callback controller in the IOS application
RedirectUris = new List<string>
{
"somecallbackuri"
},
ClientSecrets = new List<Secret>()
{
"somesecret"
},
// refresh token options
AccessTokenType = AccessTokenType.Jwt,
AccessTokenLifetime = 120,
RefreshTokenUsage = TokenUsage.OneTimeOnly,
RefreshTokenExpiration = TokenExpiration.Absolute,
AbsoluteRefreshTokenLifetime = 360,
Run Code Online (Sandbox Code Playgroud)
如您所见,它被配置为在2分钟内使访问令牌到期,在6分钟内使刷新令牌到期.我这样做是因为我想尝试在更短的时间范围内调试问题而不是我在生产中使用的那个:刷新令牌15天,访问令牌1小时.我们注意到由于某种原因,今天发布的刷新令牌明天不起作用.这就是为什么我决定减少时间,这就是发生的事情:
我注意到了更多.发生的事情是访问令牌到期后2分钟我得到400错误.它说刷新令牌无效.
这是Identity Server的日志.
w3wp.exe Information: 0 : …
Run Code Online (Sandbox Code Playgroud) 我有一个log4net的配置如下:
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<file value="C:\...\log-file.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<header value ="Start new file proccessing..."/>
<conversionPattern value="%newline%date - %message%exception" />
<footer value ="Finish with the proccessing"/>
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我希望我可以在我的页脚之后添加一个新行,所以当我不止一次地添加到我的日志文件时,上一次运行的页脚不会与开头(标题)保持在同一行第二轮.
例:
Operation started..
....
Operation endedOperationStarted
....
Operation ended
Run Code Online (Sandbox Code Playgroud)
我希望我可以看起来像:
Operation started..
....
Operation ended
OperationStarted
....
Operation ended
Run Code Online (Sandbox Code Playgroud) 我有一个简单的脚本,它使用signalr-client-py作为外部模块。
from requests import Session
from signalr import Connection
import threading
Run Code Online (Sandbox Code Playgroud)
当我尝试使用 运行我的脚本时sudo python myScriptName.py
出现错误:
Traceback (most recent call last):
File "buttonEventDetectSample.py", line 3, in <module>
from signalrManager import *
File "/home/pi/Desktop/GitRepo/DiatAssign/Main/signalrManager.py", line 2, in <module>
from signalr import Connection
ImportError: No module named signalr
Run Code Online (Sandbox Code Playgroud)
如果我只运行我的脚本输入python myScriptName.py
它工作得很好但是我需要在前面有sudo因为稍后在我的其他脚本中(使用这个脚本)我在文件系统上执行写操作。
我对 Python 很陌生,这就是为什么我需要知道如何处理这种情况。如果我输入,pydoc modules
我会得到一个列表,其中包含:
signalr
signalrManager
Run Code Online (Sandbox Code Playgroud)
如果我输入,pip freeze
我可以看到那里列出:
signalr-client==0.0.7
Run Code Online (Sandbox Code Playgroud) 当我调用first_array | second_array
两个包含自定义对象的数组时:
first_array = [co1, co2, co3]
second_array =[co2, co3, co4]
Run Code Online (Sandbox Code Playgroud)
它返回[co1, co2, co3, co2, co3, co4]
。它不会删除重复项。我试图调用uniq
结果,但它也不起作用。我该怎么办?
更新:
这是自定义对象:
class Task
attr_accessor :status, :description, :priority, :tags
def initiate_task task_line
@status = task_line.split("|")[0]
@description = task_line.split("|")[1]
@priority = task_line.split("|")[2]
@tags = task_line.split("|")[3].split(",")
return self
end
def <=>(another_task)
stat_comp = (@status == another_task.status)
desc_comp = (@description == another_task.description)
prio_comp = (@priority == another_task.priority)
tags_comp = (@tags == another_task.tags)
if(stat_comp&desc_comp&prio_comp&tags_comp) then return 0 end
end
end …
Run Code Online (Sandbox Code Playgroud) 如何==
为我的类的实例定义运算符?我试过这样的:
public bool operator == (Vector anotherVector)
{
return this.CompareTo(anotherVector) == 1 ;
}
Run Code Online (Sandbox Code Playgroud)
但它说:
可以超载的一元运算符
在分配值时是否可以逃避该效果:
irb(main):584:0>a = true
=>true
irb(main):584:0>
Run Code Online (Sandbox Code Playgroud)
我有一个代码,有很多分配,当我尝试测试它时,由于所有这些返回值,我无法看到结果:
true
false
true
false
true
true
..
Run Code Online (Sandbox Code Playgroud) 我正在尝试在我想要测试的方法内模拟服务调用。
方法体如下所示:
public string OnActionException(HttpActionContext httpRequest, Exception ex)
{
var formattedActionException = ActionLevelExceptionManager.GetActionExceptionMessage(httpRequest);
var mainErrorMessage = $"[{formattedActionException.ErrorId}]{formattedActionException.ErrorMessage}, {ex.Message}";
this.LogError(mainErrorMessage, ex);
if (this._configuration.MailSupportOnException)
Task.Run(async () => await this._mailService.SendEmailForThrownException(this._configuration.SupportEmail, $"{mainErrorMessage} ---> Stack trace: {ex.StackTrace.ToString()}"));
return $"(ErrID:{formattedActionException.ErrorId}) {formattedActionException.ErrorMessage} {formattedActionException.KindMessage}";
}
Run Code Online (Sandbox Code Playgroud)
我在测试中试图模拟的是:
Task.Run(async () => 等待 this._mailService.SendEmailForThrownException(this._configuration.SupportEmail, $"{mainErrorMessage} ---> 堆栈跟踪: {ex.StackTrace.ToString()}"));
测试方法如下所示:
[TestMethod]
public void We_Send_System_Exception_On_Email_If_Configured_In_Settings()
{
// arrange
this._configurationWrapperMock.Setup(cwm => cwm.MailSupportOnException)
.Returns(true);
this._mailServiceMock.Setup(msm => msm.SendEmailForThrownException(It.IsAny<string>(), It.IsAny<string>()))
.Returns(Task.FromResult(0));
// act
var logger = new ApiLogger(this._configurationWrapperMock.Object, this._mailServiceMock.Object);
logger.OnActionException(
new HttpActionContext(
new HttpControllerContext()
{
Request = …
Run Code Online (Sandbox Code Playgroud) 我正在构建一个基于Expo的 React 本机应用程序,我还想结合Firebase 实时数据库利用 Expo 的推送通知功能。我基本上按照此处描述的步骤进行操作。在到达必须提取推送通知令牌的部分之前,一切都很顺利。
registerForPushNotificationsAsync = async (userInfo) => {
// ... Stuff
// Get the token that uniquely identifies this device
let token = await Notifications.getExpoPushTokenAsync();
console.log("Expo token: " + token);
var updates = {}
updates['/expoToken'] = token
firebase.database().ref('Users').child(userInfo.user.uid).update(updates)
}
Run Code Online (Sandbox Code Playgroud)
问题发生在这一行:
let token = await Notifications.getExpoPushTokenAsync();
Run Code Online (Sandbox Code Playgroud)
它从不返回值,我无法获得推送令牌。这是 Android 特定的(Android 7.0),它不会出现在 iPhone (iOS 11.0.2) 上。在 iPhone 上返回一个令牌,我成功地将它存储在数据库中。
我正在做的是使用他们的 CLI 开始博览会并扫描生成的二维码(使用他们的 IOS/Android 客户端应用程序)。然后,再次在浏览器加载的 CLI 中,我分别在 iPhone 和 Android 手机上观察应用程序运行时发生的情况。软件包的版本如下:
世博会@31.0.2
firebase@5.5.7 …
push-notification react-native react-native-android firebase-cloud-messaging expo
我有一个 Firebase可调用函数,其定义如下:
exports = module.exports = functions.https.onCall((data, context) => {
// ...
})
Run Code Online (Sandbox Code Playgroud)
我想做的是将文件读取流(从 Firebase 存储读取)传输到可调用函数的响应,就像我在这个http 函数中所做的那样:
exports = module.exports = functions.https.onRequest((req, res) => {
const file = defaultStorageBucket.file(`/reports/myReport.pdf`);
const readStream = file.createReadStream();
readStream.pipe(res)
});
Run Code Online (Sandbox Code Playgroud)
是否有可能实现这一目标以及如何实现?我注意到context参数包含一个rawRequest属性,其中包含Response但我不知道如何使用它。
我的最终目标是在我的 Firebase 应用程序的客户端上立即开始下载该文件。