请考虑以下窗口设置:

目前有两个标签组打开.左选项卡组处于活动状态(ListingDetailsDTO.cs窗口处于活动状态).
我现在想切换到正确的选项卡组,因此visual studio将如下所示:

使用鼠标很容易实现(即只需左键单击右侧窗口).但是,我无法弄清楚如何单独使用键盘.为窗口 - >移动到下一个选项卡组分配快捷方式最近,但它也将当前窗口移动到下一个选项卡组,这不是我想要的.我认为Window.NextPane或Window.NextSubpane可能有效,但他们没有.
有办法做我想要的吗?我很乐意安装(最好)免费扩展,以便在必要时使其成为可能.
请考虑以下类型:
data SomeType m a = SomeType (m Integer) [a]
Run Code Online (Sandbox Code Playgroud)
我们可以使用以下代码轻松地将该类型作为Functor的实例:
instance Functor (SomeType m) where
fmap f (SomeType m lst) = SomeType m (map f lst)
Run Code Online (Sandbox Code Playgroud)
但是,如果相反SomeType类型的参数被交换:
data SomeType2 a m = SomeType2 (m Integer) [a]
Run Code Online (Sandbox Code Playgroud)
然后上面的实例定义不起作用.
有没有办法制作SomeType2Functor的实例?如果没有,那么haskell/ghc是否有任何新增功能可以实现?
举个例子Proc:
proc = Proc.new {|x,y,&block| block.call(x,y,self.instance_method)}
Run Code Online (Sandbox Code Playgroud)
它需要两个参数,x和y,以及一个块.
我想使用不同的self值来执行该块.像这样的东西几乎可以工作:
some_object.instance_exec("x arg", "y arg", &proc)
Run Code Online (Sandbox Code Playgroud)
但是,这不允许您传入一个块.这也行不通
some_object.instance_exec("x arg", "y arg", another_proc, &proc)
Run Code Online (Sandbox Code Playgroud)
也没有
some_object.instance_exec("x arg", "y arg", &another_proc, &proc)
Run Code Online (Sandbox Code Playgroud)
我不知道还有什么可以在这里工作.这是可能的,如果是这样,你怎么做?
编辑:基本上如果您可以通过更改change_scope_of_proc方法来传递此rspec文件,您已解决了我的问题.
require 'rspec'
class SomeClass
def instance_method(x)
"Hello #{x}"
end
end
class AnotherClass
def instance_method(x)
"Goodbye #{x}"
end
def make_proc
Proc.new do |x, &block|
instance_method(block.call(x))
end
end
end
def change_scope_of_proc(new_self, proc)
# TODO fix me!!!
proc
end
describe "change_scope_of_proc" do
it "should change the instance method that is called" do …Run Code Online (Sandbox Code Playgroud) 我有几个扩展方法缺失的模块:
module SaysHello
def respond_to?(method)
super.respond_to?(method) || !!(method.to_s =~ /^hello/)
end
def method_missing(method, *args, &block)
if (method.to_s =~ /^hello/)
puts "Hello, #{method}"
else
super.method_missing(method, *args, &block)
end
end
end
module SaysGoodbye
def respond_to?(method)
super.respond_to?(method) || !!(method.to_s =~ /^goodbye/)
end
def method_missing(method, *args, &block)
if (method.to_s =~ /^goodbye/)
puts "Goodbye, #{method}"
else
super.method_missing(method, *args, &block)
end
end
end
class ObjectA
include SaysHello
end
class ObjectB
include SaysGoodbye
end
Run Code Online (Sandbox Code Playgroud)
这一切都运作良好,例如ObjectA.new.hello_there输出"Hello, hello_there".同样,ObjectB.new.goodbye_xxx产出"Goodbye, xxx".respond_to?也有效,例如 …
我希望能够使用索引的当前状态为我的项目运行测试,忽略未提交的工作更改(我后来计划将其添加到预提交挂钩).但是,我无法确定如何以永不导致合并冲突的方式删除然后恢复非索引更改.我需要这个,因为它是由脚本运行的,所以它不应该在完成后改变存储库状态.
git stash --include-untracked --keep-index和git stash pop接近,但在许多情况下,即使没有在两个命令之间所做的更改导致合并冲突.
例如:
mkdir project; cd project; git init .;
# setup the initial project with file.rb and test.rb
cat > file.rb <<EOF
def func()
return 42
end
EOF
cat > test.rb <<EOF
#!/usr/bin/env ruby
load './file.rb'
if (func() == 42)
puts "Tests passed"
exit 0
else
puts "Tests failed"
exit 1
end
EOF
chmod +x test.rb
git add .
git commit -m "Initial commit"
# now change file.rb and add the …Run Code Online (Sandbox Code Playgroud) 我在haskell中编写了一个testscript用以下代码命名的脚本:
#!/usr/bin/env runhaskell
main = putStrLn "hello"
Run Code Online (Sandbox Code Playgroud)
使脚本可执行后,我可以使用它来运行它./testscript.但是,当我尝试使用ghci(即with :l testscript)加载脚本时,我收到错误
target `testscript' is not a module name or a source file
Run Code Online (Sandbox Code Playgroud)
如果我重新命名testscript到testscript.hs,并尝试与ghci的加载一遍,我得到的错误
testscript.hs:1:0: error: invalid preprocessing directive #!
phase `C pre-processor' failed (exitcode = 1)
Run Code Online (Sandbox Code Playgroud)
如果我删除shebang线它工作正常.然而,每次我想在ghci中尝试.hs脚本时,必须为脚本添加扩展,删除顶行,然后删除.hs扩展并添加shebang行是很繁琐的(这在每次我想要进行更改时都很常见它).有更简单的方法吗?
我在Mac OS X 10.6.8下使用ghc版本7.0.3
我指的是c读取线库的haskell readline库包装器.
cabal install readline 输出如下:
$ cabal install readline
Resolving dependencies...
Configuring readline-1.0.1.0...
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO …Run Code Online (Sandbox Code Playgroud) 我正在编写一个视图控制器,用于向我的应用添加新项目.它非常适合MonoTouch.Dialog,因为它可以通过基于表格的界面轻松完成,并且每个项目的相关属性都有一个字段.
这是我目前用于显示添加项目视图的代码(简化,但核心思想仍然存在):
Item item = new Item();
TapHandler handler = new TapHandler();
BindingContext bc = new BindingContext(handler, item, "Add Item");
DialogViewController dv = new DialogViewController(bc.Root, true);
this.NavigationController.PushViewController(dv, true);
Run Code Online (Sandbox Code Playgroud)
虽然这有效,但我更愿意,如果我可以将视图的细节封装到自己的视图控制器中,那么代码可能如下所示:
UIViewController controller = new AddItemViewController();
this.NavigationController.PushViewController(controller, true);
Run Code Online (Sandbox Code Playgroud)
但是,我无法弄清楚如何实现这一点.我认为合乎逻辑的做法是创建一个子类DialogViewController.但是,所有构造函数都DialogViewController需要a RootElement.要做到这一点,你需要首先创建BindingContext.因为在调用基础构造函数之前无法运行任何代码,所以它最终不会起作用.
我的第二个方法是实现子类UIViewController,创建DialogViewController和加入对话视图控制器使用我的子类的子this.AddChildViewController(dv)和this.View.AddSubView(dv.View).虽然这最初有效,但如果在UINavigationController中有新的视图控制器,并且单击了日期元素,则日期视图将显示为模式弹出窗口而不是导航控制器层次结构.(这是有道理的,因为DialogViewController它不是NavigationController本设计中层次结构的一部分).
从那里我被卡住了.我也找不到在示例中使用MonoTouch.Dialog的任何示例.这可能吗?或者如果不是,那么为什么写这样的代码是个坏主意有充分的理由吗?
我希望它与普通测试框架的工作方式类似 - 如果您从Product-> Run tests菜单项进行测试,输出应该出现在左侧边栏窗口中.
我找到了使用xcode 3和boost测试的指南,但是无法弄清楚如何翻译xcode 4的指令(如果可能的话).
最后,我正在构建一个iPhone应用程序.我可以使用#include <boost/test/included/unit_test.hpp>它来提升运行速度,但速度非常慢.使用标准会#include <boost/test/unit_test.hpp>导致链接错误,因为库是针对错误的体系结构而构建的.
我是用实验unsafeCoerce用Int8和Word8,我发现了一些奇怪的行为(我反正).
Word8是一个8位无符号数,范围为0-255.Int8是一个带符号的8位数字,范围从-128..127.
因为它们都是8位数,所以我认为相互强制转换是安全的,只需返回8位值,就好像它是有符号/无符号的一样.
例如,unsafeCoerce (-1 :: Int8) :: Word8我希望得到一个Word8255 的值(因为有符号int中的位表示-1与unsigned int中的255相同).
但是,当我执行强制执行时,Word8行为很奇怪:
> GHCi, version 7.4.1: http://www.haskell.org/ghc/ :? for help
> import Data.Int
> import Data.Word
> import Unsafe.Coerce
> class ShowType a where typeName :: a -> String
> instance ShowType Int8 where typeName _ = "Int8"
> instance ShowType Word8 where typeName _ = "Word8"
> let x = unsafeCoerce (-1 :: Int8) …Run Code Online (Sandbox Code Playgroud) 目前,我有一个WorkLog类型,有开始和结束日期.我还要添加一个持续时间镜头,它将从开始和结束日期派生.它应该是只读的,或者如果它的值被改变就改变结束日期(我想知道如何实现这两个版本,即使我只使用一个).
这是我的代码.基本上,如果你可以实现workLogDurationRO和workLogDurationRW函数来获得主要传递的所有测试,那将回答我的问题.
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Control.Lens
-- Keep times simple for this example
newtype TimeStamp = TimeStamp Int deriving (Show, Eq)
newtype TimeDifference = TimeDifference Int deriving (Show, Eq)
(-.-) :: TimeStamp -> TimeStamp -> TimeDifference
(TimeStamp a) -.- (TimeStamp b) = TimeDifference (a - b)
data WorkLog = WorkLog {
_workLogDescription :: String
, _workLogStartTime :: TimeStamp
, _workLogEndTime :: TimeStamp
}
makeLenses ''WorkLog
-- | Just return …Run Code Online (Sandbox Code Playgroud) 我想创建一个 ruby gem 来调用我编写的 ac 函数。例如:
int func(int x)
{
return x * 2;
}
Run Code Online (Sandbox Code Playgroud)
这将位于我的 rubygem 的 ac 文件中。然后我希望能够通过用 ffi 接口包装它,在 ruby 中调用它:
module TestModule
extend FFI::Library
ffi_lib 'MyLib'
attach_function 'func', [:int], :int
end
Run Code Online (Sandbox Code Playgroud)
但是我不知道如何设置它,以便当安装 gem 时,c 文件将编译成一个库(名称为“MyLib”),并且 ffi 将检测该库并在上面的代码中使用它。
有谁知道如何做到这一点,或者有更好的方法吗?请注意,我宁愿不使用扩展 ruby 的标准方法(如《实用程序员指南扩展 Ruby》部分中所述),因为这只适用于标准 ruby 解释器(我相信)。
我一直在使用珠宝商来建造我的宝石,如果这对这个问题很重要的话。
我有以下php文件:
<?php
function show_error($stage) {
echo "<p>MySql error: " . mysql_error() . '</p>';
echo "<p>ErrorCode: " . mysql_errno() . '</p>';
die($stage);
}
$link = mysql_connect('localhost', 'blog', 'sql-password');
if (!$link) {
show_error('connect');
}
mysql_select_db('blog') or show_error();
$result = mysql_query('select col1 from test_table');
if (!$result) {
show_error('query');
}
$col = mysql_result($result, 0);
echo "<p>Result is: [" . $col . "]</p>";
mysql_close($link);
?>
Run Code Online (Sandbox Code Playgroud)
当我运行这个时,我得到错误:
MySql error: No such file or directory
ErrorCode: 2002
connect
Run Code Online (Sandbox Code Playgroud)
但是,如果我改变了这条线
$link = mysql_connect('localhost', 'blog', 'my-password');
Run Code Online (Sandbox Code Playgroud)
至
$link = …Run Code Online (Sandbox Code Playgroud)