我写了一个小函数,以便更好地处理类型.
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)
我尝试使用泛型,但不知道如何从泛型参数获取类型.这是可能的?
我刚刚在Windows 10(64位)上安装了NetBeans 8.10.一切正常,但我不知道,如何关闭PHP文件中有关重命名全局函数的提示.
我在工具>选项>编辑器>提示中搜索,但没有发现任何相关的...
我已经用这个签名实现了端点
[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) 我正在尝试做一些交互式地图,我正在使用两个非常大的图像(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)
我正在使用 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
文件。我怎样才能得到后者?
我可以声明 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) 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) 我正在学习F#(第二天O :-))并且我想创建Collatz序列,其中每个值都是基于前一个计算的.我知道,在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#(再次),我试图在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) ||>
似乎很冗余......
我的评论以反斜杠结尾.就像是
...
// use \
..
Run Code Online (Sandbox Code Playgroud)
Clang(++)警告我,这是多行评论
warning: multi-line // comment [-Wcomment]
// use \
^
Run Code Online (Sandbox Code Playgroud)
所以我尝试在最后添加一些空格,但没有帮助.我可以以某种方式逃避反斜杠吗?
typescript ×3
c# ×2
f# ×2
sequence ×2
asp.net-core ×1
c++ ×1
clang++ ×1
comments ×1
css ×1
escaping ×1
generator ×1
generics ×1
getter ×1
html ×1
ienumerable ×1
mime-types ×1
netbeans ×1
php ×1
refactoring ×1
rollupjs ×1
source-maps ×1
swagger ×1
task ×1
tsc ×1
types ×1