小编dem*_*lem的帖子

如何启动rails控制台并专门使用测试数据库?

我想启动rails控制台并在不是默认数据库的数据库中创建数据库条目,例如测试数据库.我很感激任何帮助.

ruby-on-rails

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

Mockito mock在尝试存根包保护方法时调用实际方法实现

我正在尝试使用Mockito 1.8.5存根方法,但这样做会调用真正的方法实现(使用""作为parm值)会抛出异常.

package background.internal; //located in trunk/tests/java/background/internal

public class MoveStepTest {

    @Test
    public void testMoveUpdate() {
        final String returnValue = "value";
        final FileAttachmentContainer file = mock(FileAttachmentContainer.class);
        doReturn(returnValue).when(file).moveAttachment(anyString(), anyString(), anyString());
        //this also fails
        //when(file.moveAttachment(anyString(), anyString(), anyString())).thenReturn(returnValue);

        final AttachmentMoveStep move = new AttachmentMoveStep(file);
        final Action moveResult = move.advance(1, mock(Context.class));
        assertEquals(Action.done, moveResult);
    }
}
Run Code Online (Sandbox Code Playgroud)

我试图模拟的方法看起来像这样.没有最终的方法或类.

package background.internal; //located in trunk/src/background/internal


   public class FileAttachmentContainer {
        String moveAttachment(final String arg1, final String arg2, final String arg3) 
                throws CustomException {
            ...
        }

        String getPersistedValue(final Context context) …
Run Code Online (Sandbox Code Playgroud)

java mockito

28
推荐指数
1
解决办法
4万
查看次数

Java Enum作为Enum中的泛型类型

我正在尝试在抽象类中创建一个抽象方法,该方法将我自己的Enum作为参数.但我也希望Enum是通用的.

所以我这样声明:

public abstract <T extends Enum<T>> void test(Enum<T> command);
Run Code Online (Sandbox Code Playgroud)

在实现中,我已经知道了那个:

public enum PerspectiveCommands {
    PERSPECTIVE
}
Run Code Online (Sandbox Code Playgroud)

并且方法声明变为:

@Override
public <PerspectiveCommands extends Enum<PerspectiveCommands>> void test(Enum<PerspectiveCommands> command) {

}
Run Code Online (Sandbox Code Playgroud)

但如果我这样做:

@Override
public <PerspectiveCommands extends Enum<PerspectiveCommands>> void test(Enum<PerspectiveCommands> command) {
    if(command == PerspectiveCommands.PERSPECTIVE){
        //do something
    }
}
Run Code Online (Sandbox Code Playgroud)

我无权访问PerspectiveCommands.PERSPECTIVE错误:

cannot find symbol symbol: variable PERSPECTIVE   location: class Enum<PerspectiveCommands> where PerspectiveCommands is a type-variable: PerspectiveCommands extends Enum<PerspectiveCommands> declared in method <PerspectiveCommands>test(Enum<PerspectiveCommands>)
Run Code Online (Sandbox Code Playgroud)

我做了一个这样的解决方法:

public <T extends Enum<T>> byte[] executeCommand(Enum<T> command) throws Exception{
    return …
Run Code Online (Sandbox Code Playgroud)

java generics methods enums

25
推荐指数
3
解决办法
8万
查看次数

使用jquery调用ascx页面方法

我知道我可以使用以下语法使用jquery调用页面方法

$.ajax({
  type: "POST",
  url: "Default.aspx/GetDate",
  data: "{}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(msg) {
    // Replace the div's content with the page method's return.
    $("#Result").text(msg.d);
  }
});
Run Code Online (Sandbox Code Playgroud)

这适用于aspx页面但是可以使用ascx页面吗?(网页控制)

我已经尝试了大约半个小时,因为我无法让它工作,我想知道它是否可能.

注意:为了清楚,当我尝试调用ascx页面时,我正在更新jquery中的url :)

asp.net jquery web-services asmx pagemethods

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

如何在没有迭代的情况下获取给定LinkedHashSet元素的索引?

它甚至可能吗?

说你有

private Set<String> names = new LinkedHashSet<String>();
Run Code Online (Sandbox Code Playgroud)

并且Strings是"迈克","约翰","凯伦".

是否有可能在没有迭代的情况下得到"1"以回答"约翰"的索引是什么?

