以下标题之间有什么区别?
在以Apache为代理和Tomcat为原始服务器的设置中,我在到达Tomcat的HTTP请求中看到了两者。值是(这是我自己的代码,其中记录了标题名称和值对以及遇到的实际大小写)
x-forwarded-host some-server
x-forwarded-server some-server.dept.some-uni.edu
Run Code Online (Sandbox Code Playgroud)
以上是典型值吗?我应该使用这两个中的哪一个来可靠地重建浏览器询问的URL?在我的情况下,浏览器发送了一个带有some-server.dept.some-uni.edu请求URL中值的GET,这使我认为x-forwarded-server与重建URL更相关。我发现这与MDN文档有些矛盾,仅提及X-Forwarded-Host并指出这是“用于识别客户端请求的原始主机的事实上的标准标头”(在上不包含任何文档X-Forwarded-Server)
这个Apache页 OTOH描述了两个标头,如下所示:
(我很高兴要重建URL,我也需要X-Forwarded-Proto和X-Forwarded-Port)
Flow 在以下情况下可以正确使用精确类型:
type Something={|a: string|};
const x1: Something = {a: '42'}; // Flow is happy
const x2: Something = {}; // Flow correctly detects problem
const x3: Something = {a: '42', b: 42}; // --------||---------
Run Code Online (Sandbox Code Playgroud)
……但是 Flow 还抱怨以下内容:
type SomethingEmpty={||};
const x: SomethingEmpty = {};
Run Code Online (Sandbox Code Playgroud)
讯息是:
object literal. Inexact type is incompatible with exact type
Run Code Online (Sandbox Code Playgroud)
这与这种情况不同,因为没有使用价差。
用最新的0.57.3.
在以下函数定义中:
function foo(a: number = 42): number {return a+1;}
Run Code Online (Sandbox Code Playgroud)
...a: number注释的语义是什么?
是说变量a在函数体内总是有一个值,还是说客户端程序员在调用时应该总是提供一个值?
我注意到以下两个代码片段都进行了类型检查,没有错误(使用 flow-bin 0.57.3):
function foo(a: number = 42): number {return a+1;}
type FooT= (a: number)=> number
(foo: FooT)
foo();
Run Code Online (Sandbox Code Playgroud)
(在这里试试)
function foo(a: ?number = 42): number {return a+1;}
type FooT = (a: ?number)=> number
(foo: FooT)
foo();
Run Code Online (Sandbox Code Playgroud)
(在这里试试)
在这种情况下,建议的注释方法是什么?
我的首选方式是#2,因为客户端程序员只需查看FooT类型的定义即可意识到参数是可选的。这使我可以告诉我的库的用户:“只需查看函数的类型 ( FooT)”。
而对于方式#1,我必须告诉他们“函数 ( FooT)的类型似乎表明需要一个参数,但实际上并不是因为,看,如果您查看实现,则提供了默认值”。
那么,哪个片段更惯用呢?
请注意,有一个相关问题的答案似乎表明可以将类型注释为函数实现中的强制类型和声明中的可选类型。但这在这种情况下似乎不起作用。例如,以下不进行类型检查:
function foo(a: number …Run Code Online (Sandbox Code Playgroud) 几天前我开始在 Windows 上使用 vim/gvim。到目前为止我一直使用 notepad++,但想开始完全使用 gvim。
我发现的一件事是,在 gvim 中打开文件(通过双击文件)总是会打开一个新的 gvim 实例,即使另一个 gvim 实例已经在运行。我可以在 gvim 中打开任何设置,以便在已运行的 gvim 实例的新选项卡中打开文件吗?
我在 EJB3/JSF 项目中使用 JBoss 7 和默认的 Hibernate JPA 引擎。
EntityManager::getDelegate 上的javadoc读取:“返回EntityManager的底层提供程序对象,如果可用。”。
出于好奇,我尝试了以下代码:
@Stateless
public class AFacade {
@PersistenceContext(unitName="foo")
EntityManager em;
public List<A> findAll() {
l.info("underlying entity manager is: "+em.getDelegate().getClass().getSimpleName());
...
}
Run Code Online (Sandbox Code Playgroud)
然而,输出将类名指示为:org.hibernate.internal.SessionImpl,根据hibernate 文档,它是一个 Session 实现。
我在这里错过了什么?
我遇到了以下类型的代码:
@ManagedBean
@SessionScoped
SomeClass<T> {
... blah-blah
}
Run Code Online (Sandbox Code Playgroud)
由于框架将其实例化为没有类型信息的通用SomeClass对象,您是否看到此类代码的任何好处?或者你会把它归类为代码味道?
我使用的是Python 2.7.3.任何人都可以解释文字之间的区别:
'\u0391'
Run Code Online (Sandbox Code Playgroud)
和:
u'\u0391'
Run Code Online (Sandbox Code Playgroud)
以及它们在下面的REPL中回显的不同方式(特别是添加到a1的额外斜杠):
>>> a1='\u0391'
>>> a1
'\\u0391'
>>> type(a1)
<type 'str'>
>>>
>>> a2=u'\u0391'
>>> a2
u'\u0391'
>>> type(a2)
<type 'unicode'>
>>>
Run Code Online (Sandbox Code Playgroud) 我今天找到了一个错误,最终导致我的代码中的某个代码片段(我试图仅在列表中过滤"PRIMARY KEY"约束):
(filter #(= (% :constraint_type "PRIMARY KEY")) aListOfconstraints)
Run Code Online (Sandbox Code Playgroud)
而不是正确的:
(filter #(= (% :constraint_type) "PRIMARY KEY") aListOfconstraints)
Run Code Online (Sandbox Code Playgroud)
即错误是地图采用默认参数的组合效果,以防万一找不到密钥,如:
({:a 1 :b 2} :a 0)
Run Code Online (Sandbox Code Playgroud)
......以及只接受一个参数并返回true的相等函数:
(= 1) ; evals to true
Run Code Online (Sandbox Code Playgroud)
我是否可以使用任何工具来促使我使用这种有效但可疑的代码?或者也许是一些我不知道的最佳实践?
在我的clojure文件的头部,我有一系列的defs,其中一些只是踩踏石头的defs,即不打算在文件中进一步使用.即
def src-folder (File. "src")
def lib-folder (File. src-folder "lib")
def dist-folder (File. src-folder "bin")
;; I only care for the lib-folder and dist-folder beyond this point
Run Code Online (Sandbox Code Playgroud)
在Clojure中这样做的正确方法是什么?