小编nar*_*ero的帖子

Elasticsearch Bulk API - 意外的输入结束:ARRAY的预期关闭标记

我正在尝试使用POST请求批量导入localhost:9200/products/product/_bulk以下JSON:

[
  { "index": {"_index": "products", "_type": "product", "_id": 1} },
  { "title": "Product A","description": "Brand A - Product A - 1.5 kg","price": 3.49,"sku": "wi208564","supermarket": "AJ","categories": "Fruit AJ","product_type": "Sinaasappels - mandarijnen","brand": "Brand A\n"},
  { "index": {"_index": "products", "_type": "product", "_id": 2} },
  { "title": "Product B","description": "Brand B - Product B - 1 kg","price": 2.49,"sku": "wi308564","supermarket": "AJ","categories": "Fruit AJ","product_type": "Sinaasappels - mandarijnen","brand": "Brand B\n"},
  { "index": {"_index": "products", "_type": "product", "_id": 3} },
  { "title": "Product C","description": "Brand …
Run Code Online (Sandbox Code Playgroud)

elasticsearch

11
推荐指数
1
解决办法
2万
查看次数

如何在Sinatra中运行自定义Rake任务?

*我希望在我的Sinatra应用程序中运行自定义Rake任务但我会继续rake aborted! Don't know how to build task 'greet'.

这是greet.rake用于测试目的的自定义Rake任务():

task :greet do
  puts "Hello!"
end
Run Code Online (Sandbox Code Playgroud)

我已经把greet.rake./lib/tasks(滑轨).我猜Rake无法找到该文件的正确目录.

如何在Sinatra中运行自定义Rake任务?

我正在使用Ruby 2.0.0和Sinatra 1.4.4.

UPDATE

Rakefile现在看起来像这样:

require "./app"
require "sinatra/activerecord/rake"
require "./lib/tasks"
Run Code Online (Sandbox Code Playgroud)

使用时:

rake greet
Run Code Online (Sandbox Code Playgroud)

我明白了:

rake aborted!
cannot load such file -- ./lib/tasks
/Users/*/.rvm/gems/ruby-2.0.0-p247@global/gems/activesupport-        4.0.1/lib/active_support/dependencies.rb:229:in `block in require'
/Users/*/.rvm/gems/ruby-2.0.0-p247@global/gems/activesupport-    4.0.1/lib/active_support/dependencies.rb:214:in `load_dependency'
/Users/*/.rvm/gems/ruby-2.0.0-p247@global/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `require'
/Users/*/Dropbox/Development/Sinatra/sinatra-mp-experiment/Rakefile:3:in `<top    (required)>'
(See full trace by running task with --trace)
Run Code Online (Sandbox Code Playgroud)

ruby rake ruby-on-rails sinatra

7
推荐指数
1
解决办法
7523
查看次数

com.google.android.gms.internal引起的内存泄漏.*

我正在使用smart-location-lib来获取设备的当前位置.它需要在活动的生命周期中稍后使用.

一旦这样finish()的活动回到以前的活动,我收到了内存泄漏.

这是代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...

    SmartLocation.with(this).location()
    .oneFix()
    .start(new OnLocationUpdatedListener() {
        @Override
        public void onLocationUpdated(Location location) {
            mCurrentLocation = location;
        }
    });

    ...
}

...

@Override
protected void onStop() {
    super.onStop();

    SmartLocation.with(this).location().stop();
}
Run Code Online (Sandbox Code Playgroud)

正如你可以看到我在做智能位置LIB的.stop()在活动的的onStop()的文档中描述称这里.

但这并不能防止泄漏.以下是LeakCanary收集的泄漏信息:

In com.companyname.appname.development:1.0-development:1.
* com.companyname.appname.activities.TaskCheckoutActivity has leaked:
* GC ROOT com.google.android.gms.internal.zzbyw.zzfwc
* references com.google.android.gms.internal.zzbyt.zzhyy
* references io.nlopez.smartlocation.location.providers.LocationGooglePlayServicesProvider.context
* leaks com.companyname.appname.activities.TaskCheckoutActivity instance

* Retaining: 1,6 MB.
* Reference Key: ba2a19b1-d5ca-4971-a5c7-e0fd99ea95a6
* Device: samsung samsung …
Run Code Online (Sandbox Code Playgroud)

android memory-leaks

7
推荐指数
1
解决办法
832
查看次数

_tkinter.TclError:命令名称无效".4302957584"

关闭python 3程序时,我在控制台中遇到一个奇怪的异常.

Python 3代码:

from tkinter import *
from random import randint

# Return a random color string in the form of #RRGGBB
def getRandomColor():
    color = "#"
    for j in range(6):
        color += toHexChar(randint(0, 15)) # Add a random digit
    return color

# Convert an integer to a single hex digit in a character
def toHexChar(hexValue):
    if 0 <= hexValue <= 9:
        return chr(hexValue + ord('0'))
    else: # 10 <= hexValue <= 15
        return chr(hexValue - 10 + ord('A')) …
Run Code Online (Sandbox Code Playgroud)

python user-interface tkinter

6
推荐指数
2
解决办法
2万
查看次数

如何从休息客户端获取Waze的GPS数据?

我正在尝试使用rest-client lib 从Waze应用程序获取我的GPS数据.我基本上试图通过网站https://www.waze.com/伪造登录.登录后(您可以使用JohnDoeSpeedy228:gre @ tStory92)访问https://www.waze.com/editor/后,在查看网络调用后点击"驱动器",即可查看原始JSON数据.

我似乎已成功登录,但在发出请求返回所有驱动器的列表时,它返回以下内容

{"users"=>{"objects"=>[]}, "archives"=>{"totalSessions"=>0, "objects"=>[]}}
Run Code Online (Sandbox Code Playgroud)

它应该返回这样的东西:

{
   "users":{
      "objects":[

      ]
   },
   "archives":{
      "totalSessions":1,
      "objects":[
         {
            "id":<REDACTED>,
            "userID":<REDACTED>,
            "existingRoadMeters":2839,
            "newRoadMeters":0,
            "totalRoadMeters":2839,
            "startTime":1456996197000,
            "endTime":1456996636000,
            "hasFullSession":true
         }
      ]
   }
}
Run Code Online (Sandbox Code Playgroud)

这是我正在尝试的:

require 'rest-client'
require 'json'

GET_CSRF_URL = "https://www.waze.com/login/get"
SESSION_URL = "https://www.waze.com/login/create"
SESSION_LIST_URL = "https://www.waze.com/Descartes-live/app/Archive/List"
SESSON_DATA_URL = "https://www.waze.com/Descartes-live/app/Archive/Session"
AUTH = {'user_id'=>'JohnDoeSpeedy228','password'=>'gre@tStory92'}

req = RestClient.get(GET_CSRF_URL)
csrfhash = req.cookies
csrfhash['editor_env'] = 'row'
headers = {'X-CSRF-Token'=>csrfhash['_csrf_token']}

log = RestClient::Request.execute(
  method: :post,
  url: SESSION_URL,
  cookies: csrfhash,
  headers: headers,
  payload: …
Run Code Online (Sandbox Code Playgroud)

ruby rest-client waze

5
推荐指数
1
解决办法
645
查看次数

@Size 注释似乎不适用于我的课程

我有一个 Spring Boot 控制器,其端点接受以下配置类(作为 json)。该类具有参数maxIterations并将@Size注释设置为9000

...
import javax.validation.constraints.Max;
import javax.validation.constraints.Size;

public class Configuration {
    // Max iterations
    @Size(max = 9000)
    private Integer maxIterations;

    ...
}
Run Code Online (Sandbox Code Playgroud)

问题是,当使用POST以下命令调用该端点时json,它不会返回错误或警告,说明参数maxIterations高于9000

{
  "maxIterations": 15000
}
Run Code Online (Sandbox Code Playgroud)

这是我的控制器:

@PostMapping()
@ResponseStatus(HttpStatus.CREATED)
public String doSomething(@RequestBody Configuration configuration) {
    ...
}
Run Code Online (Sandbox Code Playgroud)

可能是什么问题?

java configuration annotations spring-boot

5
推荐指数
1
解决办法
1万
查看次数

如何让rufus-scheduler使用部署到Heroku的Rails应用程序?

./config/initializers我创建了一个名为的文件中task_scheduler.rb,它包含以下代码:

require 'rufus-scheduler'
require 'mechanize'

scheduler = Rufus::Scheduler.new

scheduler.every("1h") do
    puts "Starting Rufus Scheduler - Task 1 - Checking exampleShop for new orders"

    a = Mechanize.new

    a.get('http://exampleshop.nl/admin/') do |page|

        # Select the login form
        login_form = page.forms.first

        # Insert the username and password
        login_form.username = 'username'
        login_form.password = 'password'

        # Submit the login information
        dashboard_page = a.submit(login_form, login_form.buttons.first)

        # Check if the login was successfull
        puts check_1 = dashboard_page.title == 'Dashboard' ?  "CHECK 1 DASHBOARD SUCCESS" …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails passenger heroku rufus-scheduler

4
推荐指数
1
解决办法
5836
查看次数

未定义的局部变量或方法“searchkick”

我正在尝试将Searchkick添加到我的 Rails 应用程序中。我正在按照“入门”页面上的确切说明进行操作,但不断收到以下错误:

Started GET "/airports" for 10.0.2.2 at 2014-05-26 10:20:33 +0000
Processing by AirportsController#index as HTML
Completed 500 Internal Server Error in 26ms

NameError (undefined local variable or method `searchkick' for #<Class:0xb48f3ba8>):
  app/models/airport.rb:2:in `<class:Airport>'
  app/models/airport.rb:1:in `<top (required)>'
  app/controllers/airports_controller.rb:3:in `index'


  Rendered /home/vagrant/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.5ms)
  Rendered /home/vagrant/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.2ms)
  Rendered /home/vagrant/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.9ms)
  Rendered /home/vagrant/.rvm/gems/ruby-2.1.1@global/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (19.8ms)
Run Code Online (Sandbox Code Playgroud)

这是机场模型的样子:

# ./app/models/airport.rb
class Airport < ActiveRecord::Base
    searchkick
end
Run Code Online (Sandbox Code Playgroud)

这就是机场控制器的样子:

# ./app/controllers/airports_controller/rb
class AirportsController < ApplicationController
  def index
    @airports = Airport.all
  end …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails searchkick

4
推荐指数
1
解决办法
1872
查看次数

tkinter.TclError:未知选项

更新: 这只是创建 btComputePayment 时的一个错字。

解决了


我正在使用“Python 编程简介(Pearson 2013)”一书学习 Python。

目前我正在做一个练习,我必须在 Tkinter 中编写一个贷款计算器。

我似乎无法让以下代码工作:

from tkinter import *

class LoanCalculator:
    def __init__(self):
        window = Tk()
        window.title("Loan Calculator")

        # Create labels
        Label(window, text = "Annual Interest Rate").grid(row = 1, column = 1, sticky = W)
        Label(window, text = "Number of Years").grid(row = 2, column = 1, sticky = W)
        Label(window, text = "Loan Amount").grid(row = 3, column = 1, sticky = W)
        Label(window, text = "Monthly Payment").grid(row = 4, column = 1, …
Run Code Online (Sandbox Code Playgroud)

python user-interface tk-toolkit tkinter

3
推荐指数
1
解决办法
2万
查看次数

Python代码在Mac OS X(10.8)上无法正常运行但在Windows 7上运行,为什么?

我正在使用"使用Python编程简介(Pearson 2013)"一书学习Python.我在Mac OS X(10.8)上使用PyCharm 2.7来编写Pyhon 3代码.

以下代码(使用tkinter创建GUI并添加弹出菜单)在Mac OS X上无法正常运行.问题是按下鼠标右键时弹出菜单不显示.我在Windows 7 VM和Windows 7上测试了代码,它运行得很好.

所以我的问题是:为什么代码适用于Windows 7但不适用于Mac OS X?

这是代码:

from tkinter import *

class PopupMenuDemo:
    def __init__(self):
        window = Tk()
        window.title("Popup Menu Demo")

        # Create a popup menu
        self.menu = Menu(window, tearoff = 0)
        self.menu.add_command(label = "Draw a line", command = self.displayLine)
        self.menu.add_command(label = "Draw an oval", command = self.displayOval)
        self.menu.add_command(label = "Draw a rectangle", command = self.displayRectangle)
        self.menu.add_command(label = "Clear", command = self.clearCanvas)

        # Place canvas in window
        self.canvas = Canvas(window, …
Run Code Online (Sandbox Code Playgroud)

python tkinter popupmenu

3
推荐指数
1
解决办法
1680
查看次数