以下工作正常..有了这个问题,我想知道是否有更好的方法

for (String s : names) {
    ++i;
    if (s.equals(someRandomInputString)) {
        break;
    }
}
Run Code Online (Sandbox Code Playgroud)

java iteration set

24
推荐指数
1
解决办法
4万
查看次数

'CREATE VIEW'必须是查询批处理中的第一个语句

基本上它的标题是什么.这是我的代码.

USE Assignment2;
GO

/* Player View (2 marks)
    Create a view which shows the following details of all players:
        • The ID number of the player
        • The first name and surname of the player concatenated and given an alias of “full_name”
        • The team ID number of the player (if applicable)
        • The team name of the player (if applicable)
        • The coach ID number of the player (if applicable)
        • The name of the player’s coach (if …
Run Code Online (Sandbox Code Playgroud)

sql sql-server-2008

23
推荐指数
2
解决办法
5万
查看次数

使用普通Javascript隐藏所有元素

我通常用来document.getElementById('id').style.display = 'none'通过Javascript隐藏一个div.是否有一种类似的简单方法来隐藏属于同一个类的所有元素?

我需要一个不使用jQuery的简单Javascript解决方案.

javascript

22
推荐指数
5
解决办法
8万
查看次数

转换时区pandas数据帧

我有数据:

                             Symbol      bid      ask
Timestamp                                            
2014-01-01 21:55:34.378000  EUR/USD  1.37622  1.37693
2014-01-01 21:55:40.410000  EUR/USD  1.37624  1.37698
2014-01-01 21:55:47.210000  EUR/USD  1.37619  1.37696
2014-01-01 21:55:57.963000  EUR/USD  1.37616  1.37696
2014-01-01 21:56:03.117000  EUR/USD  1.37616  1.37694
Run Code Online (Sandbox Code Playgroud)

时间戳是GMT.有没有办法将其转换为东方?

请注意我这样做:

data.index
Run Code Online (Sandbox Code Playgroud)

我得到输出:

<class 'pandas.tseries.index.DatetimeIndex'>
[2014-01-01 21:55:34.378000, ..., 2014-01-01 21:56:03.117000]
Length: 5, Freq: None, Timezone: None
Run Code Online (Sandbox Code Playgroud)

python pandas

22
推荐指数
3
解决办法
3万
查看次数

在Android上的SQLite中查询和使用游标

不确定我是否是唯一感受到这一点的人......

我发现在android中使用sqlite api完全痛苦的屁股和漂亮的灵魂摧毁.有没有人有任何提示/助手让我的生活更轻松?

这是我正在谈论的一个例子.

//create code

db.execSQL("CREATE TABLE " + CUSTOMER_TABLE_NAME + " ("
                        + GENERIC_ID_KEY+ " INTEGER PRIMARY KEY NOT NULL, " 
                        + PHONE_KEY + " INTEGER NOT NULL, "
                        + CUSTOMER_NAME_KEY+ " TEXT NOT NULL, "
                        + EMAIL_KEY + " TEXT NOT NULL, "
                        + ADDRESS_KEY +" TEXT);");


//get code
    Cursor mCursor = mDb.query(true, CUSTOMER_TABLE_NAME, new String[] {GENERIC_ID_KEY,
                        ADDRESS_KEY, PHONE_KEY, EMAIL_KEY,CUSTOMER_NAME_KEY}, GENERIC_ID_KEY + "=" + customerDbId, null,
                                null, null, null, null);

        Customer customer = new Customer (customerDbId, (CharSequence)mCursor.getString(mCursor.getColumnIndexOrThrow(CUSTOMER_NAME_KEY)), …
Run Code Online (Sandbox Code Playgroud)

sqlite android

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

为什么范围对象"不是迭代器"?

我写了这个并且期望0:

>>> x = range(20)
>>> next(x)
Run Code Online (Sandbox Code Playgroud)

相反,我得到了:

TypeError:'range'对象不是迭代器

但我以为这是一个发电机?

最初的答案产生了我最初对自己说的同样的事情:它是一个可迭代的,而不是一个交互者.但是,如果两者都是简单的生成器,那么这就无法解释为什么会这样做:

>>> x = (i for i in range(30))
>>> next(x)
0
Run Code Online (Sandbox Code Playgroud)

python generator python-3.x

21
推荐指数
3
解决办法
9098
查看次数