小编Joã*_*ulo的帖子

window.location 断开 websocket

我想打开下载链接而不打开空白页面(然后,我不会使用window.open)。然后我使用window.location.hrefor window.location.assign。但问题是这两种方法都会断开我的 websockets 连接。我该如何解决这个问题?

为了更清楚起见,没有抛出任何错误消息,我在 chrome 上测试了它。Websocket 就停止工作了。

javascript window.location websocket

6
推荐指数
0
解决办法
270
查看次数

导入模块时内存使用差异

我想知道以这些方式导入模块时内存使用情况有什么区别:

import Mod1
from Mod1 import *
from Mod1 import a,b,c
Run Code Online (Sandbox Code Playgroud)

主要介于前两者之间。

python memory import-module

5
推荐指数
1
解决办法
2258
查看次数

打印时,Google地图画布变空白(Ctrl + P)

我正在尝试打印位于引导程序面板内的Google地图画布,如下所示:

<div class="panel panel-default">
    <div class="panel-body">
        <div id="map">...</div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我正在尝试以简单的方式打印,只需按下即可CTRL + P.但是在打印可视化框中,地图是空白的.可能会发生什么?

一些图片: 在页面

在页面

在打印盒

在打印盒

printing google-maps-api-3 html5boilerplate twitter-bootstrap

5
推荐指数
1
解决办法
1917
查看次数

内联是否确定内部链接?

我试图外部内联函数。我认为它应该如何工作:

//a.cpp
inline void f(int) {}
//b.cpp
extern void f(int);
int main() { f(4); }
Run Code Online (Sandbox Code Playgroud)

但是出现链接错误。然后通过阅读此内容(“ 1inline,必须在每个翻译单元中声明它)。我试过的

//a.cpp
inline void f(int) {}
//b.cpp
extern inline void f(int);
int main() { f(4); }
Run Code Online (Sandbox Code Playgroud)

仍然出现链接错误。但是现在,尝试一些我不知道自己在做什么的事情:

//a.cpp
extern inline void f(int) {}
//b.cpp
extern inline void f(int);
int main() { f(4); }
Run Code Online (Sandbox Code Playgroud)

有用。这里发生了什么事?之前加入extern的一切,fa.cpp有内在联系?

我正在将MSVC 2017(v141)与/permissive-/std:c++17

c++ inline linkage

5
推荐指数
1
解决办法
217
查看次数

对枚举使用计算值

我有以下情况:

enum T {
    A = "a"
};

enum U {
    [T.A] = "u"
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

枚举中不允许​​使用计算属性名称。

有办法解决吗?或者也许使用类似的资源可以让我有类似的行为?

enums typescript

5
推荐指数
1
解决办法
3395
查看次数

如何使用ASP.NET从SQL Server显示图像?

这是我的类(product.cs),其中插入图像的方法是:

public static void InsertProductIMG(byte[] image, string contentType) 
{
   string cs = "Data Source=(local);Initial Catalog=myApp;Integrated Security=True";
   string comandoSql = "INSERT INTO [myApp].[dbo].[product] (image, ContentType) VALUES (@image, @contentType)";

   using (SqlConnection conn = new SqlConnection(cs))
   {
       conn.Open();

       using (SqlTransaction trans = conn.BeginTransaction())
       {
           SqlCommand cmd = new SqlCommand(comandoSql, conn, trans);
           SqlParameter[] parms = new SqlParameter[2];
           parms[0] = new SqlParameter("@image", image);
           parms[1] = new SqlParameter("@contentType", contentType);
           foreach (SqlParameter p in parms)
           {
              cmd.Parameters.Add(p);
           }

           cmd.ExecuteNonQuery();
           trans.Commit();
       }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是apsx页面背后的代码,我调用上面的方法:

byte[] imageBytes = …
Run Code Online (Sandbox Code Playgroud)

c# sql-server asp.net image

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

PHP数小于10位小数

我有这种情况:

$a = (double)"8.876543456787654";
echo json_encode(["value" => $a]);
Run Code Online (Sandbox Code Playgroud)

它正在归还:

{"value":8.8765434567877}
Run Code Online (Sandbox Code Playgroud)

而不是这个,这是可取的:

{"value":8.876543456787654}
Run Code Online (Sandbox Code Playgroud)

请注意,我不能这样:

{"value":"8.876543456787654"}
Run Code Online (Sandbox Code Playgroud)

如何更改此精度并取消舍入?

php floating-accuracy

4
推荐指数
1
解决办法
243
查看次数

Is this expression an lvalue or an rvalue?

Look at this expression:

T t;    
T& ref = t;
Run Code Online (Sandbox Code Playgroud)

The ref expression is an lvalue or an rvalue? I believe it's an rvalue because ref does not "designates a function or an object":

"An lvalue (so called, historically, because lvalues could appear on the left-hand side of an assignment expression) designates a function or an object."

[open-std draft n3092]

According to cppreference, a reference is not a object.

"The following entities are not objects: value, reference …

c++ rvalue move-semantics c++11

4
推荐指数
1
解决办法
185
查看次数

在组件上注入http拦截器

我创建了这个http拦截器:

@Injectable()
export class NoopInterceptor  implements HttpInterceptor {
    public my_status: boolean = true;
    private _statusChange: Subject<boolean> = new Subject<boolean>();
    public statusChange$ = this._statusChange.asObservable();
    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        this.changeStatus(false);
        const my_req = req.clone({
            url: API_PATH + req.url
        });
        return next
            .handle(my_req)
            .do(event => {
                if (event instanceof HttpResponse)
                    this.changeStatus(true);
            });
    }

    private changeStatus(status: boolean) {
        this.my_status = status;
        this._statusChange.next(this.my_status);
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的组件中,我做到了:

export class AppComponent implements OnInit {
    public my_status: boolean;
    constructor(private httpInterceptor: NoopInterceptor) {
        this.my_status = httpInterceptor.my_status;
        httpInterceptor.statusChange$.subscribe(this.changeStatus); …
Run Code Online (Sandbox Code Playgroud)

angular-http-interceptors angular

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

C++ 17 有静态反射吗?

结合if constexpr一些<type_traits>实体,在 C++17 中,我能够在编译时检查类型。这些技术可以被认为是静态反射吗?还是只是型式检验?例子:

if constexpr (std::is_same_v<T, U>) statement
Run Code Online (Sandbox Code Playgroud)

反射概念是否仅适用于运行时?称之为静态反射是否正确?

c++ reflection c++17 if-constexpr

3
推荐指数
1
解决办法
2549
查看次数