考虑以下代码:
require 'pry'
(1..5).each {
binding.pry
puts 'test'
}
Run Code Online (Sandbox Code Playgroud)
进入firstpry的会话后,我想继续运行脚本,就好像binding.pry它不存在一样。即使当我编辑文件而不离开会话、注释掉该行并键入exitorcontinue时,它仍然会被调用。
我正在尝试应用以下迁移:
Schema::table('users', function (Blueprint $table) {
$table->timestamp('created_at')->useCurrent()->change();
});
Run Code Online (Sandbox Code Playgroud)
但是artisan说:
[Doctrine\DBAL\DBALException]
Unknown column type "timestamp" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL
\Types\Type::addType(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap(). I
f this error occurs during database introspection then you might have forgot to register all database types for a
Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMapp
edDatabaseTypes(). If the type name is empty …Run Code Online (Sandbox Code Playgroud) php database-migration doctrine-orm sql-timestamp laravel-5.2
我在主页上显示 7 个随机对象。为此,我使用基于此答案的解决方案:
class ProductManager(models.Manager):
def random(self, n_products, filter={}, select_related=None):
n_products_total = self.filter(**filter).count()
if n_products_total == 0:
return []
r = [self.random_impl(n_products_total, filter, select_related) for i in range(n_products)]
return [p for p in r if p is not None]
def random_impl(self, n_products, filter, select_related=None):
random_index = randint(0, n_products - 1)
try:
return self.filter(**filter) \
.select_related(select_related)[random_index]
except IndexError:
return None
random_products = Product.objects.random(7, filter={'enabled': True}, select_related='category')
Run Code Online (Sandbox Code Playgroud)
如果我传递prefetch_related=Prefetch('productphoto_set', queryset=ProductPhoto.objects.order_by('pk'))给random_impl方法,它会为每个产品一次预取 1 张照片。这并不奇怪。产品已经被提取后,我可以手动预提取相关对象吗?
html4说这个:
为了避免SGML换行规则的问题以及现有实现之间的不一致,作者不应该依赖用户代理在开始标记之后立即或在结束标记之前立即渲染空白.因此,作者,特别是创作工具,应该写:
<P>我们为订阅者提供免费的<A>技术支持</A>.</ P>
并不是:
<P>我们为订阅者提供免费的<A>技术支持</A>.</ P>
与此:
SGML(参见[ISO8879],第7.6.1节)指定必须忽略紧跟在开始标记之后的换行符,并且必须在结束标记之前立即换行.这适用于所有HTML元素,无例外.
必须以相同方式呈现以下两个HTML示例:
托马斯正在看电视.</ P>
<P>
托马斯在看电视.
</ P>那么必须有以下两个例子:
<A>我最喜欢的网站</A>
<A>
我最喜欢的网站
</A>
所以,不应该依赖它们被忽视.怎么样html5?
UPD或者让我们这样说:我可以将它们视为被忽视或有时它们是否重要(以某种方式表现出来)?在哪方面,如果有的话?
UPD嗯,我应该说我考虑过重构......?我试图让模板更具可读性,这就是让我思考它的原因.
控制器:
class UsersController < ApplicationController
def index
...
authorize User
end
...
Run Code Online (Sandbox Code Playgroud)
政策:
class UserPolicy < ApplicationPolicy
def index
@user.admin?
end
end
Run Code Online (Sandbox Code Playgroud)
考试:
class UsersControllerAuthorizationTest < ActionController::TestCase
tests :users
def user
@user ||= create(:user)
end
test 'should not authorize ordinary users to access the page' do
sign_in user
get :index
assert_response :error
end
end
Run Code Online (Sandbox Code Playgroud)
该应用程序Pundit::NotAuthorizedError (not allowed to index? this User)按预期失败.但测试说:
Pundit::NotDefinedError: unable to find policy UserPolicy for User
Run Code Online (Sandbox Code Playgroud)
我做错了吗?我可以让它找到政策吗?
UPD必须与rails'自动加载'有关.调用constantize上'UserPolicy'使得它自动加载 …
假设我有这个样式表:
.d1
width: 10px
.d2
width: 20px
Run Code Online (Sandbox Code Playgroud)
它会产生以下 css 代码(带有nested输出样式):
.d1 {
width: 10px; }
.d1 .d2 {
width: 20px; }
Run Code Online (Sandbox Code Playgroud)
源映射 ( v3) 包含以下映射:
AAAA,AAAA,GAAG,CAAC;EACA,KAAK,EAAE,IAAK,GAES;EAHzB,AAEI,GAFD,CAEC,GAAG,CAAC;IACA,KAAK,EAAE,IAAK,GAAG
Run Code Online (Sandbox Code Playgroud)
使用此服务对其进行解码后,我得到:
([0,0](#0)=>[0,0]) | ([0,0](#0)=>[0,0]) | ([0,3](#0)=>[0,3]) | ([0,4](#0)=>[0,4])
([1,4](#0)=>[1,2]) | ([1,9](#0)=>[1,7]) | ([1,11](#0)=>[1,9]) | ([1,16](#0)=>[1,13]) | ([3,25](#0)=>[1,16])
([0,0](#0)=>[2,2]) | ([2,4](#0)=>[2,2]) | ([0,3](#0)=>[2,5]) | ([2,4](#0)=>[2,6]) | ([2,7](#0)=>[2,9]) | ([2,8](#0)=>[2,10])
([3,8](#0)=>[3,4]) | ([3,13](#0)=>[3,9]) | ([3,15](#0)=>[3,11]) | ([3,20](#0)=>[3,15]) | ([3,23](#0)=>[3,18])
Run Code Online (Sandbox Code Playgroud)
源代码的生成方式与( )类似。node-sasslibsass
我的理解是,这些是原始文件和结果文件中的点对。但我们以第二行的最后一对为例:([3,25](#0)=>[1,16])。第 3 行第 25 列?这有点出乎你的意料,你不觉得吗? …
我有一个从旧数据库导入数据的脚本。一路上我遇到了违反唯一约束的情况。我想修改查询并再次执行它,但它说“psycopg2.InternalError:当前事务已中止,命令被忽略,直到事务块结束”:
try:
pcur.execute(sql, values)
except psycopg2.IntegrityError:
value = ...
pcur.execute(sql, values)
Run Code Online (Sandbox Code Playgroud)
如何在不切换到自动提交模式的情况下做到这一点?
我想这可以解决问题:
*
!/dir1/
!/dir2/
!/file1
!/file2
Run Code Online (Sandbox Code Playgroud)
但令我惊讶的是,事实并非如此。如果我在星号前加一个斜杠,它似乎可以工作。但我真的不明白为什么在这个改变之前它不起作用。有人能指点一下吗?
他们究竟是什么意思?如果我的理解是正确的,我不能用this.state计算新的状态时,除非我通过一个函数作为第一个参数,setState():
// Wrong
this.setState({a: f(this.state)});
// Correct
this.setState(prevState => {return {a: f(prevState)}});
Run Code Online (Sandbox Code Playgroud)
但我可以this.state用来决定做什么:
if (this.state.a)
this.setState({b: 2});
Run Code Online (Sandbox Code Playgroud)
道具怎么样?
// Correct or wrong?
this.setState({name: f(this.props)});
Run Code Online (Sandbox Code Playgroud)
据说我this.state打电话后不能指望改变this.setState:
this.setState({a: 1});
console.log(this.state.a); // not necessarily 1
Run Code Online (Sandbox Code Playgroud)
然后,说我有一个用户列表.还有一个选择,我可以让一个用户当前:
export default class App extends React.Component {
...
setCurrentUserOption(option) {
this.setState({currentUserOption: option});
if (option)
ls('currentUserOption', option);
else
ls.remove('currentUserOption');
}
handleAddUser(user) {
const nUsers = this.state.users.length;
this.setState(prevState => {
return {users: prevState.users.concat(user)};
}, () => { …Run Code Online (Sandbox Code Playgroud) 这是触发错误的代码:
#!/home/yuri/.rbenv/shims/ruby
a = []
a += [1, 2, 3].map { |v|
v++
}
Run Code Online (Sandbox Code Playgroud)
这就是它所说的:
/home/yuri/_/1.rb:5: syntax error, unexpected '}'
Run Code Online (Sandbox Code Playgroud)
这个运行没有错误:
#!/home/yuri/.rbenv/shims/ruby
a = []
a += [1, 2, 3].map { |v|
v++
v
}
Run Code Online (Sandbox Code Playgroud)
但那不是:
#!/home/yuri/.rbenv/shims/ruby
a = []
a += [1, 2, 3].map { |v|
v++ if false
v
}
Run Code Online (Sandbox Code Playgroud)
输出:
/home/yuri/_/1.rb:6: syntax error, unexpected '}', expecting keyword_end
Run Code Online (Sandbox Code Playgroud)
有没有办法解释这种行为?或者至少,如何避免它?我正在跑ruby-2.0,如果有的话.
我rvm事先已经安装好了.我决定从一个包(nginx-full和passenger)安装乘客,并希望使用ruby安装的rvm.但不知怎的,它不起作用.这是sinatra我正在使用的测试应用程序(~yuri/a1/app.rb):
require 'rubygems'
require 'sinatra'
get '/' do
"Hello and Goodbye"
end
Run Code Online (Sandbox Code Playgroud)
〜尤里/ A1/config.ru:
require 'rubygems'
require 'sinatra'
require './app.rb'
run Sinatra::Application
Run Code Online (Sandbox Code Playgroud)
nginx.conf:
http {
...
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
# the paths in the above file point out to debian repository's ruby version
server {
server_name a1;
root /home/yuri/a1;
access_log /var/log/nginx/a1-access.log;
error_log /var/log/nginx/a1-error.log;
passenger_enabled on;
passenger_ruby /home/yuri/.rvm/wrappers/ruby-1.9.3-p385@a1/ruby;
}
}
Run Code Online (Sandbox Code Playgroud)
但当我w3m http://a1 access.log说:
127.0.0.1 - - [12/Sep/2013:21:14:58 +0300] …Run Code Online (Sandbox Code Playgroud) ruby ×4
asynchronous ×1
bdd ×1
css ×1
django ×1
django-orm ×1
doctrine-orm ×1
git ×1
gitignore ×1
html ×1
html5 ×1
javascript ×1
laravel-5.2 ×1
nginx ×1
passenger ×1
php ×1
postgresql ×1
pry ×1
psycopg2 ×1
pundit ×1
python-3.x ×1
reactjs ×1
rvm ×1
sass ×1
setstate ×1
sinatra ×1
source-maps ×1
spaces ×1
testing ×1
trailing ×1
transactions ×1
whitespace ×1