问题列表 - 第36886页

如何使用可选参数构建装饰器?

我想制作一个可以使用或不使用参数的装饰器:这样的东西:

class d(object):
    def __init__(self,msg='my default message'):
        self.msg = msg
    def __call__(self,fn):
        def newfn():
            print self.msg
            return fn()
        return newfn

@d('This is working')
def hello():
    print 'hello world !'

@d
def too_bad():
    print 'does not work'
Run Code Online (Sandbox Code Playgroud)

在我的代码中,只使用带参数的装饰器工作:如何继续工作(有和没有参数)?

python decorator

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

在oracle.jdbc.pool.OracleDataSource上设置池属性

我使用oracle.jdbc.pool.OracleDataSource进行连接池.我希望游泳池检查连接是否未正确关闭并将其赶上.我尝试了以下方法:

ods = new OracleDataSource();

ods.setConnectionCachingEnabled(true);
ods.setConnectionCacheName(CACHE_NAME);

Properties cacheProps = new Properties();
cacheProps.setProperty("MinLimit", Integer.toString(1));
cacheProps.setProperty("MaxLimit", Integer.toString(6));
cacheProps.setProperty("InitialLimit", "1");
cacheProps.setProperty("AbandonedConnectionTimeout", "2");

ods.setConnectionCacheProperties(cacheProps);
Run Code Online (Sandbox Code Playgroud)

我跟这样的活动连接:

occm = OracleConnectionCacheManager.getConnectionCacheManagerInstance();
occm.getNumberOfActiveConnections(CACHE_NAME);
Run Code Online (Sandbox Code Playgroud)

如果我不关闭应用程序中的连接,那么池最多只能填充6个,所以

cacheProps.setProperty("AbandonedConnectionTimeout", "2");
Run Code Online (Sandbox Code Playgroud)

不管用.为什么?

任何提示都将不胜感激

java oracle connection-pooling

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

Twitter API:通过电子邮件搜索人员

我正试图通过Twitter API找人.我使用这样的网址:https://api.twitter.com/1/users/search.json?q = some@email.com 但是有问题.例如,当我通过电子邮件"blablabla@gmail.com"搜索时,Twitter会使用所有帐户回复我,而不是在他们的电子邮件中使用"gmail.com".所以我甚至找不到自己.

如何告诉twitter API我只想找到指定电子邮件的人?

email twitter search

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

为什么在SOA设计中CRUD操作如此糟糕?

我刚读完John EvdemonMSDN上发表的一篇文章.他抨击CRUD接口并将其称为反模式.

虽然我同意有任何状态是困难的,而Current和MoveNext是不好的想法我不同意CRUD在Create Read Update和Delete中是不好的.如果我有汽车服务而且我想让客户能够做基本操作,例如创建汽车,获取汽车详细信息,更新汽车详细信息或删除汽车,那么他们如何能够做这些事情没有CRUD操作.

或者我在这里缺少什么?

soa design-patterns crud

14
推荐指数
3
解决办法
9417
查看次数

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

使用jquery根据td的No设置td的宽度

我有几个网页,不同数量的表具有不同的列数.

我正在网上寻找一个jquery spinet,它获取表的列数,并根据列数定义每列的宽度.

防爆.

  if (noOfTdOnTable == 2) {
     tdWidth = "50%";
    }
    if (noOfTdOnTable == 3) {
      td1Width = "40%";
      td2Width = "40%";
      td3Width = "20%";
    }
    if (noOfTdOnTable == 4) {
      td1Width = "35%";
      td2Width = "25%";
      td3Width = "15%";
      td4Width = "15%";
    }
Run Code Online (Sandbox Code Playgroud)

更新

使用我给出的唯一答案我现在有这个,但只有在页面上有一个表时才有效,当有两列时我无法弄清楚如何应用.

        var num = $("table > td").length;


    if (num % 4 == 0) {
        $("table  > td:eq(0)").css("width", "50%");
        $("table > td:eq(1)").css("width", "30%");
        $("table > td:eq(2)").css("width", "10%");
        $("table > td:eq(3)").css("width", "10%");
    }
    if (num …
Run Code Online (Sandbox Code Playgroud)

jquery html-table width

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

如何完成基于时间的编程?

我不确定正确的术语是什么,但是如何制作游戏和模拟等基于时间的程序?我刚刚意识到我只编写了等待输入的程序,然后做了一些事情,我很惊讶我不知道怎么写像pong这样的东西:)

