我在windows中做一些ruby脚本,包括打开和关闭浏览器.为此,我需要一些特殊的宝石来连接本机Windows系统调用.但是当我尝试的时候
> gem install sys-proctable
Run Code Online (Sandbox Code Playgroud)
它屈服了
ERROR: Could not find a valid gem ´sys-proctable´ (>= 0), here is why:
Found sys-proctable (0.9.0), but was for platforms x86-darwin-8
,x86-freebsd-7 ,x86-solaris-2.10 ,x86-linux ,x86-mswin32-60
Run Code Online (Sandbox Code Playgroud)
问题是我的gem安装没有x86-mswin32-60 rubygems平台
> gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32]
...
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
...
Run Code Online (Sandbox Code Playgroud)
似乎问题来自我使用mingw库编译的ruby版本.所以我的问题是:如何获得ruby版本,rubygems平台包含x86-mswin32-60?我找不到任何来自rubyinstaller.org的安装程序,这些安装程序不是mingw.
---编辑---
最后一部分有点草率.实际上,rubyinstaller.org具有为mswin32构建的传统一键式安装程序.但是这个安装对我来说还有一些问题,所以我想我会尝试下面的Luis解决方案.
#include <iostream>
#include <memory>
using namespace std;
int main () {
auto_ptr<int> p;
p.reset (new int);
*p=5;
cout << *p << endl;
p.reset (new int);
*p=10;
cout << *p << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 采用以下类和两个对象定义:
class Rect{
public:
enum centimeter;
enum meter;
Rect(double len,double wid,enum centimeter){
length=(len/100);
width=(wid/100);
}
Rect(int len,int wid,enum meter){
length=len;
width=wid;
}
//rest of implementation
private:
double length;//in meters
double width;//in meters
};
Rect obj1(10,5,Rect::centimeter());
Rect obj2(10,5,Rect::meter());
Run Code Online (Sandbox Code Playgroud)
两个先前的构造函数具有伪枚举参数,以解决在这些伪参数不存在的情况下引起的调用歧义.现在尽管有可能在这里使用命名构造函数,如果我坚持使用这些虚拟参数,这是否违反了我应该注意的任何编码规则?
我正在尝试为mysql编写一个自定义的用户定义函数,所以我以http://www.mysqludf.org/index.php中的str_ucwords函数为例来构建我自己的函数.
my_bool str_ucwords_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
/* make sure user has provided exactly one string argument */
if (args->arg_count != 1 || args->arg_type[0] != STRING_RESULT || args->args[0] == NULL)
{
strcpy(message,"str_ucwords requires one string argument");
return 1;
}
/* str_ucwords() will not be returning null */
initid->maybe_null=0;
return 0;
}
char *str_ucwords(UDF_INIT *initid, UDF_ARGS *args,
char *result, unsigned long *res_length,
char *null_value, char *error)
{
int i;
int new_word = 0;
// copy the argument …Run Code Online (Sandbox Code Playgroud) 这里混淆语法,但有什么区别:
foo[x][y]
Run Code Online (Sandbox Code Playgroud)
和
foo[x, y]
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写OpenGL应用程序,因此我安装了Windows 7 SDK.但是,看起来它是OpenGL 1.1 ......
#define GL_VERSION_1_1 1
Run Code Online (Sandbox Code Playgroud)
如何找到我安装的OpenGL版本(*.dll)以及在哪里可以找到较新的*.lib/*.h文件?
我正在研究Android游戏,并且出现了一些问题,我想在位图对象上填充颜色,但我不能尝试bitmap.setPixel但我的图像是PNG格式(如圆形或不锐化,用透明色包围)和android不能getHeight()或getWidth(),即
ImageView i = new ImageView(mContext); Bitmap bMap = BitmapFactory.decodeResource(this.mContext.getResources(), mImageIds[position]);Run Code Online (Sandbox Code Playgroud)// for(int i1 = 0; i1 < bMap.getHeight();i1++) // for(int j = 0; j < bMap.getWidth(); j ++) // bMap.setPixel(i1, j, Color.RED); //can not set
i.setImageBitmap(bMap); i.setLayoutParams(new Gallery.LayoutParams(150, 100)); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setBackgroundResource(mGalleryItemBackground); i.setBackgroundColor(Color.TRANSPARENT);
我一直在努力彻底了解参考和价值类型.就在我以为自己拥有它的时候,我遇到了这个场景......
我创建了一个包含单个对象的类.
class Container
{
public object A {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
当我创建此Container类的实例(a)时,我正在创建引用类型的实例.我为类中的对象分配了一个整数.据我所知,这将被装箱作为对象,另一种参考类型.
int start = 1;
Container a = new Container{ A=start };
Run Code Online (Sandbox Code Playgroud)
我创建了Container类的另一个实例(b),但是为它分配了第一个容器的值,b的值现在是对a的引用.
Container b = a;
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,当我打印出aA和bA的值时,它们是相同的.
Console.WriteLine("a.A={0},b.A={1}",a.A,b.A);
//a.A=1,b.A=1
Run Code Online (Sandbox Code Playgroud)
并且,正如预期的那样,当我更改aA的值时,bA的值也会因为它们引用相同的对象而发生变化.
a.A = 2;
Console.WriteLine("a.A={0},b.A={1}",a.A,b.A);
// a.A=2,b.A=2
Run Code Online (Sandbox Code Playgroud)
现在我决定尝试使用单个本地对象.再次,我将整数打包到第一个对象中,并将第一个对象的值分配给第二个对象.我认为此时的对象应该是引用类型,因此c和d应该引用相同的对象.不改变任何东西,它们返回相同的值.
int start = 1;
object c = start;
object d = c;
Console.WriteLine("c={0},d={1}",c,d);
// c=1,d=1
Run Code Online (Sandbox Code Playgroud)
像以前一样,在更改初始对象的值时,我希望两个对象的值相同.
c = 2;
Console.WriteLine("c={0},d={1}",c,d);
// c=2,d=1
Run Code Online (Sandbox Code Playgroud)
当我打印这两个对象的结果时,d的值不像以前那样改变.
有人可以解释为什么这个场景中的作业与之前的作业有所不同吗?
谢谢
下面的代码片段工作正常,但我在使用该wait.until()行时有点麻烦:
wait.until(new ElementPresent(By.xpath("//a[@title='Go to Google Home']")));
Run Code Online (Sandbox Code Playgroud)
它有效,但我想发送我的PageFactory WebElement homePageLink代替:
wait.until(new ElementPresent(homePageLink));
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
这些新奇的Selenium 2功能让我的头脑有点旋转,我找不到太多的文档.
谢谢.
public class GoogleResultsPage extends TestBase {
@FindBy(xpath = "//a[@title='Go to Google Home']")
@CacheLookup
private WebElement homePageLink;
public GoogleResultsPage() {
wait.until(new ElementPresent(By.xpath("//a[@title='Go to Google Home']")));
assertThat(driver.getTitle(), containsString("Google Search"));
}
}
public class ElementPresent implements ExpectedCondition<WebElement> {
private final By locator;
public ElementPresent(By locator) {
this.locator = locator;
}
public WebElement apply(WebDriver driver) {
return driver.findElement(locator);
}
}
Run Code Online (Sandbox Code Playgroud) 一方面,我知道属性的可取用法是有一个支持字段,如下例所示:
private int m_Capacity;
public int Capacity
{
get { return m_Capacity > 0 ? m_Capacity : -666; }
set { m_Capacity = value; }
}
Run Code Online (Sandbox Code Playgroud)
另一方面,使用上面的示例而不是丢弃字段并仅将属性用于所有目的,我可以获得什么好处,如下例所示:
public int Capacity
{
get { return Capacity > 0 ? Capacity : -666; }
set { Capacity = value; }
}
Run Code Online (Sandbox Code Playgroud)
使用支持字段用于常规(非自动实现)属性有什么用处?