我有一个使用RGL的3D图.我想用颜色制作相同的图来突出显示某些变量的分布.要做到这一点,我想有相同的情节,我如何找到和设置情节的方向?
一旦我做了一个初步的情节,我移动它找到一个很好的显示角度,我想保存这个角度,并将其纳入未来的绘图脚本.有人建议如何做到这一点?
library(rgl)
plot3d(iris)
#play with the plot to find a good angle
#save the angle for future plots
Run Code Online (Sandbox Code Playgroud) 这两种方法听起来都应该做同样的事情,但它们看起来并不是彼此的别名.in_groups和之间有什么区别in_groups_of?
我刚刚发现文件中reconnect: true可以配置选项database.yml.还有哪些其他可能的配置选项?所有选项都有完整的参考吗?
已知的关键示例:
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: foo
password: bar
reconnect: true
socket: /var/sock/thing.sock
development:
<<: *default
database: app_development
Run Code Online (Sandbox Code Playgroud) 我正在尝试重定向到基于提交表单上的参数的位置.如果params [:route] = group,我想重定向到groups_path.我尝试了以下方法来重定向,但很明显,groups_path是一个变量而不是一个字符串.如何根据参数重定向?
redirect_to "#{params[:route]}s_path"
Run Code Online (Sandbox Code Playgroud)
编辑:意识到我可以重定向到实际路径,但这似乎不是一个非常铁路的方式.
redirect_to "/#{params[:route]}s"
Run Code Online (Sandbox Code Playgroud) 我有两个模型,事件和用户共享多对多关联.用户可以是管理员,经理或制作人.只有属于某个事件的生产者才能读取该事件.我试图在能力模型上应用这种限制,但它失败了,每个制作人都可以阅读所有事件.我究竟做错了什么?
class Event < ActiveRecord::Base
has_and_belongs_to_many :producers, :class_name => "User", :join_table => "events_producers"
end
class CreateEventUserJoinTable < ActiveRecord::Migration
def self.up
create_table :events_producers, :id => false do |t|
t.integer :event_id
t.integer :user_id
end
end
def self.down
drop_table :events_producers
end
end
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new() # Guest user
if user.role? :manager
can :manage, :all
elsif user.role? :admin
can :read, Event
can :update, Event
can :create, Event
elsif user.role? :producer
can :read, Event do |event|
event.try(:producers).include?(user)
end
end …Run Code Online (Sandbox Code Playgroud) 我尝试从底部列出的SO问题中获得解决方案,但我的问题是我使用的是Capybara和FactoryGirl,我似乎无法从任何地方加载seeds.rb而不会导致许多与种子数据完全分开的测试.大多数错误消息是page.should_not have_content user.email
测试后的变化,我尝试删除我通过工厂制作的用户.这些测试在我加载种子数据之前一直很好.
我所拥有的是一个管理员组,分配了管理员权限,seed.rb中的管理员用户链接在一起一种可能性是在我的seeds.rb中调用工厂来填充这些数据,但我还没弄清楚如何.
User.find_or_create_by_email(email: "admin@admin.admin",
password: "admin", password_confirmation: "admin")
%w{admin supermod}.each {|w| Group.find_or_create_by_name(w)}
%w{admin mod player}.each {|w| Permission.find_or_create_by_name(w)}
g = Group.find_by_name("admin")
g.permission_id = Permission.find_by_name("admin").id
puts "failed to add admin permission to admin group" unless g.save
u = User.find_by_email("neonmd@hotmail.co.uk")
ug = UserGroup.new
ug.group_id = Group.find_by_name("admin").id
ug.user_id = u.id
puts "failed to add admin group to #{u.name}" unless u.save && ug.save
Run Code Online (Sandbox Code Playgroud)
这在我加载seeds.rb之前通过
it "lets you remove user from group" do
user = Factory.create(:user) …Run Code Online (Sandbox Code Playgroud) 我说有一系列不确定的长度[1,2,3,4,5].我想减去1之前的所有内容3,然后添加1到后面的所有内容中3,作为示例[0,1,3,5,6].如果没有3,请添加1到所有内容:[1,2,4,5]=> [2,3,5,6].这样做最优雅的方式是什么?
我正在使用带有IdTCPServer的表单来管理来自客户端的字符串和AThread.connection.readln/writeln系统.字符串处理工作,这不是问题.
问题是,服务器上的表单挂起并且不会加载,但它仍然管理连接到它的所有客户端,因此它正在运行但它不能用作表单.我会猜测它坐在阅读线上还是什么东西......但是我不知道如何在这个时刻解决这个问题.
请帮忙.
procedure TMonitorFrm.ServerExecute(AThread: TIdPeerThread);
procedure post(PostMessage:string);
begin
try
AThread.Connection.WriteLn(PostMessage);
except
showmessage('Cannot post');
end;
end;
var
ActClient : PClient;
sTemp,
CommBlock,
NewCommBlock,
ReceiverName,
sContent,
sSQL,
sCommand : String;
iCount2,
iCount : Integer;
sldb : TSQLiteDatabase;
sltb : TSQLiteTable;
begin
if not AThread.Terminated and AThread.Connection.Connected then
begin
CommBlock := AThread.Connection.ReadLn();
ActClient := PClient(AThread.Data);
ActClient.LastAction := Now;
sCommand := copy(CommBlock,0,pos(',',CommBlock)-1); {seperate command}
sContent := copy(CommBlock,pos(',',CommBlock)+1,length(CommBlock)-(pos(',',CommBlock)+1)); {seperate data block}
iCount:= 0 ;
if sCommand = 'Announce' then //SPECIAL
begin
{ Do stuff …Run Code Online (Sandbox Code Playgroud) 用Java绘制最简单的方法是什么?
import java.awt.*;
import javax.swing.*;
public class Canvas
{
private JFrame frame;
private Graphics2D graphic;
private JPanel canvas;
public Canvas()
{
frame = new JFrame("A title");
canvas = new JPanel();
frame.setContentPane(canvas);
frame.pack();
frame.setVisible(true);
}
public void paint(Graphics g){
BufferedImage offImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Grapics2D g2 = offImg.createGraphics();
g2.setColor(new Color(255,0,0));
g2.fillRect(10,10,200,50);
}
}
Run Code Online (Sandbox Code Playgroud)
这不起作用,我不知道如何让任何东西出现.
在我的超类中,我有以下方法:
public int getSpeed(String t)
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在我的子类中,我们用这个方法覆盖了方法:
public int getSpeed(String t)
{
return x;
}
Run Code Online (Sandbox Code Playgroud)
然后我有以下内容:
ArrayList<super> //contains only objects of the subclass
for (super s:collection)
{
s.getSpeed("");
}
Run Code Online (Sandbox Code Playgroud)
这总是返回0.如何让它返回x?
编辑:我的代码几乎完全按照Bala R的解决方案显示,但是我只是对我的X做了一些愚蠢的事情,导致它每次都变为0.因此他的解决方案是正确的
java ×2
ruby ×2
activerecord ×1
arrays ×1
cancan ×1
delphi ×1
factory-bot ×1
inheritance ×1
many-to-many ×1
overriding ×1
paint ×1
r ×1
rgl ×1
routes ×1
swing ×1
tcp ×1
testing ×1