问题列表 - 第35630页

Eclipse Virgo和Eclipse Gemini有什么区别?

嘿,
Eclipse Virgo和Eclipse Gemini有什么区别?
(我理解OSGI的一般做法).

java osgi eclipse-gemini eclipse-virgo

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

如何以编程方式派生Windows下载文件夹"%USERPROFILE%/ Downloads"?

在.Net中,我们可以检索"特殊文件夹"的路径,例如Documents/Desktop等.今天我试图找到一种方法来获取"下载"文件夹的路径,但它看起来并不特别.

我知道我可以做'C:\ Users\Username\Downloads',但这似乎是一个丑陋的解决方案.那么如何使用.Net来修复路径呢?

.net registry environment-variables special-folders registrykey

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

Ruby,我如何访问do-end循环之外的局部变量

我有一个循环,我在远程机器上执行一系列命令:


   ssh.exec('cd /vmfs/volumes/4c6d95d2-b1923d5d-4dd7-f4ce46baaadc/ghettoVCB;  ./ghettoVCB.sh -f vms_to_backup -d dryrun') do|ch, stream, data|
                                    if #{stream} =~ /vmupgrade/
                                    puts value_hosts + " is " + data
                                    puts #{stream}
                                    puts data
                                    end
                            end
Run Code Online (Sandbox Code Playgroud)

我想访问#{stream}和do-end循环之外的数据

我将不胜感激任何帮助.谢谢,

嗨Jörg,

我实施了你的建议,但现在我收到了错误:


WrapperghettoVCB.rb:49: odd number list for Hash
      communicator = {ch: ch, stream: stream, data: data}
                         ^
WrapperghettoVCB.rb:49: syntax error, unexpected ':', expecting '}'
      communicator = {ch: ch, stream: stream, data: data}
                         ^
WrapperghettoVCB.rb:49: syntax error, unexpected ':', expecting '='
      communicator = {ch: ch, stream: stream, data: data}
                                     ^ …
Run Code Online (Sandbox Code Playgroud)

ruby

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

在此代码中如何选择一种方法而不是另一种方法?

这是SCJP的另一个问题.下面的代码打印出来Alpha:fooBeta:fooBeta:barBeta:bar,我不明白为什么第一个foo调用选择Alpha的foo而不是Beta的.如果Alpha.foo参数更改为String而不是String ...,那么输出是Beta:fooBeta:fooBeta:barBeta:bar有意义的.

我的理解是,当你说Alpha a = new Beta();,编译器检查Alpha.foo,但JVM实际上将运行Beta.foo.首先,Beta确实有一个foo方法,其签名与调用匹配.另一方面,我认为varargs方法只在没有其他可用的方法与调用匹配时运行.所以这就是我认为不应该运行Alpha.foo的两个原因.这种理解的哪一部分是错的?

谢谢!

class Alpha {

    public void foo(String... args) { //if this were String args, then it makes sense
        System.out.print("Alpha:foo");
    }

    public void bar(String a) {
        System.out.print("Alpha:bar");
    } }

public class Beta extends Alpha {

    public void foo(String a) {
        System.out.print("Beta:foo");
    }

    public void bar(String a) {
        System.out.print("Beta:bar");
    }

