我刚刚更新了试用rails 3,使用rvm和ruby 1.9.2-p0.
当我运行我的黄瓜规格时,我会听到奇怪的警告
/home/ubuntu/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/utils.rb:16: warning: regexp match /.../n against to UTF-8 string
/home/ubuntu/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/utils.rb:16: warning: regexp match /.../n against to UTF-8 string
/home/ubuntu/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/utils.rb:16: warning: regexp match /.../n against to UTF-8 string
Run Code Online (Sandbox Code Playgroud)
我的包包含以下宝石......
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.0)
Using builder (2.1.2)
Using i18n (0.4.1)
Using activemodel (3.0.0)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.4)
Using tzinfo (0.3.23)
Using actionpack (3.0.0)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.8)
Using mail (2.2.5) …Run Code Online (Sandbox Code Playgroud) 我似乎无法写入.NET中的事件日志.我得到以下异常:
System.Security.SecurityException:找不到源,但无法搜索部分或全部事件日志.无法访问的日志:安全性.
我不想访问安全日志.我该如何解决这个错误?谢谢!
在学习正则表达式时,我想知道底层引擎是如何工作的.可能更具体地说,我想更多地了解它如何评估,优先考虑和解析表达.我觉得RegEx引擎对我来说是一个黑盒子,我真的很喜欢破译它.
所以我想问一下,在讨论RegEx引擎理论时是否有一些我可以阅读的优秀资源.
*注意:我对构建引擎不感兴趣,只是学习引擎的内部工作原理.
JTextField是一个初始化为零的计算器显示,显示带前导0的十进制数字是错误的形式,如0123或00123. NetBeans Swing JFrame中的数字按钮(0..9)使用append()[below]删除前导零,但用户可能更喜欢键盘鼠标,并且还需要处理非数字字符.
private void append(String s) {
if (newEntry) {
newEntry = false;
calcDisplay.setText(s);
} else if (0 != Float.parseFloat(calcDisplay.getText().toString())) {
calcDisplay.setText(calcDisplay.getText().toString() + s);
}
}
Run Code Online (Sandbox Code Playgroud) 假设我有两个表:
CREATE TABLE A(
id INT PRIMARY KEY,
x INT,
y INT
)
CREATE TABLE B(
id INT PRIMARY KEY,
x INT,
y INT,
)
Run Code Online (Sandbox Code Playgroud)
表A包含从另一个供应商引入的数据,而表B是我们的数据.为简单起见,我已经使这些表在模式方面完全相同,但表B可能是表A的超集(它将包含表A不会换句话的某些列).
我想要做的是创建一个带有id,x和y列的视图C,这样值就来自表B,除非它们是NULL,在这种情况下它们将来自表A.例如,假设我有以下内容:
INSERT INTO A (id, x, y)
VALUES (1, 2, 3);
INSERT INTO B (id, x, y)
VALUES (1, NULL, NULL);
INSERT INTO A (id, x, y)
VALUES (2, 3, 4);
INSERT INTO B (id, x, y)
VALUES (2, 5, 6);
INSERT INTO A(id, x, y)
VALUES (3, 4, 5);
INSERT INTO B(id, x, …Run Code Online (Sandbox Code Playgroud) 我期望使用指定的EqualityComparer创建的HashSet在Remove操作上使用该comparer.特别是因为Contains操作返回true!
这是我正在使用的代码:
public virtual IEnumerable<Allocation> Allocations { get { return _allocations; } }
private ICollection<Allocation> _allocations;
public Activity(IActivitySubject subject) { // constructor
....
_allocations = new HashSet<Allocation>(new DurationExcludedEqualityComparer());
}
public virtual void ClockIn(Allocation a)
{
...
if (_allocations.Contains(a))
_allocations.Remove(a);
_allocations.Add(a);
}
Run Code Online (Sandbox Code Playgroud)
下面是一些快速而又脏的LINQ,它让我得到了我想要的逻辑,但我猜测基于EqualityComparer的HashSet删除会明显加快.
public virtual void ClockIn(Allocation a)
{
...
var found = _allocations.Where(x => x.StartTime.Equals(a.StartTime) && x.Resource.Equals(a.Resource)).FirstOrDefault();
if (found != null)
{
if (!Equals(found.Duration, a.Duration))
{
found.UpdateDurationTo(a.Duration);
}
}
else
{
_allocations.Add(a);
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议为什么当包含成功时删除会失败?
干杯,
Berryl
===编辑===比较器
public class DurationExcludedEqualityComparer …Run Code Online (Sandbox Code Playgroud) 主题行说明了这一切.
一些谷歌搜索显示出令人费解的缺乏相关信息.对现有工具的一些指示会很棒!
雷蒙德.
通过"蜜罐",我的意思或多或少是这种做法:
#Register form
<style>
.hideme{
display:none;
visibility: hidden;
}
</style>
<form action="register.php">
Your email: <input type="text" name="u-email" />
Choose a password: <input type="text" name="passwd" />
<div class="hideme">
Please, leave this field blank: <input type="text" name="email" /> #the comment is for text-browser users
</div>
<input type="submit" value="Register" autocomplete=off />
</form>
//register.php
<?php
if($_POST['email'] != ''){
die("You spammer!");
}
//otherwise, do the form validation and go on.
?>
Run Code Online (Sandbox Code Playgroud)
更多信息在这里.
显然,真实字段是用随机哈希命名的,而蜜罐字段可以有不同的名称(电子邮件,用户,网站,主页等等),这是spambot通常填写的.
我喜欢这种技术,因为它不会导致用户被CAPTCHA烦恼.
你有没有人对这种技术有一些经验?有效吗?
我有多个Linq2Sql类,如"Article""NewsItem""Product".
他们都有一个标题,他们都有一个唯一的ID,他们都有一个摘要.
所以,我创建了一个名为的接口 IContent
public interface IContent {
int Id { get; set; }
String Title { get; set; }
String Summary { get; set; }
String HyperLink { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在我的代码中,我试图传递一个List<T>实现IContent,然后使用我在项目中的每个部分类中实现的那些公共属性.
所以,只是澄清一下
Article是Linq实体.我创建了一个部分类并实现了IContent以下是Article.cs的片段:
#region IContent Members
public int Id {
get {
return this.ArticleID;
}
set {
this.ArticleID = value;
}
}
Run Code Online (Sandbox Code Playgroud)
很简单.在我的代码中,我正在尝试这个,但我不知道我哪里出错了:
List<IContent> items;
MyDataContext cms = new MyDataContext();
items = cms.GetArticles();
// ERROR: Can not implicitly convert List<Article> …Run Code Online (Sandbox Code Playgroud)