我有以下文件:
/spec/controllers/groups_controller_spec.rb
Run Code Online (Sandbox Code Playgroud)
在终端中使用什么命令来运行该规范以及在哪个目录中运行命令?
我的宝石文件:
# Test ENVIRONMENT GEMS
group :development, :test do
gem "autotest"
gem "rspec-rails", "~> 2.4"
gem "cucumber-rails", ">=0.3.2"
gem "webrat", ">=0.7.2"
gem 'factory_girl_rails'
gem 'email_spec'
end
Run Code Online (Sandbox Code Playgroud)
规格文件:
require 'spec_helper'
describe GroupsController do
include Devise::TestHelpers
describe "GET yourgroups" do
it "should be successful and return 3 items" do
Rails.logger.info 'HAIL MARRY'
get :yourgroups, :format => :json
response.should be_success
body = JSON.parse(response.body)
body.should have(3).items # @user1 has 3 permissions to 3 groups
end
end
end
Run Code Online (Sandbox Code Playgroud) 我目前正试图开始使用Akka,我面临一个奇怪的问题.我的演员有以下代码:
class AkkaWorkerFT extends Actor {
def receive = {
case Work(n, c) if n < 0 => throw new Exception("Negative number")
case Work(n, c) => self reply n.isProbablePrime(c);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我开始工作的方式:
val workers = Vector.fill(nrOfWorkers)(actorOf[AkkaWorkerFT].start());
val router = Routing.loadBalancerActor(SmallestMailboxFirstIterator(workers)).start()
Run Code Online (Sandbox Code Playgroud)
这就是我关闭所有东西的方式:
futures.foreach( _.await )
router ! Broadcast(PoisonPill)
router ! PoisonPill
Run Code Online (Sandbox Code Playgroud)
现在发生的事情是,如果我发送工具消息,其中n> 0(没有抛出异常),一切正常,应用程序正常关闭.但是,只要我发送一条导致异常的消息,应用程序就不会终止,因为仍有一个actor正在运行,但我无法弄清楚它来自哪里.
如果它有帮助,这是有问题的线程的堆栈:
Thread [akka:event-driven:dispatcher:event:handler-6] (Suspended)
Unsafe.park(boolean, long) line: not available [native method]
LockSupport.park(Object) line: 158
AbstractQueuedSynchronizer$ConditionObject.await() line: 1987
LinkedBlockingQueue<E>.take() line: 399
ThreadPoolExecutor.getTask() line: 947
ThreadPoolExecutor$Worker.run() line: 907
MonitorableThread(Thread).run() line: …Run Code Online (Sandbox Code Playgroud) 例如,为什么呢
val list:List[Any] = List[Int](1,2,3)
Run Code Online (Sandbox Code Playgroud)
工作,但是
val arr:Array[Any] = Array[Int](1,2,3)
Run Code Online (Sandbox Code Playgroud)
失败(因为数组是不变的).这个设计决定背后的效果是什么?
我很难让我的AJAX请求在登台服务器上运行.这一切都在我的开发机器上工作正常,但是一上传它,我的所有AJAX请求都停止了工作.我发现,如果我将相对URL(例如"index.php")更改为绝对URL(" http://example.com/index.php "),请求会再次起作用,但我不明白为什么.
示例请求:
jQuery.post('index.php', {id: 1234, action: 1, step: 1}, function(data) { /* something */ });
Run Code Online (Sandbox Code Playgroud)
这不起作用,我甚至没有出现在firebug控制台中.虽然调用了成功处理程序,但这非常令人困惑.
这很好用:
jQuery.post('http://example.com/index.php', {id: 1234, action: 1, step: 1}, function(data) { /* something */ });
Run Code Online (Sandbox Code Playgroud)
任何人都能解释为什么AJAX请求会以这种方式运行吗?X_X
我有一个带有某个字段的数据库表,一旦插入数据库就不可能更新.如何告诉我的模型它不应该允许更新某个字段?
此代码来自Scala工作表:
case class E(a: Int, b: String)
val l = List(
E(1, "One"),
E(1, "Another One"),
E(2, "Two"),
E(2, "Another Two"),
E(3, "Three")
)
l.groupBy(x => x.a)
// res11: scala.collection.immutable.Map[Int,List[com.dci.ScratchPatch.E]] =
// Map(
// 2 -> List(E(2,Two), E(2,Another Two)),
// 1 -> List(E(1,One), E(1,Another One)),
// 3 -> List(E(3,Three))
// )
Run Code Online (Sandbox Code Playgroud)
您会注意到groupBy返回一个映射,但是元素的排序现在与之前的顺序不同.知道为什么会这样,最好的方法是避免这种情况吗?
我正试图从一个组织的私人回购中检索所有问题,但没有太多运气.
我正在使用红宝石宝石"github_api",但我也试过尝试使用curl访问它
到目前为止,我能够检索我所分配的或我订阅的所有问题,但不是所有针对该特定回购的问题.
使用github_api gem(https://github.com/peter-murach/github),我已经走到了这一步
@github.issues.issues(:filter => "subscribed")
Run Code Online (Sandbox Code Playgroud)
仅供参考:我是组织和回购的所有者
看看github api(问题)似乎没有一个过滤器会返回我需要的东西.
这甚至可能吗?
谢谢!
我正在使用带有Go的Sockjs,但是当javascript客户端将json发送到服务器时,它会将其转义,并将其作为[]字节发送.我正在试图找出如何解析json,以便我可以读取数据.但我得到这个错误.
json:无法将字符串解组为main.Msg类型的Go值
我怎样才能解决这个问题?html.UnescapeString()没有效果:/
val, err := session.ReadMessage()
if err != nil {
break
}
var msg Msg
err = json.Unmarshal(val, &msg)
fmt.Printf("%v", val)
fmt.Printf("%v", err)
type Msg struct {
Channel string
Name string
Msg string
}
//Output
"{\"channel\":\"buu\",\"name\":\"john\", \"msg\":\"doe\"}"
json: cannot unmarshal string into Go value of type main.Msg
Run Code Online (Sandbox Code Playgroud) 今天我用javascript遇到了一些非常奇怪的行为.我想我现在已经弄明白了,但我想知道我认为发生的事情是否真的发生了,或者是否还有其他一些魔法.所以这是我的代码:
var SomeObject = {};
SomeObject.foo = function(a, b) {
var baz = this.bar(a, b);
console.log(baz);
console.log(baz.left);
SomeObject.magicalStuff(baz);
};
SomeObject.bar = function(a, b) {
return {left: a-b, top: b-a};
};
SomeObject.magicalStuff = function(position) {
position.left = 0;
};
SomeObject.foo(100, 50);
Run Code Online (Sandbox Code Playgroud)
这个输出类似于(取决于浏览器):
> Object
50
Run Code Online (Sandbox Code Playgroud)
如果您展开"对象"(在Chrome,Safari或Firefox(Firebug)中,您得到的是:
> Object
left: 0
top: -50
Run Code Online (Sandbox Code Playgroud)
我希望:
> Object
left: 50
top: -50
Run Code Online (Sandbox Code Playgroud)
我的想法是,console.log()实际上只是"发布"对控制台的引用,一旦你点击"展开"符号就会被读取.但是那种打败console.log()作为调试工具的目的不是那样吗?我总是希望console.log()能够"快照"我传递给它的东西.看到实际的console.log()改变了那个console.log()调用的输出之后的声明,真是令人惊讶.
或者还有其他事情发生了吗?
编辑:我也想知道浏览器开发人员是否有合理的理由来实现这样的console.log(我猜有一个,否则它在主流浏览器中不一致).
可能重复:
负数的Mod正在融化我的大脑!
我想知道是否有一个更好的算法,我正在尝试做什么:
wrapIndex(-6, 3) = 0 wrapIndex(-5, 3) = 1 wrapIndex(-4, 3) = 2 wrapIndex(-3, 3) = 0 wrapIndex(-2, 3) = 1 wrapIndex(-1, 3) = 2 wrapIndex(0, 3) = 0 wrapIndex(1, 3) = 1 wrapIndex(2, 3) = 2 wrapIndex(3, 3) = 0 wrapIndex(4, 3) = 1 wrapIndex(5, 3) = 2
我想出来了
function wrapIndex(i, i_max) {
if(i > -1)
return i%i_max;
var x = i_max + i%i_max;
if(x == i_max)
return 0;
return x;
}
有没有更好的方法来做到这一点?