我是Java和Kotlin的新手,试图建立一个联系表单Ktor,所以我从这里启用了我的Gmail的不安全连接,并在下面构建了应用程序:
blogApp.kt:
package blog
import org.jetbrains.ktor.netty.*
import org.jetbrains.ktor.routing.*
import org.jetbrains.ktor.application.*
import org.jetbrains.ktor.features.*
import org.jetbrains.ktor.host.*
import org.jetbrains.ktor.http.*
import org.jetbrains.ktor.response.*
import org.apache.commons.mail.*
fun Application.module() {
install(DefaultHeaders)
install(CallLogging)
install(Routing) {
get("/") {
call.respondText("""
My Example Blog2
<form action="/contact-us" method="post">
<input name="subject" placeholder="Subject">
<br>
<textarea name="message" placeholder="Your message ..."></textarea>
<br>
<button>Submit</button>
</form>
""", ContentType.Text.Html)
}
post("/contact-us") {
SimpleEmail().apply {
setHostName("smtp.gmail.com")
setSmtpPort(465)
setAuthenticator(DefaultAuthenticator("my_alias@gmail.com", "my_gmil_passoword"))
setSSLOnConnect(true)
setFrom("my_alias@gmail.com")
setSubject("subject") // I need to use formParam
setMsg("message") // I need to use formParam …Run Code Online (Sandbox Code Playgroud) 我有一个整数数组,并希望执行以下操作:
s += array(index+1) - array(index)
Run Code Online (Sandbox Code Playgroud)
所以,我试过以下:
let mutable s =0
for i in 0 .. slen-1 do
s <- series.[i+1] - series.[i] + s
Run Code Online (Sandbox Code Playgroud)
但我发了一个错误:
这个表达式预计有'double'类型,但这里有'unit'类型
UPDATE
完整的代码
let series = [|30;21;29;31;40;48;53;47;37;39;31;29;17;9;20;24;27;35;41;38;
27;31;27;26;21;13;21;18;33;35;40;36;22;24;21;20;17;14;17;19;
26;29;40;31;20;24;18;26;17;9;17;21;28;32;46;33;23;28;22;27;
18;8;17;21;31;34;44;38;31;30;26;32|]
let initialTrend series slen : double=
let mutable s = 0
for i in 0 .. slen-1 do
s <- series.[i+1] - series.[i] + s
Run Code Online (Sandbox Code Playgroud) 如果location是null,我想执行一个msg ,如果它不是null,我想执行另一个msg,所以我尝试使用elvis-operator作为a?.let{} ?: run{}语句,但是run部分是不可访问的,它告诉我它不是必需的也不是非-nullable!
我得到错误的函数是:
getLocation(
context,
{ location ->
location?.let {
msg = ("As of: ${Date(it.time)}, " +
"I am at: http://maps.google.com/?q=@" +
"${it.latitude}, ${it.longitude}, " +
"my speed is: ${it.speed}")
} ?: run { . // Getting error here
msg = "Sorry, it looks GPS is off, no location found\""
}
sendSMS(
context,
address,
msg,
subId
)
}
)
Run Code Online (Sandbox Code Playgroud)
个getLocation功能是:
object UtilLocation {
private lateinit var l : …Run Code Online (Sandbox Code Playgroud) 这是一个Expanded panel看起来像这样的材料设计:
我想用 做一个类似的Flutter,不确定我是否必须从下面的代码开始或知道如何完成它!
new ExpansionPanelList(
children: <ExpansionPanel>[
new ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
isExpanded = true;
return new ListTile(
// leading: item.iconpic,
title: new Text(
"First",
textAlign: TextAlign.left,
style: new TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.w400,
),
));
},
body: new Text("school"),
isExpanded: true,
),
new ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
isExpanded = true;
return new ListTile(
// leading: item.iconpic,
title: new Text(
"Second",
textAlign: TextAlign.left,
style: new TextStyle(
fontSize: 20.0, …Run Code Online (Sandbox Code Playgroud) 我创建了 2 个简单的“Hello World!” 程序,一个使用 Kotlin,一个使用 Rust:
科特林:
fun main() {
println("Hello, world!")
}
Run Code Online (Sandbox Code Playgroud)
锈:
fun main() {
println("Hello, world!")
}
Run Code Online (Sandbox Code Playgroud)
我为两者生成了可执行文件:
kotlinc-native main.kt用于 Kotlin 和cargo build --releaseRust,然后使用ls -S -lh | awk '{print $5, $9}'.
我发现 Kotlin 原生生成的文件是 Rust 生成的文件大小的 1.48 倍。
为什么会存在这种差异?
fn main() {
println!("Hello, world!");
}
Run Code Online (Sandbox Code Playgroud)
此外,Rust 可以优化得更小,Kotlin 原生有没有类似的东西?
最初设定:
$ cargo new hello_world
构建:
$ cargo build
=> 589,004 bytes
优化步骤 1:
构建:
$ cargo build --release
=> 586,028 bytes
优化步骤 …
我正在使用一个 20x20 像素的图标显示在地图上,代码如下:
当我缩放地图时,图标看起来很小,如何通过地图缩放更改图标大小?
<link rel="stylesheet" href="https://openlayers.org/en/v4.6.5/css/ol.css" type="text/css">
<script src="https://openlayers.org/en/v4.6.5/build/ol.js" type="text/javascript"></script>
<script>
var baseMapLayer = new ol.layer.Tile({
source: new ol.source.OSM()
});
var view = new ol.View({
center: ol.proj.fromLonLat([-74.0061,40.712]),
zoom: 17 //Initial Zoom Level
})
var map = new ol.Map({
target: 'map',
layers: [ baseMapLayer],
view: view
});
// Make a new feature marker
var marker = new ol.Feature({
name: 'Null Island',
population: 4000,
rainfall: 500,
geometry: new ol.geom.Point(
ol.proj.fromLonLat([-74.006,40.7127]) // new Point([0, 0])
), // Cordinates of New York's Town …Run Code Online (Sandbox Code Playgroud) 我对VBAin很陌生Excel,尝试过这个,但它对我不起作用。
我正在尝试构建一个输入数组的逆,如下图所示,将行转换为列,并将列转换为行。
作为启动,我按照以下说明进行操作,即在执行所需的反向操作之前,我想重新打印相同的输入数组,但出现错误
步骤如下:
打开 Visual Basic 编辑器。在 Excel 中,如果在 Windows 上点击Alt+ F11,如果在 Mac 上点击Fn+ Option+ F11。
插入一个新模块。从菜单:插入 -> 模块(不要跳过这个!)。
创建一个Public函数。例子:
Public Function transform(inputRange As Range) As Range
transform = inputRange
End Function
Run Code Online (Sandbox Code Playgroud)然后像使用任何其他函数一样在任何单元格中使用它:=transform(A1:B2).
我有错误 #VALUE!
如何读取 VBA 中的范围、处理其元素并返回新的元素以显示在 Excel 工作表中?
我正在将现有python代码转换为F#增加了太多的行数,不确定我是否做错了,或者有一个想要优化它的方法:
我Array想要处理这个:
let series = [|30;21;29;31;40;48;53;47;37;39;31;29;17;9;20;24;27;35;41;38;
27;31;27;26;21;13;21;18;33;35;40;36;22;24;21;20;17;14;17;19;
26;29;40;31;20;24;18;26;17;9;17;21;28;32;46;33;23;28;22;27;
18;8;17;21;31;34;44;38;31;30;26;32|]
Run Code Online (Sandbox Code Playgroud)
在Python它是:
series = [30,21,29,31,...,26,32]
Run Code Online (Sandbox Code Playgroud)
第1部分
在Python我这个:
def initial_seasonal_components(series, slen):
seasonals = {}
season_averages = []
n_seasons = int(len(series)/slen)
# compute season averages
for j in range(n_seasons):
season_averages.append(sum(series[slen*j:slen*j+slen])/float(slen))
Run Code Online (Sandbox Code Playgroud)
转换成F#我最终得到这个:
open System.Collections.Generic
let initial_seasonal_components (series : int []) (slen : int) : Dictionary<int, double> =
let seasonals = new Dictionary<int, double>()
let mutable seasonAverages = []
let nSeasons = series.Length / …Run Code Online (Sandbox Code Playgroud) 下面的代码对我来说很好,可以从Firestore调用和显示数据:
return ListView(
padding: const EdgeInsets.only(top: 20.0),
children: snapshot.map((data) => _buildListItem(context, data)).toList(),
);
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试将其放在一列中,然后在其上方添加另一个小部件,它将失败并给出stack overflow:
return Column(
children: <Widget>[
Text('Hellow'),
ListView(
padding: const EdgeInsets.only(top: 20.0),
children: snapshot.map((data) => _buildListItem(context, data)).toList(),
)]);
Run Code Online (Sandbox Code Playgroud) 我有下面的代码工作正常,并在 TextField 下显示 FlatButton:
import 'package:flutter/material.dart';
class LocationCapture extends StatelessWidget {
LocationCapture(this.clickCallback, this.tc);
final TextEditingController tc;
final VoidCallback clickCallback;
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
// Row(
// children: <Widget>[
TextField(controller: tc,),
FlatButton(
child: const Icon(Icons.my_location),
onPressed: () => clickCallback(),
)
// ])
]);
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试将Row它们添加到单行中,但它不起作用,并显示空白屏幕!!
** 更新**
通过将每个元素包装到一个容器中,我能够将它们排成一行,但仍然不满意,因为它需要我分配容器宽度,我需要自动完成:
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 180,
child: TextField(
controller: tc,
enabled: false,
textAlign: TextAlign.center,
decoration: InputDecoration.collapsed(hintText: "")
)
),
Container(
child: …Run Code Online (Sandbox Code Playgroud) 我有以下代码,即create一个新的zip文件,然后add entry使用NoCompressionie 将该文件压缩到该文件,ZERO compression ratio然后尝试将其作为普通文本读取。
using System;
using System.IO;
using System.IO.Compression;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
using (FileStream zipToOpen = new FileStream(@"d:\release.zip", FileMode.Create))
{
using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Create))
{
ZipArchiveEntry readmeEntry = archive.CreateEntry("Readme.txt", CompressionLevel.NoCompression);
using (StreamWriter writer = new StreamWriter(readmeEntry.Open()))
{
writer.WriteLine("Information about this package.");
writer.WriteLine("========================");
}
}
}
string text = System.IO.File.ReadAllText(@"d:\release.zip\Readme.txt");
Console.WriteLine("Contents of WriteText.txt = {0}", text);
}
}
}
Run Code Online (Sandbox Code Playgroud)
zip文件及其条目均已创建,我可以从Windows资源管理器中访问它们,但是一旦代码尝试读取它,它将得到以下错误: …
dart ×3
flutter ×3
kotlin ×3
f# ×2
.net-core ×1
android ×1
asp.net-core ×1
c# ×1
excel ×1
ktor ×1
openlayers ×1
openlayers-5 ×1
vba ×1
ziparchive ×1