嗨为什么 using (var sw = new StreamWriter(ms))
回来Cannot access a closed Stream
exception
.Memory Stream
在此代码之上.
using (var ms = new MemoryStream())
{
using (var sw = new StreamWriter(ms))
{
sw.WriteLine("data");
sw.WriteLine("data 2");
ms.Position = 0;
using (var sr = new StreamReader(ms))
{
Console.WriteLine(sr.ReadToEnd());
}
} //error here
}
Run Code Online (Sandbox Code Playgroud)
什么是解决它的最佳方法?谢谢
我的本地 docker 桌面上有一个本地 kubernetes 集群。
这是我的 kubernetes 服务在我执行以下操作时的样子 kubectl describe service
Name: helloworldsvc
Namespace: test
Labels: app=helloworldsvc
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"helloworldsvc"},"name":"helloworldsvc","namespace":"test...
Selector: app=helloworldapp
Type: ClusterIP
IP: 10.108.182.240
Port: http 9111/TCP
TargetPort: 80/TCP
Endpoints: 10.1.0.28:80
Session Affinity: None
Events: <none>
Run Code Online (Sandbox Code Playgroud)
此服务指向具有 Web 应用程序的部署。
我的问题是如何找到此服务的网址?我已经尝试过 http://localhost:9111/ 并且没有用。
我确认此服务指向的 pod 已启动并正在运行。
我有下面的OverlayComponent,它在异步调用期间用作处理微调器.叠加弹出没有问题但是当我尝试向其传递消息时,消息不会粘住.
子组件
import {Component, OnInit} from '@angular/core';
import {OverlayComponent} from "../../shared/app.mysite.overlay.component";
@Component({
moduleId: module.id,
selector: 'tracker-component',
templateUrl: '/public/app/templates/pages/racker/mysite.tracker.component.html',
styleUrls: ['../../../scss/pages/tracker/tracker.css'],
providers: [OverlayComponent]
})
export class TrackerComponent implements OnInit{
constructor(private overlayComponent: OverlayComponent) {
}
ngOnInit(): void {
this.overlayComponent.showOverlay("Testing 123"); //<-- shows overlay but doesn't show the message in the overlay
}
}
Run Code Online (Sandbox Code Playgroud)
子组件HTML
<div id="TrackerContainer">
<div class="col-lg-12" class="container">
<div class="jumbotron jumbotron-header">
<div>
<div id="pageTitle">Tracker</div>
</div>
</div>
<div class="content-container container">
<div *ngFor="let item of tracker.activeMenu.items">
<card-component [item]="item"></card-component>
</div>
</div>
</div>
</div>
<overlay-component …
Run Code Online (Sandbox Code Playgroud) 我正在学习一些ngrx教程,我想我已经开始集中注意力了。
我不明白的是如何做一些简单的事情,例如从以下位置获取值Store
:
目标:无需亲自去商店就能获得价值subscribe
。即:store.myStoreProperty
或store.getValue(<selector>)
或?
据我了解,从商店获取价值的唯一方法是执行以下操作:
private readonly _store: Store<ApplicationState>;
// ...
this._store.select(state => state.currentUser).subscribe(user => {
if (!user) { return; }
// ...
});
Run Code Online (Sandbox Code Playgroud)
问题:是否有任何可能的方法可以“立即”从商店获取值而无需订阅?
我可能只是很难理解选择器,但我认为这就是它们的用途。文档中的示例:
import { createSelector } from '@ngrx/store';
export interface FeatureState {
counter: number;
}
export interface AppState {
feature: FeatureState;
}
export const selectFeature = (state: AppState) => state.feature;
export const selectFeatureCount = createSelector(
selectFeature,
(state: FeatureState) => state.counter
);
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我想我可以直接调用selectFeature …
我试图找出一种在我的应用程序中为用户存储唯一ID的好方法.我正在使用facebook登录进行用户管理,并为用户提供了一个类:
function FacebookUser(userObj) {
if (userObj) {
this.name = userObj.name;
this.id = userObj.id;
this.picture = userObj.picture.data.url;
this.isLoggedIn = true;
} else {
this.name = 'Login';
this.id = 0;
this.picture = '';
this.isLoggedIn = false;
}
}
Run Code Online (Sandbox Code Playgroud)
基本上,我有角度处理Facebook登录的服务:
.service('facebookService', function () {
this.getFacebookUser = function (callback) {
$.getScript("//connect.facebook.net/en_US/sdk.js", function () {
var appId = "12312312313123";
FB.init({
appId: appId,
status: true,
cookie: true,
xfbml: true,
version: 'v2.4'
});
FB.getLoginStatus(function (response) {
if (response.status == 'connected') {
FB.api('/me?fields=picture,name,email', function (data) {
callback(new FacebookUser(data)); …
Run Code Online (Sandbox Code Playgroud) 我正在尝试建立一个股票价格的预测模型。从我读到的内容来看,LSTM 是一个很好的使用层。我不能完全理解input_shape
我的模型需要什么。
这是tail
我的DataFrame
然后我将数据拆分为训练/测试
labels = df['close'].values
x_train_df = df.drop(columns=['close'])
x_train, x_test, y_train, y_test = train_test_split(x_train_df.values, labels, test_size=0.2, shuffle=False)
min_max_scaler = MinMaxScaler()
x_train = min_max_scaler.fit_transform(x_train)
x_test = min_max_scaler.transform(x_test)
print('y_train', y_train.shape)
print('y_test', y_test.shape)
print('x_train', x_train.shape)
print('x_test', x_test.shape)
print(x_train)
Run Code Online (Sandbox Code Playgroud)
这产生:
这就是我感到困惑的地方。运行这个简单的例子,我得到以下错误:
ValueError: 层 lstm_15 的输入 0 与层不兼容:预期 ndim=3,发现 ndim=4。收到完整形状:[无、1、4026、5]
我尝试了各种乱七八糟的组合input_shape
并得出了结论,我不知道如何确定输入形状。
model = Sequential()
model.add(LSTM(32, input_shape=(1, x_train.shape[0], x_train.shape[1])))
model.compile(optimizer='adam', loss='mse', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=10)
Run Code Online (Sandbox Code Playgroud)
鉴于我的数据框,我的应该是什么input_shape
?我知道输入形状是batch size
, timesteps
, data dim
。只是不清楚如何将这些词映射到我的实际数据,因为我认为这些值实际上不是。
我刚在想: …
如何使 3 个独立的 div 拉伸到屏幕的高度而不发生溢出?
我正在使用 bootstrap 和 flexbox,但每当我将行的高度设置为 100% 时,就会出现溢出。
我希望“内容”(黄色区域)填充页面的大部分,而页眉(浅绿色区域)和页脚(粉色区域)仅占用 100 像素。
我尝试过使用 Flex-Grow 和 Stretch,但没有效果。
预先感谢您提供任何有用的意见。
https://jsfiddle.net/7xtybdrm/1/
CSS:
body {padding-top: 51px;}
html, body {
background-color: rgb(48, 48, 48);
height: 100%;
}
.body-container {
height: 100%;
display: flex;
flex-direction: column;
}
.ribbon-container {
background-color:aqua;
height: 100px;
flex: 1;
}
.content-container {
background-color: yellow;
display: flex;
flex: 2;
}
.footer-container {
height: 50px;
background-color: pink;
display: flex;
flex: 1;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<head runat="server">
<title></title>
</head>
<body>
<nav class="navbar navbar-inverse …
Run Code Online (Sandbox Code Playgroud) 我纯粹使用 SqlKata 在 C# 中构建 sql 查询。我想获取我构建的输出Query
,获取原始(编译的)sql 字符串,并针对 SQL 执行它。
我认为这会做到:
var factory = new QueryFactory(null, new SqlServerCompiler());
var query = new Query();
...
var sqlText = factory.Compiler.Compile(query).Sql;
Run Code Online (Sandbox Code Playgroud)
但这给出了:
SELECT TOP (@p0) [AllStarFull].[GameNumber], [AllStarFull].[LeagueId], [AllStarFull].[PlayedInGame] FROM [AllStarFull]
Run Code Online (Sandbox Code Playgroud)
这会引发异常,因为它(@p0)
是一个参数,而不是实际值。
在文档中,它提到了引入,Logger
但我并不真正需要日志记录功能(现在)。
https://sqlkata.com/docs/execution/logging
var db = new QueryFactory(connection, new SqlServerCompiler());
// Log the compiled query to the console
db.Logger = compiled => {
Console.WriteLine(compiled.ToString());
};
var users = db.Query("Users").Get();
Run Code Online (Sandbox Code Playgroud)
有没有办法从Query
填充了所有参数的sql 字符串中获取原始 sql 字符串?
我正在构建一个 Angular2 滑块组件,当前设置是滑块的值是百分比(基于滑块手柄的位置从 0% - 100%)。我有一个包含 n 个项目的数组,并希望滑块根据百分比(手柄所在的位置)从数组中获取适当的索引。
这是我当前的拖动事件(当用户拖动滑块手柄时触发):
handleDrag(evt, ui) {
let maxWidth = $('#slideBar').width() - 15;
let position = $('#slideHandle').css('left');
position = position.replace('px', '');
let percent = (+position / +maxWidth) * 100;
this.year = percent;
}
Run Code Online (Sandbox Code Playgroud)
百分比工作正常,但我想知道我应该如何构建算法以按百分比获取数组索引。因此,如果我处于 50%,如果数组长度为 146,我想获取数组索引 73。
有没有更简单的方法用 JavaScript 来做到这一点?我已经完成了一个类似的组件,其中我使用了表格方法,但想找出一种方法来做到这一点,而不需要向页面添加“helper html elements”。
where
如果通过 url 传入特定内容,我尝试添加一个附加子句queryParameter
,但它似乎不起作用。在我开始执行原始sql之前,我想首先弄清楚我是否做得正确(文档似乎很少,因为我找不到任何东西)
为了简洁起见最小化代码
public IActionResult RetrieveAll([FromQuery] string orderByDate, [FromQuery] string taskStatus)
{
try
{
var taskQuery = (from t in _context.Tasks select t);
switch(taskStatus)
{
case "completed":
taskQuery.Where(t => t.IsCompleted == true);
break;
case "notcompleted":
taskQuery.Where(t => t.IsCompleted == false);
break;
}
var tasks = taskQuery.ToList();
return Ok(tasks);
}
catch (Exception ex)
{
return BadRequest();
}
}
Run Code Online (Sandbox Code Playgroud)
我想只要简单地附加这个Where
条款就可以了。该代码执行正确的代码路径,但它仍然返回所有结果。