小编Lec*_*ico的帖子

rails redirect_to:返回不工作

我正在尝试使用以下内容:

class PaymentsController < ApplicationController

  def addproduct
     (session[:products] ||= []) << params[:item]
     redirect_to :back
  end

 end
Run Code Online (Sandbox Code Playgroud)

我有这个例外:

undefined method `back_url' for #<PaymentsController:0x007ff682c467a8>
Run Code Online (Sandbox Code Playgroud)

为什么会这样?

ruby redirect ruby-on-rails

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

如何将管道分隔列拆分成多行?

我有一个包含以下内容的数据框:

movieId / movieName / genre
1         example1    action|thriller|romance
2         example2    fantastic|action
Run Code Online (Sandbox Code Playgroud)

我想获得第二个数据帧(来自第一个),其中包含以下内容:

movieId / movieName / genre
1         example1    action
1         example1    thriller
1         example1    romance
2         example2    fantastic
2         example2    action
Run Code Online (Sandbox Code Playgroud)

我怎么能这样做?

apache-spark apache-spark-sql

13
推荐指数
1
解决办法
9433
查看次数

将字符串转换为 LocalDateTime

我有以下字符串:

18/07/2019 16:20

我尝试LocalDateTime使用以下代码将此字符串转换为:

val stringDate = expiration_button.text.toString()
val date = LocalDateTime.parse(stringDate, DateTimeFormatter.ofPattern("dd/MM/yyyy hh:mm")).toString()
Run Code Online (Sandbox Code Playgroud)

java.time.format.DateTimeParseException:无法解析文本“18/07/2019 04:30:00”:无法从 TemporalAccessor 获取 LocalDateTime

我缺少什么?

datetime android date kotlin

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

修改spark DataFrame列

我想更改以下数据框:

--id--rating--timestamp--
-------------------------
| 0 | 5.0  |  231312231 |
| 1 | 3.0  |  192312311 | #Epoch time (seconds from 1 Thursday, 1 January 1970)
-------------------------
Run Code Online (Sandbox Code Playgroud)

到以下数据框:

--id--rating--timestamp--
--------------------------
| 0 |  5.0  |  05        |
| 1 |  3.0  |  04        | #Month of year
--------------------------
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

dataframe apache-spark

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

从 MutableList&lt;Int&gt; 初始化 Array&lt;Int&gt;

我有以下代码:

val realm = Realm.getDefaultInstance()
val items = realm.where(ItemRealm::class.java).equalTo("Id", id).findAll()
val ids = arrayOf<Int>(locations.map { it.locationId!! })
return realm.where(LocationRealm::class.java).`in`("id", ids).findAll()
Run Code Online (Sandbox Code Playgroud)

出现以下错误:

类型推断失败。预期类型不匹配:必需的 Int,找到的列表

我知道这是因为数组构造函数的第一个参数是 Size,但我不知道如何初始化该数组。我需要它,因为Realm.where.in需要Array<Int>工作。

除了初始化以下方式之外,还有其他方式(更快)吗?

val locations = realm.where(ItemStockLocationsRealm::class.java).equalTo("stockId", id).findAll()
val ids = arrayOf(locations.size) {0}
for (i in locations.indices) { ids[i] = locations[i]?.locationId!! }
Run Code Online (Sandbox Code Playgroud)

android realm kotlin

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

使用ISODate导入CSV文件MongoDB

当我从mongoDB导出数据时,我获取以下文件:

除了ISODate的日期之外,mongoDB中的所有内容都是字符串.

123@123.com,sha1:64000:18:BTJnM903gIt5FNlSsZIRx1tLC9ErPJuB:9YVs800sgRPr1aaLj73qqnJ6,123,123,123@123.com,2017-04-28T09:20:07.480Z,cus_AYcVXIUf68nT52
Run Code Online (Sandbox Code Playgroud)

如果我将此文件导入MongoDB,它会将每个值导入为String值.我需要将日期解析为Date格式,其余的可以是字符串.

我已经看到MongoImport --columnsHaveTypes有一个参数.我试过没有任何结果:

mongoimport -u test-p test --authenticationDatabase test -h localhost:30158 --db test--collection users --type csv --file users.csv --upsert --upsertFields username --fields username.string\(\),password.string\(\),cname.string\(\),sname.string\(\),mail.string\(\),creation.date\(\),validation.auto\(\),clients.string\(\),customer.string\(\) --columnsHaveTypes
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Failed: type coercion failure in document #0 for column 'creation', could not parse token '2017-04-28T09:20:07.480Z' to type date
Run Code Online (Sandbox Code Playgroud)

我能做什么?

亲切的问候.

date mongodb isodate mongoimport

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

使用 JMX 访问 WildFly10 失败

我正在尝试通过 JMX 从我的本地机器访问带有 WildFly10 的虚拟机。在 JConsole 中,我使用以下参数:

remote process: service:jmx:http-remoting-jmx://172.28.128.3:9990
username: test
password: test
Run Code Online (Sandbox Code Playgroud)

用户名和密码都有效,因为我可以使用该用户名/密码访问 WildFly 172.28.128.3:9990

消息如下:

安全连接失败。不安全地重试?

如果我单击是,则会出现以下内容:

连接失败:重试?

我错过了什么?

编辑:

我已经看到,如果我执行 Jconsole.exe -debug 我可以在连接时看到这个错误:

java.net.MalformedURLException:不支持的协议:http-remoting-jmx

jmx wildfly wildfly-10

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

JQ:生成带有json信息的txt文件

我有以下 Json:

[{
    "_id": {
            "$oid": "59c3942baeef22b03fa573d2"
    },
    "client_id": "test@test.com",
    "name": "Windows Client"
},
{
    "_id": {
            "$oid": "59c3942baeef22b03fa573d2"
    },
    "client_id": "test2@test2.com",
    "name": "Linux Client"
}]
Run Code Online (Sandbox Code Playgroud)

我想输出以下内容:

mongo_customers,customer=test@test.com
mongo_customers,customer=test2@test.com
Run Code Online (Sandbox Code Playgroud)

我已尝试以下方法,但它不起作用:

jq -n -R \
  --slurpfile mongo mongo.json \
'
  $mongo[][].client_id] as $mongo_ids
  "mongo_customers,customer="($mongo_ids)
'
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

text json dynamically-generated jq

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

带有时间戳的 Django 过滤器模型

我有以下型号:

class User(models.Model):
    id = models.CharField(max_length=10, primary_key=True)

class Data(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    timestamp = models.IntegerField(default=0)
Run Code Online (Sandbox Code Playgroud)

给定一个用户,我想知道如何使用时间戳进行过滤。例如:

从现在到 1 小时前从 user1 获取数据。

我有当前的时间戳now = time.time(),也有 1 小时前使用hour_ago = now-3600

我想获取在这两个值之间具有时间戳的数据。

django timestamp model filter

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

Android 纵向和横向布局

我有以下布局:

在此处输入图片说明

我在纵向模式下需要以下布局:

在此处输入图片说明

但是,我获得了以下一个,但我不知道如何修改它:

在此处输入图片说明

我怎样才能做到这一点?

layout android landscape portrait

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

BLE 从特征接收 GATT 通知

我希望在该特性发生更改时收到通知Micro:Bit

\n\n

我正在做的事情基本上如下:

\n\n

1)检查系统是否兼容BLE

\n\n

2) 启用蓝牙以防其被禁用

\n\n

3) 连接到唯一一个配对设备 (Micro:Bit)

\n\n

4) 当连接发生变化时激活此代码(\xc2\xbfConnected/Disconnected?)

\n\n

5) 当特性更新时激活此代码\xc2\xbf?

\n\n
public class MainActivity extends Activity {\n\nBluetoothAdapter bleAdapter;\n\n@Override\nprotected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    setContentView(R.layout.activity_main);\n\n    **(1)**\n\n    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {\n        Toast.makeText(this, "BLE Not Supported", Toast.LENGTH_SHORT).show();\n        finish();\n    }\n\n    **(2)**\n\n    bleAdapter = ((BluetoothManager) getSystemService(BLUETOOTH_SERVICE)).getAdapter();\n\n    if (bleAdapter == null || !bleAdapter.isEnabled()) {\n        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);\n        startActivityForResult(enableBtIntent, 1);\n    }\n\n    Set<BluetoothDevice> pairedDevices = bleAdapter.getBondedDevices();\n\n    for (BluetoothDevice device : pairedDevices) {\n\n        **(3)**\n\n        device.connectGatt(this, true, new BluetoothGattCallback() …
Run Code Online (Sandbox Code Playgroud)

uuid android characteristics bluetooth-lowenergy gatt

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

在 TextView.setText 之后刷新视图

我有一个已更新的 TextView,但在我最小化并重新打开应用程序之前我看不到刷新。这是执行该操作的代码。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    bleAdapter = ((BluetoothManager) getSystemService(BLUETOOTH_SERVICE)).getAdapter();
    Set<BluetoothDevice> pairedDevices = bleAdapter.getBondedDevices();

    for (BluetoothDevice device : pairedDevices) {

        device.connectGatt(this, true, new BluetoothGattCallback() {

            @Override
            public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
                super.onConnectionStateChange(gatt, status, newState);
                TextView state;

                switch (newState) {

                    case BluetoothProfile.STATE_CONNECTED: 
                        state = (TextView)findViewById(R.id.state);
                        state.setText("Connected = True");
                        state.setTextColor(Color.GREEN);
                        break;

                    case BluetoothProfile.STATE_DISCONNECTED:
                        state = (TextView)findViewById(R.id.state);
                        state.setText("Connected = False");
                        state.setTextColor(Color.RED);
                        break;
                }
            }
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

我需要刷新那个 TextView 吗?我做错了什么吗?

android refresh textview

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

用于 ListView 的 Kotlin setOnClickListener

我有以下代码:

class BookListActivity : AppCompatActivity()
{

    var array = arrayOf("Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10", "Item 11")

    override fun onCreate(savedInstanceState: Bundle?)
    {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.book_list)

        val adapter = ArrayAdapter(this, R.layout.book_list_item, R.id.book_title, array)
        val listView : ListView = findViewById(R.id.book_list)
        listView.adapter = adapter    
    }
}
Run Code Online (Sandbox Code Playgroud)

我需要为 listView 上的每个元素添加一个点击侦听器。

我尝试了以下但不起作用:

listView.setOnItemClickListener
{
    val intent = Intent(this, BookDetailActivity::class.java)
    startActivity(intent)
}
Run Code Online (Sandbox Code Playgroud)

另外我需要知道我点击了什么 ListView 元素。我怎样才能做到这一点?

android listview kotlin onclicklistener

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