我有一个基于Mechanize的Ruby脚本来抓取一个网站.我希望通过缓存在本地下载的HTML页面,使整个加速这一"调整输出 - >运行 - >调整输出"循环更快.我不想只为这个脚本在机器上安装外部缓存.理想的解决方案是插入Mechanize并透明地缓存提取的页面,图像等.
有人知道会有这样做的图书馆吗?或者另一种实现相同结果的方法(脚本第二次运行得更快)?
我正在使用rails gem kaminari(https://github.com/amatsuda/kaminari)来分页我的帖子数据库.目前我的@posts = Post.order('id').page(params[:page]).per(5)控制器中有代码,但这会将页面从最早到最近排序.如何从最近到最早撤销此订单?
按住手机上的主屏幕按钮会弹出一个弹出窗口,显示最近的应用程序.有谁知道如何通过代码执行相同的操作?我需要能够在列表视图中选择一个.
与R合作时,我觉得自己有很多工具和技巧可以解决许多日常问题.然而,我经常意识到我可以更优雅地解决问题.例如,我阅读了关于类和方法的内容,但最后没有越过河流使用它们.很可能是因为我的日常工作并不需要.我仍然觉得我的创造力受到我能处理的工具的限制.
什么是起点,分别是超越某些先进/中级初学者/数据杂耍水平的好策略?
在Surface,Ruby看起来与其他对象orieinted语言非常相似,如Java,Php,C等.
但是,当我们开始遇到障碍时,事情变得有点奇怪.
例如,这是有效的
(0...8).max()
=> 7
Run Code Online (Sandbox Code Playgroud)
但事实并非如此
(0...8).map(puts "hello world")
hello world
ArgumentError: wrong number of arguments(1 for 0)
Run Code Online (Sandbox Code Playgroud)
Apprantly,地图方法不带参数,但不对块,所以通过更换()与{}修复错误.
(0...8).map{puts "hello world"}
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
=> [nil, nil, nil, nil, nil, nil, nil, nil]
Run Code Online (Sandbox Code Playgroud)
然后,有一些方法应该采取 - 块和参数
8.downto(1){puts "hello world"}
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
=> 8
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是如果我应该使用(),{} …
我一直在寻找一种方法来做这件事,因为看起来他们应该是一个.
我只是想从SoundCloud页面自动拉出5个最近的曲目,并将它们放在我的网站上的"最新音频"部分下.
SoundCloud甚至自己做到了这一点.如果你去特定的曲目,在页面的右下角有一个"USERNAME的更多曲目",请看一下:http: //soundcloud.com/goldenstatewarriors/mark-jackson-on-the-dan
我发现的最接近的是:
http://api.soundcloud.com/tracks?client_id={client_id}
Run Code Online (Sandbox Code Playgroud)
但为此你需要一个client_id,用于soundcloud应用程序.我尝试注册一个应用程序,但是当我client_id将上面的内容输入到上面时,我得到了一堆不属于我的音轨:
http://api.soundcloud.com/tracks?client_id=02db8e29aa2fb5bf590f478b73137c67
我只知道必须有办法做到这一点......
我实际上正在开发我的第一个Chrome扩展程序,即使它运行顺利,我从get()我用来检索一些数据的函数和代码安全性的烦人错误中得到了很多错误.
以下是涉及的代码:
<!doctype html>
<html>
<head>
<title>NGI Little Helper - Subscribes</title>
<link rel="stylesheet" href="popup.css">
<!-- JavaScript and HTML must be in separate files for security. -->
<script type="text/javascript" src="common/jquery.js"></script>
<script type="text/javascript" src="popup.js"></script>
</head>
<body>
<h1>Topics</h1>
<div id="content">..:: Loading ::..</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
此脚本开始创建$.get()远程网页.变量的内容data可以在这里找到
$.get("http://gaming.ngi.it/subscription.php?do=viewsubscription", function(data) {
var TDs = $('td[id*="td_threadtitle_"]', data);
$(document).ready(function() {
$("#content").html("<br/>");
$.each( TDs, function() {
//Removes useless elements from the source …Run Code Online (Sandbox Code Playgroud) javascript dom google-chrome google-chrome-extension content-security-policy
HTML
<table cellpadding="0" cellspacing="0" border="0">
<thead>
<tr><th width="483"><span>Product Name</span></th></tr>
</thead>
<tbody data-bind='foreach: basket.model.products()'>
<tr><td><div class="ml10 productDetails" data-bind="text: name"></div></td></tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
JAVASCRIPT代码
var ProductLine = function(data) {
var self = this;
self.name = ko.observable(data.name);
};
function BasketModel(data) {
var self = this;
self.initialData = ko.observable(data);
self.products = ko.observableArray();
$.each(self.initialData().products,function(i,val){
self.products.push(new ProductLine(this));
});
}
function renderBasket(data){
basket = { model: new BasketModel(data)};
ko.applyBindings(basket.model);
}
$(document).ready(function(){
var sampleData = [{"name":"product 1"},{"name":"product 2"}];
renderBasket(sampleData );
});
Run Code Online (Sandbox Code Playgroud)
当我在ajax帖子中添加一个新产品到篮子时,我用响应数据调用下面的函数
renderBasket(response.data);
Run Code Online (Sandbox Code Playgroud)
实施例response.data喜欢[{ "名称": "产品1"},{ "名称": "产品2"},{ "名称": …
在Android上,我想在string.xml或其他资源文件上抑制特定字符串值或特定行的lint.
<string name="suppress_lint_string">Suppress this String</string>
<string name="dont_suppress_lint_string">Don\'t Suppress this String</string>
Run Code Online (Sandbox Code Playgroud)
我想对特定字符串和布局的特定部分执行特定的lint抑制,例如缺少特定字符串的翻译,这些字符串在语言之间并不重要.
我正在使用脚本来测试网站是否运行顺畅,基本上我每20分钟左右打开一次网站并检查响应时间等等.像这样:
while True:
MechBrowser = mechanize.Browser()
Response = MechBrowser.open("http://example.com")
time.sleep(1000)
Run Code Online (Sandbox Code Playgroud)
我知道python本身会进行垃圾收集,我们真的不应该打扰,但是当我检查网络监视器时,我总会找到几个未关闭的连接,每个连接运行1小时或更长时间.并非所有打开的连接都会挂在那里,只有其中一些.我很困惑,或者有一种方法可以手动销毁这些实例?
android ×2
javascript ×2
ruby ×2
dom ×1
html ×1
java ×1
kaminari ×1
knockout.js ×1
lint ×1
mechanize ×1
pagination ×1
python ×1
r ×1
soundcloud ×1
suppress ×1
translation ×1
xml ×1