我正在尝试在纯 JS 中使用 Axios。我已经从 CDN 中包含了它。在文档中,他们正在创建 Axios 对象,如下所示:
const axios = require('axios');
如果没有 Node,我怎样才能用普通的 JS 来做同样的事情呢?
我已经定义了两个这样的表:
val tableName = "table1"
val tableName2 = "table2"
val format = new SimpleDateFormat("yyyy-MM-dd")
val data = List(
List("mike", 26, true),
List("susan", 26, false),
List("john", 33, true)
)
val data2 = List(
List("mike", "grade1", 45, "baseball", new java.sql.Date(format.parse("1957-12-10").getTime)),
List("john", "grade2", 33, "soccer", new java.sql.Date(format.parse("1978-06-07").getTime)),
List("john", "grade2", 32, "golf", new java.sql.Date(format.parse("1978-06-07").getTime)),
List("mike", "grade2", 26, "basketball", new java.sql.Date(format.parse("1978-06-07").getTime)),
List("lena", "grade2", 23, "baseball", new java.sql.Date(format.parse("1978-06-07").getTime))
)
val rdd = sparkContext.parallelize(data).map(Row.fromSeq(_))
val rdd2 = sparkContext.parallelize(data2).map(Row.fromSeq(_))
val schema = StructType(Array(
StructField("name", StringType, true),
StructField("age", IntegerType, …Run Code Online (Sandbox Code Playgroud) 尝试在Play Framework 2.4.2 Scala中安排这样的任务,但没有运气:
import akka.actor.Actor
import play.api.libs.concurrent.Akka
import scala.concurrent.duration._
import play.api.Play.current
import scala.concurrent.ExecutionContext.Implicits.global
class Scheduler extends Actor {
override def preStart() {
val dbupdate = Akka.system.scheduler.schedule(
0.microseconds, 5.minutes, self, "update")
val pictureClean = Akka.system.scheduler.schedule(
0.microseconds, 30.minutes, self, "clean")
}
def receive = {
case "update" => updateDB()
case "clean" => clean()
}
def updateDB(): Unit ={
Logger.debug("updates running")
}
def clean(): Unit ={
Logger.debug("cleanup running")
}
}
Run Code Online (Sandbox Code Playgroud)
控制台中没有打印任何内容.我做错了什么?
我试图将琐碎的htaccess文件转换为Nginx并且无法使其工作.它返回404错误.这是htaccess内容:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
Run Code Online (Sandbox Code Playgroud)
这是我目前的nginx配置:
server {
listen 80;
server_name domain.biz;
root /var/www/domain.biz;
charset utf-8;
autoindex off;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME /var/www/domain.biz$fastcgi_script_name;
}
}
Run Code Online (Sandbox Code Playgroud) 我已经让ActionRefiner从url中的参数中读取当前请求的语言:
class LangRequest[A](val lang: Lang, request: Request[A]) extends WrappedRequest[A](request)
def LangAction(lang: String) = new ActionRefiner[Request, LangRequest] {
def refine[A](input: Request[A]) = Future.successful {
val availLangs: List[String] = Play.current.configuration.getStringList("play.i18n.langs").get.toList
if (!availLangs.contains(lang))
Left {
input.acceptLanguages.head match {
case Lang(value, _) if availLangs.contains(value) => Redirect(controllers.routes.Application.index(value))
case _ => Redirect(controllers.routes.Application.index(availLangs.head))
}
}
else Right {
new LangRequest(Lang(lang), input)
}
}
}
Run Code Online (Sandbox Code Playgroud)
并试着像这样在行动中使用它:
def login(lng: String) =
LangAction(lng) {
implicit request =>
Ok("Ok")
}
Run Code Online (Sandbox Code Playgroud)
在这里,我得到了隐藏请求的"缺少参数类型"错误我做错了什么?提前致谢
我有这个测试数据:
val data = List(
List(47.5335D),
List(67.5335D),
List(69.5335D),
List(444.1235D),
List(677.5335D)
)
Run Code Online (Sandbox Code Playgroud)
我预计中位数为69.5335.但是,当我尝试使用此代码找到确切的中位数时:
df.stat.approxQuantile(column, Array(0.5), 0)
Run Code Online (Sandbox Code Playgroud)
它给了我:444.1235
为什么会如此以及如何解决?
我是这样做的:
val data = List(
List(47.5335D),
List(67.5335D),
List(69.5335D),
List(444.1235D),
List(677.5335D)
)
val rdd = sparkContext.parallelize(data).map(Row.fromSeq(_))
val schema = StructType(Array(
StructField("value", DataTypes.DoubleType, false)
))
val df = sqlContext.createDataFrame(rdd, schema)
df.createOrReplaceTempView(tableName)
val df2 = sc.sql(s"SELECT value FROM $tableName")
val median = df2.stat.approxQuantile("value", Array(0.5), 0)
Run Code Online (Sandbox Code Playgroud)
所以我正在创建临时表.然后在其中搜索,然后计算结果.它只是用于测试.
我按照文档https://www.playframework.com/documentation/2.4.x/ScalaI18N 创建此代码以在视图中使用i18n.Messages:
import play.api.data.Forms._
import play.api.i18n.I18nSupport
import play.i18n.MessagesApi
class Auth @Inject()(val messagesApi: MessagesApi) extends Controller with I18nSupport{
val adminForm = Form(mapping(
"login" -> nonEmptyText,
"password" -> nonEmptyText)(Admin.apply)(Admin.unapply))
def login = Action {
implicit request =>
Ok(views.html.admin.login(adminForm))
}
}
Run Code Online (Sandbox Code Playgroud)
有了这个我得到编译错误
重写方法messagesApi in trait I18nSupport of type => play.api.i18n.MessagesApi; 值messagesApi具有不兼容的类型
我做错了什么?
我正在尝试计算 DataFrame 中列中的空值,如下所示:
df.filter((df(colname) === null) || (df(colname) === "")).count()
Run Code Online (Sandbox Code Playgroud)
其中colname有一个列的名称。如果列类型为字符串,则此方法工作正常,但如果列类型为整数并且存在一些空值,则此代码始终返回 0。为什么会这样?如何改变它才能使其发挥作用?
我正在尝试从运行时值创建部分函数,然后像这样组合部分函数:
class Test(val function: PartialFunction[Int, Boolean]) {
def add(v: Int): Test = {
new Test(function.orElse{case v => true})
}
def contains(v: Int) = function.isDefinedAt(v)
}
val test: Test = new Test({case 1 => true})
val test2 = test.add(2)
println(test2.contains(1))
println(test2.contains(2))
println(test2.contains(3))
Run Code Online (Sandbox Code Playgroud)
此代码打印
true
true
true
Run Code Online (Sandbox Code Playgroud)
但最后一行应该是假的。为什么会这样?我做错了什么?
我有一个特征和两个扩展它的案例类:
trait Authenticatable {
val email: String
val pass: String
val id: Long
val sessionid: String
}
case class Admin(
id: Long,
email: String,
pass: String,
sessionid: Option[String] = None) extends Authenticatable
case class Client(
id: Long,
email: String,
pass: String,
sessionid: Option[String] = None) extends Authenticatable
Run Code Online (Sandbox Code Playgroud)
我有函数应该验证用户,用新的sessionid复制对象并返回它.
def auth(email: String, password: String): Try[Admin] ={
checkPass(models.Admin.findBy(sqls"email = $email"), password)
}
def auth(email: String, password: String, customer: Customer): Try[Customer] ={
checkPass(models.Customer.findBy(sqls"email = $email"), password)
}
private def checkPass (model: Option[Authenticatable], password: …Run Code Online (Sandbox Code Playgroud)