好奇 Airbnb 会 sponsor L1 吗?
%w(cat dog wombat).each.with_index.inject({}) do |h, (item, index)|
h[item] = index
h
end
$ bundle exec rails server -h
Usage: rails server [mongrel, thin, etc] [options]
-p, --port=port Runs Rails on the specified port.
Default: 3000
-b, --binding=ip Binds Rails to the specified ip.
Default: 0.0.0.0
-c, --config=file Use custom rackup configuration file
-d, --daemon Make server run as a Daemon.
-u, --debugger Enable ruby-debugging for the server.
-e, --environment=name Specifies the environment to run this server under (test/development/production).
Default: development
-P, --pid=pid Specifies the PID file.
Default: tmp/pids/server.pid
-h, --help Show this help message.
如果是 80 的话,要 sudo
.
viwS
Clojure
@GuiZi 是这个 PR 引入的 bug https://github.com/rails/rails/pull/18937
From changelog:
belongs_to
will now trigger a validation error by default if the association is not present. You can turn this off on a per-association basis withoptional: true
.
但是没有考虑你的这种情况,所以会报 validation error.
我觉得应该做的是 MySQL 还没有启动前,不应该启动 Rails.
#!/bin/bash
function is_db_up {
nc -z -w5 MYSQL_IP MYSQL_PORT
}
echo -n "Waiting for db to be up..."
until is_db_up ; do
printf '.'
sleep 1
done
echo done\!
# start rails application
Reddit 找技术相关板块,Hacker News 看文章,Youtube 看各种技术 talk,Couserea、Khan、Udacity 跟课程。
是完整的,重点是这行:result = flatten(ary, level, &mod);
flatten
方法的完整定义在这里 https://github.com/ruby/ruby/blob/eb15df1f894fa7235ccbcda7661f7d6a052045f6/array.c#L4508-L4564
static VALUE
flatten(VALUE ary, int level, int *modified)
{
long i = 0;
VALUE stack, result, tmp, elt;
st_table *memo;
st_data_t id;
stack = ary_new(0, ARY_DEFAULT_SIZE);
result = ary_new(0, RARRAY_LEN(ary));
memo = st_init_numtable();
st_insert(memo, (st_data_t)ary, (st_data_t)Qtrue);
*modified = 0;
while (1) {
while (i < RARRAY_LEN(ary)) {
elt = RARRAY_AREF(ary, i++);
if (level >= 0 && RARRAY_LEN(stack) / 2 >= level) {
rb_ary_push(result, elt);
continue;
}
tmp = rb_check_array_type(elt);
if (RBASIC(result)->klass) {
rb_raise(rb_eRuntimeError, "flatten reentered");
}
if (NIL_P(tmp)) {
rb_ary_push(result, elt);
}
else {
*modified = 1;
id = (st_data_t)tmp;
if (st_lookup(memo, id, 0)) {
st_free_table(memo);
rb_raise(rb_eArgError, "tried to flatten recursive array");
}
st_insert(memo, id, (st_data_t)Qtrue);
rb_ary_push(stack, ary);
rb_ary_push(stack, LONG2NUM(i));
ary = tmp;
i = 0;
}
}
if (RARRAY_LEN(stack) == 0) {
break;
}
id = (st_data_t)ary;
st_delete(memo, &id, 0);
tmp = rb_ary_pop(stack);
i = NUM2LONG(tmp);
ary = rb_ary_pop(stack);
}
st_free_table(memo);
RBASIC_SET_CLASS(result, rb_class_of(ary));
return result;
}
可以在 before_validation
里判断 https://github.com/ruby-grape/grape#before-and-after
before_validation do
error! "Token not found in header", 400 if headers["token"].blank?
end
$ zsh_stats
1 25960 31.9996% git
2 6960 8.57925% ll
3 5795 7.14321% vim
4 3757 4.63107% cd
5 2813 3.46745% ls
6 2248 2.771% tigs
7 2141 2.6391% tig
8 1745 2.15098% rake
9 1493 1.84035% rails
10 1286 1.58519% j
11 1285 1.58396% ssh
12 1226 1.51123% ag
13 1174 1.44713% rm
14 1155 1.42371% brew
15 1121 1.3818% cap
16 1104 1.36085% l
17 824 1.0157% bi
18 798 0.983655% bundle
19 781 0.9627% tmux
20 756 0.931884% ping
@zouchaoge
try Order.ransack({ :express_status => 0 })
?
Owning Rails
Moom
#4 楼 @yukihiro_matz 对,按照规范来即可。
Vim also allows you to execute a command directly from the editor, without needing to drop to a shell, by using bang (!) followed by the command to be run. For instance, if you're editing a file in Vim and want to find out how many words are in the file, run :! wc %
google key word: vim run external command
#2 楼 @mogodb 提示的很清楚了。git clone 下来的仓库没有对应的 svn 仓库的信息。
http://ivanz.com/2009/01/15/selective-import-of-svn-branches-into-a-gitgit-svn-repository/
try gem update --system
first.
推荐一个适合新手学习的 codebase: https://github.com/qrush/skyway
#10 楼 @luikore 如果放在 request.env
里,那跟把这些写到 ApplicationController
里,搞个 memoize 的方法存下来,没什么区别啊?而且把业务逻辑结果放在了它该存在的地方,而不是 request.env
...
warden 放在 request.env
里是为了 rack app 间的数据通信吧,warden 为了让下一层的 rack app 使用到,当然需要这么做没错,但这不代表我最后一层的 rack app 还要这么做啊。我同一层的数据共享为什么非要用到 request.env
呢...
其实说起 Global Variables 以及写这篇 blog, 主要是因为在复杂的应用中现在的 Thread.current[]
实现方式对于管理来说很困难,所以才会想说起 PerThreadRegistry
这个 module. 而实现在 request.env
里还是没有解决到这个痛点(对于我来讲是痛点,:) ),所以我还是认为使用 request.env
是个 bad idea.
solarized