我想使用nokogiri和自动保持Web客户端的时间mechanize.我需要通过代理服务器连接,但问题是,我不知道所述代理服务器的用户名和密码.我想获取存储在计算机上的此代理的缓存凭据.
例如,c#您可以使用:
string proxyUri = proxy.GetProxy(requests.RequestUri).ToString();
requests.UseDefaultCredentials = true;
requests.Proxy = new WebProxy(proxyUri, false);
requests.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
Run Code Online (Sandbox Code Playgroud)
这将获取已记录的凭据并使用它们来访问代理,Ruby有什么类似的东西吗?我知道你可以在ruby中使用代理,而且它很简单,但是我无法获得代理的任何信息(用户名密码).此代理不允许我连接到网络.有没有办法可以获得缓存的凭据(用户名,密码)并访问代理?或者,如果不可能,有办法吗?
运行带节点的程序时:
node test.js
Run Code Online (Sandbox Code Playgroud)
你怎么检查程序是否ARGV在运行时给出node test.js --example?到目前为止我尝试的是以下内容:
function say(input){
console.log(input);
}
if(process.argv[1] !== '')
{
say('false');
}
else {
say('success');
}
Run Code Online (Sandbox Code Playgroud)
if(process.argv[1] === null)
{
say('false');
}
else {
say('success');
}
Run Code Online (Sandbox Code Playgroud)
然而,第一个解决方案不会输出else,第二个解决方案只输出,NUL is not defined所以我想的是我在编码时犯了一些错误?
我对Perl非常新,所以我很抱歉,如果这是一个非常简单的问题,我正在创建一个带有数组并随机返回的小程序,问题是我不确定我是否理解如何返回一个随机排序的数组在Perl.我希望这个数组随机返回50次:
x @array = ("O", "I", "S", "Z", "L", "J", "T")
print x @array = rand(@array);
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我已经尝试过rand函数,但它在输出中给出了这个错误:
数组找到运算符在random.pl lone 1处的预期位置,在random.pl第1行的行结束语法错误,在"x @ array"附近执行random.pl由于编译错误而中止.
正如你所看到的,如果有人可以帮助我的话我就是Perl的新手,我将不胜感激
在安装 Ruby gems 时,我收到以下错误:
ERROR: Could not find a valid gem 'bundler' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - Errno::ETIMEDOUT:
Failed to open TCP connection to api.rubygems.org:443 (A connection attempt fai
led because the connected party did not properly respond after a period of time,
or established connection failed because connected host has failed to respond.
- connect(2) for "api.rubygems.org" port 443) (https://api.rubygems.org/specs.4.
8.gz)
Run Code Online (Sandbox Code Playgroud)
我尝试安装的宝石:
NokogiriMechanizeBundler (明显地)都产生相同的错误,我猜这是所有的宝石,而不仅仅是捆绑器。
我以前从未见过这个,所以我不知道该怎么办,有人能告诉我发生了什么吗?值得一提的是,我在一个安全的网络上。
更新:
我试图在我的防火墙中初始化一个新规则,它允许我通过端口 443( …
目前,我正在学习JavaScript和正在学习基本OOP的freecodecamp.我正是在这一点上,我正在创建一个对象,并试图让这个对象返回我希望它返回的内容.
该项目的整个描述是:
对象有自己的属性,称为属性,以及它们自己的函数,称为方法.
在之前的挑战中,我们使用this关键字来引用当前对象的公共属性.
我们还可以创建私有属性和私有方法,这些方法无法从对象外部访问.
为此,我们使用我们熟悉的var关键字在构造函数内创建变量,而不是将其创建为此属性.
当我们需要存储有关对象的信息但我们想控制外部代码如何使用它时,这非常有用.
例如,如果我们想要存储我们的汽车行驶速度但我们只希望外部代码能够通过加速或减速来修改它,那么速度会如何变化?
在编辑器中,您可以看到实现此模式的Car构造函数的示例.
现在亲自尝试吧!修改Bike构造函数以使用名为gear的私有属性和两个名为getGear和setGear的公共方法来获取和设置该值.
现在我理解了它如何工作的基本概念,我理解我正在做什么,但是我也在使用它node terminal来自己尝试和调试,我得出的结论是该程序将齿轮加在一起每次:
> var Bike = function() {
...
... // Only change code below this line.
... var gear = 0;
...
... this.setGear = function(switchGear){
... gear += switchGear;
... };
...
... this.getGear = function() {
... return gear;
... };
... };
undefined
> var myBike = new Bike();
undefined
> myBike.setGear(4);
undefined
> myBike.getGear();
4
> myBike.setGear(4);
undefined
> …Run Code Online (Sandbox Code Playgroud) 我写了一个小脚本来生成一个随机的 URL,它可以工作,但是我希望生成的 URL 有点可信,这意味着我希望它生成真实的单词。截至目前,它生成 7 个随机字符和数字。
def generate_url(length=7)
protocall = %w(https:// http://)
body = rand(36**length).to_s(36)
num = rand(1..999).to_s
url = "#{protocall.sample.to_s}#{body}.com/php?id=#{num}"
puts url
end
#<= http://s857yi5.com/php?id=168
#<= https://6rm0oq3.com/php?id=106
#<= http://skhvk1n.com/php?id=306
Run Code Online (Sandbox Code Playgroud)
所以我正在寻找的是一种更简单的方法,用真实的单词代替随机的 7 个字符串(请保持在 7 到 10 个字符之间)而不使用外部 gem
我的操作系统是 Windows 7
我一直在尝试根据一天中的时间输出Morning或。Afternoon我把时间变成了字符串,并尝试与它进行比较。这是我所拥有的:
t = Time.now
# => 2016-05-11 07:18:10 -0500
if t.to_s >= '12:00'
'Good afternoon'
else
'Good morning'
end
# => "Good afternoon"
Run Code Online (Sandbox Code Playgroud)
它默认为"Good afternoon". 为什么是这样?是因为 Ruby 将时间设置为 24 小时制吗?或者是编码中的某些内容?
我正在创建一个程序,可以使向用户编写电子邮件的任务变得更容易,但是我需要找到一种方法来跳过周六和周日,在我们的待处理电子邮件过程中,用户有 6 天的时间进行回复,所以我需要一种方法让 Ruby 的Date课程跳过周六和周日,并准确计算不包括周末的 6 天。
例如:
require 'date'
date = Date.today
#=> #<Date: 2016-05-06 ((2457515j,0s,0n),+0s,2299161j)>
new_date = date + 6
#=> #<Date: 2016-05-12 ((2457521j,0s,0n),+0s,2299161j)>
new_date.strftime('%A')
#=> "Thursday"
date.strftime('%A')
#=> "Friday"
Run Code Online (Sandbox Code Playgroud)
显然这个例子计算的是周六和周日,那么我如何跳过这两天并保持计数准确呢?
ARGV由于我无法安装外部宝石,我编写了一个用作参数的程序.
我到目前为止所做的是:
if ARGV[0] == '-h'
puts "Help page"
elsif ARGV[0] == '--example'
puts "Examples page"
elsif ARGV[0] == '-t'
puts "Gathering intel"
elsif ARGV[0] == '--version'
puts "Version mode"
elsif ARGV[0] == '--dev-mode'
puts "developer mode"
else
puts "Help page"
end
Run Code Online (Sandbox Code Playgroud)
这对我来说似乎不是惯用语.所以我的问题是,是否有正确的方法来解析ARGVRuby脚本中的参数?我做过一些研究,看过人们使用ARGV.shift等等,这是Ruby世界中的"首选"吗?
我正在创建一个小程序,可以选择3种不同的语言,并输出Ruby,Python或数组中的随机元素.
但是我的if语句显然有一个语法错误,因为无论我尝试什么,我都会得到这个:
syntax error at test.pl line 15, near ") {"
syntax error at test.pl line 17, near "} elsif"
Execution of test.pl aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud)
这是我现在的代码:
sub welcome {
my @choices = qw( Perl Python Ruby );
my $lang = 3;
print("Welcome, to the test script, this will test what language you would like to learn.. In order to find out these choices, write this same definition in all three different languages\n");
print("There are", $lang, "languages to …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个程序来提供文件的完整路径。这可以使用 来完成File.absolute_path,但它还会将文件名添加到路径中。例如,
def test
path = File.absolute_path("test.rb")
puts path
end
#=> C:/users/james/myscripts/test/test.rb
Run Code Online (Sandbox Code Playgroud)
我需要排除最后一部分/test.rb,以便路径仅包含:C:/users/james/myscripts/test。有没有办法做到这一点?
我有这些网址:
http://www.jobbsafari.se/jobbsoekning?q=trainers.php%253Fid%253D'%2Band''
http://www.jobbsafari.se/jobbsoekning?q=trainers.php?id%253D%2Band'
http://tay-sen.com.ua/trainers.php?id=12%26action=show_photos%26m_lang_id=9'
Run Code Online (Sandbox Code Playgroud)
我需要将它们编码回真正的URL.现在我正在使用:
string = ARGV[0]
string.gsub("%25", '%').gsub("%53", "S").gsub(etc..)
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来做多个gsubing而不必做.gsub.gsub.gsub?