小编Tim*_*m B的帖子

PHP:如何扩展/收缩Tinyurls

在PHP中,如何在search.twitter.com上复制Tinyurls的扩展/收缩功能?

php

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

是否可以发送只有jQuery的电子邮件?

我可以只使用jQuery发送电子邮件吗?我没有在网站上运行.Net或PHP等.

jquery

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

如何使用Javascript发送电子邮件?

如何使用JavaScript发送电子邮件?

我不想使用mailto,因为如果我使用mailto,它将打开一个电子邮件客户端.

javascript email

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

强制.NET测试方法从内部失败

我的大多数测试方法首先尝试两个或三个简单的操作,这应该引发异常,然后开始真正的工作.在Java中,我会这样写:

@Test
public void TestSomething() {

    try {
        testedClass.testedMethod(null);
        fail();
    catch (IllegalArgumentException ex) {
        // OK
    }

    // and now let's get to the point ...
    // ...

} 
Run Code Online (Sandbox Code Playgroud)

我想在C#中坚持这种习惯,但似乎没有办法强迫测试方法失败.我已经看了一会儿,但没有运气.我错过了什么吗?

PS:我知道测试这些情况的正确方法是:

[TestMethod]
[ExpectedException(ArgumentNullException)]
public void TestSomethingWithNull() {

    testedClass.TestedMethod(null);

}

[TestMethod]
public void TestSomething() {

   // now the non-trivial stuff...

}
Run Code Online (Sandbox Code Playgroud)

......但是,我不喜欢这个.当我有,比方说,我的测试类中的6个测试方法,并且每个测试应该从覆盖三个琐碎的,一行情况开始,这应该引发异常,使用这种方法将我的6个测试变成18个.应用程序,这确实污染了我的测试资源管理器,并使结果更难以扫描.

并且假设我想测试一个方法,该方法的职责是验证某个类的给定实例的每个属性,如果任何值不正确则引发ValidationException.这可以通过一个TestValidation()测试轻松处理,但是使用这种方法,将其转换为:

  • TestValidationWithNull();
  • TestValidationWithInvalidProperty1();
  • TestValidationWithInvalidProperty2();
  • TestValidationWithNullProperty2();

想象一下,你有20个属性...... :)

当然,如果这是唯一的方法,我会咬人.

.net c# unit-testing

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

设置Spring Security:从元素'security:http'开始发现无效内容

我正在尝试配置这里找到的spring-security,并且似乎已经限制了我对XML文件如何工作的理解.

按照说明我已经向applicationContext.xml添加了spring security,如下所示:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"
   xmlns:context="http://www.springframework.org/schema/context" 
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:security="http://www.springframework.org/schema/security">
Run Code Online (Sandbox Code Playgroud)

那一步部署得很好.

然后我去了web.xml并添加了:

<filter>
  <filter-name>springSecurityFilterChain</filter-name>
  <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
  <filter-name>springSecurityFilterChain</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)

那仍然很好.

然后我尝试添加

<http auto-config='true'>
    <intercept-url pattern="/**" access="ROLE_USER" />
</http>
Run Code Online (Sandbox Code Playgroud)

其中我也尝试过

<security:http auto-config='true'>
    <intercept-url pattern="/**" access="ROLE_USER" />
</security:http>
Run Code Online (Sandbox Code Playgroud)

在这两种情况下,当我尝试部署应用程序时,我看到了一个错误:

Error occurred during deployment: Exception while deploying the app [OmegaRM] : org.xml.sax.SAXParseException; lineNumber: 53; columnNumber: 39; Deployment descriptor file WEB-INF/web.xml in archive [web].  cvc-complex-type.2.4.a: Invalid content …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security

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

我应该为每个在不同线程之间共享其内存的对象指定volatile关键字

我刚刚阅读过不要使用volatile作为 CERT站点上的同步原语文章,并注意到编译器理论上可以优化以下代码,方法是将flag变量存储在寄存器中,而不是修改不同线程之间共享的实际内存:

