小编Mat*_*rný的帖子

获取通用参数的类型

我写了一个小函数,以便更好地处理类型.

function evaluate(variable: any, type: string): any {
    switch (type)
    {
        case 'string': return String(variable);
        case 'number': return isNumber(variable) ? Number(variable) : -1;
        case 'boolean': {
            if (typeof variable === 'boolean')
                return variable;

            if (typeof variable === 'string')
                return (<string>variable).toLowerCase() === 'true';

            if (typeof variable === 'number')
                return variable !== 0;

            return false;
        }
        default: return null;
    }
}

function isNumber(n: any): boolean {
    return !isNaN(parseFloat(n)) && isFinite(n);
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用泛型,但不知道如何从泛型参数获取类型.这是可能的?

generics types typescript

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

如何在NetBeans中启用"修复名称..."提示?

我刚刚在Windows 10(64位)上安装了NetBeans 8.10.一切正常,但我不知道,如何关闭PHP文件中有关重命名全局函数的提示.

在此输入图像描述

我在工具>选项>编辑器>提示中搜索,但没有发现任何相关的...

php configuration netbeans

9
推荐指数
1
解决办法
607
查看次数

为 Swagger 的 multipart/form-data 中的文件指定内容类型

我已经用这个签名实现了端点

[HttpPost("Test")]
public IActionResult MyTest([Required] IFormFile pdf, [Required] IFormFile image)
{
    // some stuff...

    return Ok();
}
Run Code Online (Sandbox Code Playgroud)

这会在 swagger.json (相关部分)中生成以下条目

"content": {
    "multipart/form-data": {
        "schema": {
            "required": [
                "image",
                "pdf"
            ],
            "type": "object",
            "properties": {
                "pdf": {
                    "type": "string",
                    "format": "binary"
                },
                "image": {
                    "type": "string",
                    "format": "binary"
                }
            }
        },
        "encoding": {
            "pdf": {
                "style": "form"
            },
            "image": {
                "style": "form"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,我还需要指定编码,就像在规范(v3) 中一样。所以对于我的任务,JSON 应该是这样的,我想......

"encoding": {
    "pdf": {
        "style": "form",
        "contentType": "application/pdf" …
Run Code Online (Sandbox Code Playgroud)

c# mime-types swagger asp.net-core swagger-codegen

9
推荐指数
1
解决办法
1259
查看次数

Chrome每帧都会对大图像进行解码

我正在尝试做一些交互式地图,我正在使用两个非常大的图像(3200x800和4096x1024像素).问题是,Chrome每帧都会用云解码图像...因此性能非常差(例如在代码段中).

在此输入图像描述

在这里发现类似的问题,但没有帮助.我在Linux Mint 17.1(64位)上使用Chrome 43(64位).我也试过Firefox而没有问题......

html, body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
}

div {
  position: absolute;
  width: 3200px;
  height: 1800px;
  background: url('http://i.imgur.com/p1Jf722.png'), url('http://i.imgur.com/zUkgN3j.jpg');
  animation: clouds 200s linear infinite;
  transition: 5s;
  left: 0;
  top: 0;
}

@keyframes clouds {
  from { background-position: 0 0, left top; }
  to { background-position: 4096px 0, left top; }
}

body:hover > div {
  left: -500px;
  top: -250px;
}
Run Code Online (Sandbox Code Playgroud)
<div></div>
Run Code Online (Sandbox Code Playgroud)

html css google-chrome css-animations

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

可以src吗?TSC?卷起 ?“源映射”指向原始 TypeScript src?

我正在使用 TypeScript 和 Rollup 的组合,如本文中所示。

因此math.ts

export function square(x: number) {
    return x ** 2;
}

export function cube(x: number) {
    return x ** 3;
}
Run Code Online (Sandbox Code Playgroud)

main.ts

import { square } from "./math";

console.log(square(3));
Run Code Online (Sandbox Code Playgroud)

命令后生成

tsc -t ES5 -m es2015 && rollup -f es -o app.js -m -i main.js
Run Code Online (Sandbox Code Playgroud)

文件app.js

function square(x) {
    return Math.pow(x, 2);
}

console.log(square(3));
//# sourceMappingURL=app.js.map
Run Code Online (Sandbox Code Playgroud)

但生成的源映射指向 的.js输出tsc,而不是原始.ts文件。我怎样才能得到后者?

source-maps typescript tsc rollupjs

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

可迭代 getter 的语法?

我可以声明 getter,其行为类似于函数生成器吗?

我的尝试

class Foo {
    * Test1(): IterableIterator<string> { // Works, but not a getter...
        yield "Hello!"; 
    }

    * get Test2(): IterableIterator<string> { // Syntax error
        yield "Hello!"; 
    }

    get * Test3(): IterableIterator<string> { // Syntax error
        yield "Hello!"; 
    }

    get Test4(): IterableIterator<string> { // Works, but ugly syntax...
        return function* (): IterableIterator<string> {
            yield "Hello!";
        }();
    }
}
Run Code Online (Sandbox Code Playgroud)

例如在 C# 中,这是完全有效的......

class Foo
{
    IEnumerable<string> Test
    {
        get
        {
            yield return "Hello!";
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

getter generator typescript

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

Convert IEnumerable&lt;Task&lt;T&gt;&gt; to IObservable&lt;T&gt; with exceptions handling

I want to convert IEnumerable<Task<T>> to IObservable<T>. I found solution to this here:

IObservable<T> ToObservable<T>(IEnumerable<Task<T>> source)
{
    return source.Select(t => t.ToObservable()).Merge();
}
Run Code Online (Sandbox Code Playgroud)

It is perfectly ok for usual cases, but I need to handle exceptions, that could raise in that Tasks... So IObservable<T> should not be dead after first exception.

What I read, recommendation for this use case is to use some wrapper, that will carry actual value or error. So my attempt was

IObservable<Either<T, Exception>> ToObservable<T>(IEnumerable<Task<T>> source) …
Run Code Online (Sandbox Code Playgroud)

c# ienumerable task system.reactive

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

根据以前的值创建序列

我正在学习F#(第二天O :-))并且我想创建Collat​​z序列,其中每个值都是基于前一个计算的.我知道,在C#中做到这一点

public static void Main(string[] args)
{
    Console.WriteLine(string.Join(", ", collatz(13)));
}

static IEnumerable<int> collatz(int n)
{
    while (n != 1)
    {
        yield return n;

        if (n % 2 == 0)
            n /= 2;
        else
            n = 3 * n + 1;
    }

    yield return 1;
}
Run Code Online (Sandbox Code Playgroud)

或者如何在F#中创建类似的数组

let rec collatz = function
    | 1 -> [ 1 ]
    | n when n % 2 = 0 -> n::collatz (n / 2)
    | n -> n::collatz (3 * …
Run Code Online (Sandbox Code Playgroud)

f# sequence

4
推荐指数
3
解决办法
264
查看次数

总结行的更好方法

我正在学习F#(再次),我试图在excel中总结一些行.这是我的尝试.

let sumRows (source: seq<double[]>) =
    source
    |> Seq.reduce (fun a b -> (a, b) ||> Seq.map2 (fun x y -> x + y) |> Seq.toArray)
Run Code Online (Sandbox Code Playgroud)

可以做得更好吗?我已经发现了双前进管道操作员,但现在,整个部分fun a b -> (a, b) ||>似乎很冗余......

refactoring f# sequence

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

如何在//注释中转义反斜杠

我的评论以反斜杠结尾.就像是

...

// use \

..
Run Code Online (Sandbox Code Playgroud)

Clang(++)警告我,这是多行评论

warning: multi-line // comment [-Wcomment]
    // use \
           ^
Run Code Online (Sandbox Code Playgroud)

所以我尝试在最后添加一些空格,但没有帮助.我可以以某种方式逃避反斜杠吗?

c++ comments escaping c-preprocessor clang++

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