尝试入门的完整铁轨新手.
我有两个课程,成分和单元.有三个单位,磅,加仑和几十个,每个成分只有一个单位.我想我已正确设置了关联/路由.在创建新配料时,我需要用户从这三个设置单位.我用另一个问题来解决这个问题:Drop Down Box - 填充表单中另一个表的数据 - Ruby on Rails
成分模型:
class Ingredient < ActiveRecord::Base
belongs_to :unit
end
Run Code Online (Sandbox Code Playgroud)
单位模型:
class Unit < ActiveRecord::Base
end
Run Code Online (Sandbox Code Playgroud)
路线:
map.resources :ingredients, :has_many => :unit_conversions
map.resources :units, :has_many => :ingredients
Run Code Online (Sandbox Code Playgroud)
配料新控制器
def new
@ingredient = Ingredient.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @ingredient }
end
end
Run Code Online (Sandbox Code Playgroud)
成分新视图:
<h1>New ingredient</h1>
<% form_for(@ingredient) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p> …Run Code Online (Sandbox Code Playgroud) 我有一个小问题.当从objective-c函数传递给c函数时,我有一个数组并且它的大小发生了变化.
void test(game_touch *tempTouches)
{
printf("sizeof(array): %d", sizeof(tempTouches) );
}
-(void)touchesEnded: (NSSet *)touches withEvent: (UIEvent *)event
{
game_touch tempTouches[ [touches count] ];
int i = 0;
for (UITouch *touch in touches)
{
tempTouches[i].tapCount = [touch tapCount];
tempTouches[i].touchLocation[0] = (GLfloat)[touch locationInView: self].x;
tempTouches[i].touchLocation[1] = (GLfloat)[touch locationInView: self].y;
i++;
}
printf("sizeof(array): %d", sizeof(tempTouches) );
test(tempTouches);
}
Run Code Online (Sandbox Code Playgroud)
控制台日志是:
[touchesEnded] sizeof(array): 12
[test] sizeof(array): 4
Run Code Online (Sandbox Code Playgroud)
为什么两种方法的大小不同?
在[test]方法中,返回大小始终为4,而不依赖于数组的原始大小.
谢谢.
我网站上的用户为说唱歌词创建注释(示例).我想创建一个排行榜,以奖励创建最多注释的人.
排行榜应该跟踪每个用户整体创建的注释数量,以及他在过去一周,一天中创建的数量等.
我实现整个排行榜没有问题:
@users = User.all
<table>
<tr>
<th>Contributor</th>
<th>Annotations</th>
</tr>
<% @users.sort_by{|u| u.annotations.size }.reverse.each do |u| %>
<tr>
<td><%= u %></td>
<td><%= u.annotations.size %></td>
</tr>
<% end %>
</table>
Run Code Online (Sandbox Code Playgroud)
但是当我尝试实现(比如说)每日记分牌时,我正在重复代码并且操作非常缓慢(因为它必须遍历内存中的每个注释而不是依赖于数据库排序/计数):
<table>
<tr>
<th>Contributor</th>
<th>Annotations</th>
</tr>
<% @users.sort_by{|u| u.annotations.select{|a| a.created_at > 1.day.ago }.size }.reverse.each do |u| %>
<tr>
<td><%= u %></td>
<td><%= u.annotations.select{|a| a.created_at > 1.day.ago }.size %></td>
</tr>
<% end %>
</table>
Run Code Online (Sandbox Code Playgroud)
实施每日/每周记分牌的最佳方法是什么?
这里有一点背景:
我知道数据仓库是什么,或多或少.我已经阅读了数十个关于数据仓库的指南,我玩过SSAS,我知道什么是星型模式,维度表和事实表,我知道ETL是什么以及如何做. 这不是"如何"问题或教程请求.
我的问题是,我读过的关于数据仓库的所有材料似乎都掩盖了构建数据仓库的基本原理.它们都具有象征性,或者在某些情况下字面上以" 所以你决定建立一个数据仓库...... " 这句话开头.除了我还没有做出那个决定.
因此,我希望SO成员可以指出或帮助提出某种半客观测试.我可以适应特定系统并最终得到"是的,我们需要一个数据仓库"或"不,今天的收益太小了".我认为我应该能够回答的具体问题是:
在什么时候构建数据仓库是一个值得考虑的选择?换句话说,我应该注意哪些标志,指标或其他标准可能表明标准的交易环境不再足够?
全面数据仓库有哪些替代方案?事务数据库中的非规范化和沼泽标准复制的"报告服务器"是我想到的两个; 在进入DW之前,还有其他我应该探索的吗?
为什么数据仓库比上述备选方案更好?如果答案是"它取决于",那么它依赖于什么?
什么时候不应该尝试构建数据仓库?无论背景如何,我都对所谓的"最佳实践"持怀疑态度.肯定有一些情况下DW是错误的选择 - 它们是什么?
是否有任何实际的例子我可以看一下通过引入数据仓库而改进的系统?可以向我解释的东西,端到端,他们需要仓库的决策或分析,他们如何决定放入什么,以及仓库最终如何适应更大的环境?我不想要一个人为的"让我们从AdventureWorks数据库中创建一个多维数据集" - 实现与我无关,我对所涉及的规范和设计以及整体思考过程感兴趣.
我一般不会问多方,但我认为这些都是非常密切相关的.我愿意接受至少解决前4个问题的任何答案,尽管最后一个问题确实有助于在我的脑海中明白这一点.如果有人已经写过关于这一点的链接很好,只要它们相当简洁和具体(链接到Ralph Kimball的主页=无用).
希望我已经明确了问题 - 提前感谢你的答案!
我有一个大约24MB的repo,但项目中的文件实际上只有2MB左右.我的印象是,使用--depth 1的浅层克隆几乎可以让我接近2MB的实际文件(没有整个回购).
当我做浅层克隆时,新的repo只显示当前分支但是大小相同(24MB)并且用gitx查看repo我可以看到整个历史记录回到初始提交.
我想要一种方法来获取文件的当前状态(用于上传到服务器)而没有所有历史记录.我做错了什么或只是误解了浅层克隆的目的?
每当我在eclipse中运行我的应用程序时,它就会开始构建,然后运行。由于我要进行数千个课程,因此每次构建都花费太多时间。我能知道原因吗,我该怎么做才能避免它?
我在项目中编写了自定义模型绑定器,它使用ASP.NET MVC 2.此模型绑定器仅绑定2个模型字段:
public class TaskFormBinder : DefaultModelBinder
{
protected override void BindProperty(ControllerContext controllerContext,
ModelBindingContext bindingContext,
PropertyDescriptor propertyDescriptor)
{
if (propertyDescriptor.Name == "Type")
{
var value = bindingContext.ValueProvider.GetValue("Type");
var typeId = value.ConvertTo(typeof(int));
TaskType foundedType;
using (var nhSession = Domain.GetSession())
{
foundedType = nhSession.Get<TaskType>(typeId);
}
if (foundedType != null)
{
SetProperty(controllerContext, bindingContext, propertyDescriptor, foundedType);
}
else
{
AddModelBindError(bindingContext, propertyDescriptor);
}
return;
}
if (propertyDescriptor.Name == "Priority")
{ /* Other field binding ... */
return;
}
base.BindProperty(controllerContext, bindingContext, propertyDescriptor);
}
}
Run Code Online (Sandbox Code Playgroud)
如何使用标准VS单元测试来测试此模型绑定器?花了几个小时谷歌搜索,找到几个例子( …
我正在尝试用Java计算逆矩阵.
我正在遵循伴随方法(首先计算伴随矩阵,然后转置这个矩阵,最后,将它乘以行列式值的倒数).
它在矩阵不太大时起作用.我已经检查过,对于尺寸为12x12的矩阵,可以快速得到结果.但是,当矩阵大于12x12时,完成计算所需的时间呈指数增长.
我需要反转的矩阵是19x19,需要花费太多时间.更多时间消耗的方法是用于计算行列式的方法.
我正在使用的代码是:
public static double determinant(double[][] input) {
int rows = nRows(input); //number of rows in the matrix
int columns = nColumns(input); //number of columns in the matrix
double determinant = 0;
if ((rows== 1) && (columns == 1)) return input[0][0];
int sign = 1;
for (int column = 0; column < columns; column++) {
double[][] submatrix = getSubmatrix(input, rows, columns,column);
determinant = determinant + sign*input[0][column]*determinant(submatrix);
sign*=-1;
}
return determinant;
}
Run Code Online (Sandbox Code Playgroud)
有人知道如何更有效地计算大矩阵的行列式吗?如果没有,有没有人知道如何使用其他算法计算大矩阵的逆?
谢谢
我想用Pylab绘制一个混淆矩阵.沿水平轴的类标签很长,所以我想绘制它们垂直旋转.但是,我还想将它们绘制在轴的顶部,而不是下面.
此命令可以在底部绘制垂直标签:
pylab.imshow(confusion_matrix)
pylab.xticks(..., rotation='vertical')
Run Code Online (Sandbox Code Playgroud)
并且此命令可以在顶部绘制水平标签而不旋转:
pylab.matshow(confusion_matrix)
Run Code Online (Sandbox Code Playgroud)
但我找不到两者兼而有之.以下命令不起作用.
pylab.matshow(confusion_matrix)
pylab.xticks(..., rotation='vertical')
Run Code Online (Sandbox Code Playgroud)
你能建议一种方法用垂直旋转在轴顶部用xticks绘制混淆矩阵吗?谢谢.
编辑
马克,谢谢你的帮助.通过更仔细地检查刻度属性,它让我走上正轨.与你的答案和我想要的答案的唯一区别是将这个想法应用于AxesImage,而不是绘图.经过调查,这里是答案:
im = pylab.matshow(confusion_matrix)
for label in im.axes.xaxis.get_ticklabels():
label.set_rotation(90)
im.figure.show()
Run Code Online (Sandbox Code Playgroud)
对于那些阅读...不要忘记show()!我忘了我需要刷新数字.见下面的输出.
我在C#中有一些问题
null比较之间有什么区别null == value和value == null(value是任何类型的变量:int,string,float,...)
我听说在某些情况下使用前缀增量++ i而不是i ++将增强程序性能.为什么会这样?
我有一个代码段如下:
private int _number;
public int Number
{
get { return _number}
set { _number = value}
}
public double Test
{
get
{
if (null == Number)
return 1.1;
else
return 2.2;
}
}
Run Code Online (Sandbox Code Playgroud)问题是为什么我们在这里使用null == Number但不是null == _number或Number == null或_number == null
4. if I have a struct as follow:
public struct Vector
{
public double X;
public double Y;
public Vector(double x, double y)
{
X = x; …Run Code Online (Sandbox Code Playgroud) java ×2
asp.net-mvc ×1
c# ×1
cocoa-touch ×1
comparison ×1
database ×1
determinants ×1
eclipse ×1
git ×1
iphone ×1
leaderboard ×1
matplotlib ×1
matrix ×1
modelbinders ×1
null ×1
objective-c ×1
properties ×1
unit-testing ×1