灯角

文章 0 评论 0 浏览 23

灯角 2024-12-06 07:32:13

这段代码看起来不错并且可以在我的机器上运行。可能是其他地方有问题。您确定您的文件小于 100k 吗?

This code looks fine and works on my machine. It's probably problem somewhere else. Are you sure your file is smaller than 100k ?

php: jpeg 文件上传失败

灯角 2024-12-06 05:48:24

那里有很多插件,例如 PPrice 链接到的插件。我同意其他人的观点,这将是更好的方法,除非他们由于某种原因不能满足您的需求。

如果您想让这段代码工作或者您只是为了学习而这样做,也许这就是您想要做的?

您可以将鼠标悬停在“星星”(框)上以查看颜色变化。

http://jsfiddle.net/pW3Sn/

$('#stars > div').mouseover(function() {
        $(this).prevAll().andSelf().attr('class', 'on');  
        $(this).nextAll().attr('class', 'off');  
});

There's a lot of plugins out there, such as the one PPrice links to. I agree with others that that would be the better way to go unless they don't meet your needs for some reason.

If you want to make this code work or if you're just doing this for the learning, maybe this is what you're trying to do?

You can hover over the "stars" (boxes) to see the colour change.

http://jsfiddle.net/pW3Sn/

$('#stars > div').mouseover(function() {
        $(this).prevAll().andSelf().attr('class', 'on');  
        $(this).nextAll().attr('class', 'off');  
});

jQuery 评级系统

灯角 2024-12-06 04:19:38

就像 Maurício Linhares 在他的评论中所写的那样,解决方案是按电影检查演员模型和分组。

问题是 Sunspot 不支持 Solr 3.3 或 4.0,这是唯一支持分组的 Solr 版本。

这是我使用 Sunspot 1.2.1 和 Solr 3.3 的解决方案。

在我的示例中,movie_id 放置在 actor 表中,这在我的实际应用程序中并未完成。

# == Schema Information
#
# Table name: actors
#
#  id              :integer(4)      not null, primary key
#  name            :string(255)
#  created_at      :datetime
#  updated_at      :datetime
#  movie_id        :integer(4)
#

class Actor < ActiveRecord::Base
  searchable do

    # We need to store the movie_id as an string
    # So it can be sorted. We also need to pass the
    # stored: true params
    string :movie_id, stored: true do
      movie_id.to_s
    end
  end

  def search_using_solr
    scoped = Sunspot.new_search(Actor)

    scoped.build do      
      adjust_solr_params do |params|
        params[:group]          = true
        params[:"group.field"]  = "movie_id_s"
        params[:"group.format"] = "simple"
      end
    end

    # Sunspot 1.2.1 doesn't support grouping, so we need to do some hacking.
    def scoped.hits
      @hits ||= @solr_result["grouped"].values.first["doclist"]["docs"].map do |doc|
        Sunspot::Search::Hit.new(doc, nil, self)
      end
    end

    def scoped.total
      @total ||= @solr_result["grouped"]["movie_id_s"]["matches"] || 0
    end

    # Here we'll only fetch the stored data from Solr it self, 
    # and then pass it manualy to ActiveRecord.
    Movie.where({
      id: scoped.execute.hits.map{ |h| h.stored(:movie_id) }
    })
  end
end

归功于 alindeman 为他的 示例要点

The solution, just like Maurício Linhares wrote in his comment, is to go through the actors model and group by movies.

The problem is that Sunspot doesn't support Solr 3.3 or 4.0, which is the only Solr versions that support grouping.

Here is my solution using Sunspot 1.2.1 and Solr 3.3.

In my example movie_id is placed in the actors table, this isn't done in my real application.

# == Schema Information
#
# Table name: actors
#
#  id              :integer(4)      not null, primary key
#  name            :string(255)
#  created_at      :datetime
#  updated_at      :datetime
#  movie_id        :integer(4)
#

class Actor < ActiveRecord::Base
  searchable do

    # We need to store the movie_id as an string
    # So it can be sorted. We also need to pass the
    # stored: true params
    string :movie_id, stored: true do
      movie_id.to_s
    end
  end

  def search_using_solr
    scoped = Sunspot.new_search(Actor)

    scoped.build do      
      adjust_solr_params do |params|
        params[:group]          = true
        params[:"group.field"]  = "movie_id_s"
        params[:"group.format"] = "simple"
      end
    end

    # Sunspot 1.2.1 doesn't support grouping, so we need to do some hacking.
    def scoped.hits
      @hits ||= @solr_result["grouped"].values.first["doclist"]["docs"].map do |doc|
        Sunspot::Search::Hit.new(doc, nil, self)
      end
    end

    def scoped.total
      @total ||= @solr_result["grouped"]["movie_id_s"]["matches"] || 0
    end

    # Here we'll only fetch the stored data from Solr it self, 
    # and then pass it manualy to ActiveRecord.
    Movie.where({
      id: scoped.execute.hits.map{ |h| h.stored(:movie_id) }
    })
  end