如何编写飞行模拟器?它显然不会像计算机运行它那样快.我猜测一切都是在某种循环上执行的.但是,当计算时间超过周期时,如何处理它.

另外,这个的正确用语是什么?搜索"基于时间的编程"并没有真正给我带来有用的结果.

simulation

9
推荐指数
3
解决办法
5702
查看次数

如何使用ConcurrentDictionary,INotifyCollectionChanged,INotifyPropertyChanged创建自定义可观察集合

我正在尝试创建一个ObservableConcurrentDictionary.此对象将用于多线程应用程序,它的数据用于通过控件ItemsSource属性填充控件.

这是我提出的实现:

public sealed class ObservableConcurrentDictionary<TKey, TValue> : ConcurrentDictionary<TKey, TValue>, INotifyCollectionChanged, INotifyPropertyChanged
{
    #region Constructors

    public ObservableConcurrentDictionary()
        : base()
    { 

    }

    public ObservableConcurrentDictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection)
        : base(collection)
    { 

    }


    public ObservableConcurrentDictionary(IEqualityComparer<TKey> comparer)
        : base(comparer)
    { 

    }


    public ObservableConcurrentDictionary(int concurrencyLevel, int capacity)
        : base(concurrencyLevel, capacity)
    { 

    }


    public ObservableConcurrentDictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection, IEqualityComparer<TKey> comparer)
        : base(collection, comparer)
    { 

    }


    public ObservableConcurrentDictionary(int concurrencyLevel, int capacity, IEqualityComparer<TKey> comparer)
        : base(concurrencyLevel, capacity, comparer)
    { 

    }

    public ObservableConcurrentDictionary(int concurrencyLevel, IEnumerable<KeyValuePair<TKey, TValue>> collection, IEqualityComparer<TKey> comparer)
        : base(concurrencyLevel, …
Run Code Online (Sandbox Code Playgroud)

.net wpf inotifycollectionchanged inotifypropertychanged interface-implementation

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

为什么make认为目标是最新的?

这是我的Makefile:

REBAR=./rebar
REBAR_COMPILE=$(REBAR) get-deps compile

all: compile

compile:
    $(REBAR_COMPILE)

test:
    $(REBAR_COMPILE) skip_deps=true eunit

clean:
    -rm -rf deps ebin priv doc/*

docs:
    $(REBAR_COMPILE) doc

ifeq ($(wildcard dialyzer/sqlite3.plt),)
static:
    $(REBAR_COMPILE) build_plt analyze
else
static:
    $(REBAR_COMPILE) analyze
endif
Run Code Online (Sandbox Code Playgroud)

我可以make compile多次运行并获得

aromanov@alexey-desktop:~/workspace/gm-controller/lib/erlang-sqlite$ make compile
./rebar get-deps compile
==> erlang-sqlite (get-deps)
==> erlang-sqlite (compile)
Run Code Online (Sandbox Code Playgroud)

但是,出于某种原因,跑步make test总是给出

aromanov@alexey-desktop:~/workspace/gm-controller/lib/erlang-sqlite$ make test
make: `test' is up to date.
Run Code Online (Sandbox Code Playgroud)

即使文件没有编译.问题是,为什么?

直接运行相同的命令:

aromanov@alexey-desktop:~/workspace/gm-controller/lib/erlang-sqlite$ ./rebar get-deps compile skip_deps=true eunit
==> erlang-sqlite (get-deps)
==> erlang-sqlite (compile)
Compiled src/sqlite3_lib.erl …
Run Code Online (Sandbox Code Playgroud)

makefile

197
推荐指数
4
解决办法
9万
查看次数

Java:简单组合k顺序的一组元素

我有一组数字{'1','13','25','32','49',...},我想计算这个数量k的所有可能组合.

Esample1:

set = {'1','5','23','41,'54','63'};
k = 4;
Run Code Online (Sandbox Code Playgroud)

输出1:

1 5 23 41
1 5 23 54
1 5 23 63
1 5 41 54
1 5 41 63
1 5 54 63
1 23 41 54
1 23 41 63
1 23 54 63
1 41 54 63
5 23 41 54
5 23 41 63
5 23 54 63
5 41 54 63
23 41 54 63
Run Code Online (Sandbox Code Playgroud)

例2:

set = {'a','v','f','z'};
k=3;
Run Code Online (Sandbox Code Playgroud)

输出2:

a v f …
Run Code Online (Sandbox Code Playgroud)

java combinations

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