我创建了一个Windows服务程序,我希望我的错误严格写入Windows eventLog.所以我从代码项目文章中遵循了以下步骤:
http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx
但是,当我启动或停止服务时,我没有在事件查看器窗口中创建的事件日志中看到任何自定义日志消息.另外,如何指定消息是由于错误还是仅仅是信息?
我希望我的用户注册页面显示电子邮件和密码字段,而不是用户名.我创建了这个注册表:
class RegisterForm(UserCreationForm):
email = forms.EmailField(label = "Email")
#fullname = forms.CharField(label = "First name")
class Meta:
model = User
fields = ("email", )
def save(self, commit=True):
user = super(RegisterForm, self).save(commit=False
user.email = self.cleaned_data["email"]
if commit:
user.save()
return user
Run Code Online (Sandbox Code Playgroud)
但用户名仍然显示.我需要覆盖其他内容吗?
这可能是一个相对菜鸟的问题,我有一个界面
interface Employee {
name: string
}
Run Code Online (Sandbox Code Playgroud)
我希望在将其保存到数据库后有一个扩展版本:
interface EmployeeDb {
id: string,
name: string
}
Run Code Online (Sandbox Code Playgroud)
我想在处理检查时区分它,以便在将数据保存到我的存储中后,类型检查器不会抱怨没有 id 值。这意味着我想避免使用这个:
interface Employee {
id?: string,
name: string
}
Run Code Online (Sandbox Code Playgroud)
这样我就不用到处检查id了。
所以我尝试这样做:
type Employee = {
name: string
}
type IDatabaseObject<T> = {
id: IDatabaseObjectId;
[P in keyof T]: T[P];
};
type EmployeeDb = IDatabaseObject<Employee>
Run Code Online (Sandbox Code Playgroud)
IDE 给出了 top 语法错误
计算属性名称必须为“string”、“number”、“symbol”或“any”类型。ts(2464)
所以我尝试使用接口并扩展它
interface IDatabaseObject {
id: string
}
interface EmployeeDb extends Employee, IDatabaseObject {}
Run Code Online (Sandbox Code Playgroud)
但在后端代码中,当我尝试使用此设置时,我再次收到来自 vscode eslint 的错误。我这里有一个小代码,它将数据添加到本地存储,生成一个 id 并返回数据。参见代码:
class DbAsyncStorageTemplate<
InputDataType,
OutputDataType …
Run Code Online (Sandbox Code Playgroud) 我将 Cesium 的模型之一加载到场景中,并且我想使用两个点来计算模型的方向,这是我创建的函数。
// calculate the direction which the model is facing
calculateOrientation({ position, nextPosition }) {
let dir = new Cesium.Cartesian3();
let normalizedDir = new Cesium.Cartesian3();
Cesium.Cartesian3.subtract(nextPosition, position, dir);
Cesium.Cartesian3.normalize(dir, normalizedDir);
var heading = Math.acos(normalizedDir.x);
var pitch = Math.acos(normalizedDir.y);
var roll = 0;
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
return orientation;
}
Run Code Online (Sandbox Code Playgroud)
但我得到的轮换没有任何意义。我的数学错了吗?
在@Keshet 给出第一个答案后,我查找了如何找到平面和向量之间的角度。我想如果我找到每个平面的法线和 -90 之间的角度,我应该得到正确的角度,但我不确定这是否正确。
另外我不知道Cesium Axis是如何工作的,也找不到任何描述它的文档。例如XY平面等。
let dir = new Cesium.Cartesian3();
let xyNormal = new Cesium.Cartesian3(0,0,1);
let xzNormal = …
Run Code Online (Sandbox Code Playgroud) 我有来自其他来源的> 67000条记录来到我的系统.将业务规则应用于这些记录后,我必须将它们存储到数据库中.我使用以下代码执行此操作:
using (var context = new MyEntities())
{
var importDataInfo = context.ImportDataInfoes.First(x => x.ID == importId);
importedRecords.ForEach(importDataInfo.ValuationEventFulls.Add);
context.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)
执行代码后,我收到以下错误(OutOfMemoryException)
Error in executing code|Exception of type 'System.OutOfMemoryException' was thrown.* at System.Data.Mapping.Update.Internal.KeyManager.<WalkGraph>d__5.MoveNext()
at System.Data.Mapping.Update.Internal.KeyManager.GetPrincipalValue(PropagatorResult result)
at System.Data.Mapping.Update.Internal.UpdateCompiler.GenerateValueExpression(EdmProperty property, PropagatorResult value)
at System.Data.Mapping.Update.Internal.UpdateCompiler.BuildSetClauses(DbExpressionBinding target, PropagatorResult row, PropagatorResult originalRow, TableChangeProcessor processor, Boolean insertMode, Dictionary`2& outputIdentifiers, DbExpression& returning, Boolean& rowMustBeTouched)
at System.Data.Mapping.Update.Internal.UpdateCompiler.BuildInsertCommand(PropagatorResult newRow, TableChangeProcessor processor)
at System.Data.Mapping.Update.Internal.TableChangeProcessor.CompileCommands(ChangeNode changeNode, UpdateCompiler compiler)
at System.Data.Mapping.Update.Internal.UpdateTranslator.<ProduceDynamicCommands>d__0.MoveNext()
at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
at System.Data.Mapping.Update.Internal.UpdateCommandOrderer..ctor(IEnumerable`1 commands, UpdateTranslator translator)
at System.Data.Mapping.Update.Internal.UpdateTranslator.ProduceCommands()
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager …
Run Code Online (Sandbox Code Playgroud) 在运行时在本地计算机bash中运行:
echo $((192 << 24))
3221225472
Run Code Online (Sandbox Code Playgroud)
但是在我的嵌入式目标忙框上,我得到了其他东西:
echo $((192 << 24))
-1073741824
Run Code Online (Sandbox Code Playgroud)
当我左移较小的数字时,它会起作用。嵌入式设备是64位,而我的本地主机是32位。
需要明确的是,在32位计算机上,该值为正;在64位计算机上,该值为负。
编辑:这是在带有SHELL的64位计算机的嵌入式设备上。左移23时不会发生。
echo $((192 << 23))
1610612736
echo $((192 << 24))
-1073741824
Run Code Online (Sandbox Code Playgroud)
在本地主机上,这是一台具有BASH的32台计算机:
echo $((192 << 55))
6917529027641081856
echo $((192 << 56))
-4611686018427387904
Run Code Online (Sandbox Code Playgroud) 本文档讨论编写auth.后端但从未说过放置文件的位置. https://docs.djangoproject.com/en/dev/topics/auth/#writing-an-authentication-backend
我已经实现了一个isPermutation
函数,给定两个字符串将返回,true
如果这两个是彼此的排列,否则它将返回false
.
一个使用c ++排序算法两次,而另一个使用一个int数组来跟踪字符串计数.
我运行代码几次,每次排序方法更快.我的阵列实现错了吗?
这是输出:
1
0
1
Time: 0.088 ms
1
0
1
Time: 0.014 ms
Run Code Online (Sandbox Code Playgroud)
和代码:
#include <iostream> // cout
#include <string> // string
#include <cstring> // memset
#include <algorithm> // sort
#include <ctime> // clock_t
using namespace std;
#define MAX_CHAR 255
void PrintTimeDiff(clock_t start, clock_t end) {
std::cout << "Time: " << (end - start) / (double)(CLOCKS_PER_SEC / 1000) << " ms" << std::endl;
}
// using array to keep a …
Run Code Online (Sandbox Code Playgroud) c++ optimization performance permutation performance-testing
我的QML代码中有这个:
TreeView {
...
onExpanded: {
console.log("onExpanded called", index)
}
}
Run Code Online (Sandbox Code Playgroud)
这是它被称为时的输出:
QModelIndex(1,0,0x5d9f5a0,TreeModel(0x5deae90))
Run Code Online (Sandbox Code Playgroud)
如何访问1
QML代码中的第一个值()?
我在这里理解const的用法有困难:
char* const args[];
Run Code Online (Sandbox Code Playgroud)
这是否意味着args不能指向新地址?它与以下内容有何不同:
const char* args[];
Run Code Online (Sandbox Code Playgroud)
此外,我正在尝试遍历此列表并使用单个for循环语句将值附加到字符串:
string t_command;
for(char** t= args; (*t) != NULL ; t++ && t_command.append(*t + " ")) {}
Run Code Online (Sandbox Code Playgroud)
我没有在这里做点什么,我无法弄清楚是什么.
我正在使用C++复制算法来复制字符串文字,(而不是memcpy)但我得到了分段错误我不知道为什么.这是代码:
#include <iostream>
#include <cstring>
#include <stdio.h>
using namespace std;
int main(int argc, char *argv[]) {
// if using copy with regular pointers, there
// is no need to get an output iterator, ex:
char* some_string = "this is a long string\n";
size_t some_string_len = strlen(some_string) + 1;
char* str_copy = new char(some_string_len);
copy( some_string, some_string + some_string_len, str_copy);
printf("%s", str_copy);
delete str_copy;
return 0;
}
Run Code Online (Sandbox Code Playgroud) c++ ×4
c# ×2
django ×2
javascript ×2
linux ×2
.net ×1
amqp ×1
bash ×1
c ×1
cesiumjs ×1
const ×1
copy ×1
embedded ×1
events ×1
forms ×1
logging ×1
optimization ×1
performance ×1
permutation ×1
qml ×1
qt ×1
quaternions ×1
rabbitmq ×1
rotation ×1
service ×1
shell ×1
typescript ×1