array_with_three_elements:
- 1
- 2
- 3
empty_array:
Run Code Online (Sandbox Code Playgroud)
有没有办法指定empty_array:是一个没有元素的数组,比如[]
?当我将它加载到ruby哈希时,我希望它知道它是一个数组.
谢谢
使用rails3 - 我有一个包含许多任务的项目.我想使用javascript为每个任务构建UI.我想我可以在项目展示页面上显示这些任务,方法是为每个任务渲染一个javascript.我无法获得'tasks/show'来查看任务/ show.js.erb任何想法?
在projects/show.html.erb中
<div id="tasks">
<%= render(:partial => "tasks/show", :collection => @project.tasks) %>
</div>
Run Code Online (Sandbox Code Playgroud)
任务/ show.js.erb
$("tasks").append(new TaskWidget(task.id))
Run Code Online (Sandbox Code Playgroud)
我得到了错误
ActionView::MissingTemplate in Projects#show
Missing partial tasks/show with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths .... around line #13
Run Code Online (Sandbox Code Playgroud)
谢谢
假设我在/path/to/my_script.csh中放了一个可执行的tcsh文件
我当前的目录是任何地方,例如我在/ path
所以我输入/ my_script.csh
我想在my_script.csh中有一行返回"/path/to/my_script.csh" - 就像ruby的
__FILE__
Run Code Online (Sandbox Code Playgroud) 我正在尝试在Flexbox容器中放置一个高图.图表随着容器的增长而增长,但是当容器收缩时它不会收缩.
我的项目使用angularJS和highcharts-ng,虽然我猜测问题在于flexbox本身.至少在Chrome和IE中也是如此.
这是一个说明问题的傻瓜.如果打开嵌入式视图,您会注意到当窗口变宽时,两个图表都会重新调整以适应.但是当你做得更窄时,顶部图表(在弹性箱中)保持不变.
我放入了reflow按钮来广播highcharts-ng的reflow事件,但它似乎没有效果.
我正在寻找一种解决方法或任何仍然允许我使用flexbox的解决方案.
以下是Plunkr的代码.它基于highcharts-ng的作者的另一个插件,解决了引导容器的类似问题.
的index.html
<!DOCTYPE html>
<html ng-app="highChartTest">
<head>
<link data-require="bootstrap@3.3.2" data-semver="3.3.2" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
</head>
<body ng-controller="MyHighChart as c">
<div class="page-container">
<div class="side-panel">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li><button ng-click="onReflowButtonPressed()" class="autocompare">Reflow</button></li>
</ul>
</div>
<div class="main-panel">
<highchart id="highchart01" config="c.config" height="300"></highchart>
</div>
</div>
<highchart id="highchart02" config="c.config" height="300"></highchart>
<script data-require="jquery@2.1.3" data-semver="2.1.3" src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<script data-require="angular.js@1.3.15" data-semver="1.3.15" src="https://code.angularjs.org/1.3.15/angular.js"></script>
<script data-require="ui-bootstrap-tpls-0.12.0.min.js@*" data-semver="0.12.0" src="https://rawgit.com/angular-ui/bootstrap/gh-pages/ui-bootstrap-tpls-0.12.0.min.js"></script>
<script data-require="highcharts@4.0.1" data-semver="4.0.1" src="//cdnjs.cloudflare.com/ajax/libs/highcharts/4.0.1/highcharts.js"></script>
<script data-require="highcharts-ng@0.0.9" data-semver="0.0.9" src="https://rawgit.com/pablojim/highcharts-ng/master/dist/highcharts-ng.min.js"></script>
<script src="app.js"></script>
</body>
</html> …
Run Code Online (Sandbox Code Playgroud) 我理解修饰符### %%%,但我无法弄清楚它是否可以在tcsh中将它们链接在一起.
tcsh中的示例
set f = /foo/bar/myfile.0076.jpg
echo $f:r:e
--> 0076
echo $f:h:t
--> bar
Run Code Online (Sandbox Code Playgroud)
在bash中,我想知道如何做以下事情:
echo ${f%.*#*.}
Run Code Online (Sandbox Code Playgroud)
在一条线上.
我的目标是能够在命令行上根据需要以各种方式操作文件名.我不是要为一个特定的案例编写脚本.因此,如果有一种方法可以链接这些修饰符,或者可能有另一种方式,那么我很想知道.谢谢
这个问题与此类似,但我需要转置矩形数组,而不是代表正方形的数组.
因此,给定宽度:x和高度:y,我的数组有x*y个元素.
如果宽度为4,高度为3,我有:
{0,1,2,3,4,5,6,7,8,9,10,11}
Run Code Online (Sandbox Code Playgroud)
代表矩阵:
0 1 2 3
4 5 6 7
8 9 10 11
Run Code Online (Sandbox Code Playgroud)
我想要:
{0,4,8,1,5,9,2,6,10,3,7,11}
Run Code Online (Sandbox Code Playgroud)
我知道如何通过制作一个新的数组来实现它,但我想知道如何就像前面提到的问题的解决方案一样.
我为我的流星应用程序编写了一些测试.由于他们有设置和拆卸方法删除所有文档或填充新文档,我想在专用于测试的数据库上运行它们.
我注意到db存储在.meteor/local/db中.理想情况下,我希望从不同的端口访问db_test和db_dev.
这可能吗?
在下面的代码中,我希望在编译时THE_VERSION_STRING
从环境变量的值中获取值MY_VERSION
namespace myPluginStrings {
const char* pluginVendor = "me";
const char* pluginRequires = THE_VERSION_STRING;
};
Run Code Online (Sandbox Code Playgroud)
如果我键入:
export MY_VERSION="2010.4"
Run Code Online (Sandbox Code Playgroud)
pluginRequires
将被设置为"2010.4",即使MY_VERSION
在运行时设置为其他内容.
更新:( 2月21日)感谢大家的帮助.有用.由于我使用Rake作为构建系统,我的每个CFLAGS都是一个ruby变量.值也需要以引号结束.因此我的gcc命令行需要如下所示:
gcc file.c -o file -D"PLUGIN_VERSION=\"6.5\""
Run Code Online (Sandbox Code Playgroud)
这意味着这是在我的Rakefile中:
"-D\"PLUGIN_VERSION=\\\"#{ENV['MY_VERSION']}\\\"\""
Run Code Online (Sandbox Code Playgroud) 这个问题从这里开始.但随着我对托尔的了解越来越多,这一情
我正在尝试创建一个带有参数的Thor :: Group子命令.奇怪的是,如果没有参数,它就有效.
我可以使用Thor :: Group作为子命令吗?
当我键入时,这有效: foo counter
富/斌/富
module Foo
class CLI < Thor
register(Counter, 'counter', 'counter', 'Count up from the 1.')
end
class Counter < Thor::Group
desc "Prints 1 2"
def one
puts 1
end
def two
puts 2
end
end
end
Foo::CLI.start
Run Code Online (Sandbox Code Playgroud)
但是当我键入时,这不起作用: foo counter 5
module Foo
class CLI < Thor
register(Counter, 'counter', 'counter <number>', 'Count up from the input.')
end
class Counter < Thor::Group
argument :number, :type => :numeric, :desc => …
Run Code Online (Sandbox Code Playgroud) 我想在IRB中浏览文件系统并进行快速更改以反映当前的工作目录,但我无法弄清楚如何在每个命令后进行提示更新.最终我想在日常工作中使用IRB更多,让bash溜走.我在我的.irbrc中试过这个:
require 'fileutils'
include FileUtils
IRB.conf[:PROMPT][:CUSTOM] = {
:PROMPT_N => "\e[1m:\e[m ",
:PROMPT_I => "\e[1m#{pwd} >\e[m ",
:PROMPT_S => "FOO",
:PROMPT_C => "\e[1m#{pwd} >\e[m ",
:RETURN => ""
}
IRB.conf[:PROMPT_MODE] = :CUSTOM
Run Code Online (Sandbox Code Playgroud)
但是IRB提示没有更新:
julianmann@mango:~ > irb
/users/julianmann > puts pwd
/users/julianmann
/users/julianmann > cd 'dev'
/users/julianmann > puts pwd
/users/julianmann/dev
/users/julianmann >
Run Code Online (Sandbox Code Playgroud)
我真的很喜欢改变的提示.
要设置阶段,我使用rails 3,我有这些表和关系:
user has_many lists
list has_many tasks
task has_many stints
Run Code Online (Sandbox Code Playgroud)
我想构建一个查询,允许我选择所有当前用户stints,并使list.id可用作结果中每个stint的属性.我需要将list.id重命名为list_id,否则它会覆盖结果中stint的id属性.我认为"as"会起作用,但事实并非如此.
这给了我属于用户1的最后一个限制:
Stint.joins(:task => [{:list => :user }]).where(:lists => {:user_id => 1 }).last
=> #<Stint id: 753, task_id: 245>
Run Code Online (Sandbox Code Playgroud)
但我想要的是:
=> #<Stint id: 753, task_id: 245, list_id: 2>
Run Code Online (Sandbox Code Playgroud)
所以我认为这样可行:
Stint.joins(:task => [{:list => :user }]).where(:lists => {:user_id => 1 }).select('stints.*, lists.id as list_id').last
=> #<Stint id: 753, task_id: 245>
Run Code Online (Sandbox Code Playgroud)
如你所见,没有区别.但如果我不使用"as",我会得到:
Stint.joins(:task => [{:list => :user }]).where(:lists => {:user_id => 1 }).select('stints.*, lists.id').last
=> #<Stint id: 2, task_id: 245>
Run Code Online (Sandbox Code Playgroud)
使用了list.id,但由于该属性设置为名称"id",因此它隐藏了stint.id. …
在我的gem中,我想要一个带有args的可执行命令,如下所示:
foo generate project
foo generate config
foo say_hi
Run Code Online (Sandbox Code Playgroud)
所以我做了
富/斌/富
#!/usr/bin/env ruby
require 'foo'
Foo::Foo.start
Run Code Online (Sandbox Code Playgroud)
和Foo文件在foo/lib/thor/foo.rb中
module Foo
class Foo < Thor
desc "generate [WHAT]"
def generate(*args)
end
desc "say_hi"
def say_hi(*args)
....
end
end
end
Run Code Online (Sandbox Code Playgroud)
和foo/lib/thor/generators/project.rb 和foo/lib/thor/generators/config.rb
我想在哪里指定继承自Thor :: Group的类,如katz示例...
module Foo
module Generators
class Project < Thor::Group
include Thor::Actions
....
end
end
end
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:我如何设置,以便我可以从可执行文件调用这些生成器,如:
foo generate config
Run Code Online (Sandbox Code Playgroud)
我是否在正确的轨道上?理想情况下,单独打字foo
应该say_hi
为所有生成器提供帮助.
ruby ×4
arrays ×2
gem ×2
thor ×2
activerecord ×1
algorithm ×1
angularjs ×1
bash ×1
c++ ×1
chain ×1
css ×1
directory ×1
flexbox ×1
generator ×1
highcharts ×1
irb ×1
javascript ×1
join ×1
meteor ×1
modifier ×1
mongodb ×1
partial ×1
path ×1
prompt ×1
shell ×1
sql ×1
substitution ×1
tcsh ×1
tdd ×1
transpose ×1
yaml ×1