我不确定为什么,但是当我设置此设置时,它无法编译
set :static_cache_control, [:public, :max_age => 300]
这就是我得到的
syntax error, unexpected tASSOC, expecting ']' (SyntaxError)
set :static_cache_control, [:public, :max_age => 300]
^
我只想为css,javaascript和图像文件设置"expires"标头.
谢谢.
我只是希望得到关于这个我一直在辩论的其他意见,例如我有类user_controller和类用户
class User
attr_accessor :name, :username
end
class UserController
// do something about anything about users
end
问题是我的User类中应该有逻辑吗?
user = User.new
user.do_something(user1)
or it should be
user_controller = UserController.new
user_controller.do_something(user1, user2)
我不确定哪一个是最好的设计,我个人非常喜欢第一个,所以例如它会读起来像
john = User.new
john.accept_friend(jane)
instead of
user_controller = UserController.new
user_controller.accept_friend(john, jane)
这些模式的优缺点是什么?这不仅仅是针对Ruby的,因为我的东西ruby在打字时更容易.
编辑:真的有很好的转换,但我更喜欢这里的人.感谢大家.
我正在尝试在Vagrant上为我的开发环境安装Jenkins.
我为我的盒子选择了Ubuntu http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-vagrant-amd64-disk1.box.这是我用来配置我的盒子的shell.一切都很顺利,但当我尝试从端口80或甚至8080访问该框时,它只是没有响应.浏览一直在旋转.不知道我在这里做错了什么.
这是我的剧本.
sudo apt-get update
echo "APT::Cache-Limit "100000000";" >> /etc/apt/apt.conf.d/70debconf
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get -y --force-yes install jenkins
sudo apt-get -y --force-yes install apache2
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod vhost_alias
sudo a2dissite default
echo '
ServerAdmin webmaster@localhost
ServerName ci.company.com
ServerAlias ci
ProxyRequests Off
Order deny,allow
Allow from all
ProxyPreserveHost on
ProxyPass / http://localhost:8080/
' >> /etc/apache2/sites-available/jenkins
sudo a2ensite jenkins
sudo …Run Code Online (Sandbox Code Playgroud) 我正在尝试针对XSD验证非常XML(~200MB).这花了将近3个小时.我不确定我在这里做错了什么?
SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new File(this.productExtraInfoXsd));
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = builder.parse(new File(filePath));
DOMSource domSource = new DOMSource(doc);
DOMResult result = new DOMResult();
Validator validator = schema.newValidator();
validator.validate(domSource, result);
Run Code Online (Sandbox Code Playgroud) 在接受采访时我被问到实施二分搜索以改善搜索时间,我想出了这个.我回到家测试它,但看起来线性搜索比我的二分搜索更好.我在这里做错了吗?
import time
sorted_list = range(0, 10000000)
needle = 9999999
def split_list(sorted_list):
half = len(sorted_list)/2
return sorted_list[:half], sorted_list[half:]
def bisection(haystack, needle, length_of_list):
if len(haystack) <= length_of_list/5:
return haystack
first, last = split_list(haystack)
if needle < first[-1]:
return bisection(first, needle, length_of_list)
else:
return bisection(last, needle, length_of_list)
def linear_search(smaller_ist):
for ele in smaller_list:
if ele == needle:
return 0
start_time = time.time()
smaller_list = bisection(sorted_list, needle, len(sorted_list))
print linear_search(smaller_list)
print("--- %s seconds ---" % (time.time() - start_time))
start_time = time.time()
print linear_search(sorted_list) …Run Code Online (Sandbox Code Playgroud) 我正在通过S3和Cloudfront提供静态内容。但是,Google Pagespeed标记未指定为缓存头,因此我转到了Cloudfront设置并进行了更改。

