我正在使用Nodejs.一切都很好.我的设计师希望网页使用'Proximanova'字体,这是一种非标准字体.他为我提供了相同字体的OTF文件.
如何在服务器上使用此自定义字体?
我检查了一些节点字体包,如FTPM和connect-font,但我不清楚我是否可以这样做.FTPM依赖于Google字体,但我想使用我本地托管的字体.
如果不能直接这样做,你会推荐什么?
使用对列表,想要将它们转换为集合的映射.
输入:对的列表是这样的
listOf(Pair('bob', UGLY), Pair('sue', PETTY), Pair('bob', FAT))
Run Code Online (Sandbox Code Playgroud)
所需的输出是密钥first对的集合映射,集合是second
mapOf('bob' to setOf(UGLY, FAT), 'sue' to setOf(PETTY))
Run Code Online (Sandbox Code Playgroud)
我试过这个,但哇这令人难以置信的冗长.这可以减少吗?
fun main(args: Array<String>) {
var m = HashMap<Int, MutableSet<Int>>()
listOf(1 to 1, 2 to 2, 1 to 3).map {
val set = m.getOrPut(it.first, { listOf<Int>().toMutableSet() })
set.add(it.second)
set
}
println (m)
}
-> {1=[1, 3], 2=[2]}
// yet another version, yields the correct result, but I feel a lack of clarity
// that maybe I'm missing a library function that …Run Code Online (Sandbox Code Playgroud) 我希望轮询端点的速度不会超过每秒一次,并且不会慢于轮询端点所需的时间.永远不应该有多个未完成的请求.
我想要一种反应式编程方式每秒至少轮询一次端点,但如果端点花费的时间超过1秒,则下一个请求会立即触发.
在下面的大理石图中,第2次和第3次请求的时间超过1秒,但第4次和第5次请求更快完成.下一个请求在1秒边界上触发,或者在从最后一个未完成请求获取数据后立即触发.
s---s---s---s---s---s---| # 1 second interval observable
r---r----r--------r-r---| # endpoint begin polling events
-d-------d--------dd-d--| # endpoint data response events
Run Code Online (Sandbox Code Playgroud)
我试图在大理石图中使术语正确,所以我假设端点请求的开头应该是大理石我标记为"r",而标记为"d"的大理石事件具有端点数据.
这是我用普通的js做了多少代码.但是,根据我上面的要求,随后的请求不会立即触发.
var poll;
var previousData;
var isPolling = false;
var dashboardUrl = 'gui/metrics/dashboard';
var intervalMs = updateServiceConfig.getIntervalInMilliSecondForCharts();
return {
startInterval: startInterval,
stopInterval: stopInterval
};
function startInterval() {
stopInterval();
tryPolling(); // immediately hit the dashboard
// attempt polling at the interval
poll = $interval(tryPolling, intervalMs);
}
/**
* attempt polling as long as there is no in-flight request
* …Run Code Online (Sandbox Code Playgroud) 基于类型向类添加函数的惯用方法是什么?以下示例使用List作为类,Type Parameter <T>是列表中的对象类.假设您希望根据类型使用不同的比较器对每个列表进行排序.
data class A(val foo: String)
data class B(val bar: Int)
private val aComparator: Comparator<A> = Comparator { lhs, rhs -> rhs.foo.compareTo(lhs.foo) }
private val bComparator: Comparator<B> = Comparator { lhs, rhs -> rhs.bar.compareTo(lhs.bar) }
fun <T: A> List<T>.sort(): List<T> {
return this.sortedWith<T>(aComparator)
}
fun <T: B> List<T>.sort(): List<T> {
return this.sortedWith<T>(bComparator)
}
Run Code Online (Sandbox Code Playgroud)
这给出了一个错误,指出由于Java的重载规则,两个排序函数具有相同的签名.在Java中,我可能会给它们两个不同的可识别名称,但它作为Kotlin扩展(egasortA()b.sortB())相当丑陋.Kotlin没有向List <B>显示sortA,所以似乎有更好的方法来编写sort()来处理不同对象上的不同比较器.
这个例子非常简单,但想象一下,如果我没有修改类A和B的权限,那么我就无法使用继承或在它们上实现接口.我还考虑过为每个类添加一个比较器并使用Any?但这似乎也很麻烦.
如何从环境变量中获取值,但如果未设置环境变量,则使用默认值?
这是一个不起作用的例子
---
- name: a playbook
hosts: all
vars:
build_dir: "{{ lookup('env','BUILD_DIR') | default('builds/1.0.0/LATEST') }}"
tasks:
- debug: msg="{{ build_dir }}"
Run Code Online (Sandbox Code Playgroud)
运行此剧本将返回一个空字符串而不是默认值。
$ ansible-playbook build.yml
TASK [debug] ********************
ok: [amber] => {
"msg": ""
}
Run Code Online (Sandbox Code Playgroud)
但是,它按预期工作以获取环境变量。
$ BUILD_DIR=LOL ansible-playbook build.yml
TASK [debug] ****************
ok: [amber] => {
"msg": "LOL"
}
Run Code Online (Sandbox Code Playgroud) 每次我从某个菜单执行未保存的运行操作时,Intellij 都会创建一个灰显的运行配置,无论是运行单元测试、运行 Maven 构建还是从菜单项执行其他一些操作(有很多方法可以获取临时运行配置)。
这些未保存的配置会自动切换到。运行任何内容都会更改 IDE 顶部的运行配置下拉框,但我从未要求过这种行为。
Kotlin无法编译此代码,因为编译器声明"Error:Smart cast to'Nothing'是不可能的,因为'accumulator'是一个复杂的表达式"
叶奥尔德函数被调用你所期望的,即,我希望返回indexOfMax -但为什么"智能投"未能投给什么是理解更重要accumulator的Int
fun indexOfMax(a: IntArray): Int? {
return a.foldIndexed(null) { index, accumulator, element ->
return if (accumulator is Int) {
var i:Int = accumulator
return if (accumulator == null) index
else if (element > a[i]) index
else accumulator
} else accumulator
}
}
Run Code Online (Sandbox Code Playgroud)
是的,接受的答案有效!这是解决方案:
fun indexOfMax(a: IntArray): Int? {
return a.foldIndexed(null as Int?) { index, accumulator, element ->
if (accumulator == null) index
else if (element >= a[accumulator]) index
else accumulator
}
}
Run Code Online (Sandbox Code Playgroud) 我不明白为什么perl chomp没有删除我的字符串周围的空白.我甚至尝试过两次调用chomp,例如,使用bash:
$ perl -e 'use 5.22.4; chomp(my $extra=" lol "); chomp($extra); say "<$extra>"'
< lol >
Run Code Online (Sandbox Code Playgroud)
我真的希望得到
<lol>
Run Code Online (Sandbox Code Playgroud)