使用json_encode
编码日期的阵列,它有时做一两件事,有时做另一个.
例如,如果我正在尝试编码如下:
array(6) {
[0]=>
string(6) "Jun-24"
[1]=>
string(6) "Jun-25"
[2]=>
string(6) "Jun-28"
[3]=>
string(11) "Training-24"
[4]=>
string(6) "Jun-29"
[5]=>
string(6) "Jun-30"
}
Run Code Online (Sandbox Code Playgroud)
它会输出
["Jun-24","Jun-25","Jun-28","Training-24","Jun-29","Jun-30"]
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试编码类似的东西时:
array(17) {
[0]=>
string(6) "Jun-23"
[1]=>
string(6) "Jun-24"
[2]=>
string(6) "Jun-28"
[3]=>
string(11) "Training-24"
[4]=>
string(6) "Jun-29"
[5]=>
string(6) "Jun-30"
[6]=>
string(6) "Jul-06"
[7]=>
string(6) "Jul-07"
[9]=>
string(6) "Jul-09"
[10]=>
string(6) "Jul-16"
[11]=>
string(6) "Jul-17"
[12]=>
string(6) "Jul-20"
[13]=>
string(6) "Jul-23"
[14]=>
string(6) "Jul-24"
[15]=>
string(6) "Jul-30"
[16]=>
string(6) "Aug-01"
[17]=>
string(6) …
Run Code Online (Sandbox Code Playgroud) 如何将参数添加到以下Entity Framework原始SQL命令?例如,如果我想创建Id
一个参数怎么办?
using (var context = new NorthwindDBEntities())
{
context.Database.ExecuteSqlCommand(@"
UPDATE dbo.Customers
SET Name = 'Test' WHERE Id = 1
");
}
Run Code Online (Sandbox Code Playgroud) 我试图计算Windows中已用磁盘空间的百分比,而totaldrive表示Long中的C驱动器的总磁盘空间和Long中的freedrive dentoes可用空间.
long totaloccupied = totaldrive - freedrive;
Run Code Online (Sandbox Code Playgroud)
这里计算使用百分比
Long Percentageused =(totaloccupied/totaldrive*100);
System.out.println(Percentageused);
Run Code Online (Sandbox Code Playgroud)
print语句返回0.有人可以提供帮助,因为我没有得到所需的值
我通常写我自己ToJSON
和FromJSON
实例,但我决定用deriveJSON
一个类型,因为它是如此简单:
data Priority = HIGH | MEDIUM | LOW deriving Show
$(deriveToJSON id ''Priority)
main = BS.putStrLn . encode $ HIGH
Run Code Online (Sandbox Code Playgroud)
我本来希望JSON
推导只是将枚举写为字符串。相反,它是哈希的关键!{"HIGH":[]}
为什么这是默认行为?
我想获得完美的消耗时间或从开始时间到结束时间的总时间:
我的代码:
$start_time = $this->input->post('start_time');
$end_time = $this->input->post('end_time');
$t1 = strtotime($start_time);
$t2 = strtotime($end_time);
$differenceInSeconds = $t2 - $t1;
$differenceInHours = $differenceInSeconds / 3600;
if($differenceInHours<0) {
$differenceInHours += 24;
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中, if $start_time
= 11:00:00 PM
,$end_date =11:30:00
它给了我输出0.5
而不是30minutes
。有什么合适的方法可以这样做吗?
所以如果:
$start_time = '01:00:00 PM';
$end_time = '01:25:00 PM';
$total = '25:00'; // 25 minutes
Run Code Online (Sandbox Code Playgroud)
或者:
$start_time = '11:00:00 PM';
$end_time = '11:00:25 PM';
$total = '00:00:25'; // 25seconds
Run Code Online (Sandbox Code Playgroud)
问候!
说我有这两个Backbone.Marionette视图:
var FooView = Backbone.Marionette.ItemView.extend({
tagName: p,
id: 'foo',
template: this.templates.summary
});
var BarView = Backbone.Marionette.ItemView.extend({
template: this.templates.summary
});
Run Code Online (Sandbox Code Playgroud)
然后我想在app区域中显示它们,如下所示:
App.contentRegion.show(new FooView/BarView());
Run Code Online (Sandbox Code Playgroud)
第一个视图将创建一个新视图
元素并将其附加到该地区.我认为第二种方式更像是标准的Backbone视图,并将自身附加到区域而不创建新元素,但它将其包装在标记中.有没有办法避免这种情况而不使用像setElement()这样的东西?
我是开发rails应用程序的新手,所以在大多数情况下,我只依靠rails generate命令来为整个应用程序制作支架.虽然我的应用程序的每个其他部分都可以正常工作,但这个部分会在自动生成后立即引发错误.
错误如下:
NoMethodError in ConfigurationsController#index
undefined method `all' for ActiveSupport::Configurable::Configuration:Class
Run Code Online (Sandbox Code Playgroud)
这是包含所述无方法调用的代码片段
def index
@configurations = Configuration.all
end
Run Code Online (Sandbox Code Playgroud)
这是所述模型
class Configuration < ActiveRecord::Base
belongs_to :users, class_name: 'User', foreign_key: 'user_id'
end
Run Code Online (Sandbox Code Playgroud)
我添加了belongs_to部分...无论如何,当我通过http://localhost.localhost:3000/users/1/configurations /运行它时,会弹出错误!(是的,我使用嵌套路线)
所以我点击rails控制台来检查Configuration.all返回什么,然后看看
2.0.0-p247 :004 > Configuration.all
Configuration Load (0.3ms) SELECT "configurations".* FROM "configurations"
=> #<ActiveRecord::Relation [#<Configuration id: 1, user_id: 1, port: 3000, host: "example.org", annoy: 5000, version: "1", machines: nil, created_at: "2013-08-08 02:15:32", updated_at: "2013-08-08 02:15:32">]>
Run Code Online (Sandbox Code Playgroud)
我有点迷失为什么该方法在rails控制台中工作然后在浏览器的html视图中失败.我做错什么了吗?
另外,这是webrick的输出,以防有人找到它
Started GET "/users/1/configurations/" for 192.168.1.105 at 2013-08-08 10:24:59 +0800 …
Run Code Online (Sandbox Code Playgroud) 编辑:我想,从下面我和@joran的讨论中,@ joran帮助我弄清楚如何 dist
改变距离值(它似乎是通过值[总尺寸]/[非缩放坐标的平方和 - 丢失尺寸],但这只是猜测).如果有人知道的话,我想知道的是:那是真的发生了什么?如果是这样,为什么这被认为是合理的事情呢?是否可以,或者应该有选择以dist
我提出的方式计算它(这个问题可能是模糊的或固执的性质来回答).
我想知道dist
函数如何在具有缺失值的向量上实际工作.下面是一个重新创建的例子.我使用dist
函数和更基本的实现我认为应该是欧几里德距离与sqrt,sum和powers的定义.我还期望,如果任一向量的一个组成部分NA
,那个维度将被抛出总和,这就是我实现它的方式.但是你可以看到那个定义不符合dist
.
我将使用我的基本实现来处理NA
值,但我想知道dist
当向量具有什么时实际到达值NA
,以及为什么它不符合我在下面如何计算它.我认为我的基本实现应该是默认/常用的,我无法弄清楚dist
使用什么替代方法来获得它所获得的内容.
谢谢,马特
v1 <- c(1,1,1)
v2 <- c(1,2,3)
v3 <- c(1,NA,3)
# Agree on vectors with non-missing components
# --------------------------------------------
dist(rbind(v1, v2))
# v1
# v2 2.236068
sqrt(sum((v1 - v2)^2, na.rm=TRUE))
# [1] 2.236068
# But they don't agree when there is a missing component
# Under what logic does sqrt(6) make sense as …
Run Code Online (Sandbox Code Playgroud) 我有一段时间用Python表示自unix时代以来的秒数.然而,Matplotlib需要自0001-01-01 UTC以来的几天(http://matplotlib.org/api/dates_api.html).
如何将自unix时代以来的秒数转换为自0001-01-01 UTC以来的天数?
我正在尝试一些非常简单的东西,在我想要的文本和图像链接中.
= link_to 'NVidia Graphics', inventory_url, class: 'lato' do
= image_tag 'list-highlighter.png'
Run Code Online (Sandbox Code Playgroud)
我希望输出类似于:
<a href="/inventory">
NVidia Graphics
<img src="list-highlighter.png" />
</a>
Run Code Online (Sandbox Code Playgroud)
如何使用Slim实现这一目标?我当前的代码导致网站崩溃.
用于" http://foobar.com/inventory "的未定义方法`stringify_keys' :String