    public static void main(String[] arg) {
        Alpha a = new Beta();
        Beta b = (Beta) a;
        a.foo("test");//confusing line
        b.foo("test"); …
Run Code Online (Sandbox Code Playgroud)

java polymorphism inheritance

6
推荐指数
2
解决办法
657
查看次数

需要一种按日期对100 GB日志文件进行排序的方法

所以,由于一些奇怪的原因,我最终得到一个100GB的未分类日志文件(实际上它是部分排序的),而我试图应用的算法需要排序数据.日志文件中的一行看起来像这样

data <date> data data more data
Run Code Online (Sandbox Code Playgroud)

我可以在工作站上访问C#4.0和大约4 GB的RAM.我认为合并 - 某种类型在这里最好,但是我自己实现这些算法还不够 - 我想问一下我是否可以采取某种捷径.

顺便说一句,解析日期字符串DateTime.Parse()非常慢,占用了大量的CPU时间 - chugging -rate几乎是10 MB /秒.有比以下更快的方式吗?

    public static DateTime Parse(string data)
    {            
        int year, month, day;

        int.TryParse(data.Substring(0, 4), out year);
        int.TryParse(data.Substring(5, 2), out month);
        int.TryParse(data.Substring(8, 2), out day);

        return new DateTime(year, month, day);
    }
Run Code Online (Sandbox Code Playgroud)

我写道,为了加快速度DateTime.Parse(),它确实运行良好,但仍然需要大量的循环.

请注意,对于当前的日志文件,我也对小时,分钟和秒感兴趣.我知道我可以使用格式提供DateTime.Parse(),但这似乎并没有加快它的速度.

我正在寻找正确方向的推动,提前谢谢.

编辑:有些人建议我使用字符串比较来比较日期.这适用于排序阶段,但我确实需要解析算法的日期.我仍然不知道如何在4GB的免费RAM上对100GB文件进行排序,而无需手动操作.

编辑2:嗯,多亏了我使用windows排序的一些建议,我发现Linux上有类似的工具.基本上你叫sort,它会为你修复一切.正如我们所说,它正在做一些事情,我希望它能尽快结束.我正在使用的命令是

sort -k 2b 2008.log > 2008.sorted.log
Run Code Online (Sandbox Code Playgroud)

-k指定我要对第二行进行排序,第二行是通常YYYY-MM-DD hh:mm:ss.msek格式的日期时间字符串.我必须承认,man-pages缺乏解释所有选项,但我通过运行找到了很多例子info coreutils …

c# sorting date-sorting

33
推荐指数
5
解决办法
9364
查看次数

Mongoid命名范围比较同一文档中的两个时间字段

我需要在Mongoid中创建一个命名范围,用于比较同一文档中的两个时间字段.如

scope :foo, :where => {:updated_at.gt => :checked_at}

这显然不会起作用,因为它被视为:checked_at一个符号,而不是实际的领域.有关如何做到这一点的任何建议?

更新1

这是我的模型,我声明了这个范围,删除了许多额外的代码.

class User
  include Mongoid::Document
  include Mongoid::Paranoia
  include Mongoid::Timestamps

  field :checked_at, :type => Time

  scope :unresolved, :where => { :updated_at.gt => self.checked_at }
end
Run Code Online (Sandbox Code Playgroud)

这给了我以下错误:

'<class:User>': undefined method 'checked_at' for User:Class (NoMethodError)

ruby-on-rails mongodb mongoid

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

使用反引号时逃避空格

我有一个搜索,从我的角度来看,使用反引号是解决这个问题的唯一方法.我正在尝试mdls从Perl中调用目录中每个文件的命令,以找到它上次访问的时间.我遇到的问题是,在我的文件名中,find我有非转义空格,bash显然不喜欢.有没有一种简单的方法可以在传递文件名之前转义文件名中的所有空格mdls.如果这是一个明显的问题,请原谅我.我对Perl很新.

my $top_dir = '/Volumes/hydrogen/FLAC';

sub wanted { # Learn about sub routines 
    if ($File::Find::name) { 
         my $curr_file_path = $File::Find::name. "\n";
        `mdls $curr_file_path`;
         print $_;
    }
}

find(\&wanted, $top_dir);
Run Code Online (Sandbox Code Playgroud)

macos perl whitespace find backticks

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

为什么我需要Forward Iterator来实现我自定义的std :: search

我正在研究Koenig&Moo的"Accelerated C++"一书.

练习8-2问我对我自己来实现一些模板化的功能<algorithm><numeric>,并指定什么样的迭代器做我的实现需要.

在尝试实现时std::search,我确定我只需要"输入"迭代器.

到目前为止,这是我的代码:

template <class In1, class In2>
In1 search(In1 b, In1 e, In2 b2, In2 e2)
{
    if (b2 != e2) {
        while (b != e) {
            if (*b == *b2) {
                In1 bc = b;
                In2 b2c = b2;
                while (bc != e && b2c != e2 && *bc == *b2c) {
                    ++bc;
                    ++b2c;
                }
                if (b2c == e2)
                    return b;
            }
            ++b;
        }
    }
    return e;
}
Run Code Online (Sandbox Code Playgroud)

但是,看看std::search …

c++ iterator

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

为什么我的jquery .each()函数无法正常工作?

我写了这个函数:

jQuery(document).ready(function() {
    jQuery('input[type=text]').each( function(i) {
        thisval = jQuery(this).val();

        jQuery(this).blur( function() {
            if (jQuery(this).val() == '') {
                jQuery(this).val(thisval);
            }
        }); // end blur function
        jQuery(this).focus( function() {
            if (jQuery(this).val() == thisval) {
                jQuery(this).val('');
            };
        });// end focus function
    }); //END each function
}); // END document ready function
Run Code Online (Sandbox Code Playgroud)

它旨在获取输入的值,然后如果用户点击而不输入新值,则返回旧值.这适用于页面上的一个输入,但不适用于其他输入.但是,当我删除.blur和.focus函数并只使用alert(thisval); 它警告每个输入的名称,所以我的功能有问题,但我无法弄清楚是什么.有帮助吗?

javascript jquery

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

为什么SetString在Delphi中使用较少的内存(使用Unicode)?

这是Delphi 2009,因此Unicode适用.

我有一些代码将缓冲区中的字符串加载到StringList中,如下所示:

      var Buffer: TBytes; RecStart, RecEnd: PChar; S: string;

      FileStream.Read(Buffer[0], Size);

      repeat
         ... find next record RecStart and RecEnd that point into the buffer;        

         SetString(S, RecStart, RecEnd - RecStart);
         MyStringList.Add(S);
      until end of buffer
Run Code Online (Sandbox Code Playgroud)

但是在一些修改过程中,我改变了逻辑,以便最终添加相同的记录,但是作为单独派生的字符串而不是通过SetString,即

      var SRecord: string;

      repeat
        SRecord := '';
        repeat
          SRecord := SRecord + ... processed line from the buffer;
        until end of record in the buffer

        MyStringList.Add(SRecord);
      until end of buffer
Run Code Online (Sandbox Code Playgroud)

我注意到的是StringList的内存使用从52 MB上升到大约70 MB.这增加了30%以上.

为了回到我的较低的内存使用量,我发现我必须使用SetString来创建字符串变量以添加到我的StringList,如下所示:

      repeat
        SRecord := '';
        repeat
          SRecord := SRecord + …
Run Code Online (Sandbox Code Playgroud)

delphi string unicode pchar setstring

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