问题列表 - 第11467页

从string和int创建哈希

我记得eclipse和idea有这个模板根据其属性自动创建一个对象的hashCode.

如果使用数字和字符串,其中一种策略是这样的.

  return stringValue.hashCode() + intValue * 32;
Run Code Online (Sandbox Code Playgroud)

这样的东西.

我手头没有也没有eclipse或想法,我想创建这样的功能.

编辑

根据答案,我创建了这个迷你课程

    class StringInt {
        private final String s;
        private final int i;

        static StringInt valueOf( String string , int value ) {
            return new StringInt( string, value );
        }
        private StringInt( String string, int value ) {
            this.s = string;
            this.i = value;
        }
        public boolean equals( Object o ) {
            if( o != null && o instanceof StringInt ){
                StringInt other = ( StringInt ) o;
                return this.s …
Run Code Online (Sandbox Code Playgroud)

java eclipse hash code-generation intellij-idea

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

如何从SQLAlchemy控制MySQL超时?

使用SQLAlchemy从客户端运行MySQL数据库时,控制超时的正确方法是什么?该connect_timeoutURL参数似乎是不够的.

我对运行数据库的机器发生的事情更感兴趣,例如,意外地从网络中消失.我并不担心查询本身需要太长时间.

如果somehost 到达while循环之前不可用,则以下脚本执行您期望的操作(即,大约一秒后超时).但是,如果,某下降过程中while循环(例如,尝试唬弄了其网线循环开始后),然后超时似乎至少需要18秒.我缺少一些额外的设置或参数吗?

wait_timeout会话变量不起作用并不奇怪,因为我认为这是一个服务器端变量.但我把它扔在那里只是为了确保.

from sqlalchemy import *
from sqlalchemy.exc import *
import time
import sys

engine = create_engine("mysql://user:password@somehost/test?connect_timeout=1")
try:
    engine.execute("set session wait_timeout = 1;")
    while True:
        t = time.time()
        print t
        engine.execute("show tables;")
except DBAPIError:
    pass
finally:
    print time.time() - t, "seconds to time out"
Run Code Online (Sandbox Code Playgroud)

python mysql sqlalchemy

9
推荐指数
1
解决办法
5474
查看次数

XML文档的松散合并

我有两个文档 - 一个是自定义XML文件格式,另一个是带有一堆自定义扩展的RSS源.我希望在一个元素值匹配时使用RSS提要中的值填充XML文件中的字段.

这适用于将手动运行几次的脱机过程 - 它不需要执行良好,所有容错,等等.手动劳动或干预是好的.

我的主XML文档如下所示:

    <videos>
        <video>
            <title>First Video</title>
            <code>AAA123</code>
            <id>decaf-decaf-decaf-decaf</id>
            <description>lots of text here...</description>
        </video>
        <video>
            <title>Second Video with no code</title>
            <code></code>
            <id>badab-badab-badab-badab</id>
            <description>lots of text here...</description>
        </video>
    </videos>
Run Code Online (Sandbox Code Playgroud)

RSS提要是标准的RSS,有一些额外的字段:

  <ns:code>AAA123</ns:code>
  <ns:type>Awesome</ns:type>
  <ns:group>Wonderful</ns:group>
Run Code Online (Sandbox Code Playgroud)

__CODE____CODE__动态修改属性时,我想将RSS文档中的额外字段拉入XML文档,以报告需要几秒钟才能完成的过程.问题是在Firefox上,在脚本完成之前,页面实际上并未重新呈现以反映该更改.这使得应用程序感觉迟钝.有没有办法确保即使运行更多脚本,HTML的更改也会立即显示?

c# xml linq-to-xml

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

How do I detect if a scriptmanager is on the page?

How do I detect if a scriptmanager is loaded on a page? Some aspx pages have it and others don't and I need a user control to understand this so that it can either load it if needed and also for dealing with viewstate.

asp.net scriptmanager

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

Scala best way of turning a Collection into a Map-by-key? (2nd variant)

(This is a variant to this Q&A)

Say I have this:

List( "foo", "bar", "spam" )
Run Code Online (Sandbox Code Playgroud)

I want to create a Map for which the key is the length of the String and the value is a Collection of all the Strings that have that length. In other words, given the about List, we'd get:

Map( 3 -> List(foo, bar), 4 -> List(spam) )
Run Code Online (Sandbox Code Playgroud)

The code I've written to do this is:

list.foldLeft(Map[Long, List[String]]()) {
  (m, s) => m(s.length) …
Run Code Online (Sandbox Code Playgroud)

scala list map scala-collections

8
推荐指数
2
解决办法
1892
查看次数

PHP Simultaneous File Writes

I have two different PHP files that both write to the same file. Each PHP script is called by a user action of two different HTML pages. I know it will be possible for the two PHP files to be called, but will both PHP files attempt to write to the file at the same time? If yes, what will happen? Also, it is possible to make one of the PHP fail gracefully (file write will just fail, and the …

php file-io file

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

How can I force the browser to redraw while my script is doing some heavy processing?

I am using the innerHTML property to modify a DIV dynamically, to report on a process that takes a few seconds to finish. The problem is that on Firefox the page is not actually re-rendered to reflect that change until after the script has finished. This makes the app feel sluggish. Is there a way to make sure that changes to the HTML show up immediately, even if more scripts are running?

html javascript css dom

8
推荐指数
2
解决办法
4060
查看次数

MySQL Connector/JDBC线程安全吗?

标准的MySQL JDBC驱动程序是否是线程安全的?具体来说,我想在所有线程中使用单个连接,但每个语句只能在单个线程中使用.是否存在某些安全的情况,而其他情况则不然?你在这里有什么经历?

java mysql concurrency jdbc thread-safety

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

<ul>中的所有内容都必须包含在<li>中吗?

我需要一些关于HTML中嵌套列表的指导.

我有一个我希望如下构建的布局.嵌套一个没有被包裹的元素是一件可怕的事<li>吗?我很确定这是违反标准的,但不知道它有什么不良影响.

<ul>
  <li>
    <h1>header 1</h1>
    <li>
       <ul>
         <li>nested</li>
         <li>list</li>
       </ul>
    </li>
  </li>
  <li>
    <h1>header 2</h1>
    <li>
       <ul>
         <li>nested</li>
         <li>list</li>
       </ul>
    </li>
  </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

html

10
推荐指数
4
解决办法
5451
查看次数

我可以在一个Windows Server 2008框中打开的最大HTTP连接数是多少?

我有一个托管HTTP聊天应用程序的Web服务器,可以使用长轮询.

这意味着客户端浏览器"轮询"新信息,并且服务器在有信息要发回之前不响应,因此HTTP连接长时间保持打开状态,最多一分钟.

我的问题是服务器在死亡之前可以同时打开多少个连接.
当然,没有确切的数字,但我想掌握一个数量级(1,000,10,000,10000?)

根据您可能拥有的任何经验,任何与此相关的见解都非常受欢迎!

iis performance http windows-server-2008

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