抱歉,标题含糊不清!我有一个包含大量 PDF 文件且每月带宽有限的网站。我想要实现的(在 PHP 中)是一种将每个用户($_SESSION?)限制在某个限制的方法 - 比如说 50MB,超过这个限制,当他们点击下载另一个文件时,他们将被重定向到一个网页,拒绝任何进一步的下载(在接下来的 24 小时内,比如说)。
这可能吗?我不确定我的下载“计数器”是否只能计算.pdf文件(如果访问者达到限制,我不希望访问者被阻止浏览站点)。任何伪代码将不胜感激。
我是C++的新手,我很难尝试获取一个函数(它接受一个数组)来返回一个数组.该函数是一个非常基本的排序算法,适用于大小为4的整数数组.具体如下:
int[] sortArrayAscending(int arrayToSort[3]) {
int sortedArray[3];
sortedArray[0] = minOfFour(arrayToSort[0],arrayToSort[1],arrayToSort[2],arrayToSort[3]);
sortedArray[1] = lowerMidOfFour(arrayToSort[0],arrayToSort[1],arrayToSort[2],arrayToSort[3]);
sortedArray[2] = higherMidOfFour(arrayToSort[0],arrayToSort[1],arrayToSort[2],arrayToSort[3]);
sortedArray[3] = maxOfFour(arrayToSort[0],arrayToSort[1],arrayToSort[2],arrayToSort[3]);
return sortedArray;
}
Run Code Online (Sandbox Code Playgroud)
我想我真的很困惑我需要使用的语法(函数调用min,lower,higher,max都可以正常工作.
我真的很感激一些帮助.
谢谢
EDIT2:感谢您的所有评论.由于@ Rook和@Bob Yoplait的回答,我现在已经解决了这个问题.代码用于:
int* sortArrayAscending(int arrayToSort[4], int sortedArray[4]) {
sortedArray[0] = minOfFour(arrayToSort[0],arrayToSort[1],arrayToSort[2],arrayToSort[3]);
sortedArray[1] = lowerMidOfFour(arrayToSort[0],arrayToSort[1],arrayToSort[2],arrayToSort[3]);
sortedArray[2] = higherMidOfFour(arrayToSort[0],arrayToSort[1],arrayToSort[2],arrayToSort[3]);
sortedArray[3] = maxOfFour(arrayToSort[0],arrayToSort[1],arrayToSort[2],arrayToSort[3]);
return sortedArray;
}
int _tmain(int argc, _TCHAR* argv[])
{
int testNumbers[4] = {8,14,1,27};
int testSorted[4];
sortArrayAscending(testNumbers,testSorted);
for (int i = 0; i < 4; i++) {
cout << testSorted[i] << endl;
}
system("pause");
return …Run Code Online (Sandbox Code Playgroud) 我继承了以下代码:
// Show / Hide table rows from checkboxes
$("table.data#report-table .warning").toggle($("#warning_checkbox").is(":checked"));
$("#warning_checkbox").click(function() {
$("table.data#report-table .warning").toggle($("#warning_checkbox").is(":checked"));
$('.data_table#report-table').dataTable().fnDraw();
});
Run Code Online (Sandbox Code Playgroud)
选中带有id warning_checkbox的复选框时,它会显示/隐藏具有该类的行(实际上是tbody元素)table.data#report-table.warning
据我所知,'.data_table#report-table页面上没有元素 - 所以我认为某些东西不起作用.但是 - 它(神奇地?)确实如此,即表格按预期重新绘制,保留其正确的设置.但是,我在Chrome控制台中收到以下错误:
Uncaught TypeError: Cannot read property 'oFeatures' of null
Run Code Online (Sandbox Code Playgroud)
我认为可能是由于缺少元素(但那么它是如何工作的?)无论如何,我重写了代码作为函数,因为我需要在其他地方重用它:
var checkbox_rows = function(checkbox_id, table_id, tbody_class) {
var checkbox = $('div.buttons input[id$='+checkbox_id+']');
var table = $('table.data[id$='+table_id+']');
checkbox.click(function() {
$('tbody[class$='+tbody_class+']', table).toggle(checkbox.is(':checked'));
table.fnDraw();
});
}
checkbox_rows('warning_checkbox', 'report-table', 'warning');
Run Code Online (Sandbox Code Playgroud)
这也有效(对我来说更有意义) - 但现在我在Chrome控制台中收到了不同的错误:
Uncaught TypeError: Object [object Object] has no method 'fnDraw'
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,我做错了什么?重绘DataTable的正确方法是什么?
谢谢
关于使用SSL证书部署Rails应用程序,我有几个问题.
背景:
根据https://gist.github.com/fnichol/867550,使用Ruby的Windows客户端net/http不信任Ubuntu服务器上的证书.我假设这是因为SSL_CERT_FILE没有设置环境变量(尽管内部根证书安装在Ubuntu服务器上并通过组策略部署到Windows客户端..?)
我希望能够从我的应用程序的任何客户端(Windows或Ubuntu)运行以下代码片段
require 'net/http'
uri = URI.parse('https://ubuntu-server.internal.com/')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.start { |agent| agent.get(uri.path) }
Run Code Online (Sandbox Code Playgroud)
我应该将内部CA根证书(和中间证书,以及CURL证书捆绑的其余部分)与应用程序捆绑在一起,然后ENV['SSL_CERT_FILE']在代码中设置吗?)
我应该只在应用程序中包含内部CA根证书,并使用初始化程序在使用前设置net/http吗?这似乎是RubyInstaller https://github.com/oneclick/rubyinstaller/blob/master/rake/contrib/uri_ext.rb#L287-295的方法,但我真的不知道如何编写这个?
别的什么?
到目前为止,选项2对我来说似乎是最好的,但正如我所说,我不知道我将如何设置
http.use_ssl = true
http.ca_file = "#{Rails.root}/config/internal-ca.crt"
Run Code Online (Sandbox Code Playgroud)
在Rails初始化程序中.
任何帮助/建议将不胜感激.
谢谢
我有一个采用DateTime(当前为字符串)的方法,然后将其转换为DateTime对象,例如:
def foo(time)
the_time = Time.parse(time)
...
end
Run Code Online (Sandbox Code Playgroud)
所以,
foo("2012-09-03")
Run Code Online (Sandbox Code Playgroud)
我还希望能够解析DateTime对象:
foo(Time.now)
Run Code Online (Sandbox Code Playgroud)
但是Time.parse抱怨我没有给它一个字符串:
NoMethodError: undefined method `gsub!' for 2012-08-08 15:59:00 UTC:Time
Run Code Online (Sandbox Code Playgroud)
有没有一种优雅的方法(一行?)从字符串或DateTime对象返回DateTime对象(我宁愿避免使用if语句)
谢谢
编辑:感谢您的评论-我并没有真正反对使用if语句,我只是在看是否有更好的东西
说我有一张桌子,values看起来像:
id|field_id|value|date
1 |1 |2 |2013-06-01
2 |2 |5 |2013-06-01
3 |1 |3 |2013-06-02
4 |2 |9 |2013-06-02
5 |1 |6 |2013-06-03
6 |2 |4 |2013-06-03
Run Code Online (Sandbox Code Playgroud)
另一张表,fields看起来像
id|code
1 |small_value
2 |large_value
Run Code Online (Sandbox Code Playgroud)
我想从values哪里选择small_value大于large_value相同的行date.因此,对于上面的示例,查询应返回自from 6,(field_id= 1== small_value)> 4(field_id= 2== large_value)以来的最后两行.
数据库是Microsoft SQL Server 2012.
谢谢你的帮助
我一直在尝试为我们的内部Rails应用程序使用SSL(SAN)证书.
我使用OpenSSL创建了证书文件,并让它们与Apache很好地协同工作:
<VirtualHost *:443>
ServerName server-name
RailsEnv uat
DocumentRoot /var/www/server-name/current/public
<Directory /var/www/server-name/current/public>
AllowOverride All
Options -MultiViews
</Directory>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/hostname.cer
SSLCertificateKeyFile /etc/apache2/ssl/hostname.key
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
这很好用.
我的问题是当使用open-uri与某些Rails控制器通信时,我收到错误消息:
require "net/https"
uri = URI.parse("https://server-name.domain.com/controller.json?date=2013-09-03")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.start {
http.request_get(uri.path) {|res|
print res.body
}
}
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
Run Code Online (Sandbox Code Playgroud)
我看过许多StackOverflow文章建议只需关闭SSL验证,使用:
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
Run Code Online (Sandbox Code Playgroud)
但我不认为这是一种令人满意的方法.我也看到这表明我需要指出的文章open-uri,以/etc/ssl/certs/ca-certificates.crt这显然是公共证书.所以对于我的自签名证书,我尝试了以下内容:
uri = URI.parse("https://server-name.domain.com/controller.json?date=2013-09-03")
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == "https" …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的数据帧:
item price source day
book 5 shop 2012-01-01
car 100 shop 2012-01-01
desk 10 shop 2012-01-01
book 4 internet 2012-01-01
car 99 internet 2012-01-01
desk 9 internet 2012-01-01
book 6 shop 2012-01-02
car 101 shop 2012-01-02
desk 11 shop 2012-01-02
book 4 internet 2012-01-02
car 100 internet 2012-01-02
desk 10 internet 2012-01-02
Run Code Online (Sandbox Code Playgroud)
我想,每天,每个项目的每个价格,如:
item price.shop price.internet day
book 5 4 2012-01-01
car 100 99 2012-01-01
desk 10 9 2012-01-01
book 6 5 2012-01-02
car 101 100 2012-01-02
desk 11 …Run Code Online (Sandbox Code Playgroud) 说我有三个型号:
class Foo < ActiveRecord::Base
has_many :things
end
class Thing < ActiveRecord::Base
belongs_to :foo
belongs_to :other_thing
end
class OtherThing
has_many :things
end
Run Code Online (Sandbox Code Playgroud)
我怎样才能从以下方面出发Foo并急切地加载OtherThing:
Foo.includes([:things => [:other_things]})
我搜索过但找不到任何东西.
谢谢