end

Cred to alindeman for his example gist.

使用 Sunspot/Solr 进行组?

灯角 2024-12-06 00:06:14

也许你只需要这个:

<?php file_get_contents('http://webtoconnect.com'); ?>

我不确定你真正需要什么:D

maybe you just need this:

<?php file_get_contents('http://webtoconnect.com'); ?>

I'm not sure what you realy need :D

require_once 连接到其他网站

灯角 2024-12-05 22:07:50

我认为您只想覆盖 OnLoad方法:

public class Parent
{
    public Parent()
    {
       InitializeComponent();
    }

    protected override void OnLoad(EventArgs e)
    {
        // put initialization code here

        base.OnLoad(e);
    }
}

父子组件初始化时调用。
不要忘记调用 base.OnLoad 以便 Load 事件处理程序(如果有)接收该事件。

I think you just want to override OnLoad method:

public class Parent
{
    public Parent()
    {
       InitializeComponent();
    }

    protected override void OnLoad(EventArgs e)
    {
        // put initialization code here

        base.OnLoad(e);
    }
}

It is called when both parent and child components are initialized.
Don't forget to call base.OnLoad so that Load event handlers, if any, receive the event.

在子构造函数的 InitializeComponent 完成后运行方法,而不在子类中隐式调用

灯角 2024-12-05 13:38:39

您需要选择您需要的特定列

Art.select(:user_id).group(:user_id).limit(10)

当您尝试在查询中选择标题时,它会引发错误,例如

Art.select(:user_id, :title).group(:user_id).limit(10)

列“arts.title”必须出现在 GROUP BY 子句中或在聚合函数中使用

这是因为当您尝试分组时user_id,查询不知道如何处理组中的标题,因为该组包含多个标题。

所以例外已经提到你需要出现在分组依据中

Art.select(:user_id, :title).group(:user_id, :title).limit(10)

或在聚合函数中使用

Art.select("user_id, array_agg(title) 作为标题").group(:user_id).limit(10)

You need to select the specific columns you need

Art.select(:user_id).group(:user_id).limit(10)

It will raise error when you try to select title in the query, for example

Art.select(:user_id, :title).group(:user_id).limit(10)

column "arts.title" must appear in the GROUP BY clause or be used in an aggregate function

That is because when you try to group by user_id, the query has no idea how to handle the title in the group, because the group contains several titles.

so the exception already mention you need to appear in group by

Art.select(:user_id, :title).group(:user_id, :title).limit(10)

or be used in an aggregate function

Art.select("user_id, array_agg(title) as titles").group(:user_id).limit(10)

Rails 3.1 与 PostgreSQL:GROUP BY 必须在聚合函数中使用

灯角 2024-12-05 13:37:47

您需要 datetime,尤其是 timedelta http://docs.python.org/library/datetime.html

例如:(

import time
from datetime import datetime, timedelta
import random

MAX_DURATION = timedelta(seconds=60)
start = datetime.now()
while 1:
    time.sleep(random.random())
    now = datetime.now()
    if now - start > MAX_DURATION:
        break

当然,在这个非常简单的情况下,最好简单地使用 time.time() (它返回一个 时间戳),然后将其与秒数进行比较(例如,time.time() - start > MAX_SECONDS)…但这就是你以“完全通用”的方式做到这一点)

You'll want datetime and especially timedelta: http://docs.python.org/library/datetime.html

For example:

import time
from datetime import datetime, timedelta
import random

MAX_DURATION = timedelta(seconds=60)
start = datetime.now()
while 1:
    time.sleep(random.random())
    now = datetime.now()
    if now - start > MAX_DURATION:
        break

