我正在尝试对以下 json 响应进行排序以选择最新版本:
[
{
"TagVersion": "1.0.11"
},
{
"TagVersion": "1.1.8"
},
{
"TagVersion": "1.0.10",
},
{
"TagVersion": "1.0.9",
},
{
"TagVersion": "1.0.77"
}
]
Run Code Online (Sandbox Code Playgroud)
正确的排序应该是:
{
"TagVersion": "1.0.9",
},
{
"TagVersion": "1.0.10",
},
{
"TagVersion": "1.0.11"
},
{
"TagVersion": "1.0.77"
},
{
"TagVersion": "1.1.8"
}
Run Code Online (Sandbox Code Playgroud)
我目前能够完成部分工作。它适用于简单的情况(所有版本部分主要/次要/错误具有相同的位数)。
jq -r [.[]]|max_by(.TagVersion|split(".") | map(tonumber)
在我看来,最好的方法应该是在每个部分上添加一个乘法。例子:
# With condition than every "part" as a maximum of 2 digits. It won't work with 3 digits
# Version 1.23.87
1 * 1000 + 23 * …Run Code Online (Sandbox Code Playgroud) 当有更大的工作要优化性能时,我正在尝试分离我的应用程序工作.我的问题是NSManagedObjectContext在另一个线程中使用而不是主线程.
我打电话给:
[NSThread detachNewThreadSelector:@selector(test:) toTarget:self withObject:myObject];
Run Code Online (Sandbox Code Playgroud)
在test方法上有一些事情要做,我有一个问题:
NSArray *fetchResults = [moc
executeFetchRequest:request
error:&error];
Run Code Online (Sandbox Code Playgroud)
这是我的test方法:
-(void) test:(MyObject *)myObject{
@autoreleasepool {
//Mycode
}
}
Run Code Online (Sandbox Code Playgroud)
在第二时间我所说的test方法中,当我的新线程被阻塞executeFetchRequest时调用.当我的test方法被连续多次调用时,这个问题就出现了.我认为问题来自moc但我不能理解为什么.
编辑:
用@ Charlie的方法它几乎可以工作.这是我保存我的代码NSManagedObjectContext(在我的新线程上创建的对象).
- (void) saveContext:(NSManagedObjectContext *) moc{
NSError *error = nil;
if ([moc hasChanges] && ![moc save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
}
Run Code Online (Sandbox Code Playgroud)
在新线程上调用此方法.我现在的问题是,通过这次保存,我遇到了僵局,我真的不明白为什么.没有它完美的工作.
EDIT2
我正在研究这个问题,但我还是无法修复它.我改变了我的代码detachNewThreadSelector.这是我的新代码:
NSManagedObjectContext* context = [[NSManagedObjectContext alloc]
initWithConcurrencyType:NSPrivateQueueConcurrencyType]; …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个查看空关联的范围。
我有 4 节课:User、Idea Project和UserJoins。
多个用户可以有相同的想法或相同的项目。
我想创建一个范围来隔离没有想法的用户。
has_many :user_joins
has_many :users, through: :user_joins
Run Code Online (Sandbox Code Playgroud)
has_many :user_joins
has_many :users, through: :user_joins
Run Code Online (Sandbox Code Playgroud)
has_many :user_joins
has_many :ideas, through: user_joins, source: :imaginable, source_type: 'Idea'
has_many :projects, through: user_joins, source: :imaginable, source_type: 'Project'
scope :without_ideas, ->{
# I'm stuck here.
}
Run Code Online (Sandbox Code Playgroud)
belongs_to :imaginable, polymorphic: true
belongs_to :user
Run Code Online (Sandbox Code Playgroud)
我正在使用Rails 3.2.17和Ruby 2.0.0
有人有办法解决这个问题吗?
我正在寻找rake routes与index嵌套资源路径不匹配的原因。
这是我的代码:
namespace :api do
resources :photos do
resource :comments
end
end
Run Code Online (Sandbox Code Playgroud)
这是命令的结果: rake routes | grep comment
batch_action_admin_user_comments POST /admin/user_comments/batch_action(.:format) admin/user_comments#batch_action
admin_user_comments GET /admin/user_comments(.:format) admin/user_comments#index
POST /admin/user_comments(.:format) admin/user_comments#create
new_admin_user_comment GET /admin/user_comments/new(.:format) admin/user_comments#new
edit_admin_user_comment GET /admin/user_comments/:id/edit(.:format) admin/user_comments#edit
admin_user_comment GET /admin/user_comments/:id(.:format) admin/user_comments#show
PATCH /admin/user_comments/:id(.:format) admin/user_comments#update
PUT /admin/user_comments/:id(.:format) admin/user_comments#update
DELETE /admin/user_comments/:id(.:format) admin/user_comments#destroy
admin_comments GET /admin/comments(.:format) admin/comments#index
POST /admin/comments(.:format) admin/comments#create
admin_comment GET /admin/comments/:id(.:format) admin/comments#show
api_photo_comments POST /api/photos/:photo_id/comments(.:format) api/comments#create
new_api_photo_comments GET /api/photos/:photo_id/comments/new(.:format) api/comments#new
edit_api_photo_comments GET /api/photos/:photo_id/comments/edit(.:format) api/comments#edit
GET /api/photos/:photo_id/comments(.:format) …Run Code Online (Sandbox Code Playgroud) 我正在使用python编写功能脚本脚本,我无法处理此命令行的结果:
os.system("ps aux -u %s | grep %s | grep -v 'grep' | awk '{print $2}'" % (username, process_name)
Run Code Online (Sandbox Code Playgroud)
它显示了我的pids但我不能用它作为List.
如果我测试:
pids = os.system("ps aux -u %s | grep %s | grep -v 'grep' | awk '{print $2}'" % (username, process_name)
print type(pids)
#Results
29719
30205
31037
31612
<type 'int'>
Run Code Online (Sandbox Code Playgroud)
为什么pids一个int?我该如何处理这个结果List?
陌生人:
print type(os.system("ps aux -u %s | grep %s | grep -v 'grep' | awk '{print $2}'" % (username, process_name))
Run Code Online (Sandbox Code Playgroud)
空无一物.我的控制台上没有写任何类型..
activerecord ×1
associations ×1
indexing ×1
ios ×1
jq ×1
json ×1
objective-c ×1
os.system ×1
python ×1
routes ×1
ruby ×1
scope ×1
sorting ×1
version ×1