小编Jon*_*röm的帖子

有64位Ruby吗?

似乎人们正在为64位平台编译MRI Ruby(1.8.7).我一直在寻找和阅读一段时间而没有真正得到我想要的答案.我想知道的是,如果你们中的任何人实际上在Ruby中使用了超过4GB的内存?如果以这种方式编译,Ruby真的是64位吗?

我在源代码中发现了注释,表明它没有在64位上进行测试.例如,它说"BigDecimal尚未在64位整数系统上编译和测试." BigDecimal的评论中.

了解Ruby的其他实现如何以64位进行操作也很有趣.

ruby 64-bit

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

列出<T>和IEnumerable的区别

在实现这种通用的合并排序时,作为一种Code Kata,我偶然发现了IEnumerable和List之间的差异,我需要帮助弄清楚.

这是MergeSort

public class MergeSort<T>
{
    public IEnumerable<T> Sort(IEnumerable<T> arr)
    {
        if (arr.Count() <= 1) return arr;

        int middle = arr.Count() / 2;
        var left = arr.Take(middle).ToList();
        var right = arr.Skip(middle).ToList();
        return Merge(Sort(left), Sort(right));
    }

    private static IEnumerable<T> Merge(IEnumerable<T> left, IEnumerable<T> right)
    {
        var arrSorted = new List<T>();

        while (left.Count() > 0 && right.Count() > 0)
        {
            if (Comparer<T>.Default.Compare(left.First(), right.First()) < 0)
            {
                arrSorted.Add(left.First());
                left=left.Skip(1);
            }
            else
            {
                arrSorted.Add(right.First());  
                right=right.Skip(1);  
            }
        }

        return arrSorted.Concat(left).Concat(right);
    } …
Run Code Online (Sandbox Code Playgroud)

c# generics ienumerable

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

c#:从可空类型中分配

如果我有一个可以为空的"十进制?d"并且我想将d分配给不可为空的e,那么正确的方法是什么?

c# nullable

4
推荐指数
2
解决办法
3619
查看次数

如何使用LINQ在List <Order>中获取产品的唯一条目

我有一个经典的Order - > Order Row场景,如下所示:

public class Order 
{
    public int Id { get; set; }
    public string Name { get; set; }
    public List<OrderRow> OrderRows { get; set; }
}

public class OrderRow
{
    public int Id { get; set; }
    public int ProductId { get; set; }
    public int Amount { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

和一个List <Order>.从订单列表中我想获得所有唯一ProductIds的列表.

我这样解决了:

var orders = new List<Order>();
// TODO get the orders from DB
var products = new Dictionary<int,int>();
orders.ForEach(order => order.OrderRows.ForEach(row …
Run Code Online (Sandbox Code Playgroud)

c# linq linq-to-objects

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

如何让Json.NET将空XML元素序列化为空字符串

Json.NET 6.0 Release 3 的发行说明指出

更改 - 空白XML元素将写为空字符串而不是null

但这不是我的经历.

var xmlText = @"<document xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" Version=""1.1"">
                    <empty/>
                    <space> </space>
                    <null xsi:nil=""true""/>
                </document>";
var doc = new XmlDocument();
doc.LoadXml(xmlText);
var jsonText = JsonConvert.SerializeXmlNode(doc);
Run Code Online (Sandbox Code Playgroud)

我期望

"empty":"", "space":" ", "null":{"@xsi:nil":"true"}
Run Code Online (Sandbox Code Playgroud)

但得到了

"empty":null, "space":"", "null":{"@xsi:nil":"true"}
Run Code Online (Sandbox Code Playgroud)

丢失的空间现在不是问题,但我真的希望将空XML元素序列化为""而不是null.这可能吗?

c# json json.net

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

怎么做更好的零检查?

我收到以下错误:'未定义的方法`有效吗?' 为零:NilClass'

当我试着打电话

@user.subscription.active?
Run Code Online (Sandbox Code Playgroud)

因为有时订阅尚未创建.然后我写了一个方法来检查用户是否有一个现有的有效订阅:

  def active_subscription?
    if !self.subscription.nil?
      if self.subscription.active?
        return true
      else
        return false
      end
    else
      return false
    end
  end
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来编写这个active_subscription?没有所有if else检查和/或返回语句的方法?

以下是订阅模型中检查订阅状态是否处于活动状态的方法

def active?
 status == 'active'
end
Run Code Online (Sandbox Code Playgroud)

ruby refactoring ruby-on-rails

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

Perl https 代理问题

我似乎无法通过代理获取 https。

例子:

require LWP::UserAgent;

my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->proxy('https', 'https://proxy:8080');
# $ua->proxy(['https'], 'https://proxy:8080'); # Fails
# $ua->env_proxy; # This also fails.

my $response = $ua->get('https://aws.amazon.com/cloudwatch/');

if ($response->is_success) {
    print $response->decoded_content;  # or whatever
}
else {
    die $response->status_line;
}
Run Code Online (Sandbox Code Playgroud)

结果:

500 无法连接到 aws.amazon.com:443(超时)位于 test.pl 第 17 行。

但如果我尝试使用curl(还有wget)使用相同的代理,它就可以正常工作。

$ curl --head --proxy https://proxy:8080 https://aws.amazon.com/cloudwatch/
HTTP/1.1 200 Connection established

HTTP/1.1 200 OK
Server: Server
Date: Thu, 08 Dec 2016 16:42:01 GMT
Content-Type: text/html;charset=UTF-8
Content-Length: 214187
Run Code Online (Sandbox Code Playgroud)

Perl 版本

$ perl …
Run Code Online (Sandbox Code Playgroud)

perl lwp lwp-useragent

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

Swift相当于each_slice

是否有类似于Swift中Ruby的Enumerable#each_slice?

Ruby示例:

arr = ["a", "b", "c", "d"]
arr.each_slice(2) {|s1, s2| puts s1 + s2 }
Run Code Online (Sandbox Code Playgroud)

输出:

ab
cd
Run Code Online (Sandbox Code Playgroud)

swift

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

Windows上的mono AOT给了我一个DLL

我在Windows上,我正在提前尝试Main.exe使用Mono C#编译器进行编译gmcs(也尝试过mcs).

>mono --aot Main.exe
Mono Ahead of Time compiler - compiling assembly C:\test\Main.exe 
Code: 21   Info: 4 Ex Info: 8 Class Info: 30 PLT: 2 GOT 
Info: 6 GOT Info Offsets: 8 GOT: 12 
Executing the native assembler: as C:\DOCUME~1\MigueldeIcaza\LOCALS~1\Temp\mono_aot_D2 ID2U -o C:\DOCUME~1\MigueldeIcaza\LOCALS~1\Temp\mono_aot_D2ID2U.o 
Executing the native linker: gcc -shared --dll -mno-cygwin -o C:\test\Main.exe.dll C:\DOCUME~1\MigueldeIcaza\LOCALS~1\Temp\mono_aot_D2ID2U.o 
Compiled 2 out of 2 methods (100%) Methods without GOT slots: 2 (100%) 
Direct calls: 0 (100%) JIT time: …
Run Code Online (Sandbox Code Playgroud)

windows mono aot

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