小编Ken*_*ton的帖子

python:任意顺序

在Oracle SQL中,有一个要按如下顺序排序的功能:

order by decode("carrot" = 2
               ,"banana" = 1
               ,"apple" = 3)
Run Code Online (Sandbox Code Playgroud)

在python中实现它的最佳方法是什么?

我希望能够通过它的键来命令一个字典.而且该顺序不一定按字母顺序或任何顺序 - 我确定顺序.

python sql-order-by

3
推荐指数
2
解决办法
4484
查看次数

按关系属性排序 neo4j

使用 Neo4j 1.9.3 -

我想创建一个音乐节目列表。在一个给定的程序中,可能会执行三个片段。每首曲子都有一个与之相关联的作曲家,并且可能出现在许多不同的程序中,因此我无法在曲子节点上放置序列号。

我假设我可以创建程序,与每个部分的关系如下:

(program1)-[:PROGRAM_PIECE {program_seq: 1}]->(piece1)
(program1)-[:PROGRAM_PIECE {program_seq: 2}]->(piece2)
(program1)-[:PROGRAM_PIECE {program_seq: 3}]->(piece3)
Run Code Online (Sandbox Code Playgroud)

我的问题是,我如何查询图形以便这些部分按关系属性的顺序排列program_seq?我很好地将 ORDER BY 与节点属性一起使用,但在关系方面没有成功(我的生活故事......)

sql-order-by neo4j

3
推荐指数
1
解决办法
2517
查看次数

如何在表单编辑中定义textarea内容(Symfony2/TWIG)

我想在我的editForm textarea中显示一个特定的内容,所以我尝试像文本字段但它不起作用:

{{ form_widget(edit_form.description, { 'attr': {'value': 'content'} }) }} {{ form_errors(edit_form.description) }}
Run Code Online (Sandbox Code Playgroud)

我怎么能在TWIG中做到这一点?

forms textarea symfony twig

3
推荐指数
1
解决办法
2048
查看次数

当键是一个只知道第一个元素的元组时,如何获取scala Map值?

假设我有一个scala不可变Map[(String, Boolean), Set[String]],例如:

val myMap = Map(("a",true) -> Set("b","c"))
Run Code Online (Sandbox Code Playgroud)

现在假设我只知道关键元组的第一个元素,"a".可以(如果是的话)我得到这个键的地图值如果:

1)我知道密钥可以是("a", true)("a", false)(不能有两个密钥与第一个元素具有相同的字符串)

2)我不知道,在这种情况下,我希望对可能的两个值进行某种连接,例如v1.union(v2)or v1 ++ v2等.

我可以使用scala"魔法" myMap.get(("a", Any))吗?

scala tuples key

3
推荐指数
2
解决办法
4098
查看次数

Java - 修改对象的内部数据,或使用修改后的数据创建新对象

问题

在Java中,按照标准的代码风格和设计原则,什么时候修改对象的内部数据比较合适,什么时候用修改后的数据新建一个对象比较合适呢?

例如,假设我有一个类 Vector2D,它包含一个 x 分量和一个 y 分量,我想旋转该向量:

方法A

public class Vector2D{
    private int x;
    private int y;
    public Vector2D(int x, int y){
        this.x = x;
        this.y = y;
    }
    public void rotate(double angle){
        //code for finding rotated vector
        x = rotated_x;
        y = rotated_y;
    }
}
Run Code Online (Sandbox Code Playgroud)

然后可以旋转 Vector2D 对象 vector1.rotate(angle)

方法B

