我正在开发一个使用自定义配置文件的个人项目.该文件的基本格式如下所示:
[users]
name: bob
attributes:
hat: brown
shirt: black
another_section:
key: value
key2: value2
name: sally
sex: female
attributes:
pants: yellow
shirt: red
Run Code Online (Sandbox Code Playgroud)
可以有任意数量的用户,每个用户可以有不同的键/值对,并且可以使用制表位在一个节下面嵌套键/值.我知道我可以为这个配置文件使用json,yaml甚至xml,但是,我现在想保持自定义.
解析应该不难,因为我已经编写了解析它的代码.我的问题是,使用干净和结构化的代码解析这个问题的最佳方法是什么,以及在未来不会发生变化的方式编写(未来可能会有多个嵌套).现在,我的代码看起来非常恶心.例如,
private void parseDocument() {
String current;
while((current = reader.readLine()) != null) {
if(current.equals("") || current.startsWith("#")) {
continue; //comment
}
else if(current.startsWith("[users]")) {
parseUsers();
}
else if(current.startsWith("[backgrounds]")) {
parseBackgrounds();
}
}
}
private void parseUsers() {
String current;
while((current = reader.readLine()) != null) {
if(current.startsWith("attributes:")) {
while((current = reader.readLine()) != null) { …Run Code Online (Sandbox Code Playgroud) 我在rails应用程序中有一个带有以下架构的sqlite3数据库
ActiveRecord::Schema.define(:version => 20100816231714) do
create_table "comments", :force => true do |t|
t.string "commenter"
t.text "body"
t.integer "post_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "posts", :force => true do |t|
t.string "name"
t.string "title"
t.text "content"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "tags", :force => true do |t|
t.string "name"
t.integer "post_id"
t.datetime "created_at"
t.datetime "updated_at"
end
end
Run Code Online (Sandbox Code Playgroud)
我开始使用Post:has_many与标签的关系,因此每个标签都有一个post_id引用.
我现在想要将此关系更改为'has_and_belongs_to_many',我知道我必须创建连接表等....这不是问题而且正在工作
当我尝试从标签表中删除post_id形式时出现问题.我的迁移看起来像这样:
class RemoveFieldsToTags < ActiveRecord::Migration
def self.up
remove_column :tags, :post_id
end
def self.down
add_column :tags, :post_id, :references
end
end
Run Code Online (Sandbox Code Playgroud)
当我运行rake …
在AssemblyOne中考虑一下
public class A
{
internal A (string s)
{ }
}
public class B : A
{
internal B (string s) : base(s)
{ }
}
Run Code Online (Sandbox Code Playgroud)
在AssemblyTwo中
public class C : B
{
// Can't do this - ctor in B is inaccessible
public C (string s) : base(s)
}
Run Code Online (Sandbox Code Playgroud)
显然这是代码味道,但无论是否一个坏主意,是否可以在不更改AssemblyOne的情况下从C的ctor调用B的ctor?
class Foo {
public:
static const int kType = 42;
};
void Func() {
Foo *bar = NULL;
int x = bar->kType;
putc(x, stderr);
}
Run Code Online (Sandbox Code Playgroud)
这是定义的行为吗?我阅读了C++标准但是找不到任何关于访问静态const值的内容......我已经检查了GCC 4.2,Clang ++和Visual Studio 2010生成的程序集,并且它们都没有执行NULL的解引用指针,但我想确定.
我刚刚升级到visual studio 2010并安装了代码合同msi.当我尝试使用它时,我得到一个编译器错误,即v3.5和v4框架中都存在system.diagnostics.contracts.contract dll.有谁知道我该怎么做才能解决这个问题?谢谢.
我无法弄清楚这一点.
这就是我想要发生的事情......
我有一个应用程序,用户使用boto和django将文件上传到S3.我希望这些文件是私有的,只能通过我的应用程序使用我的api凭据访问.
因此,如果用户通过我的应用上传照片,他或其他任何人可以下载的唯一方法是通过我的应用上的帐户.这是可能的,如果是这样,我如何使用boto的acl规则进行设置.我不需要代码,(希望)我可以解决这个问题,只需要了解如何做到这一点.
这有意义吗?我知道我没有很好地传达它,我提前道歉.另外,谢谢你的帮助.
我在a.com上有一个网站(例如).我还有一些其他域名,我没有使用任何东西:b.com和c.com.他们目前转发到a.com.我注意到Google正在使用b.com/stuff和c.com/stuff从我的网站索引内容,而不仅仅是a.com/stuff.告诉Google只通过a.com索引内容的正确方法是什么,而不是b.com和c.com?
似乎通过htaccess进行301重定向是最佳解决方案,但我不知道该怎么做.只有一个htaccess文件(每个域都没有自己的htaccess文件).
b.com和c.com并不是a.com的别名,它们只是我为未来可能的项目保留的其他域名.
当我想要一些链接不做任何事情但只响应javascript动作时,什么是避免链接滚动到页面顶部边缘的最佳方法?
我知道几种方法,它们似乎都很好:
<a href="javascript:void(0)">Hello</a>
Run Code Online (Sandbox Code Playgroud)
要么
<a id="hello" href="#">Hello</a>
<script type="text/javascript>
$(document).ready(function() {
$("#toto").click(function(){
//...
return false;
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
乃至 :
<a id="hello" href="#">Hello</a>
<script type="text/javascript>
$(document).ready(function() {
$("#toto").click(function(event){
event.preventDefault();
//...
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
你有什么偏好吗?为什么?在哪些条件?
PS:当然上面的例子假设你使用的是jquery,但是mootools或prototype的等价物.
找出特定$.ajax()请求需要多长时间的好方法是什么?
我想获取此信息,然后在某个页面上显示它.
回答??::::
我是javascript的新手,如果你不想内联"成功"函数(因为它将是一个更大的功能),这是我能想到的最好的东西.这甚至是一个很好的方法吗?我觉得我太复杂了......:
makeRequest = function(){
// Set start time
var start_time = new Date().getTime();
$.ajax({
async : true,
success : getRquestSuccessFunction(start_time),
});
}
getRquestSuccessFunction = function(start_time){
return function(data, textStatus, request){
var request_time = new Date().getTime() - start_time;
}
}
Run Code Online (Sandbox Code Playgroud)