如果我有以下,
<% @feed.sort_by{|t| - t.created_at.to_i}.each do |feed| %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
如何限制它只显示最近的10个结果
我有一个猜测表,每个猜测只是一个日期.我想知道如何将两个或更多日期变成平均值.
<div id="logic">
<% foo = Date.today %>
<% bar = Date.today + 10 %>
<%= (foo + bar) / 2 %>
Run Code Online (Sandbox Code Playgroud)
像这样的东西,但显然Ruby不会让我分开这两个日期.
我试图获得以下XML输出
<?xml version="1.0" encoding="UTF-8"?>
<CreateHostedZoneRequest xmlns="https://route53.amazonaws.com/doc/2012-12-12/">
<Name>DNS domain name</Name>
<CallerReference>unique description</CallerReference>
<HostedZoneConfig>
<Comment>optional comment</Comment>
</HostedZoneConfig>
</CreateHostedZoneRequest>
Run Code Online (Sandbox Code Playgroud)
我有以下输出非常接近的XML,但我无法编码到CreateHostedZoneRequest
的xmlns ="https://route53.amazonaws.com/doc/2012-12-12/
package main
import "fmt"
import "encoding/xml"
type ZoneRequest struct {
Name string
CallerReference string
Comment string `xml:"HostedZoneConfig>Comment"`
}
var zoneRequest = ZoneRequest{
Name: "DNS domain name",
CallerReference: "unique description",
Comment: "optional comment",
}
func main() {
tmp, _ := createHostedZoneXML(zoneRequest)
fmt.Println(tmp)
}
func createHostedZoneXML(zoneRequest ZoneRequest) (response string, err error) {
tmp := struct {
ZoneRequest
XMLName struct{} `xml:"CreateHostedZoneRequest"`
}{ZoneRequest: zoneRequest}
byteXML, …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过串口发送一个整数到我的Ardunio.然后芯片将在LED上显示二进制数字.但是,我在尝试通过串行端口将数据作为一个字节发送时遇到了很多麻烦,只要我可以调试以下代码将其作为ASC char值发送.
谁能指出我正确的方向或发现错误?我真的很感激.我已经把头发拉了很长时间.
红宝石
require 'rubygems'
require 'serialport' # use Kernel::require on windows, works better.
#params for serial port
port_str = "/dev/tty.usbserial-A700dZt3" #may be different for you
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
i = 15
#just write forever
while true do
sp.write(i.to_s(2))
sleep 10
end
Run Code Online (Sandbox Code Playgroud)
Arduino的
int ledPin = 10;
int ledPin1 = 11;
int ledPin2 = 12;
int ledPin3 = 13;
byte incomingByte; // for …Run Code Online (Sandbox Code Playgroud) 我在一个子模块中工作,并且无法解开一个装满文件的文件夹
$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: public/javascripts/app/fckeditor/editor/skins/office2003/fck_dialog.css
# modified: public/javascripts/app/fckeditor/editor/skins/office2003/fck_editor.css
# modified: public/javascripts/app/fckeditor/editor/skins/silver/fck_dialog.css
# modified: public/javascripts/app/fckeditor/editor/skins/silver/fck_editor.css
# modified: public/javascripts/app/fckeditor/fckconfig.js
# modified: public/javascripts/app/fckeditor/fckeditor.js
# modified: public/javascripts/app/fckeditor/fckpackager.xml
Run Code Online (Sandbox Code Playgroud)
我打字
git reset --hard
Run Code Online (Sandbox Code Playgroud)
返回
HEAD现在在b2c5a77什么都没有
但是当我打字的时候
git status
Run Code Online (Sandbox Code Playgroud)
我再次受到长长的文件列表的欢迎.我试过了
git clean -f
Run Code Online (Sandbox Code Playgroud)
并删除整个子模块并从主服务器检出.我还试图删除子模块所属的整个项目,拉出然后启动并更新子模块但无济于事.
rm -rf project
git clone foo@bar.project.net:/home/rails/repo/gits/project.com
#Cloning …Run Code Online (Sandbox Code Playgroud) 我在Google Go lang中实施AWS Request Authentication
package main
import "fmt"
import "crypto/hmac"
import "crypto/sha256"
import "time"
import "encoding/base64"
func main() {
AWSAccessKeyId := "MHAPUBLICKEY"
AWSSecretKeyId := "MHAPRIVATEKEY"
sha256 := sha256.New
time := time.Now().UTC().Format(time.ANSIC)
hash := hmac.New(sha256, []byte(AWSSecretKeyId))
hash.Write([]byte(time))
sha := base64.URLEncoding.EncodeToString(hash.Sum(nil))
fmt.Println("Date", time)
fmt.Println("Content-Type","text/xml; charset=UTF-8")
fmt.Println("AWS3-HTTPS AWSAccessKeyId=" + AWSAccessKeyId + ",Algorithm=HmacSHA256,Signature=" + sha)
}
Run Code Online (Sandbox Code Playgroud)
我从亚马逊获得有效输出,但只有当'sha'哈希不包含任何_或 - 时
工作
'WFKzWNQlZEyTC9JFGFyqdf8AYj54aBj5btxPIaGTDbM ='
不工作HTTP/1.1 403 Forbidden SignatureDoesNotMatch
'H-FIs7of_CJ7LusAoQPzSWVt9hlXF_5gCQgedn_85lk ='
如何对AWS3-HTTPS标头进行编码,使其适用于任何一种情况?只是因为它是相关的,我目前正在复制并将输出粘贴到cURL中.我计划在Google Go中实现请求,并使其可靠地运行.
例如,如何从Savon请求中删除HTTP标头
client.request 'v5:ProcessShipments' do
client.http.headers["SOAPAction"] = "example_post"
end
Run Code Online (Sandbox Code Playgroud)
这会产生
DEBUG -- : SOAPAction: example_post
Run Code Online (Sandbox Code Playgroud)
服务器会响应
Server did not recognize the value of HTTP Header SOAPAction: example_post.
Run Code Online (Sandbox Code Playgroud)
但是,我不想要任何SOAPAction(s)
我试图清除变量并删除它.我搜索了一会儿,找不到任何东西,所以我希望以前没有问过.
提前致谢.
如果我不覆盖它,那么默认情况下Savon将使用client.request'v5:ProcessShipments',这也是不正确的.
我不明白为什么
(var ||= []) << 1
Run Code Online (Sandbox Code Playgroud)
按预期工作但是
(var ||= true) = false
Run Code Online (Sandbox Code Playgroud)
没有.
任何人都可以解释为什么它不起作用,这里发生了什么?
class Account < ActiveRecord::Base
after_update :give_user_credit, :on => :update
def give_user_credit
credit = User.current_user.credit + 3.8
User.current_user.update_attribute(:credit, credit)
end
end
Run Code Online (Sandbox Code Playgroud)
当我使用它时服务器挂起,当我完全重新启动后回到应用程序时,我的信用额度为1000英镑.
这里发生了什么..
感谢:D
ruby ×6
go ×2
activerecord ×1
arduino ×1
average ×1
date ×1
git ×1
header ×1
http ×1
loops ×1
marshalling ×1
model ×1
savon ×1
serial-port ×1
xml ×1