bool flag = false;//Not declaring as {{volatile}} is wrong. But even by declaring {{volatile}} this code is still erroneous
void test() {
  while (!flag) {
    Sleep(1000); // sleeps for 1000 milliseconds
  }
}
void Wakeup() {
  flag = true;
}
void debit(int amount){
   test();
   account_balance -= amount;//We think it is safe to go inside the critical section
}
Run Code Online (Sandbox Code Playgroud)

我对吗?

我是否需要为volatile程序中的每个对象使用关键字来共享不同线程之间的内存?不是因为它为我做了某种同步(我需要使用互斥或​​任何其他同步原语来完成这样的任务)但仅仅因为编译器可能优化我的代码并将所有共享变量存储在寄存器中其他线程永远不会获得更新值?

c++ multithreading volatile

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

从Winform App使用Web服务时出错 - "无法执行程序......"

我有一个winform应用程序调用Web服务来检查更新.这在dev中工作,它也适用于我尝试过的其他任何地方,而不是在我的机器上安装的副本上(在开发中恰好相同).

错误是:

无法执行程序.正在执行的命令是"C:\ WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe"/ noconfig/fullpaths @"C:\ Documents and Settings\Giovanni.DOUBLE-AFSSZ043\Local Settings\Temp\squ8oock .cmdline".

防火墙被禁用,我找了"C:\ Documents and Settings\Giovanni.DOUBLE-AFSSZ043\Local Settings\Temp\squ8oock.cmdline",它不在那里.请注意,每次我尝试使用Web服务时,".cmdline"文件都不同,例如第二次运行它时,它是"dae8rgen.cmdline".无论它有什么名字,我都找不到文件.

有什么建议?

.net web-services winforms

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

如何在.net中有条件地继承类

我不确定这是否可能,但是我有一个需要有条件地继承类的要求。

例如我有一个类Name ABC需要在某个时候继承PQR,而XYZ有条件地像

Public Class ABC : PQR OR Public Class ABC:XYZ
Run Code Online (Sandbox Code Playgroud)

因此,如果我们需要Old Config继承PQR或XYZ,那么我想在web.config应用程序设置的帮助下进行操作

.net c# asp.net asp.net-mvc-4

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

不同线程释放的可重入ReadWriteLock

我正在单个服务器上实现乐观事务(BOCC)。在提交时,根据当前数据库状态验证读取和写入集(如果自读取后状态发生更改,则事务将中止)。如果验证成功,所有对象都会写入数据库。

对不同对象集的验证(加上数据库更新)可以是并发的,但必须使用读锁和写锁来保护重叠的对象集。

我使用ReentrantReadWriteLock来确保验证的安全,效果很好。现在我正在编写一个恢复机制,如果由于某些错误(验证后)并非所有对象都写入数据库,该机制会重复更新过程。

因此恢复会重复数据库写入,然后尝试释放锁(恢复成功后)。问题是我尝试从不同的线程释放锁(因为恢复是由另一个后台服务执行的),这会抛出IllegalMonitorStateException. 该方法的注释unlock验证了此行为。

    /**
     * Attempts to release this lock.
     *
     * <p>If the current thread is the holder of this lock then
     * the hold count is decremented. If the hold count is now
     * zero then the lock is released.  If the current thread is
     * not the holder of this lock then {@link
     * IllegalMonitorStateException} is thrown.
     *
     * @throws IllegalMonitorStateException if the current thread does not
     * hold …
Run Code Online (Sandbox Code Playgroud)

java concurrency multithreading locking transactions

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

java编译器是否会使用常量优化对Math.exp的调用?

如果我正在实现一个包含1-Math.exp(-50)并希望结果具有高效性的公式,我应该预先计算该常量并将其保存在static final doubleJava编译器中,或者是Java编译器是否足够智能以实现结果是常量并预先计算它做一些更简单的事情1-50/7

java performance compiler-optimization

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