救命.我开始学习Scala.我的程序在我的Windows PC上正常运行,但无论何时我尝试在我的Linux机器上运行程序(ibmp2),输出只是打印两次的主机名.见下面的例子.怎么了?
[sean@ibmp2 ~]$ cat hello.scala
val oneTwo = List(1, 2)
val threeFour = List(3, 4)
val oneTwoThreeFour = oneTwo ::: threeFour
println(""+ oneTwo +" and "+ threeFour +" were not mutated.")
println("Thus, "+ oneTwoThreeFour +" is a new list.")
[sean@ibmp2 ~]$ scala hello.scala
ibmp2: ibmp2
[sean@ibmp2 ~]$ which scala
/usr/local/scala-2.8.1.final/bin/scala
[sean@ibmp2 ~]$ scala
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) Client VM, Java 1.6.0_17).
Type in expressions to have them evaluated.
Type :help for more information.
scala> println("hello")
hello … 我创建一个SQLiteDatabase实例并以这种方式调用getReadableDatabase()或getWritableDatabase()操作数据,但我从不关闭数据库db.close().不关闭它不好吗?我尝试添加db.close()到我的onStop()或onDestroy()方法,但它只是强制关闭.
背景资料:
我正在使用GIT来获取包含Ruby文件的项目的存储库.该项目位于我Mac上主目录下的SITES文件夹中.
我有Ruby:1.8.7
我刚刚将Rails升级到:3.0.3
我想要完成的就是能够在我已经下载的GIT项目的浏览器中渲染localhost.com:3000,这样我就可以在本地工作了.
我运行命令'rails server'并返回以下消息::
Usage:
rails new APP_PATH [options]
Options:
[--skip-gemfile] # Don't create a Gemfile
-m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL)
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db)
# Default: sqlite3
-O, [--skip-active-record] # Skip Active Record files
-J, [--skip-prototype] # Skip Prototype files
-T, [--skip-test-unit] # Skip Test::Unit files
[--dev] # Setup the application with Gemfile pointing to your Rails checkout
-r, [--ruby=PATH] # …Run Code Online (Sandbox Code Playgroud) 我正在使用Ruby 1.9,我想知道是否有一个简单的正则表达方式来做到这一点.
我有很多字符串看起来像这样的一些变化:
str = "Allocation: Random, Control: Active Control, Endpoint Classification: Safety Study, Intervention Model: Parallel Assignment, Masking: Double Blind (Subject, Caregiver, Investigator, Outcomes Assessor), Primary Purpose: Treatment"
Run Code Online (Sandbox Code Playgroud)
我的想法是,我想将这个字符串分解为其功能组件
字符串的"语法"是存在"密钥",其由一个或多个"单词或其他字符"(例如干预模型)组成,后跟冒号(:).每个键都有一个相应的"值"(例如,并行赋值),紧跟在冒号(:)之后......"值"由单词,逗号(无论如何)组成,但"值"的结尾用逗号表示.
键/值对的数量是可变的.我还假设冒号(:)不允许成为"值"的一部分,并且逗号(,)不允许成为"键"的一部分.
人们会认为有一种"regexy"方法可以将其分解为组件,但我尝试制作一个合适的匹配正则表达式只会选择第一个键/值对,而我不确定如何捕获其他键.关于如何捕捉其他比赛的任何想法?
regex = /(([^,]+?): ([^:]+?,))+?/
=> /(([^,]+?): ([^:]+?,))+?/
irb(main):139:0> str = "Allocation: Random, Control: Active Control, Endpoint Classification: Safety Study, Intervention Model: Parallel Assignment, Masking: Double Blind (Subject, Caregiver, Investigator, Outcomes Assessor), Primary Purpose: Treatment"
=> "Allocation: …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个Ruby类,其中该initialize方法采用选项的哈希值.然后,我将这些选项作为attr_accessor课程的选项.现在,我可以做点什么
class User
attr_accessor :name, :email, :phone
def initialize(options)
self.name = options[:name]
self.email = options[:email]
self.phone = options[:phone]
end
end
User.new(:name => 'Some Name', :email => 'some-name@some-company.com', :phone => 435543093)
Run Code Online (Sandbox Code Playgroud)
但它对我来说并不觉得很干.相反,我想做
class User
attr_accessor :name, :email, :phone
def initialize(options)
options.each do |option_name, option_value|
# Does not work!!
self.send(option_name, '=', option_value)
# Does not work either!!
self.send(option_name, '=' + option_value)
end
end
end
User.new(:name => 'Some Name', :email => 'some-name@some-company.com', :phone => 435543093)
Run Code Online (Sandbox Code Playgroud)
但我不能让语法工作!
我究竟做错了什么?
我对Objective-C有一些基本的了解,但更喜欢Ruby,所以我想和MacRuby一起玩.是否可以使用MacRuby为Mac App Store开发应用程序,还是必须使用Objective-C?(请注意,我现在并不关心iOS/iPhone和iPad商店,只关注Mac OS X应用程序商店.)
如何通过单击链接显示表单字段,我想在链接的同一位置显示字段(使用jquery/javascript),以便链接消失并显示表单框?谢谢.
在我正在使用的ASP.Net网站中
String.Format("{0:C}", param)
Run Code Online (Sandbox Code Playgroud)
格式化货币值.在我的本地机器上这很好用,但是当将网站部署到服务器时,输出从€切换到$.
显然服务器有不同的文化设置,是否有一种简单的方法来改变这个应用程序?(无法直接访问服务器设置)
我可以更改web.config条目吗?
CDATA-blocks非常适合将大块HTML或CSS编码为字符串.但是,我无法弄清楚如何在一个变量值中使用变量值.
例如,请考虑以下JavaScript代码:
var FullName = "Friedrich Hayek";
var ProfileCode = (<><![CDATA[
<div id="BigHonkingChunkO_HTML">
...Lot's o' code...
Name: $FullName$
Birth: $Birthdate$
...Lot's o' code...
... $FullName$ ...
...Lot's o' code...
</div>
]]></>).toString ();
Run Code Online (Sandbox Code Playgroud)
如何$FullName$渲染为"Friedrich Hayek"而不是"$ FullName $"?
请注意,有多个变量,每个变量可以在CDATA块中使用几次.
替代代码示例:
var UserColorPref = "red";
var UI_CSS = (<><![CDATA[
body {
color: $UserColorPref$;
}
]]></>).toString ();
Run Code Online (Sandbox Code Playgroud)
希望将颜色属性设置为red.
我很困惑为什么这段代码不显示任何图像:
在app委托中:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSRect rect = window.frame;
rect.origin.x = 0;
rect.origin.y = 0;
BlueImageView *blueImageView = [[BlueImageView alloc]initWithFrame:rect];
window.contentView = blueImageView; // also tried [window.contentView addSubview: blueImageView];
}
Run Code Online (Sandbox Code Playgroud)
BlueImageView.h:
@interface BlueImageView : NSImageView {
}
@end
Run Code Online (Sandbox Code Playgroud)
BlueImageView.m:
@implementation BlueImageView
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setImage: [NSImage imageNamed:@"imagefile.png"]];
NSAssert(self.image, @"");
NSLog (@"Initialized");
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect {
}
@end
Run Code Online (Sandbox Code Playgroud)
文件imagefile.png存在.NSAssert不会导致异常.NSLog正在解雇.但窗口中没有图像显示.