我正在尝试使用可选列表作为查询参数来定义路由
GET /places controllers.Application.query(filter: Option[Seq[Int]])
Run Code Online (Sandbox Code Playgroud)
但得到这个错误
conf/routes - PlayException: Compilation error [`)' expected but `]' found]
Run Code Online (Sandbox Code Playgroud)
我知道Play 2处理得Option很好,我希望它传递Seq给我的自定义QueryStringBindable,如何实现这一目标?
我有库方法采用变量参数列表和生成数据
class Data
def process(elems: String*): Data = new Data
Run Code Online (Sandbox Code Playgroud)
我希望我的字符串被隐式转换为 Data
implicit def strToData(ts: String): Data = process(t)
Run Code Online (Sandbox Code Playgroud)
所以我可以写类似的东西
val data: Data = "one"
Run Code Online (Sandbox Code Playgroud)
但是我想要隐式转换字符串元组.我添加了另一个隐含的内容
implicit def strsToData(ts: String*): Data = process(ts: _*)
Run Code Online (Sandbox Code Playgroud)
编译很好,但转换失败
val data: Data = ("one", "two")
val dat3: Data = ("one", "two", "three")
val dat4: Data = ("one", "two", "three", "four")
Run Code Online (Sandbox Code Playgroud)
同
found : Seq[java.lang.String]
required: this.Data
val data: Data = Seq("one", "two")
Run Code Online (Sandbox Code Playgroud)
有没有办法隐式转换元组,或者为什么可以实现它?
更新:元组可以是任何arity.
我正在尝试通过远程身份验证服务对用户进行身份验证.我写了帮助方法,用于向服务发送消息并等待结果:
def authenticateAwait(email: String,
password: String
): Either[String, Option[User]] = {
try {
val future = authenticate(email, password)
Right(Await.result(future, timeout.duration))
} catch {
case _ ? Left("Unable to connect to authentication server")
}
}
Run Code Online (Sandbox Code Playgroud)
Left[String]如果无法发送消息,或者没有响应,则返回错误描述.如果收到服务响应,则返回Right[Option[User]].服务Option[User]根据身份验证结果进行响应.
为了执行实际的身份验证,我创建了一些带有几个验证器的表单,这里是:
val loginForm = Form(
tuple(
"email" ? email,
"password" ? nonEmptyText
) verifying ("Invalid email or password", result => result match {
case (email, password) ?
User.authenticateAwait(email, password) match {
case Left(_) ? true
case Right(optUser) ? optUser.isDefined
} …Run Code Online (Sandbox Code Playgroud) 我有一个UITabBarController作为其主控制器的应用程序.
当用户点击一个按钮(不在标签栏,只是其他一些按钮)时,我想在我的UITabBarController中添加新的UIViewController并显示它,但我不希望新的UITabBarItem出现在标签栏中.如何实现这样的行为?
我试图将tabBarController.selectedViewController属性设置为不在tabBarController.viewControllers数组中的视图控制器,但没有任何反应.如果我将视图控制器添加到tabBarController.viewControllers数组新项目自动出现在选项卡栏中.
更新
感谢Levi,我扩展了我的标签栏控制器来处理不存在的控制器.viewControllers.
@interface MainTabBarController : UITabBarController
/**
* By setting this property, tab bar controller will display
* given controller as it was added to the viewControllers and activated
* but icon will not appear in the tab bar.
*/
@property (strong, nonatomic) UIViewController *foreignController;
@end
#import "MainTabBarController.h"
@implementation MainTabBarController
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
self.foreignController = nil;
}
- (void)setForeignController:(UIViewController *)foreignController
{
if (foreignController) {
CGFloat reducedHeight …Run Code Online (Sandbox Code Playgroud) 我试图@font-face在cassius模板中使用选择器而没有运气.
Cassius @用于插值,有什么方法可以逃脱它吗?
我试过@@和\@,他们没有工作.
以下模板
@font-face
font-family: 'Monsieur La Doulaise'
src: url('http://fonts.googleapis.com/css?family=Monsieur+La+Doulaise')
Run Code Online (Sandbox Code Playgroud)
结果是
src: url('http://fonts.googleapis.com/css?family=Monsieur+La+Doulaise');}
Run Code Online (Sandbox Code Playgroud) 虽然看着scala.collection.mutable.SynchronizedStack我注意到synchronized使用不同,但有些方法使用synchronized[this.type]表单
override def push(elem: A): this.type = synchronized[this.type] { super.push(elem) }
override def pushAll(xs: TraversableOnce[A]): this.type = synchronized[this.type] { super.pushAll(elems) }
Run Code Online (Sandbox Code Playgroud)
和一些使用synchronized形式
override def isEmpty: Boolean = synchronized { super.isEmpty }
override def pop(): A = synchronized { super.pop }
Run Code Online (Sandbox Code Playgroud)
有什么不同?
我想为Play2 Framework应用程序创建自定义身份验证方法.我在Scala和Play中尝试它 - 我对两者都是新手.
在zentask示例中,Trait Secured中存在一个名为IsAuthenticated的函数:
def IsAuthenticated(f: => String => Request[AnyContent] => Result) = Security.Authenticated(username, onUnauthorized) { user =>
Action(request => f(user)(request))
}
Run Code Online (Sandbox Code Playgroud)
这个定义相当复杂.我在stackoverflow上找到了一些关于这个定义语法的问题,但是我还是不确定如何改变它.
我可以通过数据库查找看到User.authenticate中发生的身份验证检查.但我想要做的身份验证不使用数据库.我不确定如何或在哪里连接不同类型的身份验证.Security.Authenticated()是否连接到使用User类/对象?
有没有办法在Haskell中扩展库模块?
例如,我想添加firstToLower功能Data.String.当我创建自己的Data.String掩码库时:
module Data.String where
import Prelude
import Data.Char (toLower)
firstToLower :: String -> String
firstToLower (c:cs) = toLower c : cs
firstToLower "" = ""
Run Code Online (Sandbox Code Playgroud)
然后我试图错误import Data.String (lines):
Module `Data.String' does not export `lines'
Run Code Online (Sandbox Code Playgroud)
如果可能的话,这将是非常好的.如果没有,这种情况的最佳做法是什么?应该放置哪些扩展?
谢谢.
更新
我不打算将我的扩展版本作为库发布,只是想以有意义的方式在我的项目中组织它.
我很惊讶地知道Aeson编码()为空阵列.这种行为背后的原因是什么?我觉得null会更自然,我错了吗?
*Main> encode ()
"[]"
Run Code Online (Sandbox Code Playgroud) 我有简单的控制器代码,如:
// UserController.groovy
class UserController {
static allowedMethods = [
signIn: 'GET',
authenticate: 'POST',
signOut: 'POST',
register: 'GET',
save: 'POST'
]
// ... code omitted
def register() { }
def save() {
render 'ok'
}
}
Run Code Online (Sandbox Code Playgroud)
报名表格:
<!-- register.gsp -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="layout" content="main" />
<title>Withme: Register</title>
</head>
<body>
<g:form mapping="register">
<!-- Code omitted -->
<g:actionSubmit value="Register" />
</g:form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
和网址映射:
//UrlMappings.groovy
class UrlMappings {
static mappings = {
name register: '/register'(controller: 'user') …Run Code Online (Sandbox Code Playgroud) 我是CL的新手,我无法弄清楚如何从我的简单项目中构建二进制文件.
我创建了app.asd包含以下内容的文件:
(asdf:defsystem game
:version "0.0.1"
:components ((:file "package")
(:file "main")))
Run Code Online (Sandbox Code Playgroud)
package.lisp 内容
(defpackage :app
(:use :common-lisp :asdf)
(:export :start))
Run Code Online (Sandbox Code Playgroud)
和 main.lisp
(in-package :app)
(defun start (args)
(format t "Hello"))
Run Code Online (Sandbox Code Playgroud)
我也符号链接app.asd到~/quicklisp/quicklisp/app.asd,当我执行
(require 'asdf)
(asdf:operate 'asdf:load-op :app)
Run Code Online (Sandbox Code Playgroud)
它看起来像编译的东西,但我无法在任何地方找到二进制文件/目标文件.
如何构建我的项目,以便将其复制到另一台没有安装CL并运行的机器上?
我在osx上使用sbcl 1.1.13和asdf 3.0.2.
scala ×5
haskell ×3
aeson ×1
asdf ×1
cocoa-touch ×1
common-lisp ×1
escaping ×1
forms ×1
grails ×1
grails-2.0 ×1
ios ×1
json ×1
libraries ×1
module ×1
sbcl ×1
uitabbaritem ×1
url-routing ×1
validation ×1
yesod ×1