我在很多应用程序中都看到了这一点,但在文档或在线示例中找不到任何内容.
当您调用PhotoChooserTask时,某些应用程序可让您调整大小/裁剪以仅使用该图像的一部分(通过显示白色矩形).如何使用它并为目标图像设置我自己的尺寸?
我正在尝试开发一个类似于VS 2010中的"注释"工具栏按钮的扩展,但我想将所有文本标记为已注释,并在其上方添加注释.
这是一个例子.我知道这很简单,但它更容易.我的想法是有一些额外的工具栏按钮来标记不再使用的代码,标记有错误的代码......以及类似的东西......这可以在任务窗口中选取,因为它以TODO开头:
// TODO MARTIN CODE NO LONGER USED
/*if (myItem)
{
txtTest.Enabled = false;
txtTest1.Value = 0;
btnOk.Enabled = false;
}*/
Run Code Online (Sandbox Code Playgroud)
我认为我需要使用:
DTE.ActiveDocument
Run Code Online (Sandbox Code Playgroud)
和:
(((TextDocument)myDoc).Selection.Text).
Run Code Online (Sandbox Code Playgroud)
然后再次写出代码,我需要做什么?
我完全不知道为什么这不起作用?
我正在迭代一个日期范围,一步一步地加1小时.直到本周,这个工作正常.基本上直到日期为2011年3月27日01:00:00 GMT + 0100.然后它只是卡住而不添加任何东西.如果我加+ 3h然后它再次起作用,但不是+1.
我在Firefox上使用Firebug并在控制台中尝试了它.
Sun Mar 27 2011 01:00:00 GMT+0100
>>> this.setHours(0);
1301180400000
>>> this.setHours(1);
1301184000000
>>> this.setHours(2);
1301184000000
>>> this.setHours(3);
1301187600000
Run Code Online (Sandbox Code Playgroud)
这是代码:
Date.prototype.addHours = function (h) {
this.setHours(this.getHours() + h);
return this;
}
Run Code Online (Sandbox Code Playgroud)
我在Safari和Chrome中遇到了同样的错误.
class A{}
class Z{}
class S{}
public class Demo6 {
void fun(A a){
System.out.println("A reference");
}
void fun(Z z){
System.out.println("Z reference");
}
void fun(Object o){
System.out.println("other reference");
}
public static void main(String args[]){
new Demo6().fun(new A());
new Demo6().fun(new S());
}
}
Run Code Online (Sandbox Code Playgroud)
以上代码的输出即将到来:
一个参考
其他参考
我的困惑是当我们传递'S'类对象时,"其他引用"是如何打印的.详细说明'S'类对象如何与"Object"类兼容的实际机制.
例:
string str = "I am going to reverse myself.";
string strrev = "I ma gniog ot esrever .flesym"; //An easy way to achieve this
Run Code Online (Sandbox Code Playgroud)
因为我认为我必须遍历每个单词然后每个单词的每个字母.
我做的很好.但我需要轻松/简短的方式.
C#代码:
string str = "I am going to reverse myself.";
string strrev = "";
foreach (var word in str.Split(' '))
{
string temp = "";
foreach (var ch in word.ToCharArray())
{
temp = ch + temp;
}
strrev = strrev + temp + "";
}
Console.WriteLine(strrev); //I ma gniog ot esrever .flesym
Run Code Online (Sandbox Code Playgroud) 我需要做的是循环大量不同的文件并(尝试)从文件中获取元数据.
我可以创建一个大的if ... elif ...并测试每个扩展,但我认为将扩展存储在变量中会更容易,检查是否存在具有该名称的函数,然后执行它.
这是我目前的解决方案,取自另一个stackoverflow线程:
try:
getattr(modulename, funcname)(arg)
except AttributeError:
print 'function not found "%s" (%s)' % (funcname, arg)
Run Code Online (Sandbox Code Playgroud)
这有一个问题:如果底层函数引发了AttributeError,则会将其注册为"找不到函数"错误.我可以添加try ...除了块到所有函数,但这也不是特别漂亮......
我正在寻找的更像是:
if function_exists(fun):
execute_function(fun, arg)
Run Code Online (Sandbox Code Playgroud)
有这么简单的方法吗?
谢谢 :-)
我使用标准AVFoundation类来捕获视频和显示预览(http://developer.apple.com/library/ios/#qa/qa1702/_index.html)
这是我的代码:
- (void)setupCaptureSession {
NSError *error = nil;
[self setCaptureSession: [[AVCaptureSession alloc] init]];
self.captureSession.sessionPreset = AVCaptureSessionPresetMedium;
device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([device isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus] && [device lockForConfiguration:&error]) {
[device setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
[device unlockForConfiguration];
}
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
error:&error];
if (!input) {
// TODO: Obs?uga b??du, gdy nie uda si? utworzy? wej?cia
}
[[self captureSession] addInput:input];
AVCaptureVideoDataOutput *output = [[[AVCaptureVideoDataOutput alloc] init] autorelease];
[[self captureSession] addOutput:output];
dispatch_queue_t queue = dispatch_queue_create("myQueue", NULL);
[output setSampleBufferDelegate:self queue:queue];
dispatch_release(queue);
output.videoSettings =
[NSDictionary …
Run Code Online (Sandbox Code Playgroud) 我被困在解决以下面试实践问题:
我必须写一个函数:
int triangle(int[] A);
Run Code Online (Sandbox Code Playgroud)
给定零索引数组A由N
整数组成,1
如果存在三重(P,Q,R)则返回0 < P < Q < R < N
.
A[P] + A[Q] > A[R],
A[Q] + A[R] > A[P],
A[R] + A[P] > A[Q].
Run Code Online (Sandbox Code Playgroud)
0
如果不存在这样的三元组,则该函数应该返回.假设0 < N < 100,000
.假设数组的每个元素都是范围内的整数[-1,000,000..1,000,000]
.
例如,给定的数组就是A
这样
A[0]=10, A[1]=2, A[2]=5, A[3]=1, A[4]=8, A[5]=20
Run Code Online (Sandbox Code Playgroud)
函数应该返回1
,因为三元组(0, 2, 4)
满足所有必需条件.
对于A
这样的阵列
A[0]=10, A[1]=50, A[2]=5, A[3]=1
Run Code Online (Sandbox Code Playgroud)
该函数应该返回0
.
如果我做一个三重循环,这将非常非常慢(复杂性:) O(n^3)
.我想也许可以用来存储数组的额外副本并对其进行排序,并使用二进制搜索特定的数字.但我不知道如何解决这个问题.
有任何想法吗?
我有很多代码可以用来做这样的事情
bool GetIsUnique(IEnumerable<T> values)
{
return values.Count() == values.Distinct().Count;
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的更快更好的方法来做到这一点?