一旦发布被部署。Google Pagespeed仍然无法识别。
我还将缓存控制添加到S3上的对象。当我直接从S3中命中对象时,我可以看到响应头,但是当我使用Cloudfront URL时,我看不到缓存控制头。
这是我得到的回应
Accept-Ranges:bytes
Age:641
Connection:keep-alive
Content-Length:44715
Content-Type:image/png
Date:Fri, 17 Jul 2015 18:39:50 GMT
ETag:"e0b19573b90781f60f8865705c80f11d"
Last-Modified:Fri, 17 Jul 2015 17:50:27 GMT
Server:AmazonS3
Via:1.1 (CloudFront)
X-Amz-Cf-Id:
X-Cache:Hit from cloudfront
Run Code Online (Sandbox Code Playgroud) 我有一个函数,如果发现任何东西,它将查找缓存,否则它将继续并获取数据并设置缓存。这是很标准的。我想知道错误是否发生在最内部的函数上,它将使气泡上升到最外部的Promise吗?因此,我只能拥有一个catch而不是一个。
这是我的代码。
我正在使用蓝鸟
var _self = this;
return new Promise(function(resolve, reject) {
_self.get(url, redisClient).then(function getCacheFunc(cacheResponse) {
if(cacheResponse) {
return resolve(JSON.parse(cacheResponse));
}
webCrawl(url).then(function webCrawl(crawlResults) {
_self.set(url, JSON.stringify(crawlResults), redisClient);
return resolve(crawlResults);
}).catch(function catchFunc(error) {
return reject(error); // can I delete this catch
});
}).catch(function getCacheErrorFunc(cacheError) {
return reject(cacheError); // and let this catch handle everything?
});
});
Run Code Online (Sandbox Code Playgroud) 我正在使用amqplib它试图实现重新连接机制。但是,重新建立连接后,我的频道似乎仍处于关闭状态。我该如何解决这个问题?这是我的代码。
var pubQueue = [];
module.exports = {
connect: function (callback) {
var self = this;
amqp.connect(config.queue.url, function(err, connection) {
if (err) {
console.error("[AMQP]", err.message);
return setTimeout(module.exports.connect, 2000);
}
connection.on("error", function(err) {
if (err.message !== "Connection closing") {
console.error("[AMQP] conn error", err.message);
}
});
connection.on("close", function() {
console.error("[AMQP] reconnecting");
return setTimeout(module.exports.connect, 2000);
});
connection.createChannel(function(err, ch) {
console.log('connection is reestablished');
self.channel = ch;
return callback ? callback() : false;
});
});
},
publish: function (message, callback) {
var self …Run Code Online (Sandbox Code Playgroud) 我的Nginx中有此配置
server {
listen 8080;
add_header Access-Control-Allow-Origin *;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Content-Type';
}
Run Code Online (Sandbox Code Playgroud)
现在,我有我的web应用程序,它确实GET和POST为GET它工作正常,但如果我这样做阿贾克斯POST我得到这个错误
XMLHttpRequest无法加载'URL'。对预检请求的响应未通过访问控制检查:请求的资源上不存在“ Access-Control-Allow-Origin”标头。因此,不允许访问来源“来源”。响应的HTTP状态码为404。
如果我执行“ GET”请求,则可以在响应中看到这一点。
Access-Control-Allow-Headers:Content-Type
Access-Control-Allow-Methods:GET, POST, OPTIONS
Access-Control-Allow-Origin:*
Run Code Online (Sandbox Code Playgroud)
但是,如果我发表文章,我什么也看不到。
我使用 React 和 React Router 构建了一个 SPA。我还使用https://github.com/facebookincubator/create-react-app因为它是一个非常简单的应用程序。当我使用 webpack 进行开发时,我可以很好地看到页面。npm run build但是,在我使用from进行生产构建后create-react-app我通常会获得 HTML 文件、css 和 js。我将所有内容上传到 S3,但是当我转到该页面时,我只看到空白页面
这就是我所看到的
<!-- react-empty: 1 -->
Run Code Online (Sandbox Code Playgroud)
我猜是这样的,因为 S3 是默认的index.html,我无法更改它。React Router 不知道如何处理index.html,但我也将/root 作为默认值,但我仍然看到一个空白页面。不知道如何解决这个问题?
这是我的路由器
ReactDOM.render(
<Router history={browserHistory}>
<Route path="/" component={App}>
<IndexRoute component={Home} />
<Route path="question2" component={Question2} />
<Route path="question3" component={Question3} />
<Route path="thankyou" component={Thankyou} />
</Route>
</Router>,
document.getElementById('root')
);
Run Code Online (Sandbox Code Playgroud)
这就是模板的creawte-react-app使用,并且在开发中运行良好。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link …Run Code Online (Sandbox Code Playgroud)