public class Vector2D{
    private final int x;
    private final int y;
    public Vector2D(int x, int y){
        this.x = x;
        this.y = y;
    }
    public Vector2D rotate(double angle){
        //code …
Run Code Online (Sandbox Code Playgroud)

java oop immutability

3
推荐指数
1
解决办法
1211
查看次数

有没有办法让[X(),Y(),Z()]中的"X()"返回True?

我在这个项目中有一个自定义对象,叫做Page.页面的标识功能是其标题.页是通常通过调用创建Wiki.page,Wiki.categoryWiki.template,或通过从其它的方法,如生成它们Wiki.random.(我建议你在继续之前先看看它是什么.)

有时,此模块的用户可能希望生成一些页面并将该生成器转换为正常list.在获得该页面列表后,他们可能想要检查他们获得的另一个页面是否该列表中.但是,这个:

>>> wp = mw_api_client.Wiki('https://en.wikipedia.org/w/api.php')
>>> wp.page('title') in [wp.page('title'),
                         wp.page('not this'),
                         wp.page('not this either')]
False
Run Code Online (Sandbox Code Playgroud)

应该是True,而不是False,因为其中一个带有title"title" 的页面.有没有一种神奇的方法可以用来制作真的?我已经尝试过使用__eq__(for equality)和__hash__(for hash checking)(commit),但似乎都没有.列表只是使用身份吗?或者还有其他我想念的东西?我该怎么做呢?

python contains operators

2
推荐指数
1
解决办法
86
查看次数

如何返回常见的lisp中的最后一个值

我知道values函数有助于控制REPL,但我想显式返回函数的最后一个值.唯一接近我设法找到我想要的东西是

 (setf (values q a) (floor 1.5))
Run Code Online (Sandbox Code Playgroud)

但我只对它返回的0.5感兴趣.我的问题是我怎么才能只返回函数的最后一个值而不仅仅是第二个值而是第n个值(以它为准)?

lisp return common-lisp

2
推荐指数
1
解决办法
170
查看次数

如何获取当前焦点窗口的选定文本?

因此,我正在尝试制作一个执行以下操作的应用程序:

  1. 监听键盘快捷键(使用此库
  2. 当按下快捷键时,检索当前选定文本的内容,并
  3. 处理文本

我已使用此答案的最新编辑共享的方法(此方法)将我的应用程序附加到焦点控件,但GetText该方法中的功能不能满足我的需要。

我也看过这个答案,但它只提供了如何通过双击获得聚焦窗口的详细步骤,这不是我需要的。它确实链接到这个问题,导致我尝试该WM_KEYDOWN方法(如下所示),但这也不起作用。

到目前为止,我已经尝试过这些GetText方法(全部在 MSDN 帖子的上下文中):

string GetText(IntPtr handle)
{
    // works in Notepad, but not Chrome
    SendMessageW(handle, WM_COPY, 0, 0);
    string w = Clipboard.GetText();
    return w;

    // works in every app, but in Notepad gets the complete contents
    // and in Chrome gets the window title
    int maxLength = 160;
    IntPtr buffer = Marshal.AllocHGlobal((maxLength + 1) * 2);
    SendMessageW(handle, WM_GETTEXT, maxLength, …
Run Code Online (Sandbox Code Playgroud)

c# focus selection

2
推荐指数
1
解决办法
3333
查看次数

java @Value 如何工作?

我像这样使用了java @Value,它工作正常,并且可以正确解析变量“baiduurl”:

package com.lanyyyy.springdemo.controllers;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.lanyyyy.springdemo.service.*;
@RestController
public class GetURL {
    @Value("${baiduurl}")
    public String baiduurl;

    @RequestMapping(path="/getbaidu", method=RequestMethod.GET)
    public String getBaiduurl(){
//        return "hello";
        return baiduurl;
    }

}
Run Code Online (Sandbox Code Playgroud)

======================

但是当我这样使用时,变量“baiduurl”无法解析:

package com.lanyyyy.springdemo.service;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;

@PropertySource("classpath:application.properties")
public class UrlService {
    @Value("${baiduurl}")
    public String baiduurl;

    //    @RequestMapping(path="/getbaidu", method=RequestMethod.GET)
    public String getBaiduurl() {
        return baiduurl;
    }
}
Run Code Online (Sandbox Code Playgroud)

有什么不对的吗?????或者我用错了@Value????

在我的 applicaiton.properties 中:

baiduurl=http://www.baidu.com
server.port=8888
Run Code Online (Sandbox Code Playgroud)

java annotations spring-mvc spring-boot

0
推荐指数
1
解决办法
296
查看次数