小编syl*_*ian的帖子

`map`基于条件

我有这样的结构:

Struct.new("Test", :loc, :type, :hostname, :ip)

clients = [
Struct::TestClient.new(1, :pc, "pc1", "192.168.0.1")
Struct::TestClient.new(1, :pc, "pc2", "192.168.0.2")
Struct::TestClient.new(1, :tablet, "tablet1", "192.168.0.3")
Struct::TestClient.new(1, :tablet, "tablet2", "192.168.0.3")
and etc...
]
Run Code Online (Sandbox Code Playgroud)

如果我想获得所有设备的IP地址,我可以使用test_clients.map(&:ip).如何选择特定设备的IP地址,比如所谓的所有设备类型"tablet"?我怎么能这样做map

ruby struct

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

根据另一列的最小值选择一列

我有下表。

test_type |  brand  | model  | band | firmware_version | avg_throughput
-----------+---------+--------+------+-----------------+----------------
 1client   | Linksys | N600   | 5ghz | 1               |          66.94
 1client   | Linksys | N600   | 5ghz | 2               |          94.98
 1client   | Linksys | N600   | 5ghz | 4               |         132.40
 1client   | Linksys | EA6500 | 5ghz | 1               |         216.46
 1client   | Linksys | EA6500 | 5ghz | 2               |         176.79
 1client   | Linksys | EA6500 | 5ghz | 4               |         191.44
Run Code Online (Sandbox Code Playgroud)

我想选择 …

sql postgresql greatest-n-per-group

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

使用google-drive-ruby gem在google驱动器中创建文件夹

我知道这里有一个类似的问题,但是由于我的情况有点不同,我仍然无法完成这项工作.我想通过使用google-drive-ruby gem在google驱动器中创建一个文件夹.

据谷歌(https://developers.google.com/drive/folder)使用"驱动器" API,您可以通过插入用的MIME类型"application/vnd.google-apps.folder"文件中创建一个文件夹时,

例如

POST https://www.googleapis.com/drive/v2/files
Authorization: Bearer {ACCESS_TOKEN}
Content-Type: application/json
...
{
  "title": "pets",
  "parents": [{"id":"0ADK06pfg"}]
  "mimeType": "application/vnd.google-apps.folder"
}
Run Code Online (Sandbox Code Playgroud)

在我的情况下,我希望能够做同样的事情,但在使用google_drive API时.它有一个接受的mime-type选项的upload_from_file选项,但是这仍然不为我工作,我走到这一步,执行以下代码时是最好的结果是从谷歌此错误消息.

session.upload_from_file("test.zip","test",:content_type =>"application/vnd.google-apps.folder")

"Mime-type application/vnd.google-apps.folder无效.无法使用Google mime-types创建文件.

如果你能给我任何建议,我将不胜感激.

ruby google-drive-api

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

内嵌图像与红宝石邮件宝石

对不起,如果我错过了一篇好文章,但我找不到一个很好的例子,说明如何使用ruby和邮件gem使用内联图像(我没有使用RoR)我能找到的最好的例子就在这里,但是我不明白.cid方法的来源.

这里是上述帖子的摘录,其中使用了该.cid方法.

html_part do
    content_type 'text/html; charset=UTF-8'
    body "<img width=597 height=162 id='Banner0' src='cid:#{pic.cid}'>"
end
Run Code Online (Sandbox Code Playgroud)

我有邮件gem工作,它可以发送图像作为附件,但我需要它们显示在电子邮件内,而无需打开附件.

ruby inline-images

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

bash脚本根据stdout消息发出蜂鸣声

从来没有在bash上编码但需要紧急的东西.对不起,如果这不是常态,但我真的想得到一些帮助.

我有一些抛出到stdout的消息,根据消息类型(消息是一个带有"found"字样的字符串)我需要bash脚本发出蜂鸣声.

到目前为止,我已经想出了这个.

  output=$(command 1) # getting stdout stream?
  while [ true ]; do
    if [ "$output" = "found" ]; then # if the stdout has the word "found" 
     echo  $(echo -e '\a') # this makes the beep sound
    fi
  done
Run Code Online (Sandbox Code Playgroud)

我不知道在哪里/如何添加grepawk命令检查具有单词"found"的字符串并且仅返回"found",以便在if条件下它可以检查该单词.

谢谢!

bash stdout beep

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