问题列表 - 第27427页

Arel中的嵌套查询

我试图在Arel和/或Rails 3中的Active Record中嵌套SELECT查询以生成以下SQL语句.

SELECT sorted.* FROM (SELECT * FROM points ORDER BY points.timestamp DESC) AS sorted GROUP BY sorted.client_id
Run Code Online (Sandbox Code Playgroud)

可以通过执行创建子查询的别名

points = Table(:points)
sorted = points.order('timestamp DESC').alias
Run Code Online (Sandbox Code Playgroud)

但后来我被困在如何将它传递给父查询(缺少调用#to_sql,这听起来很难看).

如何使用SELECT语句作为Arel(或Active Record)中的子查询来完成上述操作?也许有一种完全不同的方式来完成这个不使用嵌套查询的查询?

ruby-on-rails arel

19
推荐指数
4
解决办法
1万
查看次数

使用Solr全文搜索不规则说唱歌手的名字

我正在我的说唱网站上实现全文搜索功能,而且我遇到了一些关于说唱歌手和歌曲名称的问题.

例如,某人可能想要使用查询"camron" 搜索说唱歌手" Cam'ron "(省略中间词撇号).同样,有人可能会使用查询"3peat" 搜索歌曲" 3 Peat ".

" 臭名昭着的BIG "是一个奇怪的案例:"臭名昭着的BIG"和"臭名昭着的BIG"都有效(我猜因为solr.StandardFilterFactory从首字母缩略词中删除了点?),但是"臭名昭着的BIG"(即,减去尾随点)没有.

理想情况下,这些名称的所有合理变体都应该有效 我猜这个答案与solr.WordDelimiterFilterFactory有关,但我不确定.

此外,如果相关,我正在使用带有Rails的太阳黑子.

ruby solr ruby-on-rails sunspot

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

C#图像裁剪,分割,保存

如主题所述,我有一个图像:

    private Image testing;
    testing = new Bitmap(@"sampleimg.jpg");
Run Code Online (Sandbox Code Playgroud)

我想将它分成3 x 3矩阵,总共意味着9张图片并保存.有什么提示或技巧可以做到这一点吗?我正在使用视觉工作室2008并致力于智能设备.试过一些方法,但我无法得到它.这是我试过的:

        int x = 0;
        int y = 0;
        int width = 3;
        int height = 3;


        int count = testing.Width / width;
        Bitmap bmp = new Bitmap(width, height);


        Graphics g = Graphics.FromImage(bmp);


        for (int i = 0; i < count; i++)
        {
            g.Clear(Color.Transparent);
            g.DrawImage(testing, new Rectangle(0, 0, width, height), new Rectangle(x, y, width, height), GraphicsUnit.Pixel);
            bmp.Save(Path.ChangeExtension(@"C\AndrewPictures\", String.Format(".{0}.bmp",i)));
            x += width;
        } 
Run Code Online (Sandbox Code Playgroud)

c# split image crop save

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

Wpf:Storyboard.TargetName有效,但Setter TargetName没有

假设我们有一个像这样的XAML代码:

<Style TargetType="{x:Type ListBoxItem}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                <Border HorizontalAlignment="Center" VerticalAlignment="Center">
                    <Border.LayoutTransform>
                        <!--We are rotating randomly each image. Selected one will be rotated to 45°.-->
                        <RotateTransform Angle="{Binding RandomAngle}" x:Name="globalRotation"/>
                    </Border.LayoutTransform>
                    <Grid>
                        <Image Source="{Binding ImageLocation}" Stretch="None" />
                        <TextBlock x:Name="title" Text="{Binding Title}" />
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter TargetName="title" Property="Visibility" Value="Visible"/>
                        <!--The next line will not compile.-->
                        <Setter TargetName="globalRotation" Property="Angle" Value="45"/>
                        <Trigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <!--This compiles well.-->
                                    <DoubleAnimation Storyboard.TargetName="globalRotation" Storyboard.TargetProperty="Angle" To="45" Duration="00:00:03"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </Trigger.EnterActions>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate> …
Run Code Online (Sandbox Code Playgroud)

wpf xaml storyboard

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

递归程序

我正在尝试制作一个计算每年利息的递归程序.它会提示用户启动金额(1000),利率(10%)和年数(1).(括号内为样本)

手动我意识到兴趣来自公式YT(1 + R)-----第一年的利息是1100.

第二年YT(1 + R/2 + R2/2)// R平方

第二年YT(1 + R/3 + R2/3 + 3R3 /)// R立方

如何编写一个计算兴趣的递归程序?以下是我尝试过的功能

//编辑后的最新内容

double calculateInterest2(double start, double rate, int duration) 
{ 
    if (0 == duration) { 
        return start; 
    } else { 
        return (1+rate) * calculateInterest2(start, rate, duration - 1); 
    } 
} 
Run Code Online (Sandbox Code Playgroud)

c++ recursion

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

Scala地图转换

我很害怕Scala新手:我正在尝试根据一些简单的逻辑将Map转换为新的Map:

val postVals = Map("test" -> "testing1", "test2" -> "testing2", "test3" -> "testing3")
Run Code Online (Sandbox Code Playgroud)

我想测试值"testing1"并更改值(创建新Map时)

def modMap(postVals: Map[String, String]): Map[String, String] = {
  postVals foreach {case(k, v) => if(v=="testing1") postVals.update(k, "new value")}
}
Run Code Online (Sandbox Code Playgroud)

scala map

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

BBP算法所需的工作精度?

我想在低内存环境中计算Pi的第n位数.因为我没有可用的小数,所以Python中这个仅整数的BBP算法是一个很好的起点.我只需要一次计算一位Pi.如何确定我可以设置的最低值D,即"工作精度的位数"?

D = 4给了我许多正确的数字,但是一些数字会被一个数字关闭.例如,计算精度为4的数字393给出了0xafda,我从中提取数字0xa.但是,正确的数字是0xb.

无论我设置多高D,似乎测试足够数量的数字会找到公式返回不正确值的数字.

当数字"接近"另一个时,我已经尝试提高精度,例如0x3fff或0x1000,但是找不到任何好的"关闭"定义; 例如,在数字计算9798给我0X Ç DE6,这是不是很接近0xd000,但正确的数字是0xd中.

任何人都可以帮我弄清楚使用这种算法计算给定数字需要多少工作精度?

谢谢,

编辑
供参考:

precision (D)   first wrong digit
-------------   ------------------
3               27
4               161
5               733
6               4329
7               21139
8+              ???

请注意,我一次计算一位数,例如:


for i in range(1,n):
    D = 3 # or whatever precision I'm testing
    digit = pi(i) # extracts most significant digit from integer-only BBP result
    if( digit != HARDCODED_PI[i] ):
        print("non matching digit #%d, got %x instead of %x" % …
Run Code Online (Sandbox Code Playgroud)

python algorithm math precision pi

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

如何在Mac OS X中实现全局键盘挂钩?

我知道这可以在Windows上完成,XGrabKey也可以在X11上使用,但是Mac OS X呢?我想创建一个类,该类允许设置即使在应用程序窗口处于非活动状态时也可以调用的快捷键。

macos keyboard-hook

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

初始化并将值分配给没有循环的整数列表

有没有更短的方法来做到这一点:

        List<int> mins = new List<int>();
        for(int i = 0; i<60; i++)
        {
            mins.Add(i+1);
        }
Run Code Online (Sandbox Code Playgroud)

功能版本也很受欢迎,如果在c#中可用,也欢迎f#版本.

c# f#

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

在C++中比较结构

所以在C++中很多时候你需要创建一个"索引"类.例如:

class GameID{
   public:
      string name;
      int regionid;
      int gameid;
      bool operator<(const GameID& rhs) const;
}
Run Code Online (Sandbox Code Playgroud)

现在,如果我们将GameID表示为pair<string, pair<int, int> >,那么运算符比较就是它.有没有其他方法来获得自动运算符比较而不必使用std :: pair <>?

c++ comparison class

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

标签 统计

c# ×2

c++ ×2

ruby-on-rails ×2

algorithm ×1

arel ×1

class ×1

comparison ×1

crop ×1

f# ×1

image ×1

keyboard-hook ×1

macos ×1

map ×1

math ×1

pi ×1

precision ×1

python ×1

recursion ×1

ruby ×1

save ×1

scala ×1

solr ×1

split ×1

storyboard ×1

sunspot ×1

wpf ×1

xaml ×1