当我在掌握时,我只需要输入'git push'来将提交推送到远程仓库.我希望在我在另一个分支上时可以这样做,而不指定远程名称和分支名称.像那样:
现在: git push origin experimental:origin/experimental
需要: git push
我在命名空间中有一堆控制器Foo.我想before_filter 'require_user'对所有这些应用,但不应用于不属于Foo命名空间的其他控制器.
除了在每个控制器中显式调用before_filter方法之外,还有什么办法可以实现这个目的吗?
每当我定义这样的私有方法时:
class ParentClass {
sayHi() { _initiateGreeting(); }
_initiateGreeting() { print("I'm a parent class"); }
}
Run Code Online (Sandbox Code Playgroud)
不可能在子类中重新定义它:
class ChildClass extends ParentClass {
_initiateGreeting() { print("I'm a child class"); } // redefining the method
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我创建了一个 aChildClass和 callsayHi()方法的实例,那么ParentClass实际调用的是 a 中的私有方法:
var child = new ChildClass();
child.sayHi(); // outputs "I'm a parent class"
Run Code Online (Sandbox Code Playgroud)
但是,如果_initiateGreeting()在任何地方都公开(即剥离了_),则child.sayHi()在输出中调用results I'm a child class。
为什么?如何重新定义私有方法以便在子类中调用它?
据我所知,目前 Dart 没有明确的方法从内存中删除对象,并且不再在任何地方引用的对象会自动删除。
但我一直在进行一些基准测试。这是代码:
import 'dart:html';
import 'dart:async';
var components = [];
var times_to_run = 10;
class MockComponent {
Element element = new Element.html('<table></table>');
remove() {
element.remove();
element = null;
}
}
createAndRemoveComponents(t) {
var n = 50000; // number of objects to create and delete in this run
print("***Run #${times_to_run}");
print("creating $n objects...");
for(var i=0; i < n; i++) {
components.add(new MockComponent());
}
print("...done");
print("removing $n objects...");
while(components.length > 0) {
components.removeAt(0).remove();
}
print("...done");
times_to_run -= 1;
if(times_to_run <= …Run Code Online (Sandbox Code Playgroud) 有人可以拆解它并向我解释它是如何工作的吗?这是受保护的电子邮件链接.
<script type="text/javascript">
//<![CDATA[
<!--
var x="function f(x){var i,o=\"\",l=x.length;for(i=0;i<l;i+=2) {if(i+1<l)o+=" +
"x.charAt(i+1);try{o+=x.charAt(i);}catch(e){}}return o;}f(\"ufcnitnof x({)av" +
" r,i=o\\\"\\\"o,=l.xelgnhtl,o=;lhwli(e.xhcraoCedtAl(1/)3=!11)1t{yrx{=+;x+ll" +
"=};acct(h)e}{f}roi(l=1-i;=>;0-i)-o{=+.xhcratAi(;)r}teru n.oussbrt0(o,)l};(f" +
")\\\"43\\\\,q\\\"sydn%{~l/,\\\\\\\\\\\\\\\\20\\\\0r\\\\gggo2>02\\\\\\\\27\\" +
"\\07\\\\01\\\\\\\\23\\\\07\\\\02\\\\\\\\13\\\\0Y\\\\30\\\\04\\\\02\\\\\\\\3" +
"1\\\\04\\\\03\\\\\\\\00\\\\0O\\\\3R1L6Q01\\\\\\\\06\\\\05\\\\03\\\\\\\\01\\" +
"\\03\\\\02\\\\\\\\GF6801\\\\\\\\\\\\r2\\\\00\\\\\\\\3N<7<132\\\\06\\\\#3;?}" +
"'0< =w<?# &*)1d03\\\\\\\\%y3'7(03\\\\\\\\1_00\\\\\\\\36\\\\03\\\\02\\\\\\\\" +
"UTC]G_5C03\\\\\\\\_FBUN[OC\\\"\\\\f(;} ornture;}))++(y)^(iAtdeCoarchx.e(odr" +
"ChamCro.fngriSt+=;o27=1y%2;*=)yy)3+(4i>f({i+)i+l;i<0;i=r(foh;gten.l=x,l\\\"" +
"\\\\\\\"\\\\o=i,r va){,y(x fontincfu)\\\"\")" ;
while(x=eval(x));
//-->
//]]>
</script>
Run Code Online (Sandbox Code Playgroud) 我正在使用Paperclip,这是我在模型中删除附件的内容:
def before_save
self.avatar = nil if @delete_avatar == 1.to_s
end
Run Code Online (Sandbox Code Playgroud)
除非@delete_avatar在用户实际上传图像时设置了标志(因此模型同时接收params[:user][:avatar]和params[:user][:delete_avatar].),否则工作正常.这会导致以下错误:
TypeError: can't convert nil into String
from /Work/project/src/vendor/plugins/paperclip/lib/paperclip/storage.rb:40:in `dirname'
from /Work/project/src/vendor/plugins/paperclip/lib/paperclip/storage.rb:40:in `flush_writes'
from /Work/project/src/vendor/plugins/paperclip/lib/paperclip/storage.rb:38:in `each'
from /Work/project/src/vendor/plugins/paperclip/lib/paperclip/storage.rb:38:in `flush_writes'
from /Work/project/src/vendor/plugins/paperclip/lib/paperclip/attachment.rb:144:in `save'
from /Work/project/src/vendor/plugins/paperclip/lib/paperclip/attachment.rb:162:in `destroy'
from /Work/project/src/app/models/user.rb:72:in `before_save'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/callbacks.rb:347:in `send'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/callbacks.rb:347:in `callback'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/callbacks.rb:249:in `create_or_update'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2538:in `save_without_validation'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/validations.rb:1078:in `save_without_dirty'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/dirty.rb:79:in `save_without_transactions'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:229:in `send'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:229:in `with_transaction_returning_status'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:182:in `transaction'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:228:in `with_transaction_returning_status'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:196:in …Run Code Online (Sandbox Code Playgroud) 我需要在bash启动后立即运行命令,然后保持在会话中.我期待类似的东西可以工作bash && cd ~/Work,但是,显然,它会在初始会话中运行第二个命令,而不是我正在开始的那个.
我在新shell中发现了这个运行bash命令,并在此命令执行线程后保留在新shell中,但运行bash --rcfile对我不起作用,因为我仍然需要加载rcfile.
我希望能够使用Dart类构造函数执行此类操作:
class Model {
// ... setting instance variables
Model(Map fields) {
fields.forEach((k,v) => this[k] = v);
}
}
Run Code Online (Sandbox Code Playgroud)
显然,这不起作用,因为this没有[]=方法.
有没有办法让它发挥作用,或者它根本不是做事的"飞镖方式"?如果不是,你能告诉我解决这个问题的正确方法吗?
如何检查对象的类是否包含mixin?例如:
class AClass extends Object with MyMixin {}
class BClass extends Object {}
classIncludesMixin(new AClass(), 'MyMixin'); // => true
classIncludesMixin(new BClass(), 'MyMixin'); // => false
Run Code Online (Sandbox Code Playgroud)
classIncludesMixin()为了让它起作用,这个方法应该是什么?
我的test_dir中有一堆文件,问题是它们必须单独运行,因为其中一个是测试只能在浏览器中运行的代码,另一个是测试只能在后端运行的代码.
现在,我知道有一个用于指定测试名称的-n参数pub run test,但是如何运行特定文件?从文档中看不是很清楚,我无法成功完成。
dart ×5
bash ×1
controllers ×1
dart-mirrors ×1
email ×1
filter ×1
git ×1
inheritance ×1
javascript ×1
memory-leaks ×1
mixins ×1
namespaces ×1
paperclip ×1
testing ×1
unit-testing ×1