(of course, in this very simple case it might be better to simply use time.time() (which returns a timestamp), then compare that with a number of seconds (ex, time.time() - start > MAX_SECONDS)… But this is how you'd do it in a “fully general” way)

检查时间以确保我在循环中不会超过设置的最大持续时间? (Python)

灯角 2024-12-05 08:08:17

使用 加载数据文件 。 CSV 文档中的示例是:

LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name
  FIELDS TERMINATED BY ',' ENCLOSED BY '"'
  LINES TERMINATED BY '\r\n'
  IGNORE 1 LINES;

如果 CSV 数据中没有标题行,则应删除 IGNORE 1 LINES 子句。

另请注意,文件中数据的顺序应与表中列的顺序匹配。如果没有,您将需要像这样指定顺序:

LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name
  (column1, column2, ...)
  FIELDS TERMINATED BY ',' ENCLOSED BY '"'
  LINES TERMINATED BY '\r\n'
  IGNORE 1 LINES;

Using LOAD DATA INFILE. The example in the docs for CSV is:

LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name
  FIELDS TERMINATED BY ',' ENCLOSED BY '"'
  LINES TERMINATED BY '\r\n'
  IGNORE 1 LINES;

You should remove the IGNORE 1 LINES clause if there is no header row in the CSV data.

Also, note that the order of the data in the file should match the order of the columns in the table. If they do not, you will need to specify the order like this:

LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name
  (column1, column2, ...)
  FIELDS TERMINATED BY ',' ENCLOSED BY '"'
  LINES TERMINATED BY '\r\n'
  IGNORE 1 LINES;

如何将 .csv 数据转换为 mysql?

灯角 2024-12-05 06:16:09

是的。使用 stats=true&stats.field=price

Yes.Use stats=true&stats.field=price

Solr 在 stats.field 上排除?

灯角 2024-12-04 19:43:04

您可以将选项卡选择索引设置为所需的选项卡索引,它从 0 开始

您可以编写类似 tabbarcontroller.tabbar.selectedindex =1; 的内容;

原谅语法错误...你应该尝试这个。 xCode 是丰富的编辑器。

you can set tabbar selected index to your desired tab index it starts from 0

you can write something like tabbarcontroller.tabbar.selectedindex =1;

Forgive syntax errors... you should try this. xCode is rich editor.

如何制作选项卡栏,使得选项卡栏的第一个选项卡不应保持选中状态

灯角 2024-12-04 19:12:16

请参阅 Daniel Kocherga 的答案,因为它在大多数情况下都适合您。

除了获取属性值的方法之外,您有时可能还需要获取selectmultiselect 的标签。在这种情况下,我创建了这个方法,并将其存储在辅助类中:

/**
 * @param int $entityId
 * @param int|string|array $attribute atrribute's ids or codes
 * @param null|int|Mage_Core_Model_Store $store
 *
 * @return bool|null|string
 * @throws Mage_Core_Exception
 */
public function getAttributeRawLabel($entityId, $attribute, $store=null) {
    if (!$store) {
        $store = Mage::app()->getStore();
    }

    $value = (string)Mage::getResourceModel('catalog/product')->getAttributeRawValue($entityId, $attribute, $store);
    if (!empty($value)) {
        return Mage::getModel('catalog/product')->getResource()->getAttribute($attribute)->getSource()->getOptionText($value);
    }

    return null;
}

Please see Daniel Kocherga's answer, as it'll work for you in most cases.

In addition to that method to get the attribute's value, you may sometimes want to get the label of a select or multiselect. In that case, I have created this method which I store in a helper class:

/**
 * @param int $entityId
 * @param int|string|array $attribute atrribute's ids or codes
 * @param null|int|Mage_Core_Model_Store $store
 *
 * @return bool|null|string
 * @throws Mage_Core_Exception
 */
public function getAttributeRawLabel($entityId, $attribute, $store=null) {
    if (!$store) {
        $store = Mage::app()->getStore();
    }

    $value = (string)Mage::getResourceModel('catalog/product')->getAttributeRawValue($entityId, $attribute, $store);
    if (!empty($value)) {
        return Mage::getModel('catalog/product')->getResource()->getAttribute($attribute)->getSource()->getOptionText($value);
    }

    return null;
}

Magento 产品属性获取值

灯角 2024-12-04 17:39:57

我想尝试基于 osgx 使用 scanf 的建议:

freopen("testcases.in", "r", stdin);
while( count < total_values)
       {
         scanf("%f,",&values[count]);
         count++;
       }

I wanted to try something based on osgx's suggestion of using scanf:

freopen("testcases.in", "r", stdin);
while( count < total_values)
       {
         scanf("%f,",&values[count]);
         count++;
       }

提高读取文件时的空间复杂度

灯角 2024-12-04 14:23:33

更好的编码方法是始终初始化数组,而不是简单地迭代列表进行空检查,在空的情况下,列表不会执行任何操作,因为它是空的(不是空的)。

public class MyPost {
    private int id;
    private List<Label> labels = new ArrayList<Label>;
    public MyPost(int id){ this.id = id }

    //getter setters for both plus this added method:
    public void addLabel(Label aLabel) {
        labels.add(aLabel);
    }
}

// then later...
public void someProcessing() {
    for (Label label: labels) {
        // process label here
    }
}

现在您不再有 NPE,并且您不必拥有看起来令人讨厌的空检查代码,您只需依赖于空列表不会迭代的事实。

或者(正如我在评论中所说),如果您必须延迟实例化 List,请执行此操作,但始终返回一个可以迭代的有效 List 对象,方法是将 getLabels() 更改为

public List<Label> getLabels() {
    return labels == null ? Collections.emptyList() : labels
}

这意味着没有调用 getLabels() 的方法当需要检查空对象时,他们可以简单地迭代返回的对象,这大概就是您最终将对列表执行的操作。这确实提高了代码的可靠性和可读性。我必须审查很多具有这种腰带和护腕方法的代码,在访问对象之前始终检查空值,这可以通过确保返回的对象按照其名称而不是可能为空来清理。

编辑:在OP更新有关实际使用的 if 语句的帖子后删除有关 getLabels() 的部分,并添加有关使列表充当列表的注释。

A better way to code it would be to always initialise the array, and instead of null checking simply iterate over the list, which in the empty case would do nothing because it's empty (not null).

public class MyPost {
    private int id;
    private List<Label> labels = new ArrayList<Label>;
    public MyPost(int id){ this.id = id }

    //getter setters for both plus this added method:
    public void addLabel(Label aLabel) {
        labels.add(aLabel);
    }
}

// then later...
public void someProcessing() {
    for (Label label: labels) {
        // process label here
    }
}

Now you no longer have a NPE, and you're not having to have nasty looking null checking code, you simply rely on the fact an empty list won't iterate.

Alternatively (as I say in my comments) if you have to lazy instantiate the List, do that but always return a valid List object that can be iterated over, by changing the getLabels() to

public List<Label> getLabels() {
    return labels == null ? Collections.emptyList() : labels
}

This means that no method that calls getLabels() ever need check for a null object, they can simply iterate over the returned object, which is presumably what you'll end up doing to the list eventually. This really does improve code reliability, and readability. I have to review a lot of code that has this belt and bracers approach of always checking for nulls before accessing objects, which could all be cleaned up by ensuring the returned object acts as its name sake instead of potentially being null.

EDIT: remove the section about the getLabels() after OP updated post about the actual if statement used, and added the comments about making the List act as a List.

执行空检查而不引发 NullPointerException 的最佳方法是什么?

灯角 2024-12-04 14:14:26

类方法在类上下文中执行,line是实例方法,您不能直接从self.output访问它。

您真的想从类方法访问实例属性吗?也许您需要的是类属性。如果是这样,您可以像这样声明它:

class Run
  class << self
    attr_accessor :line
  end
end

,并且能够在类方法中获取它的值。

如果您确实需要从类方法访问实例属性 - 将该实例作为参数传递给方法并调用它的访问器。

Class method is executed in class context and line is instance method, you can't directly access it from self.output.

Do you really want to access instance attribute from class method? Maybe what you need is class attribute. If so, you can declare it like this:

class Run
  class << self
    attr_accessor :line
  end
end

, and will be able to get it's value within class method.

If you do need to access instance attribute from class method — pass that instance as argument to method and call accessor on it.

在类方法中获取属性的值

灯角 2024-12-04 08:22:28

当使用 TestSuite 时,您一次向套件添加一个测试用例,您的语法应该看起来更像这样:

suite.addTest(new VolumeCompare("testCase1"));
suite.addTest(new VolumeCompare("testCase2"));
suite.addTest(new VolumeCompare("testCase3"));

基本上您没有传递要运行的测试的名称,因此它尝试运行“null”并失败。

When using a TestSuite you add test cases to your suite one testcase at a time, your syntax should look more like this:

suite.addTest(new VolumeCompare("testCase1"));
suite.addTest(new VolumeCompare("testCase2"));
suite.addTest(new VolumeCompare("testCase3"));

Basically you aren't passing the name of a test to run and so it tries to run "null" and fails.

Ant、JUnit 和 TestSuite

更多

推荐作者

苍风燃霜

文章 0 评论 0

悸初

文章 0 评论 0

撧情箌佬

文章 0 评论 0

森罗

文章 0 评论 0

lyn1245

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文